Open isapansoni opened 8 months ago
``from neo_api_client import NeoAPI from cred import * import requests from logger import Logger from datetime import datetime as dt, timedelta import math
logger = Logger(name)
class NeoAPIClient: def init(self , MobileNo , Password, ): self.consumer_key = consumer_key.strip() self.consumer_secret = consumer_secret.strip() self.environment = 'prod' self.client = None self.login(MobileNo, Password)
def on_message(self, message):
print(message)
def on_error(self, error_message):
print(error_message)
def login(self, mobilenumber, password):
self.client = NeoAPI(
consumer_key=self.consumer_key,
consumer_secret=self.consumer_secret,
environment=self.environment,
on_message=self.on_message,
on_error=self.on_error,
)
self.client.login(mobilenumber=mobilenumber, password=password)
otp = input("Enter OTP: ")
self.client.session_2fa(OTP=otp)
def run_websocket(self, inst_tokens):
ret = self.client.subscribe(instrument_tokens=inst_tokens , isIndex=True)
def get_master_scripts(self):
ret = self.client.scrip_master()
for url in ret['filesPaths']:
file_name = url.split("/")[-1]
if file_name in ['nse_cm.csv', 'nse_fo.csv']:
response = requests.get(url)
if response.status_code == 200:
with open(file_name, "wb") as file:
file.write(response.content)
logger.debug(f"Downloaded {file_name}")
else:
logger.error(f"Failed to download {file_name}")
pass
def get_orderbook(self):
return self.client.order_report()
def get_tradebook(self,str_param=None):
pass
def place_order(self,price:float,qty:int,bs:str,scripcode:int,triggerprc:float=0,ordertype:str="MIS",variety:str="REGULAR",validity:str="GFD"):
pass
#return success, order_id
def get_quote(self,inst_tokens):
return self.client.quotes(instrument_tokens=inst_tokens, quote_type="", isIndex=False)
if name == "main":
neo_client = NeoAPIClient(MobileNo=Mobile, Password=Pass)
inst_tokens = inst_tokens = [{"instrument_token": "11536", "exchange_segment": "nse_cm"},
{"instrument_token": "1594", "exchange_segment": "nse_cm"},
{"instrument_token": "11915", "exchange_segment": "nse_cm"},
{"instrument_token": "13245", "exchange_segment": "nse_cm"}]
#neo_client.get_master_scripts()
q = neo_client.get_quote(inst_tokens)
print(q)
I am getting error of web socket not supported with code I have shared
@Kotak-Neo can you please have a look ?
@Kotak-Neo please help
@isapansoni Kindly force reinstall the SDK once and check again if the issue persists.
this issue still persists Have you solved @isapansoni @Kotak-Neo
@chitrakshadusane just create your venv again , it should solve it Also I just discovered Dhan Apis they are very easy to deploy , no otp require to login and good support Kotak is not reliable
WebSocket not supported! Traceback (most recent call last): File "/Users/sapansoni/Desktop/my_codes/kotak/utils/KotakApi.py", line 123, in
q = neo_client.get_quote(inst_tokens)
File "/Users/sapansoni/Desktop/my_codes/kotak/utils/KotakApi.py", line 75, in get_quote
return self.client.quotes(instrument_tokens=inst_tokens, quote_type="", isIndex=False)
File "/Users/sapansoni/Desktop/my_codes/kotak/venv_neo/lib/python3.9/site-packages/neo_api_client/neo_api.py", line 594, in quotes
self.NeoWebSocket.get_quotes(instrument_tokens=instrument_tokens, quote_type=quote_type, isIndex=isIndex,
File "/Users/sapansoni/Desktop/my_codes/kotak/venv_neo/lib/python3.9/site-packages/neo_api_client/NeoWebSocket.py", line 201, in get_quotes
self.hsWebsocket.open_connection(neo_api_client.WEBSOCKET_URL, self.access_token, self.sid,
File "/Users/sapansoni/Desktop/my_codes/kotak/venv_neo/lib/python3.9/site-packages/neo_api_client/HSWebSocketLib.py", line 1170, in open_connection
StartServer(self.url, token, sid, self.onopen, self.onmessage, self.on_error, self.onclose)
File "/Users/sapansoni/Desktop/my_codes/kotak/venv_neo/lib/python3.9/site-packages/neo_api_client/HSWebSocketLib.py", line 1106, in init
if ws:
NameError: name 'ws' is not defined