Skip to content

Commit

Permalink
We shouldn't fail if there are no bids when closing
Browse files Browse the repository at this point in the history
  • Loading branch information
brndnmtthws committed Dec 18, 2024
1 parent f6da81c commit dcb6c38
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions thetagang/portfolio_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,13 +1252,18 @@ async def close_positions(self, right: str, positions: List[PortfolioItem]) -> N
for position in positions:
try:
position.contract.exchange = self.get_order_exchange()
ticker = await self.ibkr.get_ticker_for_contract(position.contract)
is_short = position.position < 0
price = (
round(get_lower_price(ticker), 2)
if is_short
else round(get_higher_price(ticker), 2)
)
price = None
try:
ticker = await self.ibkr.get_ticker_for_contract(position.contract)
is_short = position.position < 0
price = (
round(get_lower_price(ticker), 2)
if is_short
else round(get_higher_price(ticker), 2)
)
except RequiredFieldValidationError:
# no market price was available, fallback to minimum tick
pass
if util.isNan(price) or math.isnan(price) or not price:
# if the price is near zero or NaN, use the minimum price
log.warning(
Expand Down

0 comments on commit dcb6c38

Please sign in to comment.