【问题标题】:Bitfinex Ticker API for multiple currencies适用于多种货币的 Bitfinex Ticker API
【发布时间】:2017-12-20 16:57:47
【问题描述】:

我想从 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

【问题讨论】:

    标签: javascript api websocket


    【解决方案1】:

    我使用“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))
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 2013-04-23
      • 2014-07-05
      • 2013-06-11
      • 2012-03-13
      • 2020-11-22
      • 2022-01-12
      • 2014-08-01
      相关资源
      最近更新 更多