def loginZerodha(args): userConfig = getUserConfig() global kite kite = KiteConnect(api_key=userConfig['apiKey']) if 'request_token' in args: requestToken = args['request_token'] print('requestToken = ' + requestToken) session = kite.generate_session(requestToken, api_secret=userConfig['apiSecret']) accessToken = session['access_token'] print('accessToken = ' + accessToken) kite.set_access_token(accessToken) holdings = kite.holdings() print('holdings => ', holdings) return '<p>Login successful. accessToken = ' + accessToken + '</p>' else: loginUrl = kite.login_url() print('login url => ' + loginUrl) return redirect(loginUrl, code=302)
api_key = config_object.get_zerodha_api_key() public_token = config_object.get_zerodha_public_token() api_secret = config_object.get_zerodha_api_secret() # KITE-CONNECT kite = KiteConnect(api_key=api_key) data = kite.generate_session(public_token, api_secret=api_secret) access_token = data['access_token'] kite.set_access_token(access_token) kws = KiteTicker(api_key, access_token) # Gets the holdings holdings = kite.holdings() # Example of holdings """holdings = [{'average_price': 153.1375, 'close_price': 129.35, 'collateral_quantity': 0, 'collateral_type': '', 'day_change': 0, 'day_change_percentage': 0, 'exchange': 'NSE', 'instrument_token': 54273, 'isin': 'INE208A01029', 'last_price': 129.35, 'pnl': -7611.999999999998, 'price': 0, 'product': 'CNC',
from kiteconnect import KiteConnect from kiteconnect import KiteTicker import pandas as pd import os import time from datetime import datetime import datetime import functions import Connection as con import sys kws = "" kite = "" cwd = os.chdir("F:/Final") #generate trading session access_token = open("access_token.txt", 'r').read() key_secret = open("api_key.txt", 'r').read().split() kite = KiteConnect(api_key=key_secret[0]) kite.set_access_token(access_token) kws = KiteTicker(key_secret[0], access_token) holdings = pd.DataFrame(kite.holdings()) # print(kite.holdings()) # print(holdings) # print(holdings['tradingsymbol'] == 'IDEA') print(holdings.loc[(holdings['tradingsymbol'] == 'IDEA') & ( holdings['isin'].isin(["INE669E01016"]))]["instrument_token"])