INNER CODE UNIT · Python

connect

nkaz001/sample-trading-bot · tradingbot/binancefutures.py:345

    async def connect(self):
        try:
            await self.cancel_all_orders()
            self.running_qty = await self.open_position()
            self.listen_key = await self.open_user_data_stream()
            if self.testnet:
                # url = 'wss://stream.binancefuture.com/stream?streams=%s/%s/%s' % (self.listen_key, '%s@depth@0ms' % self.symbol, '%s@aggTrade' % self.symbol)
                url = 'wss://stream.binancefuture.com/stream?streams=%s/%s/%s' % (self.listen_key, '%s@depth@0ms' % self.symbol, '%s@trade' % self.symbol)
            else:
                # url = 'wss://fstream.binance.com/stream?streams=%s/%s/%s' % (self.listen_key, '%s@depth@0ms' % self.symbol, '%s@aggTrade' % self.symbol)
                url = 'wss://fstream.binance.com/stream?streams=%s/%s/%s' % (self.listen_key, '%s@depth@0ms' % self.symbol, '%s@trade' % self.symbol)
            async with ClientSession() as session:
                async with session.ws_connect(url) as ws:
                    logging.info('WS Connected.')
                    self.ws = ws
                    self.keep_alive = asyncio.create_task(self.__keep_alive())
                    async for msg in ws:
                        if msg.type == WSMsgType.TEXT:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…