Skip to content

Commit

Permalink
Additional changes for #9 including configuration, tr_timestamp and t…
Browse files Browse the repository at this point in the history
…r_side transformation updates
  • Loading branch information
Gerard Moroney committed Jan 2, 2018
1 parent 0488131 commit 2a793ad
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
22 changes: 21 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,27 @@
"docurl": "https://www.okex.com/ws_getStarted.html",
"wssurl": "wss://real.okex.com:10440/websocket/okexapi",
"pairs": [
{ "symbol": "LTC_BTC" }
{ "symbol": "LTC_BTC" },
{ "symbol": "ETH_BTC" },
{ "symbol": "ETC_BTC" },
{ "symbol": "BCH_BTC" },
{ "symbol": "BTC_USDT" },
{ "symbol": "ETH_USDT" },
{ "symbol": "LTC_USDT" },
{ "symbol": "ETC_USDT" },
{ "symbol": "BCH_USDT" },
{ "symbol": "ETC_ETH" },
{ "symbol": "BT1_BTC" },
{ "symbol": "BT2_BTC" },
{ "symbol": "BTG_BTC" },
{ "symbol": "QTUM_BTC" },
{ "symbol": "HSR_BTC" },
{ "symbol": "NEO_BTC" },
{ "symbol": "GAS_BTC" },
{ "symbol": "QTUM_USDT" },
{ "symbol": "HSR_USDT" },
{ "symbol": "NEO_USDT" },
{ "symbol": "GAS_USDT" }
],
"active": "N"
},
Expand Down
27 changes: 18 additions & 9 deletions functions/exchange_functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var moment=require('moment');

// Function to subscribe to stream, transform data and publish to Redis from BITFINEX
function processBITFINEX(client, exchange_name,exchange_wss,exchange_symbol) {

Expand Down Expand Up @@ -255,20 +257,27 @@ function processOKEX(client, exchange_name,exchange_wss,exchange_symbol) {
records = resp[0].data;
for ( i = 0; i < records.length; i++ )
{
console.log(i,records[i]);
tr_timestamp=records[i][3];
tr_id=records[i][0];
tr_price=records[i][1];
tr_amount=records[i][2];
// Have used this routine to convert time to GMT; it assumes source also has daylight saving time.
// This is not the best way to do it so will need to be revisited sometime.
var tr_ts=records[i][3].split(":");
var tr_th=Number(tr_ts[0]) + 16;
tr_th=( tr_th > 23 ? tr_th = tr_th - 24 : tr_th );
var tr_d=moment().format("YYYY/MM/DD");
var tr_timestamp = new Date(tr_d + " " + tr_th + ":" + tr_ts[1] + ":" + tr_ts[2]);

var tr_id=records[i][0];
var tr_price=records[i][1];
var tr_amount=records[i][2];

// https://tinyurl.com/ydet9asx
// The ask price is what sellers are willing to take for it.
// The ask price is what sellers are willing to take for it.
// - if you are selling a stock, you are going to get the bid price,
// - if you are buying a stock you are going to get the ask price.
// not sure if what below is correct. Need to recheck
tr_side=( records[i][4] == "ask" ? "buy" : "sell" );
msg = { "tr_id": tr_id, "tr_timestamp": tr_timestamp, "tr_price": tr_price, "tr_amount": tr_amount, "tr_side": tr_side };
console.log(msg);
client.publish(bc_queue,JSON.stringify(msg));
msgout = { "tr_id": tr_id, "tr_timestamp": tr_timestamp, "tr_price": tr_price, "tr_amount": tr_amount, "tr_side": tr_side };
client.publish(bc_queue,JSON.stringify(msgout));

}
} else {
console.log("Unexpected record. Please investigate");
Expand Down
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",
"moment": "^2.20.1",
"node.bittrex.api": "^1.0.0",
"pako": "^1.0.6",
"redis": "^2.8.0",
Expand Down

0 comments on commit 2a793ad

Please sign in to comment.