Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 27, 2024
1 parent 9a77ba0 commit e2b934d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions risk/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ async def _handle_reverse(
and long_position
and not short_position
):
await self._process_signal_exit(long_position, event.entry_price)
await self._process_reverse_exit(long_position, event.entry_price)
if (
isinstance(event, GoLongSignalReceived)
and short_position
and not long_position
):
await self._process_signal_exit(short_position, event.entry_price)
await self._process_reverse_exit(short_position, event.entry_price)

async def _handle_signal_exit(
self, event: Union[ExitLongSignalReceived, ExitShortSignalReceived]
Expand Down Expand Up @@ -215,6 +215,20 @@ def _create_exit_event(self, position: Position, ohlcv: OHLCV):

return None

async def _process_reverse_exit(
self,
position: Position,
price: float,
):
take_profit_price = position.take_profit_price
stop_loss_price = position.stop_loss_price

distance_to_take_profit = abs(price - take_profit_price)
distance_to_stop_loss = abs(price - stop_loss_price)

if distance_to_take_profit < distance_to_stop_loss:
await self.tell(RiskThresholdBreached(position, price, RiskType.REVERSE))

async def _process_signal_exit(
self,
position: Position,
Expand Down

0 comments on commit e2b934d

Please sign in to comment.