altangent / ccxws

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

candlePeriod as a parameter #335

Closed nileio closed 1 year ago

nileio commented 1 year ago

Just FYI , I implemented a very simple workaround solution in my fork to enable a single client to subscribe multiple candlePeriods, as many as the exchange allows of course. you can simply subscribe to multiple resolutions (candlePeriod) aka timeframes, in a loop or so if you like. the property is added to the Market type and can be used as

const binance=new BinanceClient({useMarketCandlePeriod:true})
let market = {
  id: "BTCUSDT", // remote_id used by the exchange
  base: "BTC", // standardized base symbol for Bitcoin
  quote: "USDT", // standardized quote symbol for Tether
  candlePriod: CandlePeriod._1m
};
binance.subscribeCandles(market);

Only Binance is implemented at this time, I will implement for Kucoin next. any exchange can adopt the new property and handle it in its own unique way given every exchange has a different data structure. Note this is a quick and possibly dirty solution but it shouldn't break anything ! suggestions welcome but I won't possibly do something drastically different !! This should only be set if you will be using subscribeCandles.. I didn't test the behaviour if this property is set when using other APIs. https://github.com/nileio/ccxws/blob/master/CHANGELOG.md https://github.com/nileio/ccxws/commit/ac9fe11f5df0f769b45d0b84713b6a5618336170

nileio commented 1 year ago

abondon