bludnic / opentrader

🤖 Powerful open-source crypto trading bot. Give it a ⭐ to support the project!
Apache License 2.0
231 stars 26 forks source link

Use subscription approach to retrieve market data instead of `watch` method inside a loop #67

Open bludnic opened 1 month ago

bludnic commented 1 month ago

This feature is not yet supported by CCXT.

Instead of:

while (true) {
  try {
    const ticker = await exchange.watchTicker("BTC/USDT");
  } catch (err) {
    // ...
  }
}

Use subscription:

const handleTicker = (ticker) => {
  // ...
}

exchange.onTicker("BTC/USDT", handleTicker)
exchange.offTicker("BTC/USDT", handleTicker)

Same approach for watchOrderbook and watchTrades.

Discussion: https://github.com/ccxt/ccxt/issues/15188 https://github.com/ccxt/ccxt/issues/9248#issuecomment-2423779762