Closed mmxxst7 closed 3 years ago
Hello!
You are receiving a string with a JSON structure (as sent by Binance). You can convert it to a dict by using output="dict"
or you convert it to well named dicts by using output="UnicornFy"
.
Here is an example file: https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/blob/master/example_kline_1m_with_unicorn_fy.py
You can controll this once for all streams with output_default
and also overwrite this for every specific stream with output
:
https://oliver-zehentleitner.github.io/unicorn-binance-websocket-api/unicorn_binance_websocket_api.html?highlight=output#module-unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager
UnicornFy: https://github.com/oliver-zehentleitner/unicorn-fy
Thank you for your reply! It works!
May I ask you why I get the following error when I retrieve oldest_stream_data_from_stream_buffer['o']['ot']
:
'STOP_MARKET'
'STOP_MARKET'
Exception in thread Thread-5:
Traceback (most recent call last):
File "/Users/xxx/.conda/envs/untitled3/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/Users/xxx/.conda/envs/untitled3/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/xxx/Workfiles/Python/vs_binance_algo/testnet/binance_testnet_futures_stp+tp separately_merge.py", line 59, in print_stream_data_from_stream_buffer
pprint.pprint(oldest_stream_data_from_stream_buffer['o']['ot'])
KeyError: 'o'
KeyError: 'o'
means that oldest_stream_data_from_stream_buffer['o']
does not exists.
Since the initial topic is solved i am closing this issue.
Hello,
I'm trying to access single key values from the pop_stream_data_from_stream_buffer, in order to cancel either the stop order if the take profit has been filled, or vice versa.
I use your code this way:
How can I access the value from key 'X' ("X":"FILLED", ), or 'ot' ("ot":"STOP_MARKET") ?
I tried it this way:
print(oldest_stream_data_from_stream_buffer['ot'])
But I get anTypeError: string indices must be integers