Kotak-Neo / kotak-neo-api

96 stars 79 forks source link

unable to place order #166

Open Manoj250 opened 1 month ago

Manoj250 commented 1 month ago

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'}]}

nprejit commented 1 month ago

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)

saurabhguptarock commented 1 month ago

@nprejit still same error

Screenshot 2024-06-01 123531

nprejit commented 1 month ago

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

saurabhguptarock commented 1 month ago

prefixing with +91 also does not do anything

image

saurabhguptarock commented 1 month ago

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.

nprejit commented 1 month ago

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

nprejit commented 1 month ago

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 commented 1 month ago

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

3.9 and yes

adityaparakh1 commented 2 weeks ago

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)

nprejit commented 2 weeks ago

@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)