Commit d9440099 by ken

防御措施

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