1

我需要通过当前看到的 websocets 获取最近的订单,这不是使用 node-binance-api

// The only time the user data (account balances) and order execution websockets will fire, is if you create or cancel an order, or an order gets filled or partially filled
function balance_update(data) {
    console.log("Balance Update");
    for ( let obj of data.B ) {
        let { a:asset, f:available, l:onOrder } = obj;
        if ( available == "0.00000000" ) continue;
        console.log(asset+"\tavailable: "+available+" ("+onOrder+" on order)");
    }
}
function execution_update(data) {
    let { x:executionType, s:symbol, p:price, q:quantity, S:side, o:orderType, i:orderId, X:orderStatus } = data;
    if ( executionType == "NEW" ) {
        if ( orderStatus == "REJECTED" ) {
            console.log("Order Failed! Reason: "+data.r);
        }
        console.log(symbol+" "+side+" "+orderType+" ORDER #"+orderId+" ("+orderStatus+")");
        console.log("..price: "+price+", quantity: "+quantity);
        return;
    }
    //NEW, CANCELED, REPLACED, REJECTED, TRADE, EXPIRED
    console.log(symbol+"\t"+side+" "+executionType+" "+orderType+" ORDER #"+orderId);
}
binance.websockets.userData(balance_update, execution_update);

但我只需要单独获取最近的订单数据以及订单状态,如打开、部分填充或完全填充。无论如何这是否可能 - 就像在 ws 流上获取这些数据一样

我目前使用

const WS = require('ws');
const ws = new WS('wss://stream.binance.com:9443/ws/shibusdt@bookTicker');
ws.on('message', function incoming(sdata) {}

像这样,所以对于订单信息,我可以创建其他 ws 变量并获取传入的数据形式,或者类似的东西。有可能。

4

1 回答 1

1

您的示例代码需要 node-binance-api。看到 binance.websockets.userData(balance_update, execution_update)); 它需要 API KEY 和 SECRET 才能访问。要通过此安全请求获取实时订单,请尝试...

binance.websockets.trades(['SHIBUSDT','ETHBTC'], (trades) => {
  let {e:eventType, E:eventTime, s:symbol, p:price, q:quantity, m:maker, a:tradeId} = trades;
  console.info(symbol+" trade update. price: "+price+", quantity: "+quantity+", maker: "+maker);
});

要通过 websockets 获取实时订单,请尝试使用 @trade 而不是 @bookTicker

const ws = new WS('wss://stream.binance.com:9443/ws/shibusdt@trade');
于 2021-12-08T14:33:12.973 回答