How to get multiple instrument/field rights in get_data() [Python]

I am trying to get open interest and implied volatility for a few options as a time series, but it seems like I can only access OI&IV through get_data instead of time_series.


instruments = ['TKMB700K1', 'TKMB800W1']

df_, _ = ek.get_data(
instruments = [instrument],
fields = [f'TR.OPENINTEREST(Frq=D,SDate=2019-01-01,EDate=2021-01-01).Timestamp',
f'TR.OPENINTEREST(Frq=D,SDate=2019-01-01,EDate=2021-01-01).Value']
)

It works if I get the data for each instrument separately, but it doesn't give the right dataframe back if I send a list of different instruments.

I also tried to add [f'TR.IMPLIEDVOLATILITY(Frq=D,SDate=2019-01-01,EDate=2021-01-01).Timestamp',
f'TR.IMPLIEDVOLATILITY(Frq=D,SDate=2019-01-01,EDate=2021-01-01).Value'] into the field list and again that doesn't work.


I am very new to this API and would like to have some guidance in terms of how to proceed with this. Thanks!

Best Answer

  • @bgner So the code below does work - i could not find the instruments you tried - are they valid RICs? I tried this for the crude oil future and it returns open interest (obviously IV is only for options so it returns nothing for a future). There is no need to add parameters to each field - you can add them once at the end to apply to all fields.

    instruments = ['CLc1','CLc2']
    fields = ['TR.OPENINTEREST.timestamp','TR.OPENINTEREST','TR.IMPLIEDVOLATILITY']

    df, err = ek.get_data(instruments,fields,
    parameters={'SDate':'2019-01-01',
    'EDate':'2021-01-01',
    'Frq':'D'})

    df

    1634314494207.png

    I hope this can help.