Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Apr 9, 2024
1 parent 32da36c commit 890195d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions executor/_paper_order_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,26 @@ async def _adjust_position(self, event: RiskAdjustRequested):
size = current_position.size + current_position.size
fill_price = total_value / size

order = Order(
status=OrderStatus.EXECUTED,
type=OrderType.PAPER,
fee=fill_price * size * current_position.signal.symbol.taker_fee,
price=fill_price,
size=size,
)
if (
current_position.side == PositionSide.LONG and current_position.stop_loss_price > current_position.take_profit_price
) or (
current_position.side == PositionSide.SHORT and current_position.stop_loss_price < current_position.take_profit_price
):
logger.error(f"Wrong Adjust: {current_position}")
return
else:
order = Order(
status=OrderStatus.EXECUTED,
type=OrderType.PAPER,
fee=fill_price * size * current_position.signal.symbol.taker_fee,
price=fill_price,
size=size,
)

current_position = current_position.add_order(order)
current_position = current_position.add_order(order)

logger.info(f"Adjusted Position: {current_position}")
logger.info(f"Adjusted Position: {current_position}")

if current_position.closed:
await self.tell(BrokerPositionClosed(current_position))
else:
await self.tell(BrokerPositionAdjusted(current_position))

async def _close_position(self, event: PositionCloseRequested):
Expand Down

0 comments on commit 890195d

Please sign in to comment.