'segment' / 'instrument_type' in positions API

mlearner

kite.positions () API JSON response has only 'exchange' info. Any reason why 'segment' or 'instrument_type' are excluded in this API response?

Sample position API response -

{'tradingsymbol': 'NIFTY21JUN15400CE', 'exchange': 'NFO', 'instrument_token': 13142530, 'product': 'MIS', 'quantity': 0, 'overnight_quantity': 0, 'multiplier': 1, 'average_price': 0, 'close_price': 0, 'last_price': 246, 'value': -4365, 'pnl': -4365, 'm2m': -4365, 'unrealised': -4365, 'realised': 0, 'buy_quantity': 225, 'buy_price': 238.26666666666668, 'buy_value': 53610, 'buy_m2m': 53610, 'sell_quantity': 225, 'sell_price': 218.86666666666667, 'sell_value': 49245, 'sell_m2m': 49245, 'day_buy_quantity': 225, 'day_buy_price': 238.26666666666668, 'day_buy_value': 53610, 'day_sell_quantity': 225, 'day_sell_price': 218.86666666666667, 'day_sell_value': 49245}

Becomes difficult to segregate NFO-OPT from NFO-FUT in positions response unless we do string based filtering on 'tradingsymbol' like if it contains 'FUT' then segment is NFO-FUT, or if it contains 'PE' or 'CE', segment is NFO-OPT. This can be error prone.
  • mlearner
    And similarly, kite.orders() also has 'segment' / 'instrument_type' missing in its response, only has 'exchange' which is common for both FUT / OPT -

    {'placed_by': 'XI2093', 'order_id': '210621000898374', 'exchange_order_id': '1000000010640841', 'parent_order_id': None, 'status': 'COMPLETE', 'status_message': None, 'status_message_raw': None, 'order_timestamp': datetime.datetime(2021, 6, 21, 9, 35), 'exchange_update_timestamp': '2021-06-21 09:35:00', 'exchange_timestamp': datetime.datetime(2021, 6, 21, 9, 35), 'variety': 'regular', 'exchange': 'NFO', 'tradingsymbol': 'NIFTY21JUN15500PE', 'instrument_token': 11648258, 'order_type': 'MARKET', 'transaction_type': 'SELL', 'validity': 'DAY', 'product': 'MIS', 'quantity': 225, 'disclosed_quantity': 0, 'price': 0, 'trigger_price': 0, 'average_price': 85.73333333000001, 'filled_quantity': 225, 'pending_quantity': 0, 'cancelled_quantity': 0, 'market_protection': 0, 'meta': {}, 'tag': None, 'guid': '20673XCqdP9qwkhhEm'}
  • mlearner
    Any input on this?
  • rakeshr
    kite.positions () API JSON response has only 'exchange' info. Any reason why 'segment' or 'instrument_type' are excluded in this API response?
    And similarly, kite.orders() also has 'segment' / 'instrument_type' missing in its response, only has 'exchange' which is common for both FUT / OPT
    As these fields are not required while order placement on exchange. So, we don't show it in all order-related places.
  • mlearner
    Becomes difficult to segregate NFO-OPT from NFO-FUT in positions response unless we do string based filtering on 'tradingsymbol' like if it contains 'FUT' then segment is NFO-FUT, or if it contains 'PE' or 'CE', segment is NFO-OPT. This can be error prone.
    @rakeshr - Can you please reply on this too? Do you have any suggestions/input on segregating FUT & OPT instruments apart from string based search.
  • sujith
    How is it error-prone? a future instrument will not end with PE or CE and vice versa.
  • tahseen
    tahseen edited July 2021
    @mlearner

    create map for your comfort using the instruments files, which you can download at 8:45am

    Like below

    df = pd.read_csv("all_instruments", low_memory = False)
    my_instrument_type = dict( zip( df.instrument_token, df.instrument_type ) )
    my_segment = dict( zip( df.instrument_token, df.segment ) )

    # Now initialise df to None to flush the RAM else dataframe would consume RAM
    df = None

    instrument_type = my_instrument_type[ json_data[ 'instrument_token' ] ]
    segment = my_segment[ json_data[ 'instrument_token' ] ]
    You can even update your JSON with segment and instrument_type now
Sign In or Register to comment.