Kotak-Neo / kotak-neo-api

100 stars 86 forks source link

Accessing REST API and login flow in Java #69

Closed prasadraju070 closed 9 months ago

prasadraju070 commented 9 months ago

Hi please any one could provide working coded in java for login and accessing websocket for bank nifty index. I am totally new to python

geek-coder commented 9 months ago

Hi Prasad,

These are not REST APIs at all, even in python. That's reason for all mess. It works well once, i.e just subscribe and receive updates. If you make call to any other API, you will see random behaviours. Specifically with quotes/un_subscribe after a subscribe is in progress.

prasadraju070 commented 9 months ago

Ok can u please provide login code in python and save the session for the whole day. From there I could pick up . Please do needful. Thank you bro

darshil-lakhani commented 9 months ago

Ok can u please provide login code in python and save the session for the whole day. From there I could pick up . Please do needful. Thank you bro

Login Code

from neo_api_client import NeoAPI
client = NeoAPI(consumer_key="", consumer_secret="", 
                environment='prod', on_message=on_message, on_error=on_error, on_close=None, on_open=None)
client.login(mobilenumber="+919999999999", password="XXXX")
client.session_2fa(OTP="")

Currently there are some caveats regarding reusing the session, I have created a PR #67 which solves this issue, you can check that and continue from there.

geek-coder commented 9 months ago

Hi, I directly pickle configuration and reuse it. This works with existing codebase. First create venv and do pip install yaml pickle sys

Attaching code

sample prog for live streaming of bank nifty index with reuse of session.

  1. install above packages using pip install
  2. store credentials in credKotak.yml
  3. For first time during day you would receive TOTP prompt, enter totp
  4. Now you can do ctrl C and start again , streaming will start without asking any totp.

You can rename initKotak.txt to initKotak.py after download. Will create PR later . Please do comment if any issues.

credKotak.txt

initKotak.txt

ashxos commented 9 months ago

Getting error in 2nd run

Code: client = getApi() print("client**",client) data=client.positions() print(data) data= client.holdings() print(data)

output:

Returning a set session client** <neo_api_client.neo_api.NeoAPI object at 0x00000298DD3309D0> {'error': [{'code': '91010', 'message': 'Service error'}]} {'error': [{'code': '10020', 'message': 'Authentication Failed'}]}

geek-coder commented 9 months ago

subscribe will work, check orignal program.