feat(position_manager): 添加多级止盈字段以支持部分止盈
扩展 position_info 字典,新增 takeProfit1、takeProfit2、partialProfitTaken 和 remainingQuantity 字段。 当 take_profit_2 未设置时,默认使用 take_profit_price 作为其值,确保向后兼容。
This commit is contained in:
parent
2061583482
commit
550d0b278d
|
|
@ -2284,6 +2284,8 @@ class PositionManager:
|
||||||
leverage = float(pos.get('leverage', 10) or trade.get('leverage', 10) or 10)
|
leverage = float(pos.get('leverage', 10) or trade.get('leverage', 10) or 10)
|
||||||
stop_loss_price = trade.get('stop_loss_price')
|
stop_loss_price = trade.get('stop_loss_price')
|
||||||
take_profit_price = trade.get('take_profit_price') or trade.get('take_profit_1')
|
take_profit_price = trade.get('take_profit_price') or trade.get('take_profit_1')
|
||||||
|
take_profit_1 = trade.get('take_profit_1')
|
||||||
|
take_profit_2 = trade.get('take_profit_2')
|
||||||
if stop_loss_price is None or take_profit_price is None:
|
if stop_loss_price is None or take_profit_price is None:
|
||||||
stop_loss_pct = config.TRADING_CONFIG.get('STOP_LOSS_PERCENT', 0.08)
|
stop_loss_pct = config.TRADING_CONFIG.get('STOP_LOSS_PERCENT', 0.08)
|
||||||
if stop_loss_pct is not None and stop_loss_pct > 1:
|
if stop_loss_pct is not None and stop_loss_pct > 1:
|
||||||
|
|
@ -2295,12 +2297,28 @@ class PositionManager:
|
||||||
take_profit_pct = (stop_loss_pct or 0.08) * 2.0
|
take_profit_pct = (stop_loss_pct or 0.08) * 2.0
|
||||||
stop_loss_price = self.risk_manager.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=stop_loss_pct)
|
stop_loss_price = self.risk_manager.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=stop_loss_pct)
|
||||||
take_profit_price = take_profit_price or self.risk_manager.get_take_profit_price(entry_price, side, quantity, leverage, take_profit_pct=take_profit_pct)
|
take_profit_price = take_profit_price or self.risk_manager.get_take_profit_price(entry_price, side, quantity, leverage, take_profit_pct=take_profit_pct)
|
||||||
|
if take_profit_2 is None and take_profit_price is not None:
|
||||||
|
take_profit_2 = take_profit_price
|
||||||
position_info = {
|
position_info = {
|
||||||
'symbol': symbol, 'side': side, 'quantity': quantity, 'entryPrice': entry_price,
|
'symbol': symbol,
|
||||||
'changePercent': 0, 'orderId': trade.get('entry_order_id'), 'tradeId': trade.get('id'),
|
'side': side,
|
||||||
'stopLoss': stop_loss_price, 'takeProfit': take_profit_price, 'initialStopLoss': stop_loss_price,
|
'quantity': quantity,
|
||||||
'leverage': leverage, 'entryReason': trade.get('entry_reason') or 'db_sync', 'atr': trade.get('atr'),
|
'entryPrice': entry_price,
|
||||||
'maxProfit': 0.0, 'trailingStopActivated': False,
|
'changePercent': 0,
|
||||||
|
'orderId': trade.get('entry_order_id'),
|
||||||
|
'tradeId': trade.get('id'),
|
||||||
|
'stopLoss': stop_loss_price,
|
||||||
|
'takeProfit': take_profit_price,
|
||||||
|
'takeProfit1': take_profit_1,
|
||||||
|
'takeProfit2': take_profit_2,
|
||||||
|
'partialProfitTaken': False,
|
||||||
|
'remainingQuantity': quantity,
|
||||||
|
'initialStopLoss': stop_loss_price,
|
||||||
|
'leverage': leverage,
|
||||||
|
'entryReason': trade.get('entry_reason') or 'db_sync',
|
||||||
|
'atr': trade.get('atr'),
|
||||||
|
'maxProfit': 0.0,
|
||||||
|
'trailingStopActivated': False,
|
||||||
}
|
}
|
||||||
self.active_positions[symbol] = position_info
|
self.active_positions[symbol] = position_info
|
||||||
logger.debug(f"{symbol} 已从 DB 载入到 active_positions,便于监控")
|
logger.debug(f"{symbol} 已从 DB 载入到 active_positions,便于监控")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user