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

{'exchange': 'NSE', 'token': 3045, 'ltp': 196.0, 'change': 4294967226, 'exchange_time_stamp': 1603785487, 'volume': 26000881, 'instrument': Instrument(exchange='NSE', token=3045, symbol='SBIN', name='STATE BANK OF INDIA', expiry=None, lot_size=None)}
How can i read the content from instrument key. It’s namedtuple should i parse it?