Store tick by tick data into database using sqlite3 or mysql

db = sqlite3.connect(‘reliance.db’)
def create_tables(tickers):
cur = db.cursor()
cur.execute(“CREATE TABLE IF NOT EXISTS {} (ts datetime primary key,SYMBOL text,LTP real(15,5))”.format(‘RELIANCE’))
try:
db.commit()
except:
db.rollback()

def insert_data(message):

ts = datetime.datetime.fromtimestamp(message['exchange_time_stamp'])
exchange = message['exchange']
Token = message['token']
symbol = message['instrument'][2]
LTP = message['ltp']
print(f'{ts} => SYMBOL: [{symbol}] LTP: {LTP}')

try:
    print('connecting db')
    cur = db.cursor()
    vals = (ts,symbol,LTP)
    query = "INSERT INTO {} VALUES (?,?,?)".format(symbol)
    cur.execute(query,vals)
except:
    print('not inserted')
    pass
try:
    print('commited')
    db.commit()
except:
    db.rollback()

#create tables
create_tables(‘RELIANCE’)

I want to store the streaming webscoket data into database using sqlite3. But It was not inserting data into table. The above code doesn’t show error.

Any one suggest me how to insert streaming data into database.

@dexter
I have tried to insert tick by tick data into sqlite3 database.
but it is not inserting and not showing any error. Any suggestion?

The code you pasted has wrong incendation. So I think You have pasted wrong. Try to repost it properly or post it in G-Collab and Paste that’s link or as Github Gist.

Also tell the error.