Kotak-Neo / kotak-neo-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to place order

Manoj250 opened this issue · comments

I'm getting {'code': '10020', 'message': 'Authentication Failed'} for place order . Please help.

code :

client = NeoAPI(
    consumer_key="",
    consumer_secret="",
    environment="prod",
    access_token="",
    neo_fin_key="neotradeapi",
)
client.login(mobilenumber="+91", mpin="")
otp = input("enter otp: ")
client.session_2fa(OTP=otp)

try:
    od = client.place_order(exchange_segment="nse_cm", product="CNC", price="0", order_type="MKT", quantity="1", validity="DAY", trading_symbol="SBIN-EQ",
                       transaction_type="B", amo="YES", disclosed_quantity="0", market_protection="0", pf="N",
                       trigger_price="0", tag=None)
    print(od)
except Exception as e:
    print("Exception when calling OrderApi->place_order: %s\n" % e)

below place order also fails:

client.place_order(exchange_segment="nse_fo", product="NRML", price="0", order_type="MKT", quantity="15", validity="DAY", trading_symbol="BANKNIFTY2451547500CE", transaction_type="B", amo="YES", disclosed_quantity="0", market_protection="0", pf="N", trigger_price="0", tag=None)

response:
{'stat': 'Not_Ok', 'error': [{'code': '10020', 'message': 'Authentication Failed'}]}

try this format.
install latest version api, no need of neo_fin_key, pass none or leave it, and no need to pass access_token, leave this none or dont pass,
client login by mobile number and your trading platform password (NOT api login password)
2fa can validate by giving OTP or MPIN (both are valid)

consumer_key = ""
secret_key = ""
mobile_number = "+91"
login_password = ""

client = NeoAPI(consumer_key= consumer_key,consumer_secret=secret_key,environment="prod")
client.login(mobilenumber= mobile_number, password=login_password)

otp = input("enter otp: ")
client.session_2fa(OTP=otp)

@nprejit still same error

Screenshot 2024-06-01 123531

@saurabhguptarock
mobile number with prefix +91
ex. "+919876543210"
show me the error

prefixing with +91 also does not do anything

image

I am using the latest version of SDK, which was just updated, also I have tried using the API password and NEO web password both are not working.

@saurabhguptarock
which python version u are using?
is this order placing response?

image
image

here is my response, working.
please check rid and sid value should be match, on both login response and otp valdation, if not authentication not done correctly.

@saurabhguptarock which python version u are using? is this order placing response?

3.9 and yes

Same Issue,
How were you able to resolve it ?

I am able to login fine / get instrument files / get quotes via socket - all fine
But when placing the order

{'stat': 'Not_Ok', 'error': [{'code': '10020', 'message': 'Authentication Failed'}]}

  1. Tried both the passwords - API Portal and Trading
  2. Have to use PAN , as my mobile is associated with two accounts
  3. Use the Default PIN , instead of OTP

client = NeoAPI(consumer_key=consumer_key,consumer_secret=consumer_secret,environment="prod")
client.login(pan="dddd", password="ddddd")
client.session_2fa("123456")

try:
# Place a Order
a = client.place_order(exchange_segment="nse_fo", product="NRML",price="0", order_type="MKT", quantity="20", validity="DAY", trading_symbol="SENSEX2461476800CE",
transaction_type="B", amo="NO", disclosed_quantity="0", market_protection="0", pf="N",
trigger_price="0", tag=None)
print(a)
except Exception as e:
print("Exception when calling OrderApi->place_order: %s\n" % e)

@adityaparakh1

Same Issue, How were you able to resolve it ?

I am able to login fine / get instrument files / get quotes via socket - all fine But when placing the order

{'stat': 'Not_Ok', 'error': [{'code': '10020', 'message': 'Authentication Failed'}]}

  1. Tried both the passwords - API Portal and Trading
  2. Have to use PAN , as my mobile is associated with two accounts
  3. Use the Default PIN , instead of OTP

client = NeoAPI(consumer_key=consumer_key,consumer_secret=consumer_secret,environment="prod") client.login(pan="dddd", password="ddddd") client.session_2fa("123456")

try: # Place a Order a = client.place_order(exchange_segment="nse_fo", product="NRML",price="0", order_type="MKT", quantity="20", validity="DAY", trading_symbol="SENSEX2461476800CE", transaction_type="B", amo="NO", disclosed_quantity="0", market_protection="0", pf="N", trigger_price="0", tag=None) print(a) except Exception as e: print("Exception when calling OrderApi->place_order: %s\n" % e)

Hi,
please download latest neo api from github. no need to install it , just extract the file and place "neo_api_client" folder, where you run the code from, (you can find this folder inside the extracted "kotak-neo-api-main" folder.
in place order code you are using sensex to trade, so you have to use "bse_fo" as exchange_segment. Rest your code looks good.👍
use trading login password, dont use api portal password.
try this also, use the below code to accept otp from user

otp=input("Enter Kotak OTP: ")
client.session_2fa(otp)

and try with otp (here you can give both otp received on mobile or MPIN)

Im having the same issue, even though my sid and rid are matching for login and 2fa.
I am trying:

client.place_order(exchange_segment="nse_fo", product="NRML", price="0", order_type="MKT", quantity="15", validity="DAY", trading_symbol="BANKNIFTY2451547500CE", transaction_type="B", amo="YES", disclosed_quantity="0", market_protection="0", pf="N", trigger_price="0", tag=None)

as from working example. But i get :

{'stat': 'Not_Ok', 'error': [{'code': '10020', 'message': 'Authentication Failed'}], 'tid': 'server3_1792187'}

show me ur login process code

show me ur login process code
login failed

fairly simple, from all the examples ive seen. Using pan as login because multiple accounts... I copy the generated otp and enter it manually.

client login pass only pan and password (NOT API LOGIN PASSWORD, PASSWORD OF YOUR TRADING LOGIN)
client.login(pan="dddd", password="ddddd")

AND GIVE MPIN AS 2FA (otp also work)
client.session_2fa("123456")

before this check you are using latest version of kotak API else update to latest kotak api from github

use latest symbol.
"BANKNIFTY2451547500CE" has expired,
this can also throw an error

client login pass only pan and password (NOT API LOGIN PASSWORD, PASSWORD OF YOUR TRADING LOGIN) client.login(pan="dddd", password="ddddd")

AND GIVE MPIN AS 2FA (otp also work) client.session_2fa("123456")

before this check you are using latest version of kotak API else update to latest kotak api from github

This seems to have been the problem nd it seems to be working now! tysm!

I changed my password and it started working. Thanks everyone for the help