diff --git a/thetagang/portfolio_manager.py b/thetagang/portfolio_manager.py index eef901a97..663781170 100644 --- a/thetagang/portfolio_manager.py +++ b/thetagang/portfolio_manager.py @@ -246,7 +246,7 @@ async def call_is_itm(self, contract: Contract) -> bool: def call_can_be_closed(self, call: PortfolioItem, table: Table) -> bool: return self.position_can_be_closed(call, table) - def call_can_be_rolled(self, call: PortfolioItem, table: Table) -> bool: + async def call_can_be_rolled(self, call: PortfolioItem, table: Table) -> bool: # Ignore long positions, we only roll shorts if call.position > 0: return False @@ -256,7 +256,7 @@ def call_can_be_rolled(self, call: PortfolioItem, table: Table) -> bool: if ( isinstance(call.contract, Option) - and self.call_is_itm(call.contract) + and await self.call_is_itm(call.contract) and self.config["roll_when"]["calls"]["always_when_itm"] ): table.add_row( @@ -271,7 +271,7 @@ def call_can_be_rolled(self, call: PortfolioItem, table: Table) -> bool: if ( not self.config["roll_when"]["calls"]["itm"] and isinstance(call.contract, Option) - and self.call_is_itm(call.contract) + and await self.call_is_itm(call.contract) ): return False @@ -569,7 +569,7 @@ async def manage(self) -> None: (rollable_puts, closeable_puts, group1) = await self.check_puts( portfolio_positions ) - (rollable_calls, closeable_calls, group2) = self.check_calls( + (rollable_calls, closeable_calls, group2) = await self.check_calls( portfolio_positions ) console.print(Panel(Group(group1, group2))) @@ -657,7 +657,7 @@ async def check_put_can_be_rolled_task( return (rollable_puts, closeable_puts, group) - def check_calls( + async def check_calls( self, portfolio_positions: Dict[str, List[PortfolioItem]] ) -> Tuple[List[Any], List[Any], Group]: # Check for calls which may be rolled to the next expiration or a better price @@ -675,7 +675,7 @@ def check_calls( table.add_column("Detail") for c in tqdm(calls, desc="Checking rollable/closeable calls..."): - if self.call_can_be_rolled(c, table): + if await self.call_can_be_rolled(c, table): rollable_calls.append(c) elif self.call_can_be_closed(c, table): closeable_calls.append(c)