It looks like you're new here. If you want to get involved, click one of these buttons!
from kiteconnect import KiteTicker
import time
__api_key__ = ""
__access_token__ = ""
__ilist__ = [738561]
class DataLoader:
def __init__(self, api_key, access_token, ilist):
self.api_key = api_key
self.access_token = access_token
self.ilist = ilist
def main(self):
try:
self.t = KiteTicker(self.api_key, self.access_token, reconnect=True, reconnect_max_delay=5, reconnect_max_tries=300)
self.load_data()
except Exception as e:
print(e)
def save(self, ticks):
for tick in ticks:
print("Will be inserting to DB")
def on_ticks(self, ws, ticks):
self.save(ticks)
def on_connect(self, ws, response):
ws.subscribe(self.ilist)
ws.set_mode(ws.MODE_FULL, self.ilist)
def on_close(self, ws, code, reason):
ws.stop()
def on_error(self, ws, code, reason):
print("Error Code: " + str(code))
print("Error: " + str(reason))
def load_data(self):
self.t.on_ticks = self.on_ticks
self.t.on_close = self.on_close
self.t.on_error = self.on_error
self.t.on_connect = self.on_connect
self.t.connect(threaded=True)
while True:
if not self.t.is_connected():
self.t.connect(threaded=True)
time.sleep(3)
my = DataLoader(__api_key__, __access_token__, __ilist__)
my.main()
ws.stop()
insideon_close