Kotak-Neo / kotak-neo-api

96 stars 80 forks source link

All the token symbol are not pulling the ltp. #155

Open IshwariSaraogi opened 3 months ago

IshwariSaraogi commented 3 months ago

My script for 'datafeed' is below:

from neo_api_client import NeoAPI import xlwings as xw import pandas as pd from threading import Thread import pyotp import numpy as np from openpyxl import Workbook

wb = xw.Book('KotakNeoDataFeed.xlsm') credential = wb.sheets('credential') kotakneologinid = credential.range('b1').value kotakneopassword = credential.range('b2').value kotakneoapikey = credential.range('b3').value kotakneoSecretKey = credential.range('b4').value kotakneompin = int(credential.range('b5').value)

live_data = {} def on_message(message): global live_data try: print(f"message : {message}") for i in message: live_data[i['ts']] = i['ltp'] except Exception as e: print(f"Error {e}")

def on_error(error_message): print(error_message) client = NeoAPI(consumer_key=kotakneoapikey, consumer_secret=kotakneoSecretKey, environment='prod', on_message=on_message, on_error=on_error, on_close=None, on_open=None) client.login(mobilenumber=kotakneologinid, password=kotakneopassword) client.session_2fa(OTP=kotakneompin)

cashnseUrl = client.scrip_master(exchange_segment= "nse_cm") cashbserUrl = client.scrip_master(exchange_segment= "bse_cm")

livefeed = wb.sheets('livefeed')

exchange = livefeed.range('b2:b51').value

token = livefeed.range('d2:d51').value

token = [str(int(num)) for num in token if isinstance(num, float) or isinstance(num, int)]

print (exchange, token)

inst_tokens = [{"instrument_token": token[g], "exchange_segment": exchange[g]} for g in range(50)]

inst_tokens

while True: try: quote = client.quotes(instrument_tokens=inst_tokens, quote_type="ltp") quotes_list.append(quote) print(quote['message'][0]['ltp'])

ltp_values_formatted = [[value] for value in quotes_list]

    # livefeed.range('e2:e51').options(transpose=True).value = ltp_values_formatted

except Exception as e:
    print("Exception when calling get Quote api->quotes: %s\n" % e)
    break  # Exit the loop if an exception occurs

HELP Required - Above code is not pulling all the ltp for the symbols stored in inst_token. It is skipping some of the symbols.

inst_token symbol request -

[{'instrument_token': '2885', 'exchange_segment': 'nse_cm'}, {'instrument_token': '6663', 'exchange_segment': 'nse_cm'}, {'instrument_token': '501421', 'exchange_segment': 'bse_cm'}, {'instrument_token': '11149', 'exchange_segment': 'nse_cm'}, {'instrument_token': '3126', 'exchange_segment': 'nse_cm'}, {'instrument_token': '524204', 'exchange_segment': 'bse_cm'}, {'instrument_token': '17186', 'exchange_segment': 'nse_cm'}, {'instrument_token': '4306', 'exchange_segment': 'nse_cm'}, {'instrument_token': '7200', 'exchange_segment': 'nse_cm'}, {'instrument_token': '17684', 'exchange_segment': 'nse_cm'}, {'instrument_token': '6451', 'exchange_segment': 'nse_cm'}, {'instrument_token': '10192', 'exchange_segment': 'nse_cm'}, {'instrument_token': '4693', 'exchange_segment': 'nse_cm'}, {'instrument_token': '13740', 'exchange_segment': 'nse_cm'}, {'instrument_token': '19440', 'exchange_segment': 'nse_cm'}, {'instrument_token': '3148', 'exchange_segment': 'nse_cm'}, {'instrument_token': '3150', 'exchange_segment': 'nse_cm'}, {'instrument_token': '6663', 'exchange_segment': 'nse_cm'}, {'instrument_token': '4522', 'exchange_segment': 'nse_cm'}, {'instrument_token': '16658', 'exchange_segment': 'nse_cm'}, {'instrument_token': '18743', 'exchange_segment': 'nse_cm'}, {'instrument_token': '22656', 'exchange_segment': 'nse_cm'}, {'instrument_token': '6226', 'exchange_segment': 'nse_cm'}, {'instrument_token': '11297', 'exchange_segment': 'nse_cm'}, {'instrument_token': '15094', 'exchange_segment': 'nse_cm'}, {'instrument_token': '2495', 'exchange_segment': 'nse_cm'}, {'instrument_token': '4105', 'exchange_segment': 'nse_cm'}, {'instrument_token': '19097', 'exchange_segment': 'nse_cm'}, {'instrument_token': '8003', 'exchange_segment': 'nse_cm'}, {'instrument_token': '10761', 'exchange_segment': 'nse_cm'}, {'instrument_token': '8080', 'exchange_segment': 'nse_cm'}, {'instrument_token': '15085', 'exchange_segment': 'nse_cm'}, {'instrument_token': '7942', 'exchange_segment': 'nse_cm'}, {'instrument_token': '8238', 'exchange_segment': 'nse_cm'}, {'instrument_token': '9422', 'exchange_segment': 'nse_cm'}, {'instrument_token': '16777', 'exchange_segment': 'nse_cm'}, {'instrument_token': '14612', 'exchange_segment': 'nse_cm'}, {'instrument_token': '9331', 'exchange_segment': 'nse_cm'}, {'instrument_token': '16859', 'exchange_segment': 'nse_cm'}, {'instrument_token': '381', 'exchange_segment': 'nse_cm'}, {'instrument_token': '11050', 'exchange_segment': 'nse_cm'}, {'instrument_token': '21501', 'exchange_segment': 'nse_cm'}, {'instrument_token': '14001', 'exchange_segment': 'nse_cm'}, {'instrument_token': '14096', 'exchange_segment': 'nse_cm'}, {'instrument_token': '20542', 'exchange_segment': 'nse_cm'}, {'instrument_token': '6643', 'exchange_segment': 'nse_cm'}, {'instrument_token': '18883', 'exchange_segment': 'nse_cm'}, {'instrument_token': '3186', 'exchange_segment': 'nse_cm'}, {'instrument_token': '15232', 'exchange_segment': 'nse_cm'}, {'instrument_token': '9428', 'exchange_segment': 'nse_cm'}]

Above scrip is not producing ltp for all the above symbols. It skips for some symbols.

Please help

shamdhage commented 3 months ago

I'm also facing same issue. I also noticed that on the console the actual response values are displayed after some time. There seems to be some delay.

crypt0inf0 commented 3 months ago

Use webSocket instead of client.quotes but the websocket connection will be disconnected after few minutes. I think the latest release fixed it on v1.2.1 but I don't know.

dev3180 commented 3 weeks ago

kotak neo trading api is west of time and money, angel one is much batter for algo trading