Closed botradingblog1 closed 1 year ago
Please post your code!
I guess you have only one stream and are using high_performance=True
? Try with setting to False!
Hi, thanks for the feedback. I'm not explicitly setting high_performance.
Here my code:
from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager
binance_us_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.us")
def process_stream_data(binance_websocket_api_manager):
while True:
if binance_websocket_api_manager.is_manager_stopping():
exit(0)
oldest_data = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
is_empty = is_empty_message(oldest_data)
if is_empty:
time.sleep(0.02)
else:
oldest_data_dict = json.loads(oldest_data)
data = oldest_data_dict['data']
# Handle price change
handle_price_change(symbol=data['s'], timestamp=data['T'], price=float(data['p']))
def start_websocket_listener():
global stop_running
channels = {'trade', }
try:
binance_us_websocket_api_manager.create_stream(channels, markets=lc_symbols, api_key=TEST_API_KEY, api_secret=TEST_API_SECRET)
# Start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=process_stream_data, args=(binance_us_websocket_api_manager,))
worker_thread.start()
except Exception as e:
logger.error('Failure in worker thread for websocket: ', e)
I dont see the reason sorry.
I need to test this, but it will need a while, i am very busy with other stuff at the moment.
You mix api test key with binance us? I think that is in general not supported?
Version of this library.
1.41.0
Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.
Hardware?
Local server/workstation
Operating System?
Windows
Python version?
Python3.9
Installed packages
Logging output
Processing method?
process_stream_data
Used endpoint?
binance.us
Issue
This happens with binance-us testnet. I ran the websocket connection for about 5 hours when the issue occurred. It may just be an issue on the Binance side. Can you tell me how I could handle this exception and restart the websocket listener? Thanks!