Placing Order Shows error

sb1314
sb1314 edited September 2019 in API clients
in my code i given header value perfact all other order related code are working excpeted when i place order kindly sovle it

elseif Request.QueryString("out") = "0" then

data = "exchange=NFO&tradingsymbol=NIFTY1991911200CE&transaction_type=SELL&order_type=MARKET&price=64.0000m&quantity=75&product=NRML&variety=regular&validity=DAY&trigger_price=0"

UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular/?" & data,"POST","data","Yes")

Function UrlReturnVal(Url,Method,PostData,HeadReq)

Dim httpRequest, postResponse

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open Method, Url, False

if HeadReq="Yes" then
httpRequest.SetRequestHeader "X-Kite-Version", "3"
httpRequest.SetRequestHeader "Authorization", "token zfu63d25sfgjhlx4123lhi:bq8F9HaVFebKuTbHSIJsD3h7crFJ985095asY4PE"
end if

if Method = "POST" Then
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send PostData
else
httpRequest.Send
end if

postResponse = httpRequest.ResponseText

UrlReturnVal= postResponse

End Function

output

{"status":"error","message":"Invalid `api_key` or `access_token`.","data":null,"error_type":"InputException"}


this order code is working

elseif Request.QueryString("out") = "L" then

UrlPrint=UrlReturnVal("https://api.kite.trade/orders","GET","","Yes")

output

