适用于多种货币的Bitfinex Ticker API

时间:2017-12-20 16:57:47

标签: javascript api websocket

我想从Bitfinex websocket API检索多个股票通道的JSON数据,但似乎我只能连接到一个货币对。

如何为多对配对?

以下是一对的示例代码:

var bfx = new WebSocket("wss://api.bitfinex.com/ws");
bfx.onopen = function(){
   bfx.send(JSON.stringify({"event":"subscribe","channel":"ticker","pair":"BCHUSD"}));
};
var bchprc=0;
bfx.onmessage = function(msg){
    var response = JSON.parse(msg.data);
    bchprc = response[1];
    if(bchprc!="hb"){
        $("#bitfinex_bch_prc").html(response[7]);
    }
};

Refer to this link

1 个答案:

答案 0 :(得分:0)

我使用“ for”循环来检索它们。我认为这是系统允许的。

for (let i of ['BTC','EOS','ZRX','XML','blah','blahh']) {
    let pair = {"event":"subscribe", "channel":"ticker"}
    if (i !== 'BTC') {
        pair.symbol = `t${i}BTC`  //3rd key is 'symbol'
        WSS.send(JSON.stringify(pair))
    }
    pair.symbol = "t${i}USD"
    WSS.send(JSON.stringify(pair))
}
相关问题