Mapping between Cash instrument and it's derivatives

Hello,

How does one pickup derivative instruments (Futures and Options) of a cash/spot instrument?

Say, I want to know the futures of ADANIPORTS or say an Option on an NSE INDEX.

Since there is no common column between cash and F&O CSVs, (in terms of databases, a foreign key or a column on which we can join), there is no easy way to get this mapping. Let me know if I’m wrong (we shouldn’t be hardcoding instrument names all throughout the software - a very bad software design/practice).

Can Upstox revise the design of instrument master file to include a new column with base symbol name?

Something similar to what Aliceblue has done:

This will help join cash with F&O instrument master and get derivatives and also the reverse (spot instrument from it’s derivative).

Regards,
SRK

Thank you for your feedback; we acknowledge it as a legitimate need. We are currently enhancing the BOD file, and this issue will be addressed in coming releases.

Please make sure to have the “same name” for indices too.
This is one thing which almost every broker has got it wrong! Even Aliceblue!

Have raised another request there:

Specially on Indices as they have spaces and what not.

Let the “name” of an instrument have any fancy name, with spaces, full length name, etc.
But a “Symbol” column (or whatever you call it) should be able to identify all related instruments together.

Stirring up this thread as it is lacking any traction and seem dead after acknowledging the issue.

Upstox, we don’t have eternity to wait on small (but big on impact) issues. Please help fix this ASAP. Our software design “depends” on how Upstox is designing their instrument master.

In the absence of this common column that identifies an instrument and it’s derivatives (or vica-a-versa), below is what I’m doing - which again is adding complexity to the code and very prone to breakage if there are any changes.

Look at the below case:

To get the instrument for which a derivative belongs to, I’m doing this at the moment:

