Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option modelGreeks is None #77

Open
hcleungca opened this issue Oct 4, 2024 · 3 comments
Open

Option modelGreeks is None #77

hcleungca opened this issue Oct 4, 2024 · 3 comments

Comments

@hcleungca
Copy link

Hi I'm new to ib_async

I'm trying to get the modelGreeks property of the SPY option, the codes I used is shown below

from ib_async import *

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=123)

ib.reqMarketDataType(3)

expiration_date = '20241115'
strike = 540
right = 'C'

contract = Option('SPY', expiration_date, strike, right, 'SMART', tradingClass='SPY')

contracts = ib.qualifyContracts(contract)

tickers = ib.reqTickers(*contracts)

ticker_idx = 0

print(tickers[ticker_idx])
print(tickers[ticker_idx].modelGreeks)
print(tickers[ticker_idx].bidGreeks)
print(tickers[ticker_idx].askGreeks)
print(tickers[ticker_idx].lastGreeks)

ib.disconnect()

the console output are

Ticker(contract=Option(conId=706885237, symbol='SPY', lastTradeDateOrContractMonth='20241115', strike=540.0, right='C', multiplier='100', exchange='SMART', currency='USD', localSymbol='SPY   241115C00540000', tradingClass='SPY'), time=datetime.datetime(2024, 10, 4, 3, 52, 20, 332739, tzinfo=datetime.timezone.utc), minTick=0.01, bid=-1.0, bidSize=0.0, ask=-1.0, askSize=0.0, close=37.34, halted=0.0, bboExchange='c70003')
None
None
None
None

All the greeks properties are None, did I do anything wrong? Please help, thank you very much

@mattsta
Copy link
Contributor

mattsta commented Oct 4, 2024

That's actually normal because each field is populated asynchronously, so sometimes it takes a couple seconds for all data to "appear" after being requested.

You could either wait longer before reading all the fields (be sure to read the intro docs about how time needs to work if you aren't using connectAsync() directly) or you could attach an event handler to check for updates and stop when you have enough data.

An event handler could look something like:

def checkTickerUpdates(tickers):
    for ticker in tickers:
        if ticker.modelGreeks:
            ... do something ...

ib.pendingTickersEvent += checkTickerUpdates

@hcleungca
Copy link
Author

Thanks for reply, I just tried the codes now when the market is open,
And I can get the results.

The None results are from yesterday when the market was closed,
Is the data unavailable if the market is closed?

Below is what I get today


Ticker(contract=Option(conId=706885237, symbol='SPY', lastTradeDateOrContractMonth='20241115', strike=540.0, right='C', multiplier='100', exchange='SMART', currency='USD', localSymbol='SPY   241115C00540000', tradingClass='SPY'), time=datetime.datetime(2024, 10, 4, 17, 49, 5, 142653, tzinfo=datetime.timezone.utc), minTick=0.01, bid=38.85, bidSize=10.0, bidExchange='N', ask=38.97, askSize=30.0, askExchange='N', last=38.01, lastSize=1.0, volume=10.0, high=39.02, low=38.01, close=36.92, halted=0.0, bidGreeks=OptionComputation(tickAttrib=0, impliedVol=0.21419604931197095, delta=0.812249392640076, optPrice=38.849998474121094, pvDividend=0.0, gamma=0.006510464209727961, vega=0.5543929671075318, theta=-0.1901612213707661, undPrice=571.1799926757812), askGreeks=OptionComputation(tickAttrib=0, impliedVol=0.21583111157083218, delta=0.8104971743676316, optPrice=38.970001220703125, pvDividend=0.0, gamma=0.006495591014640249, vega=0.5548763814456237, theta=-0.19175211343873672, undPrice=571.1799926757812), lastGreeks=OptionComputation(tickAttrib=0, impliedVol=0.21676224295909574, delta=0.8095110120973181, optPrice=38.0099983215332, pvDividend=0.0, gamma=0.006486980850975886, vega=0.5551469692866036, theta=-0.19265878251125385, undPrice=571.1799926757812), modelGreeks=OptionComputation(tickAttrib=0, impliedVol=0.21560477867723649, delta=0.8107381572295266, optPrice=38.71923442104989, pvDividend=0.0, gamma=0.006497668818987877, vega=0.5548100971756043, theta=-0.1915318020046982, undPrice=571.1799926757812), bboExchange='c70003', snapshotPermissions=3)
OptionComputation(tickAttrib=0, impliedVol=0.21560477867723649, delta=0.8107381572295266, optPrice=38.71923442104989, pvDividend=0.0, gamma=0.006497668818987877, vega=0.5548100971756043, theta=-0.1915318020046982, undPrice=571.1799926757812)
OptionComputation(tickAttrib=0, impliedVol=0.21419604931197095, delta=0.812249392640076, optPrice=38.849998474121094, pvDividend=0.0, gamma=0.006510464209727961, vega=0.5543929671075318, theta=-0.1901612213707661, undPrice=571.1799926757812)
OptionComputation(tickAttrib=0, impliedVol=0.21583111157083218, delta=0.8104971743676316, optPrice=38.970001220703125, pvDividend=0.0, gamma=0.006495591014640249, vega=0.5548763814456237, theta=-0.19175211343873672, undPrice=571.1799926757812)
OptionComputation(tickAttrib=0, impliedVol=0.21676224295909574, delta=0.8095110120973181, optPrice=38.0099983215332, pvDividend=0.0, gamma=0.006486980850975886, vega=0.5551469692866036, theta=-0.19265878251125385, undPrice=571.1799926757812)

@mattsta
Copy link
Contributor

mattsta commented Oct 4, 2024

I think their systems do respond to data requests faster during market hours (probably caching things), but it should at least return modelGreeks after hours as well. It usually returns bid/ask/last greeks after hours up until the next pre-market daily reset period (something like 15-30 minutes before next market open).

If you request even more detailed fields like histVolatility or impliedVolatility on instruments directly, sometimes those can take 10 to 30 seconds before the data begins populating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants