Aliceblue stream to database

Function to store tick data to sqlite database

def insert_ticks(message):
try:
con = sqlite3.connect(dbfile)
c = con.cursor()
tok = “TOKEN”+str(message[‘token’])
vals = [time.strftime(’%Y-%m-%d %H:%M:%S’, time.localtime(message[‘exchange_time_stamp’])),message[‘ltp’], message[‘volume’]]
query = “INSERT INTO {}(ts,price,volume) VALUES (?,?,?)”.format(tok)
con.execute(query,vals)
except:
pass
try:
con.commit()
except:
con.rollback()

1 Like

Thank bro. :slight_smile: This will help many people for sure.

Sir, Please help me i am updating in event_handler_quote_update(message):
but i am getting socket error
i am using in aliceblue only

Paste the full error? Otherwise how can anyone will tell anything

Problem solved
Thank you

1 Like