altangent / ccxws

WebSocket client for 38 cryptocurrency exchanges
MIT License
619 stars 187 forks source link

just binance can get data back ? #272

Closed oss-jtyd closed 3 years ago

oss-jtyd commented 3 years ago

hi all,can some one help,the code below, just binance can get data :

const ccxws = require("../index.js");

var map = {
  binance: new ccxws.Binance(),
  huobi: new ccxws.Huobi(),
  OKEx: new ccxws.OKEx()
}

const fs = require('fs');
const path="./exchanges_config.json";
fs.readFile(path, function(err, data){
    if(err){
        console.log(err);
    }else{
        let exchangeStr=data.toString();    
        exchangeJson=JSON.parse(exchangeStr);       
    console.log(exchangeJson.length);
    for (let i=0; i < exchangeJson.length; i++) {
      const key = exchangeJson[i].exchange;
      console.log(key);
      const instance = map[key];

      const market = {
        id: "BTCUSDT", // remote_id used by the exchange
        base: "BTC", // standardized base symbol for Bitcoin
        quote: "USDT", // standardized quote symbol for Tether
      };

      // handle trade events
      instance.on("trade", trade => {
        console.log(trade)
      });
      // subscribe to trades
      binance.subscribeTrades(market);
     }
    }
});
bmancini55 commented 3 years ago

Thanks for submitting the issue! In your loop you only call subscribeTrades using the binance client binance.subscribeTrades(market);. Also beware that markets (especially the id property are different between exchanges.