INNER CODE UNIT · Python

open_user_data_stream

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

    async def open_user_data_stream(self):
        response = await self.__curl_binancefutures(verb='POST', path='/v1/listenKey')
        return response["listenKey"]

    async def keepalive_user_data_stream(self):
        return await self.__curl_binancefutures(verb='PUT', path='/v1/listenKey')

    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)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…