Commit fba843ff by ken

depth

parent 32d69cad
......@@ -125,24 +125,8 @@ function subscribe() {
}
} else {
const depth = data;
// const key = depth.channel.replace('_', '').toUpperCase() + '@zb';
const symbol = depth.channel.replace('_depth', '').toUpperCase();
_handleDepthData(symbol, data, "websocket");
// const lastEventTime = lastEventTimeMap[symbol] || 0;
// 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, bids, symbol});
// if (asks[0][0] >= bids[0][0]) {
// redisClient.set(key, depthJson, 'EX', 2);
// redisClient.publish(publishKey, publishContent);
// } else {
// console.error("买一大于卖一,数据有误")
// }
// }
}
});
}
......@@ -177,7 +161,7 @@ function _handleDepthData(symbol, data, source) {
const key = symbol.replace('_', '').toUpperCase() + 'DEPTH@zb';
symbol = symbol.toUpperCase();
const lastEventTime = lastEventTimeMap[symbol] || 0;
if (data.timestamp > lastEventTime || (source === "rest" && data.timestamp === lastEventTime && JSON.stringify(data) !== lastDataMap[symbol] && JSON.stringify(data) !== lastLastDataMap[symbol])) {
if (data.timestamp > lastEventTime || (data.timestamp === lastEventTime && JSON.stringify(data) !== lastDataMap[symbol] && JSON.stringify(data) !== lastLastDataMap[symbol])) {
if (symbol === "BTCUSDT") {
let consoleMethod = console.log;
if (data.timestamp === lastEventTime) {
......@@ -248,13 +232,13 @@ function getBalanceByRest() {
function run() {
subscribe();
const depthInterval = Math.max(60 * 1000 / (900 * ips.length / observerSymbol.length), 80);
console.log(depthInterval);
setInterval(() => {
for (const symbol of observerSymbol) {
depthByRest(symbol);
}
}, depthInterval);
// const depthInterval = Math.max(60 * 1000 / (900 * ips.length / observerSymbol.length), 80);
// console.log(depthInterval);
// setInterval(() => {
// for (const symbol of observerSymbol) {
// depthByRest(symbol);
// }
// }, depthInterval);
setInterval(() => {
getBalanceByRest();
}, 2000);
......
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