【问题标题】:get recent trade orders info in web socket streams binance api(node js)在网络套接字流binance api(节点js)中获取最近的交易订单信息
【发布时间】:2021-09-23 04:42:24
【问题描述】:

我需要通过 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 变量并获取传入的数据形式,或者类似的东西。有可能。

【问题讨论】:

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


    【解决方案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');
    

    【讨论】:

      猜你喜欢
      • 2018-08-18
      • 2017-09-05
      • 2023-03-23
      • 1970-01-01
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      相关资源
      最近更新 更多