Aggregate Trade Websocket Stream disconnection

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()

Yes. Please reconnect every 24h

But data stream stops before 24h. As I said, 1h or 3h, but always stopped before 24h. There is request limit as 1200 per 1 minute for something as I remember. It means 20 request in 1 second. Can my data stream problem be related with this request limit? Is it enough to add “time.sleep()” ?

Please check your network stability. I can connect to it and last for more than 10 hours. No problem from server end.