A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
I am trying to write terminal output to csv. Currently my code looks like this:
def print_stream_data_from_stream_buffer(binance_websocket_api_manager):
while True:
if binance_websocket_api_manager.is_manager_stopping():
exit(0)
oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer()
if oldest_stream_data_from_stream_buffer is False:
time.sleep(0.01)
else:
print(oldest_stream_data_from_stream_buffer)
with open('tradehistory.csv', 'w') as f:
w = csv.DictWriter(f, oldest_stream_data_from_stream_buffer)
w.writerow(oldest_stream_data_from_stream_buffer)**
I get this error output:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\ProgramData\Anaconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\asus\Documents\Personal\Corporate\Python\bad_apple.py", line 34, in print_stream_data_from_stream_buffer
w.writerow(oldest_stream_data_from_stream_buffer)
File "C:\ProgramData\Anaconda3\lib\csv.py", line 154, in writerow
return self.writer.writerow(self._dict_to_list(rowdict))
File "C:\ProgramData\Anaconda3\lib\csv.py", line 147, in _dict_to_list
wrong_fields = rowdict.keys() - self.fieldnames
AttributeError: 'str' object has no attribute 'keys'
Very new to coding and appreciate any advice given.
Hello,
I am trying to write terminal output to csv. Currently my code looks like this:
def print_stream_data_from_stream_buffer(binance_websocket_api_manager): while True: if binance_websocket_api_manager.is_manager_stopping(): exit(0) oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer() if oldest_stream_data_from_stream_buffer is False: time.sleep(0.01) else: print(oldest_stream_data_from_stream_buffer) with open('tradehistory.csv', 'w') as f: w = csv.DictWriter(f, oldest_stream_data_from_stream_buffer) w.writerow(oldest_stream_data_from_stream_buffer)**
I get this error output:
Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\ProgramData\Anaconda3\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\Users\asus\Documents\Personal\Corporate\Python\bad_apple.py", line 34, in print_stream_data_from_stream_buffer w.writerow(oldest_stream_data_from_stream_buffer) File "C:\ProgramData\Anaconda3\lib\csv.py", line 154, in writerow return self.writer.writerow(self._dict_to_list(rowdict)) File "C:\ProgramData\Anaconda3\lib\csv.py", line 147, in _dict_to_list wrong_fields = rowdict.keys() - self.fieldnames AttributeError: 'str' object has no attribute 'keys'
Very new to coding and appreciate any advice given.