binance-connector-python
binance-connector-python copied to clipboard
streaming message line handling
Hi, i don't know if it's here i can ask this question (all new to python & co.).
could this problem be due to a misshandling of the threading ? if yes, how could i correct this in order to treat each incoming line ?
Thanks
Issue subject
when streaming the data, using the streaming script, i'm subscribing to streams.
ws_client.live_subscribe(stream=["btcusdt@kline_1m"],
id=1, callback=message_handler)
def message_handler(message):
print(message)
line_export = message.get('k')
int_opentime = int(line_export.get('o'))
print(int_opentime)`
i tried this in the message_handler function :
message.get('k').get('o')
in order to extract the open time
Expected behaviour
i thought i should be able to extract data and treat them from the streaming functions
Actual behaviour
error messages : Unhandled Error
Traceback (most recent call last):
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/python/log.py", line 96, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/python/log.py", line 80, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/python/context.py", line 117, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/python/context.py", line 82, in callWithContext
return func(*args, **kw)
--- <exception caught here> ---
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/internet/selectreactor.py", line 148, in _doReadOrWrite
why = getattr(selectable, method)()
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/internet/tcp.py", line 248, in doRead
return self._dataReceived(data)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/internet/tcp.py", line 253, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/protocols/tls.py", line 330, in dataReceived
self._flushReceiveBIO()
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/protocols/tls.py", line 296, in _flushReceiveBIO
ProtocolWrapper.dataReceived(self, bytes)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/twisted/protocols/policies.py", line 110, in dataReceived
self.wrappedProtocol.dataReceived(data)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/twisted/websocket.py", line 348, in dataReceived
self._dataReceived(data)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/websocket/protocol.py", line 1243, in _dataReceived
self.consumeData()
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/websocket/protocol.py", line 1255, in consumeData
while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/websocket/protocol.py", line 1619, in processData
fr = self.onFrameEnd()
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/websocket/protocol.py", line 1747, in onFrameEnd
self._onMessageEnd()
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/twisted/websocket.py", line 376, in _onMessageEnd
self.onMessageEnd()
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/websocket/protocol.py", line 647, in onMessageEnd
self._onMessage(payload, self.message_is_binary)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/autobahn/twisted/websocket.py", line 379, in _onMessage
self.onMessage(payload, isBinary)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/env/lib/python3.9/site-packages/binance/websocket/binance_client_protocol.py", line 31, in onMessage
self.factory.callback(payload_obj)
File "/Users/thomas/Documents/OneDrive - Famille_Wernher/Personnal/Python_Code/Crypto_App_binance-connector-python/test_stream_binanceapi_get-data-from-messagehandler_20221016.py", line 114, in message_handler
get_message_flow(str_msg)
Steps to reproduce
modify the callback function in order to interact with the data and the problem appears
Environment
Provide any relevant information about your setup, such as:
- Version of binance-connector-python : 0.6.0
- Python version : 3.9
- Operating system : MacOsX
can you upgrade the library to latest version 1.18.0
and try again.
thanks