Back to Ccxt

One Exchange Many Streams 2

wiki/examples/ts/one-exchange-many-streams-2.md

4.5.53970 B
Original Source
javascript

'use strict';

import ccxt from '../../js/ccxt.js';

console.log ('CCXT Version:', ccxt.version);


async function main () {
   const exchange = new ccxt.pro.binance ();
   const symbols = [ 'BTC/USDT', 'ETH/BTC', 'ETH/USDT' ];

   const loop = async (symbol) => {
       while (true) {
           try {
               const orderbook = await exchange.watchOrderBook (symbol);
               console.log (new Date (), symbol, orderbook['asks'][0], orderbook['bids'][0]);
           } catch (e: any) {
               console.log (symbol, e);
               // do nothing and retry on next loop iteration
               // throw e // uncomment to break all loops in case of an error in any one of them
               // break // you can also break just this one loop if it fails
           }
       }
   }

   await Promise.all (symbols.map ((symbol) => loop (symbol)));

}

main ();