Commit 502b07f0 by zihan

添加如果有version就用version来判断数据新旧

parent b4919a1a
...@@ -101,7 +101,7 @@ class biboxApi { ...@@ -101,7 +101,7 @@ class biboxApi {
console.log("fetch ws token error"); console.log("fetch ws token error");
this.subscribeSymbols(symbols, depth, callback); this.subscribeSymbols(symbols, depth, callback);
}else{ }else{
// for(let i=0;i<3;i++){ // for(let i=0;i<2;i++){
const ip = IPs[0]; const ip = IPs[0];
// setTimeout(()=>{ // setTimeout(()=>{
this._openWs(result, symbols, depth,ip, callback); this._openWs(result, symbols, depth,ip, callback);
...@@ -147,7 +147,7 @@ class biboxApi { ...@@ -147,7 +147,7 @@ class biboxApi {
} }
totalOrderbook[symbol].bids = bids; totalOrderbook[symbol].bids = bids;
totalOrderbook[symbol].asks = asks; totalOrderbook[symbol].asks = asks;
const ret = {data: {SELL: asks, BUY: bids}, timestamp: timeStamp, symbol: symbol} const ret = {data: {SELL: asks, BUY: bids}, timestamp: timeStamp, symbol: symbol,seq:response.seq};
callback(null, ret); callback(null, ret);
} }
// else { // else {
......
...@@ -25,13 +25,18 @@ class BaseCollector { ...@@ -25,13 +25,18 @@ class BaseCollector {
* @param timeStamp 从服务器获取的数据的时间戳 * @param timeStamp 从服务器获取的数据的时间戳
* @private * @private
*/ */
_publishDataForStrategy3(asks, bids, symbol, timeStamp) { _publishDataForStrategy3(asks, bids, symbol, timeStamp,version) {
if(!asks.length || !bids.length){ if(!asks.length || !bids.length){
return; return;
} }
const realSymbol = this._convertSymbolName(symbol); const realSymbol = this._convertSymbolName(symbol);
const lastEventTime = this.getSymbolEventTime(realSymbol); const lastEventTime = this.getSymbolEventTime(realSymbol);
if(lastEventTime >= timeStamp){ const lastVersion = this._getLastDataVersion(realSymbol);
if(lastVersion >0 && version){
if(lastVersion >= version){
return;
}
} else if(lastEventTime >= timeStamp){
return; return;
} }
...@@ -44,6 +49,7 @@ class BaseCollector { ...@@ -44,6 +49,7 @@ class BaseCollector {
symbol: realSymbol, symbol: realSymbol,
asks: asks, asks: asks,
bids: bids, bids: bids,
version:version,
} }
if(parseFloat(data.bestBid) > parseFloat(data.bestAsk)){ if(parseFloat(data.bestBid) > parseFloat(data.bestAsk)){
// console.error("同一交易对,卖价低于买价,可能数据有误:"+realSymbol); // console.error("同一交易对,卖价低于买价,可能数据有误:"+realSymbol);
...@@ -149,6 +155,14 @@ class BaseCollector { ...@@ -149,6 +155,14 @@ class BaseCollector {
} }
return 0; return 0;
} }
_getLastDataVersion(symbol){
const keySymbol = this._convertSymbolName(symbol);
let lastData = lastDataMap[keySymbol];
if(lastData){
return lastData['version'] || -1;
}
return -1;
}
isBaseCurrency(currency) { isBaseCurrency(currency) {
return this.baseCurrencies.includes(currency); return this.baseCurrencies.includes(currency);
......
...@@ -92,7 +92,7 @@ class BiboxCollector extends BaseCollector{ ...@@ -92,7 +92,7 @@ class BiboxCollector extends BaseCollector{
const data = result.data; const data = result.data;
const timeStamp = result.timestamp; const timeStamp = result.timestamp;
const symbol = result.symbol; const symbol = result.symbol;
callback(data.SELL.slice(0, depth), data.BUY.slice(0, depth), symbol, timeStamp); callback(data.SELL.slice(0, depth), data.BUY.slice(0, depth), symbol, timeStamp,result.seq);
} }
}) })
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"scripts": { "scripts": {
"strategy2": "node $NODE_DEBUG_OPTION strategy2.js", "strategy2": "node $NODE_DEBUG_OPTION strategy2.js",
"test": "export MACHINE=K; export http_proxy='http://localhost:8118';export https_proxy='http://localhost:8118';export agent='socks:127.0.0.1:1086';node $NODE_DEBUG_OPTION test_kucoin.js", "test": "export MACHINE=K; export http_proxy='http://localhost:8118';export https_proxy='http://localhost:8118';export agent='socks:127.0.0.1:1086';node $NODE_DEBUG_OPTION test_kucoin.js",
"strategy3": "export http_proxy='http://localhost:8118';export https_proxy='http://localhost:8118';export agent='socks:127.0.0.1:1086';node $NODE_DEBUG_OPTION kucoinStrategy3.js" "strategy3": "export MACHINE=K;export http_proxy='http://localhost:8118';export https_proxy='http://localhost:8118';export agent='socks:127.0.0.1:1086';node $NODE_DEBUG_OPTION kucoinStrategy3.js"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment