1
我嘗試使用此代碼過濾來自WS流的具體數據:如何過濾Bitfinex API ws2流數據?
bws.on('open',() => {
console.log('WS open')
bws.subscribeTrades('BTCUSD')
bws.on('trade', (pair, msg) => {
var trades = msg.map(function (msg) {
return {
trade_id: msg.ID,
time: msg.MTS,
size: Math.abs(msg.AMOUNT),
price: msg.PRICE,
side: msg.AMOUNT > 0 ? 'buy' : 'sell'
}
})
console.log('Trades:\n', trades)
})
我得到了一個未定義的數據:
WS open
Trades:
[ {
<..>
{
trade_id: 43477863,
time: 1500037112000,
size: 0.01,
price: 2259.7,
side: 'buy'
} ]
Trades:
[ { trade_id: undefined,
time: undefined,
size: NaN,
price: undefined,
side: 'sell'
}, {
trade_id: 43478179,
time: 1500037170000,
size: 0.35702096,
price: 2259.9,
side: 'sell'
} ]
Trades:
[ { trade_id: undefined,
time: undefined,
size: NaN,
price: undefined,
side: 'sell'
}, {
trade_id: 43478179,
time: 1500037170000,
size: 0.35702096,
price: 2259.9,
side: 'sell'
} ]
這是第一塊流
[{ID:,MTS:,AMOUNT:,PRICE},{ID:,MTS:,AMOUNT:,PRICE:}]
,然後更新與
['te',{ID:,MTS:,AMOUNT:,PRICE:}]
和
['tu', {ID:,MTS:,AMOUNT:,PRICE:}]
我想我得到「未定義」當發生這些更新。我如何管理? 它已通過API解析JSON。