Extracting Live OHLC and Volume data using KiteConnect to use with Indicators in 1 min to 15 min TF.

pratyushbgr
Is there a ready code to dump OHLC or LTP live data for around 200 scripts to Mysql DB along with Volume. To avoid any delay, appreciate if there is a thread implementation? Appreciate any help in this regard. I have few good strategies, those will do wonders if I can do this.
  • ZI4453
    ZI4453 edited September 29
    import sqlite3
    conn=sqlite3.connect(r"DB")
    mouse=conn.cursor()
    mouse.execute("DROP TABLE tickdata")
    mouse.execute("CREATE TABLE IF NOT EXISTS tickdata(TokenID integer,ExchangeSegment integer,ExchangeInstrumentID integer NOT NULL PRIMARY KEY,ExchangeTimeStamp real,B_S1 integer,B_P1 real,B_O1 integer,B_BM1 integer,B_S2 integer,B_P2 real,B_O2 integer,B_BM2 integer,B_S3 integer,B_P3 real,B_O3 integer,B_BM3 integer,B_S4 integer,B_P4 real,B_O4 integer,B_BM4 integer,B_S5 integer,B_P5 real,B_O5 integer,B_BM5 integer,S_S1 integer,S_P1 real,S_O1 integer,S_BM1 integer,S_S2 integer,S_P2 real,S_O2 integer,S_BM2 integer,S_S3 integer,S_P3 real,S_O3 integer,S_BM3 integer,S_S4 integer,S_P4 real,S_O4 integer,S_BM4 integer,S_S5 integer,S_P5 real,S_O5 integer,S_BM5 integer,B_ Size integer,B_Price real,B_TotalOrders integer,B_BuyBackMarketMaker integer,A_Size integer,A_Price real,A_TotalOrders integer,A_BuyBackMarketMaker integer,LastTradedPrice real,LastTradedQunatity integer,TotalBuyQuantity integer, TotalSellQuantity integer,TotalTradedQuantity integer,AverageTradedPrice real,LastTradedTime real,LastUpdateTime real,PercentChange real,Open real,High real,Low real,Close real,TotalValueTraded real,BuyBackTotalBuy integer,BuyBackTotalSell integer)")
    for items in Instrumentlist:
    mouse.execute("INSERT INTO tickdata(TokenID,ExchangeSegment,ExchangeInstrumentID,ExchangeTimeStamp,B_S1,B_P1,B_O1,B_BM1,B_S2,B_P2,B_O2,B_BM2,B_S3,B_P3,B_O3,B_BM3,B_S4,B_P4,B_O4,B_BM4,B_S5,B_P5,B_O5,B_BM5,S_S1,S_P1,S_O1,S_BM1,S_S2,S_P2,S_O2,S_BM2,S_S3,S_P3,S_O3,S_BM3,S_S4,S_P4,S_O4,S_BM4,S_S5,S_P5,S_O5,S_BM5,B_ Size,B_Price,B_TotalOrders,B_BuyBackMarketMaker,A_Size,A_Price,A_TotalOrders,A_BuyBackMarketMaker,LastTradedPrice,LastTradedQunatity,TotalBuyQuantity,TotalSellQuantity,TotalTradedQuantity,AverageTradedPrice,LastTradedTime,LastUpdateTime,PercentChange,Open,High,Low,Close,TotalValueTraded,BuyBackTotalBuy,BuyBackTotalSell)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(0,0,items,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0,0.0,0,0,0.0,0,0,0,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0))
    for data in (livestream):
    try:
    mouse.execute(("UPDATE tickdata SET ExchangeSegment=?,ExchangeTimeStamp=?,B_S1=?,B_P1=?,B_O1=?,B_BM1=?,B_S2=?,B_P2=?,B_O2=?,B_BM2=?,B_S3=?,B_P3=?,B_O3=?,B_BM3=?,B_S4=?,B_P4=?,B_O4=?,B_BM4=?,B_S5=?,B_P5=?,B_O5=?,B_BM5=?,S_S1=?,S_P1=?,S_O1=?,S_BM1=?,S_S2=?,S_P2=?,S_O2=?,S_BM2=?,S_S3=?,S_P3=?,S_O3=?,S_BM3=?,S_S4=?,S_P4=?,S_O4=?,S_BM4=?,S_S5=?,S_P5=?,S_O5=?,S_BM5=?,B_ Size=?,B_Price=?,B_TotalOrders=?,B_BuyBackMarketMaker=?,A_Size=?,A_Price=?,A_TotalOrders=?,A_BuyBackMarketMaker=?,LastTradedPrice=?,LastTradedQunatity=?,TotalBuyQuantity=?,TotalSellQuantity=?,TotalTradedQuantity=?,AverageTradedPrice=?,LastTradedTime=?,LastUpdateTime=?,PercentChange=?,Open=?,High=?,Low=?,Close=?,TotalValueTraded=?,BuyBackTotalBuy=?,BuyBackTotalSell=? WHERE ExchangeInstrumentID=?"),(data['ExchangeSegment'],data['ExchangeTimeStamp'],data['Bids'][0]['Size'],data['Bids'][0]['Price'],data['Bids'][0]['TotalOrders'],data['Bids'][0]['BuyBackMarketMaker'],data['Bids'][1]['Size'],data['Bids'][1]['Price'],data['Bids'][1]['TotalOrders'],data['Bids'][1]['BuyBackMarketMaker'],data['Bids'][2]['Size'],data['Bids'][2]['Price'],data['Bids'][2]['TotalOrders'],data['Bids'][2]['BuyBackMarketMaker'],data['Bids'][3]['Size'],data['Bids'][3]['Price'],data['Bids'][3]['TotalOrders'],data['Bids'][3]['BuyBackMarketMaker'],data['Bids'][4]['Size'],data['Bids'][4]['Price'],data['Bids'][4]['TotalOrders'],data['Bids'][4]['BuyBackMarketMaker'],data['Asks'][0]['Size'],data['Asks'][0]['Price'],data['Asks'][0]['TotalOrders'],data['Asks'][0]['BuyBackMarketMaker'],data['Asks'][1]['Size'],data['Asks'][1]['Price'],data['Asks'][1]['TotalOrders'],data['Asks'][1]['BuyBackMarketMaker'],data['Asks'][2]['Size'],data['Asks'][2]['Price'],data['Asks'][2]['TotalOrders'],data['Asks'][2]['BuyBackMarketMaker'],data['Asks'][3]['Size'],data['Asks'][3]['Price'],data['Asks'][3]['TotalOrders'],data['Asks'][3]['BuyBackMarketMaker'],data['Asks'][4]['Size'],data['Asks'][4]['Price'],data['Asks'][4]['TotalOrders'],data['Asks'][4]['BuyBackMarketMaker'],data['Touchline']['BidInfo']['Size'],data['Touchline']['BidInfo']['Price'],data['Touchline']['BidInfo']['TotalOrders'],data['Touchline']['BidInfo']['BuyBackMarketMaker'],data['Touchline']['AskInfo']['Size'],data['Touchline']['AskInfo']['Price'],data['Touchline']['AskInfo']['TotalOrders'],data['Touchline']['AskInfo']['BuyBackMarketMaker'],data['Touchline']['LastTradedPrice'],data['Touchline']['LastTradedQunatity'],data['Touchline']['TotalBuyQuantity'],data['Touchline']['TotalSellQuantity'],data['Touchline']['TotalTradedQuantity'],data['Touchline']['AverageTradedPrice'],data['Touchline']['LastTradedTime'],data['Touchline']['LastUpdateTime'],data['Touchline']['PercentChange'],data['Touchline']['Open'],data['Touchline']['High'],data['Touchline']['Low'],data['Touchline']['Close'],data['Touchline']['TotalValueTraded'],data['Touchline']['BuyBackTotalBuy'],data['Touchline']['BuyBackTotalSell'],data['ExchangeInstrumentID'] ))
    except:
    continue
    conn.commit()
    conn.close()
Sign In or Register to comment.