I am using DOCKER container to run my programs. When subscribing to book_ticker and run the code in a DOCKER container all works fine. When doing the same on user_data and run the code in a DOCKER container I get no response after calling the SUBSCRIBE method. When I run the code directly (not using DOCKER) it works.
BASE_URL=https://testnet.binancefuture.com
STREAM_URL=wss://stream.binancefuture.com
#!/usr/bin/env python
import logging
import os
import sys
from binance.lib.utils import config_logging
from binance.um_futures import UMFutures
from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient
from dotenv import load_dotenv
config_logging(logging, logging.DEBUG)
load_dotenv(os.getcwd() + '/.env')
sys.path.append(os.getcwd())
def __listen_key() -> str:
um_client = UMFutures(key=os.getenv('API_KEY'), base_url=os.getenv('BASE_URL'))
response = um_client.new_listen_key()
return response['listenKey']
def ws_book_ticker(func) -> UMFuturesWebsocketClient:
client = UMFuturesWebsocketClient()
client.start()
client.book_ticker(id=13, callback=func, symbol='btcusdt')
return client
def ws_user_account(func) -> UMFuturesWebsocketClient:
client = UMFuturesWebsocketClient(stream_url=os.getenv('STREAM_URL'))
client.start()
client.user_data(listen_key=__listen_key(), id=1, callback=func)
return client
LOG:
DEBUG:root:url: https://testnet.binancefuture.com/fapi/v1/listenKey
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): testnet.binancefuture.com:443
DEBUG:urllib3.connectionpool:https://testnet.binancefuture.com:443 "POST /fapi/v1/listenKey HTTP/1.1" 200 None
DEBUG:root:raw response from server:{"listenKey":"JBOuEEwWxge26bWB8U8QwgtaZRrau1L8uCfop1zksm9qgK6S7sYszQPg1a98Cl2D"}
INFO:root:Connection with URL: wss://stream.binancefuture.com/ws
INFO:root:Start to connect....
INFO:root:Server connected
INFO:root:Sending message to Server: b'{"method": "SUBSCRIBE", "params": ["JBOuEEwWxge26bWB8U8QwgtaZRrau1L8uCfop1zksm9qgK6S7sYszQPg1a98Cl2D"], "id": 1}'
I expect the following message from Binance, but this is not delivered when running the code from a DOCKER container and thus I receive no updates from the USER_DATA stream.
{'id': 1, 'result': None}
Please advice.