brndnmtthws / thetagang

ThetaGang is an IBKR bot for collecting money

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runtime error

wiselee978 opened this issue · comments

Hi,

I'm getting runtime error when I iexcute the thetagang application, Please check and help me to fix this issue. Do I need to make any config changes? I got Snapshot requests limitation exceeded:100 per 1 second(s), contract: Option(conId=449748871, symbol='SPY'.. in one of my log. Not sure if i need to limit the number of request per sec to IBKR through some settings.

Config:

Account details:
Number = DU*******
Cancel existing orders = True
Margin usage = 0.5 (50.0%)
Market data type = 1

Roll options when either condition is true:
Days to expiry <= 15 and P&L >= 0.0 (0.0%)
P&L >= 0.9 (90.0%)

Write options with targets of:
Days to expiry >= 45
Default delta <= 0.3
Maximum new contracts = 15
Minimum open interest = 10

Symbols:
SPY, weight = 0.4 (40.0%), delta = 0.3p, 0.3c
QQQ, weight = 0.3 (30.0%), delta = 0.5p, 0.3c
TLT, weight = 0.3 (30.0%), delta = 0.4p, 0.4c

Account summary:

Excess liquidity = 1000000.00
Net liquidation = 1000000.00
Cushion = 1 (100.0%)
Full maint margin = 0.00
Buying power = 4000000.00
Total cash value = 1000000.00

Portfolio positions:

Checking positions...

0 puts will be rolled
0 calls will be rolled

Total buying power: $500000 at 50.0% margin usage
Total value: $500000

SPY
Current position quantity 0
Target value $200000.0
Target quantity 511
Target additional quantity (excl. existing options) 511
QQQ
Current position quantity 0
Target value $150000.0
Target quantity 451
Target additional quantity (excl. existing options) 451
TLT
Current position quantity 0
Target value $150000.0
Target quantity 1033
Target additional quantity (excl. existing options) 1033

Preparing to write additional 5 puts to purchase SPY, capped at 15

Searching option chain for symbol=SPY right=P, this can take a while...

An exception was raised, exiting
Check log for details

2021-02-20 09:48:11,465 ib_insync.Watchdog INFO Starting
2021-02-20 09:48:11,466 ib_insync.IBC INFO Starting
2021-02-20 09:48:41,479 ib_insync.client INFO Connecting to 127.0.0.1:4002 with clientId 1...
2021-02-20 09:48:41,481 ib_insync.client INFO Connected
2021-02-20 09:48:41,571 ib_insync.client INFO Logged on to server version 152
2021-02-20 09:48:41,587 ib_insync.client INFO API connection ready
2021-02-20 09:48:41,612 ib_insync.wrapper INFO Warning 2158, reqId -1: Sec-def data farm connection is OK:secdefil
2021-02-20 09:48:42,675 ib_insync.ib INFO Synchronization complete
2021-02-20 09:48:43,078 ib_insync.wrapper INFO Warning 2119, reqId -1: Market data farm is connecting:usfarm
2021-02-20 09:48:43,713 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:usfarm
2021-02-20 09:49:33,012 ib_insync.wrapper ERROR Error 200, reqId 14: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210416', strike=352.5, right='P', exchange='SMART', tradingClass='SPY')
2021-02-20 09:49:33,017 ib_insync.wrapper ERROR Error 200, reqId 20: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210416', strike=357.5, right='P', exchange='SMART', tradingClass='SPY')

2021-02-20 09:49:37,943 ib_insync.wrapper ERROR Error 200, reqId 250: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210716', strike=382.5, right='P', exchange='SMART', tradingClass='SPY')
2021-02-20 09:49:37,944 ib_insync.wrapper ERROR Error 200, reqId 256: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210716', strike=387.5, right='P', exchange='SMART', tradingClass='SPY')
2021-02-20 09:49:38,225 ib_insync.ib ERROR Unknown contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210416', strike=352.5, right='P', exchange='SMART', tradingClass='SPY')
2021-02-20 09:49:38,225 ib_insync.ib ERROR Unknown contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210416', strike=357.5, right='P', exchange='SMART', tradingClass='SPY')
2021-02-20 09:49:38,226 ib_insync.ib ERROR Unknown contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20210416', strike=362.5, right='P', exchange='SMART', tradingClass='SPY')
2021-02-20 09:49:39,424 ib_insync.wrapper INFO Warning 2119, reqId -1: Market data farm is connecting:usopt
2021-02-20 09:49:39,613 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:usopt
2021-02-20 09:49:54,275 eventkit.event ERROR Value () caused exception for event Event<connectedEvent, [[None, None, <function start..onConnected at 0x7fb4338158b0>]]>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/eventkit/event.py", line 181, in emit
func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/thetagang/thetagang.py", line 113, in onConnected
portfolio_manager.manage()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/thetagang/portfolio_manager.py", line 271, in manage
self.check_if_can_write_puts(account_summary, portfolio_positions)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/thetagang/portfolio_manager.py", line 499, in check_if_can_write_puts
self.write_puts(symbol, puts_to_write)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/thetagang/portfolio_manager.py", line 390, in write_puts
sell_ticker = self.find_eligible_contracts(symbol, "P")
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/thetagang/portfolio_manager.py", line 673, in find_eligible_contracts
raise RuntimeError(f"No valid contracts found for {symbol}. Aborting.")
RuntimeError: No valid contracts found for SPY. Aborting.
2021-02-20 09:49:54,287 ib_insync.Watchdog INFO Stopping
2021-02-20 09:49:54,288 ib_insync.ib INFO Disconnecting from 127.0.0.1:4002, 35.4 kB sent in 475 messages, 599 kB received in 2424 messages, session time 103 s.
2021-02-20 09:49:54,288 ib_insync.client INFO Disconnecting
2021-02-20 09:49:54,291 ib_insync.client INFO Disconnected
2021-02-20 09:49:54,297 ib_insync.Watchdog WARNING Disconnected
2021-02-20 09:49:54,298 ib_insync.IBC INFO Terminating

What settings do you have for loading the option chains? The defaults are as such:

[option_chains]
# Number of expirations to load from option chains
expirations = 5
# Number of strikes to load from option chains
strikes = 50

Check that this is sufficient for your case. You need to set the values high enough that it will scan enough contracts to find one that matches your parameters. Try increasing the number of strikes first (try 75, then 100, etc). I wouldn't load more than 5 expirations unless you're doing something unusual (in fact, you could probably lower that to 3 expirations).

SPY has a lot of contracts, so you need to make sure you load enough of them. It will load the option chain according to your settings (code is here), and then load the market data for each contract to figure out delta and whatnot after the contracts have been scanned.

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 30 days.

This issue was closed because it has been stalled for 30 days with no activity.