Skip to content

Commit

Permalink
Further changes for #8. Have not added redis part as don't know how t…
Browse files Browse the repository at this point in the history
…o extract and transform data. Have logged a question on another github page. See what happens ....
  • Loading branch information
Gerard Moroney committed Jan 1, 2018
1 parent 210fb65 commit 2e6f196
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
5 changes: 3 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@
{
"name": "bittrex",
"docurl": "https://www.npmjs.com/package/node.bittrex.api",
"wssurl": "???",
"wssurl": "Not Available",
"pairs": [
{ "symbol": "NONE"}
{ "symbol": "BTC-ETH"},
{ "symbol": "BTC-XRP"}
],
"active": "N"
},
Expand Down
37 changes: 35 additions & 2 deletions functions/exchange_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function processHUOBIAPI(client,exchange_name,exchange_wss,exchange_symbol)

// Parse channel information and send to Redis
// IMPORTANT: Do not know why wss.on works and not wss.onmessage. Created stackoverflow question for this at https://tinyurl.com/y7tj5a9o.
// Seems to be to do with fact that it is a wrapper but not exactly sure why.
// Seems to be to do with fact that it is a wrapper but not exactly sure why.
wss.on ('message', (data) => {
{
console.log("Receive message", data);
Expand Down Expand Up @@ -185,9 +185,42 @@ function processHUOBIAPI(client,exchange_name,exchange_wss,exchange_symbol)
}});
}


// Function to subscribe to stream, transform data and publish to Redis from BITTREX
function processBITTREX(client,exchange_name,exchange_wss,exchange_symbol)
{
// Define constants
var bittrex = require('../node_modules/node.bittrex.api/node.bittrex.api');

bittrex.options({
websockets: {
onConnect: function() {
console.log('Websocket connected');
bittrex.websockets.subscribe(['BTC-ETH','BTC-XRP'], function(data) {
if (data.M === 'updateExchangeState') {
data.A.forEach(function(data_for) {
console.log(data_for);
});
}
});
},
onDisconnect: function() {
console.log('Websocket disconnected');
}
}
});

var websocketClient;
bittrex.websockets.client(function(client) {
websocketClient = client;
});

}

module.exports = {
processBITFINEX,
processHITBTC,
processGEMINI,
processHUOBIAPI
processHUOBIAPI,
processBITTREX
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"chai": "^4.1.2",
"config": "^1.29.0",
"express": "^4.15.2",
"node.bittrex.api": "^1.0.0",
"pako": "^1.0.6",
"redis": "^2.8.0",
"websockets": "^0.2.0",
Expand Down
21 changes: 20 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// General Libraries Needed By Application
var sys = require('util');
//var bittrex = require('../node_modules/node.bittrex.api/node.bittrex.api');
var config = require('../config/default.json');

// Connect to Redis
Expand Down Expand Up @@ -54,7 +55,7 @@ function main () {
}
}

if ( exchange_name == 'HUOBIAPI')
if ( exchange_name == 'xHUOBIAPI')
{
for(var j = 0; j < exchange_symbol_array.length; j++)
{
Expand All @@ -64,6 +65,24 @@ function main () {
}
}

if ( exchange_name == 'BITTREX')
{
for(var j = 0; j < exchange_symbol_array.length; j++)
{
// concatenate all of the symbols together because thats the way this API works for some reason
if ( j == 0 ) {
exchange_symbol = "\'" + exchange_symbol_array[j].symbol + "\'" ;
} else {
exchange_symbol = exchange_symbol + "," + "\'" + exchange_symbol_array[j].symbol + "\'";
}
if ( j == ( exchange_symbol_array.length - 1) )
{
console.log(exchange_name, exchange_wss, exchange_symbol);
exFn.processBITTREX(client, exchange_name, exchange_wss, exchange_symbol);
}
}
}

}

// End of main function
Expand Down

0 comments on commit 2e6f196

Please sign in to comment.