INNER CODE UNIT · Python
modify_position
flukelaster/ai-trading-agent · mt5_bridge/main.py:323
async def modify_position(ticket: int, req: ModifyPositionRequest):
if not ensure_connected():
return mt5_response(False, error="MT5 not connected")
position = mt5.positions_get(ticket=ticket)
if not position:
return mt5_response(False, error=f"Position {ticket} not found")
pos = position[0]
new_sl = req.sl if req.sl is not None else pos.sl
new_tp = req.tp if req.tp is not None else pos.tp
request = {
"action": mt5.TRADE_ACTION_SLTP,
"symbol": pos.symbol,
"position": ticket,
"sl": new_sl,
"tp": new_tp,