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.