####### Extract only Index Futures from master instrument list:
records_of_interest = records_of_interest[ records_of_interest[‘instrument_type’]==index_futures ]
####### Using Regular Expression, extract the non-digit part from the start (^ anchoring)
records_of_interest[‘Symbol’] = records_of_interest[‘tradingsymbol’].str.extract(r’^([A-Za-z]+)')

So, this works with most of the symbols but “SENSEX50” which has digits in it’s name. :frowning:

Now, to add to the complexity, Upstox has variable number of characters representing Month (2 for Feb… until we go to Oct which is 10 - 2 digits):

So, how does one handle such conditions? using conditions - thus making the code complex and slow!!!
Something like;

  • Get the current month
  • If the month is less than Oct, use single digit or else use 2 digits in the code for month
  • Then parse the symbol to extract base instrument/symbol

And, it is not just one place that you put this in.
You have to keep adding this everywhere it is required or maintain a mapping.

Can we not have uniform 2 digits for month (02 for Feb, 05 for May, …) so the Regular Expression used can be straight and simple to read/understand and maintain?

If yes, please get this done ASAP. This is not a big breaking change. Or keep another file in parallel so migration for people is smooth. Also, please add base symbol column, so each “related” instrument can be identified in one go and simply!

Thanks!

The separate JSON instrument file has been made available. This new JSON file includes underlying details for futures and options, including the symbol, key, and type. Additionally, we have standardized the format of the trading symbol.

For more information, please visit: Instruments | Upstox Developer API

You can also view a Sample JSON Object for reference.

I hope you find this information useful.

1 Like

I’m really glad Upstox is listening! Thanks!! Cheers!!!

Below is the new instrument master:

Equities:

    {
        "segment": "NSE_EQ",
        "name": "RELIANCE INDUSTRIES LTD",
        "exchange": "NSE",
        "isin": "INE002A01018",
        "instrument_type": "EQ",
        "instrument_key": "NSE_EQ|INE002A01018",
        "lot_size": 1,
        "freeze_quantity": 100000.0,
        "exchange_token": "2885",
        "tick_size": 5.0,
        "trading_symbol": "RELIANCE",
        "short_name": "Reliance Industries",
        "security_type": "NORMAL"
    },

RELIANCE Monthly Future:

    {
        "weekly": false,
        "segment": "NSE_FO",
        "name": "RELIANCE INDUSTRIES LTD",
        "exchange": "NSE",
        "expiry": 1709231399000,
        "instrument_type": "FUT",
        "asset_symbol": "RELIANCE",
        "underlying_symbol": "RELIANCE",
        "instrument_key": "NSE_FO|71891",
        "lot_size": 250,
        "freeze_quantity": 10000.0,
        "exchange_token": "71891",
        "minimum_lot": 250,
        "asset_key": "NSE_EQ|INE002A01018",
        "underlying_key": "NSE_EQ|INE002A01018",
        "tick_size": 5.0,
        "asset_type": "EQUITY",
        "underlying_type": "EQUITY",
        "trading_symbol": "RELIANCE FUT 29 FEB 24",
        "strike_price": 0.0
    },

RELIANCE Monthly Option:

    {
        "weekly": false,
        "segment": "NSE_FO",
        "name": "RELIANCE INDUSTRIES LTD",
        "exchange": "NSE",
        "expiry": 1709231399000,
        "instrument_type": "CE",
        "asset_symbol": "RELIANCE",
        "underlying_symbol": "RELIANCE",
        "instrument_key": "NSE_FO|170873",
        "lot_size": 250,
        "freeze_quantity": 10000.0,
        "exchange_token": "170873",
        "minimum_lot": 250,
        "asset_key": "NSE_EQ|INE002A01018",
        "underlying_key": "NSE_EQ|INE002A01018",
        "tick_size": 5.0,
        "asset_type": "EQUITY",
        "underlying_type": "EQUITY",
        "trading_symbol": "RELIANCE 3360 CE 29 FEB 24",
        "strike_price": 3360.0
    },

BANKNIFTY Weekly:

    {
        "weekly": true,
        "segment": "NSE_FO",
        "name": "BANKNIFTY",
        "exchange": "NSE",
        "expiry": 1709749799000,
        "instrument_type": "CE",
        "asset_symbol": "BANKNIFTY",
        "underlying_symbol": "BANKNIFTY",
        "instrument_key": "NSE_FO|39161",
        "lot_size": 15,
        "freeze_quantity": 900.0,
        "exchange_token": "39161",
        "minimum_lot": 15,
        "asset_key": "NSE_INDEX|Nifty Bank",
        "underlying_key": "NSE_INDEX|Nifty Bank",
        "tick_size": 5.0,
        "asset_type": "INDEX",
        "underlying_type": "INDEX",
        "trading_symbol": "BANKNIFTY 45500 CE 06 MAR 24",
        "strike_price": 45500.0
    },

#1: --------------------------------------------------------------------------------------------------------

Looks like with the current design, we’ve to follow this pattern:

A:
To get derivatives from EQUITY, use EQUITY’s “trading_symbol” and look for derivative records where “underlying_symbol” == ''trading_symbol"

B:
To get Equity from derivatives, use “underlying_symbol”

Can this not be made simpler, where, “asset_symbol” for both equity and derivatives is same/common? Unless “asset_symbol” is solving some other purpose (I’m not sure what that is, hence Qn 4 below). With this, we group by “asset_symbol” and lookup either “segment” or “instrument_type” to know what that instrument is. I’m sure, the current design can be simplified further. Suggested or some other way.

#2: --------------------------------------------------------------------------------------------------------

Looks like below needs either some correction or documentation:

    "tick_size": 5.0

It is 5 paisa: 0.05. So, if the amount quoted is in basis points, it should be documented as such. There is no mention or this is a bug!

image

#3: --------------------------------------------------------------------------------------------------------

This is confusing: What does it even mean to have “minimum lot size” - min lot size is always 1. Isn’t it? And the name of field suggests the unit is “lot” and then the values surprise us with number of underlying equity. WOW! So that each one is always surprised - pretty cool!

    "minimum_lot": 15,
    "asset_key": "NSE_INDEX|Nifty Bank",
    "underlying_key": "NSE_INDEX|Nifty Bank",

isn’t “lot_size”: 15, already covering what “minimum_lot”: 15, is covering? Please explain!

#4: --------------------------------------------------------------------------------------------------------

What purpose are the below groups of two fields solving? Kindly help us understand the different ways it can be used: “asset_type”, “asset_key”, “asset_symbol”

    "asset_type": "INDEX",
    "underlying_type": "INDEX",

    "asset_key": "NSE_INDEX|Nifty Bank",
    "underlying_key": "NSE_INDEX|Nifty Bank",

    "asset_symbol": "BANKNIFTY",
    "underlying_symbol": "BANKNIFTY",

#5: --------------------------------------------------------------------------------------------------------

“asset_type” of a derivatives instrument is “EQUITY”. Should it be “DERIVATIVES” or “EQUITY_DERIVATIVES” ? Reason being: “underlying_type” already is specifying it is “EQUITY”

::::
::::
“underlying_key”: “NSE_EQ|INE101A01026”,
“tick_size”: 5.0,
“asset_type”: “EQUITY”,
“underlying_type”: “EQUITY”,
“trading_symbol”: “M&M 1520 CE 29 FEB 24”,
“strike_price”: 1520.0
},

Similarly, “DERIVATIVES”" or “INDEX_DERIVATIVES” for Indices:

    "asset_type": "INDEX",                                                  "asset_type": "INDEX",
    "underlying_type": "INDEX",                                             "underlying_type": "INDEX",
    "trading_symbol": "BANKNIFTY 49600 PE 29 FEB 24",                       "trading_symbol": "BANKNIFTY 54000 CE 20 MAR 24",
    "strike_price": 49600.0                                                 "strike_price": 54000.0
},                                                                      },