Hi,
I want to get realtime BTC price via aggregate trade websocket and write in a csv file. All is ok, I can write, but after a random time (someties 1h, sometimes 4h) I see that it is not writing in csv anymore. Actually I dont see any error in python as well. Is there a disconnection issue? Or is there an issue about stop websocket streaming? As I read in documents, aggregate websocket is alive 24h.
import csv
from binance.client import Client
import time
import datetime
import pandas as pd
from binance.websockets import BinanceSocketManager
from twisted.internet import reactor
from binance.enums import *
api_key = ‘’
api_secret = ‘’
client = Client(api_key, api_secret)
price = pd.DataFrame(columns=[‘Symbol’, ‘UnixDate’, ‘UTCTime’, ‘price’])
def btcPrice(msg):
from datetime import datetime
formatted_time = datetime.utcnow().strftime(’%Y-%m-%d %H:%M:%S.%f’)[:-1]
price.loc[len(price)] = [str(msg[‘s’]), float(msg[‘E’]), formatted_time, float(msg[‘p’])]
price.to_csv(‘btcTickData.csv’, index=False)
bm = BinanceSocketManager(client)
conn_key = bm.start_aggtrade_socket(‘BTCUSDT’, btcPrice)
bm.start()