diff --git a/config/default.json b/config/default.json index af2a84d..9102fbf 100644 --- a/config/default.json +++ b/config/default.json @@ -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" }, diff --git a/functions/exchange_functions.js b/functions/exchange_functions.js index 903bb7d..366ea21 100644 --- a/functions/exchange_functions.js +++ b/functions/exchange_functions.js @@ -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) { @@ -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"); diff --git a/package.json b/package.json index 957efb2..e6fae8b 100644 --- a/package.json +++ b/package.json @@ -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",