{"status":"success","data":[{"average_price": 0, "cancelled_quantity": 0, "disclosed_quantity": 0, "exchange": "NFO", "exchange_order_id": null, "exchange_timestamp": null, "exchange_update_timestamp": null, "filled_quantity": 0, "guid": "01XLD7KjVXhRBpE", "instrument_token": 11382018, "market_protection": 0, "order_id": "190917000481005", "order_timestamp": "2019-09-17 09:39:19", "order_type": "MARKET", "parent_order_id": null, "pending_quantity": 0, "placed_by": "SB1314", "price": 0, "product": "NRML", "quantity": 75, "status": "REJECTED", "status_message": "Insufficient funds. Required margin is 93671.60 but available margin is 0.00.", "status_message_raw": "RMS:Margin Exceeds,Required:93671.60, Available:0.00 for entity account-SB1314 across exchange across segment across product ", "tag": null, "tradingsymbol": "NIFTY19SEPFUT", "transaction_type": "BUY", "trigger_price": 0, "validity": "DAY", "variety": "regular"},{"average_price": 0, "cancelled_quantity": 0, "disclosed_quantity": 0, "exchange": "NFO", "exchange_order_id": null, "exchange_timestamp": null, "exchange_update_timestamp": null, "filled_quantity": 0, "guid": "01XFj16HIy76sAB", "instrument_token": 11382018, "market_protection": 0, "order_id": "190917000570446", "order_timestamp": "2019-09-17 09:46:33", "order_type": "MARKET", "parent_order_id": null, "pending_quantity": 0, "placed_by": "SB1314", "price": 0, "product": "NRML", "quantity": 75, "status": "REJECTED", "status_message": "Insufficient funds. Required margin is 93034.57 but available margin is 0.00.", "status_message_raw": "RMS:Margin Exceeds,Required:93034.57, Available:0.00 for entity account-SB1314 across exchange across segment across product ", "tag": null, "tradingsymbol": "NIFTY19SEPFUT", "transaction_type": "SELL", "trigger_price": 0, "validity": "DAY", "variety": "regular"},{"average_price": 0, "cancelled_quantity": 0, "disclosed_quantity": 0, "exchange": "NFO", "exchange_order_id": null, "exchange_timestamp": null, "exchange_update_timestamp": null, "filled_quantity": 0, "guid": "01XL202uTEU1Kos", "instrument_token": 11190018, "market_protection": 0, "order_id": "190917000580905", "order_timestamp": "2019-09-17 09:47:20", "order_type": "MARKET", "parent_order_id": null, "pending_quantity": 0, "placed_by": "SB1314", "price": 0, "product": "NRML", "quantity": 75, "status": "REJECTED", "status_message": "Insufficient funds. Required margin is 92946.64 but available margin is 0.00.", "status_message_raw": "RMS:Margin Exceeds,Required:92946.64, Available:0.00 for entity account-SB1314 across exchange across segment across product ", "tag": null, "tradingsymbol": "NIFTY1991911000CE", "transaction_type": "SELL", "trigger_price": 0, "validity": "DAY", "variety": "regular"},{"average_price": 0, "cancelled_quantity": 0, "disclosed_quantity": 0, "exchange": "NFO", "exchange_order_id": null, "exchange_timestamp": null, "exchange_update_timestamp": null, "filled_quantity": 0, "guid": "01XTVn00Be52vUy", "instrument_token": 11190018, "market_protection": 0, "order_id": "190917000584627", "order_timestamp": "2019-09-17 09:47:38", "order_type": "MARKET", "parent_order_id": null, "pending_quantity": 0, "placed_by": "SB1314", "price": 0, "product": "NRML", "quantity": 75, "status": "REJECTED", "status_message": "Insufficient funds. Required margin is 3371.59 but available margin is 0.00.", "status_message_raw": "RMS:Margin Exceeds,Required:3371.59, Available:0.00 for entity account-SB1314 across exchange across segment across product ", "tag": null, "tradingsymbol": "NIFTY1991911000CE", "transaction_type": "BUY", "trigger_price": 0, "validity": "DAY", "variety": "regular"}]}
  • sujith
    Please refrain from posting app and client-specific data on the public threads.
    The 64.0000m is a .NET notation, api doesn't understand this.

    Another thing is Zerodha doesn't allow market orders for options. You need to place a limit order with the LTP to fire market order.
  • sb1314
    same error after given limit order with price also

    data = "tradingsymbol=ACC&exchange=NSE&transaction_type=BUY&order_type=LIMIT&quantity=1&product=NRML&validity=DAY&price=64.23&variety=regular"

    UrlPrint=UrlReturnVal("https://api.kite.trade/orders/regular/?" & data,"POST","data","Yes")

    {"status":"error","message":"Invalid `api_key` or `access_token`.","data":null,"error_type":"InputException"}
  • sb1314
    same error for all type of order kindly resolve it
  • sujith
    You seem to be not sending a wrong header. You need to send authorization key for every request. You can know more from the documentation.
  • sb1314
    I send authorization for each request check my code proper
  • ZI4453
    shared your token too ?
  • sb1314
    today also same error I shared my token below kindly check it

    httpRequest.SetRequestHeader "X-Kite-Version", "3"
    httpRequest.SetRequestHeader "Authorization", "token zfu63d25jhlx4lhi:n61aeURzB6307D471WHQBpMKwrr3Lyh0"

    error

    {"status":"error","message":"Invalid `api_key` or `access_token`.","data":null,"error_type":"InputException"}
    out=0
  • ZI4453
    that was meant as an exclamation , please remove your token .. Its not supposed to be shared in public forum
  • sb1314
    today also same error I shared my token below kindly check it

    httpRequest.SetRequestHeader "X-Kite-Version", "3"
    httpRequest.SetRequestHeader "Authorization", "token zfu63d25jhlx4lhi:n61aeURzB6307D471WHQBpMKwrr3Lyh0"

    error

    {"status":"error","message":"Invalid `api_key` or `access_token`.","data":null,"error_type":"InputException"}
    out=0

    expect buy and sell order all other working
  • HowUTrade
    @sb1314

    Your are sending wrong authorization header.

    It should be
    ApiKey = "your-api-key"
    Token = "your-access-token"
    httpRequest.SetRequestHeader "Authorization", "token " & ApiKey & ":" & Token
  • sb1314
    sb1314 edited September 2019
    I already set same check above codes
    12.jpg 262.5K
  • sb1314
    sb1314 edited September 2019
    httpRequest.SetRequestHeader "Authorization", "token zfu63d25jhlx4lhi:n61aeURzB6307D471WHQBpMKwrr3Lyh0"

    my present token is n61aeURzB6307D471WHQBpMKwrr3Lyh0

    kindly solve it
  • ZI4453
    try this please,
    httpRequest.SetRequestHeader "X-Kite-Version", "3"
    httpRequest.SetRequestHeader "Authorization","zfu63d25jhlx4lhi:n61aeURzB6307D471WHQBpMKwrr3Lyh0"

    Note- You are not supposed post your tokens here... i just edited your codes and posted it..
  • sb1314
    ur not understand im using this tokens only I just copied above for your knowledge kindly solve error

    httpRequest.SetRequestHeader "X-Kite-Version", "3"
    httpRequest.SetRequestHeader "Authorization","zfu63d25jhlx4lhi:n61aeURzB6307D471WHQBpMKwrr3Lyh0"
  • sb1314
    kindly come to remote
  • sb1314
    sb1314 edited September 2019
    I solved this issues my self url in this request ends with / so token not works
This discussion has been closed.