It looks like you're new here. If you want to get involved, click one of these buttons!
from kiteconnect import KiteTicker, KiteConnect
import pandas as pd
from datetime import datetime, timedelta
import time
import csv
# Initialise
api_key = open('api_key.txt','r').read()
access_token = open('access_token.txt','r').read()
kws = KiteTicker(api_key, access_token)
#Getting the tokens for NIFTY based on date, and strike price
df = pd.read_csv('instrumenttoken.csv')
expiry = input("Enter the expiry in YYYY-MM-DD format: ")
print(expiry)
strike_pe = int(input("Enter the strike for PUT option: "))
print(df.loc[(df['expiry'] == expiry) & (df['instrument_type'] == 'PE') & (df['strike'] == strike_pe)])
instrument_token_pe = df.loc[(df['expiry'] == expiry) & (df['instrument_type'] == 'PE') & (df['strike'] == strike_pe)]['instrument_token'].values[0]
trading_symbol_pe = df.loc[(df['expiry'] == expiry) & (df['instrument_type'] == 'PE') & (df['strike'] == strike_pe)]['tradingsymbol'].values[0]
strike_ce = int(input("Enter the strike for CALL option: "))
print(df.loc[(df['expiry'] == expiry) & (df['instrument_type'] == 'CE') & (df['strike'] == strike_ce)])
instrument_token_ce = df.loc[(df['expiry'] == expiry) & (df['instrument_type'] == 'CE') & (df['strike'] == strike_ce)]['instrument_token'].values[0]
trading_symbol_ce = df.loc[(df['expiry'] == expiry) & (df['instrument_type'] == 'CE') & (df['strike'] == strike_ce)]['tradingsymbol'].values[0]
tokens_dict = {instrument_token_pe:trading_symbol_pe, instrument_token_ce:trading_symbol_ce }
print(tokens_dict)
token = [instrument_token_pe, instrument_token_ce]
print(token)
symbol = [trading_symbol_pe, trading_symbol_ce]
#Receiving the ticks data and collecting the useful values like the name, timestamp and price
def on_ticks(ws, ticks):
# Callback to receive ticks.
print("Ticks: {}".format(ticks))
def on_connect(ws, response):
# Callback on successful connect.
ws.subscribe(token)
ws.set_mode(ws.MODE_FULL, token)
# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()