brndnmtthws / thetagang

ThetaGang is an IBKR bot for collecting money
GNU Affero General Public License v3.0
2k stars 266 forks source link

ValueError: cannot convert float NaN to integer #228

Closed cjian0001 closed 9 months ago

cjian0001 commented 1 year ago

so boss, here is what i got, how to fix

2022-12-17 09:59:16,079 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:usfarm 2022-12-17 10:01:25,149 eventkit.event ERROR Value () caused exception for event Event<connectedEvent, [[None, None, <function start..onConnected at 0x7f905169fac0>]]> Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/eventkit/event.py", line 198, in emit result = func(*args) File "/usr/local/lib/python3.10/dist-packages/thetagang/thetagang.py", line 172, in onConnected portfolio_manager.manage() File "/usr/local/lib/python3.10/dist-packages/thetagang/portfolio_manager.py", line 460, in manage self.check_if_can_write_puts(account_summary, portfolio_positions) File "/usr/local/lib/python3.10/dist-packages/thetagang/portfolio_manager.py", line 762, in check_if_can_write_puts target_quantity = math.floor(targets[symbol] / ticker.marketPrice()) ValueError: cannot convert float NaN to integer 2022-12-17 10:01:25,152 ib_insync.Watchdog INFO Stopping 2022-12-17 10:01:25,153 ib_insync.ib INFO Disconnecting from 127.0.0.1:7497, 928 B sent in 16 messages, 84.5 kB received in 1756 messages, session time 163 s.

brndnmtthws commented 1 year ago

There's either no market price available for the ticker you specified, or you didn't supply a valid target weight.

cjian0001 commented 1 year ago

thanks boss,i'll try it again on monday ;)

cjian0001 commented 1 year ago

so boss, here is what i have changed, and im sure i have the market data " cancel_orders = true

margin_usage = 1.2 market_data_type = 1

[orders] exchange = "SMART"

[orders.algo] strategy = "Adaptive" params = [["adaptivePriority", "Patient"]]

[option_chains] expirations = 3 strikes = 50

[roll_when] pnl = 0.9 dte = 0 min_pnl = 0.0 close_at_pnl = 0.85

[roll_when.calls] itm = true [roll_when.puts] itm = false

[target] dte = 3

maximum_new_contracts_percent = 1.0 minimum_open_interest = 10

[target.puts] delta = 0.1 [target.calls] delta = 0.05

[symbols]

[symbols.SPY] weight = 1.0

[symbols.SPY.puts] delta = 0.1

[ib_insync] logfile = '/etc/thetagang/ib_insync.log' "

cjian0001 commented 1 year ago

and one more thing when i change spy to spx, it shows this "ValueError: Contract Stock(symbol='SPX', exchange='SMART', currency='USD') can't be hashed 2022-12-18 22:30:23,213 ib_insync.Watchdog INFO Stopping"

and i already change to exchange=cboe type=ind symbol=spx

brndnmtthws commented 1 year ago

SPX is an index, not an ETF or stock. There are cash-settled options, but thetagang doesn't support cash settled options (like index options and futures).

Are you running this during market hours? If you try to run it outside market hours, the data won't be available so it could fail. If you want to test it, use 2, 3, or 4 for market_data_type. See https://github.com/brndnmtthws/thetagang/blob/main/thetagang.toml#L34-L36.

You also need to make sure you have the market data subscriptions available.

cjian0001 commented 1 year ago

thanks boss

github-actions[bot] commented 10 months ago

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

github-actions[bot] commented 9 months ago

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