在网络套接字流中获取最近的交易订单信息 binance api(node js)

时间:2021-07-14 07:48:27

标签: node.js trading binance binance-api-client

我需要获取最近的订单 vie 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 变量并从那个或类似的东西中获取传入数据。标识可能的。

0 个答案:

没有答案