brndnmtthws / thetagang

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

ValueError: cannot convert float NaN to integer #306

Closed wihoho closed 1 year ago

wihoho commented 1 year ago

Calculating target positions... 0% -:--:-- ╭───────────────────── Traceback (most recent call last) ──────────────────────╮ │ /usr/local/lib/python3.10/dist-packages/thetagang/portfolio_manager.py:581 │ │ in manage │ │ │ │ 578 │ │ │ │ positions_table, │ │ 579 │ │ │ │ put_actions_table, │ │ 580 │ │ │ │ puts_to_write, │ │ ❱ 581 │ │ │ ) = self.check_if_can_write_puts(account_summary, portfol │ │ 582 │ │ │ │ │ 583 │ │ │ # Look for lots of stock that don't have covered calls │ │ 584 │ │ │ (call_actions_table, calls_to_write) = self.check_for_unc │ │ │ │ /usr/local/lib/python3.10/dist-packages/thetagang/portfolio_manager.py:983 │ │ in check_if_can_write_puts │ │ │ │ 980 │ │ │ targets[symbol] = round( │ │ 981 │ │ │ │ self.config["symbols"][symbol]["weight"] * total_buyi │ │ 982 │ │ │ ) │ │ ❱ 983 │ │ │ target_quantity = math.floor(targets[symbol] / ticker.mar │ │ 984 │ │ │ │ │ 985 │ │ │ # Current number of short puts │ │ 986 │ │ │ put_count = count_short_option_positions(symbol, portfoli │ ╰──────────────────────────────────────────────────────────────────────────────╯

brndnmtthws commented 1 year ago

You're going to need to provide a little more information, but I'm guessing you're running the code outside market hours, and ticker.marketPrice() is returning NaN (hence the error).

You can try setting account.market_data_type = 4, as per the IBKR API docs: https://interactivebrokers.github.io/tws-api/market_data_type.html

wihoho commented 1 year ago

Right. Because of non-market hours.