Request help - Code for Price Extraction from LTP response

aabhalerao
Hi,
Being new with Python (though pretty good at C) I am stuck as I am unable to extract the price value from the response received from kite.ltp

I use
>>> cmp=kite.ltp("NFO:NIFTY18JUNFUT")
>>> cmp
{'NFO:NIFTY18JUNFUT': {'instrument_token': 12374274, 'last_price': 10711.9}}

How do I (what code would do the job) extract the last_price value from this response into a float type variable say price?
so that i can use it like
if (price > 10000) etc.

I am facing same issue in extracting the Order Status from the Big Response received with

>>> kite.order_history(order_id=order_id)

Thanks in advance...
  • Man7630
    Hi, Please try below for getting LTP (last traded price)

    StockName1="NFO:NIFTY18JUNFUT"
    LTP=kite.ltp(StockName1).get(StockName1,"").get("last_price","")
    print (LTP)

  • aabhalerao
    Thanks a lot Man7630..
This discussion has been closed.