Commit d9440099 by ken

防御措施

parent fe0f53d6
......@@ -129,10 +129,16 @@ function subscribe() {
if (depth.timestamp > lastEventTime) {
lastEventTimeMap[symbol] = depth.timestamp;
console.log(symbol + '@' + depth.timestamp * 1000 + ' from websocket');
const asks = depth.asks.reverse();
const bids = depth.bids;
const publishContent = JSON.stringify({symbol, time: depth.timestamp * 1000});
const depthJson = JSON.stringify({asks: depth.asks.reverse(), bids: depth.bids, symbol});
const depthJson = JSON.stringify({asks, bids, symbol});
if (asks[0][0] >= bids[0][0]) {
redisClient.set(key, depthJson, 'EX', 2);
redisClient.publish(publishKey, publishContent);
} else {
console.error("买一大于卖一,数据有误")
}
}
}
});
......@@ -177,9 +183,15 @@ function depthByRest(symbol,callback) {
lastEventTimeMap[symbol] = data.timestamp;
console.log(symbol + '@' + data.timestamp * 1000 + ' from rest');
const publishContent = JSON.stringify({symbol, time: data.timestamp * 1000});
const depthJson = JSON.stringify({asks: data.asks.reverse(), bids: data.bids, symbol});
const asks = data.asks.reverse();
const bids = data.bids;
const depthJson = JSON.stringify({asks, bids, symbol});
if (asks[0][0] >= bids[0][0]) {
redisClient.set(key, depthJson, 'EX', 2);
redisClient.publish(publishKey, publishContent);
} else {
console.error("买一大于卖一,数据有误")
}
}
}
if (callback) {
......@@ -220,7 +232,7 @@ function getBalanceByRest() {
function run() {
subscribe();
const depthInterval = Math.max(60 * 1000 / (900 * ips.length / observerSymbol.length), 300);
const depthInterval = Math.max(60 * 1000 / (900 * ips.length / observerSymbol.length), 100);
console.log(depthInterval);
setInterval(() => {
for (const symbol of observerSymbol) {
......
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