Commit b0716d4e by zihan

深度数据合并bug修复

parent 17a258b8
......@@ -10,6 +10,32 @@ const constants = require('./constants');
const {IPs, mergeDepth} = require('./util');
let totalOrderbook = {};
let getUpdatedData = function (currentData, response) {
const updateData = [];
let newCount = 0;
let has = false;
for (const a of currentData) {
if (response.data.price === a[0]) {
has = true;
newCount = a[1];
if (response.data.action === 'ADD') {
newCount += response.data.count;
}
else if (response.data.action === 'CANCEL') {
newCount -= response.data.count;
}
break;
}
}
if (!has && response.data.action !== 'CANCEL') {
updateData.push([response.data.price, response.data.count])
} else {
// updateData = [[response.data.price, newCount]];
updateData.push([response.data.price, newCount]);
}
return updateData;
};
class biboxApi {
constructor() {
this.apiKey = '5ba054d2e0abb830dee81e1d';
......@@ -93,58 +119,15 @@ class biboxApi {
const symbol = response.topic.replace('/trade/','').replace('_TRADE','');
let asks = totalOrderbook[symbol].asks || [];
let bids = totalOrderbook[symbol].bids || [];
let updateData = [];
let newCount = 0
if(response.data.type === 'SELL'){
const oldD = totalOrderbook[symbol];
let has = false;
for(const a of oldD.asks){
if(response.data.price === a[0]) {
has = true;
newCount = a[1];
if (response.data.action === 'ADD') {
newCount += response.data.count;
}
else if (response.data.action === 'CANCEL') {
newCount -= response.data.count;
} else {
}
break;
}
}
if(!has){
updateData = [[response.data.price, response.data.count]];
}else{
updateData = [[response.data.price, newCount]];
}
const updateData = getUpdatedData(oldD.asks, response);
asks = mergeDepth(asks, updateData, true);
}else if(response.data.type === 'BUY'){
const oldD = totalOrderbook[symbol];
let has = false;
for(const a of oldD.bids){
if(response.data.price === a[0]) {
has = true;
newCount = a[1];
if (response.data.action === 'ADD') {
newCount += response.data.count;
}
else if (response.data.action === 'CANCEL') {
newCount -= response.data.count;
} else {
}
break;
}
}
if(!has){
updateData = [[response.data.price, response.data.count]];
}else{
updateData = [[response.data.price, newCount]];
}
const updateData = getUpdatedData(oldD.bids,response);
bids = mergeDepth(bids, updateData, false);
}
if(symbol === 'NEO-BTC'){
console.log() //todo 这里输出日志,与网页对比
}
totalOrderbook[symbol].bids = bids
totalOrderbook[symbol].asks = asks
const ret = {data: {SELL: asks, BUY: bids}, timestamp: timeStamp, symbol: symbol}
......
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