I get data from Binance websocket end point in a working thread and filter the streaming data and print the filtered output. but cant add the data to my table. i have read all the topics in updating components but could not do any progress. please take a look at my code:
note: please dony mind the details in function. it works properly. just the table update does not happens.
-------------------------------------------------
import streamlit as st
import time
import threading
from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
import unicorn_binance_websocket_api
import unicorn_binance_rest_api
from unicorn_fy.unicorn_fy import UnicornFy
import numpy as np
import pandas as pd
import streamlit.report_thread as ReportThread
def print_stream_data_from_stream_buffer(binance_websocket_api_manager,arbitriangle):
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:
unicorn_fied_stream_data = UnicornFy.binance_com_websocket(oldest_stream_data_from_stream_buffer)
try:
if unicorn_fied_stream_data['symbol'] in p0:
indices = [index for index, element in enumerate(p0) if element == unicorn_fied_stream_data['symbol']]
for i in indices:
for j in graphlist[i]:
if j==unicorn_fied_stream_data['symbol']:
graphlist[i][j]=float(unicorn_fied_stream_data['best_bid_price'])
if unicorn_fied_stream_data['symbol'] in p1:
indices = [index for index, element in enumerate(p1) if element == unicorn_fied_stream_data['symbol']]
for i in indices:
for j in graphlist[i]:
if j==unicorn_fied_stream_data['symbol']:
graphlist[i][j]=1/float(unicorn_fied_stream_data['best_ask_price'])
if unicorn_fied_stream_data['symbol'] in p2:
indices = [index for index, element in enumerate(p2) if element == unicorn_fied_stream_data['symbol']]
for i in indices:
for j in graphlist[i]:
if j==unicorn_fied_stream_data['symbol']:
graphlist[i][j]=1/float(unicorn_fied_stream_data['best_ask_price'])
for i in indices:
thevalues = [x for x in graphlist[i].values()]
thekeys = [x for x in graphlist[i].keys()]
if (np.prod(thevalues)) >= 1.006 :
profit = np.prod(thevalues)
sym1 = thekeys[0]
price1 = thevalues[0]
sym2 = thekeys[1]
price2 = thevalues[1]
sym3 = thekeys[2]
price3 = thevalues[2]
print([sym1,price1,sym2,price2,sym3,price3,profit])
arbitriangle.add_rows([[sym1,price1,sym2,price2,sym3,price3,profit]])
except:
print('err')
arbitriangle = st.table(pd.DataFrame())
binance_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com")
worker_thread = threading.Thread(target=print_stream_data_from_stream_buffer, args=(binance_websocket_api_manager,arbitriangle))
worker_thread.start()
ReportThread.add_report_ctx(worker_thread)
markets = newp
channels = ['bookTicker']
stream_id = binance_websocket_api_manager.create_stream(channels, markets)
binance_websocket_api_manager.subscribe_to_stream(stream_id, markets=markets)
binance_websocket_api_manager.get_stream_subscriptions(stream_id)