It looks like you're new here. If you want to get involved, click one of these buttons!
kws = KiteTicker("***", "**")
# # list = [738561, 5633]
file_tokens = pd.read_csv(
"C:\\Users\\kvslb\\.spyder-py3\\BACKDATA_PY\\VirtualApp\\symbols_id_VP.csv")
list = file_tokens['Zerodha_token'].to_list()
def on_connect(ws, response):
# Callback on successful connect.
ws.subscribe(list)
# Set tick in `full` mode.
ws.set_mode(ws.MODE_FULL, list)
def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))
def on_close(ws, code, reason):
print("-------- Stopping ------------")
ws.stop()
print("--------- Stopped ----------")
host = '*****.amazonaws.com'
user = 'admin'
password = '*****'
database = '*****'
port = 3306
engine = create_engine(
url="mysql+pymysql://{0}:{1}@{2}:{3}/{4}".format(
user, password, host, port, database
)
)
# will hold list of JSON objects
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.connect(threaded=True)
while True:
def on_ticks(ws, ticks):
helper_method(ticks)
def helper_method(ticks):
data = pd.DataFrame(ticks)
merged = data.merge(
file_tokens, left_on='instrument_token', right_on='Zerodha_token')
data_final = pd.DataFrame(
columns=['symbol_id', 'timestamp', 'close', 'change'])
data_final['symbol_id'] = merged['id']
data_final['timestamp'] = merged['exchange_timestamp']
data_final['close'] = merged['last_price']
data_final['change'] = merged['change']
data_final.to_sql('symbol_minute_quote', con=engine,
if_exists='append', index=False)
# if (datetime.datetime.now().hour >= hour) and (datetime.datetime.now().minute >= minute):
# kws.stop()
# kws.unsubscribe(list)
# kws.close()
kws.on_ticks = on_ticks
What is wrong here ?