|
|
@@ -216,7 +216,8 @@ class TradingStrategy:
|
|
|
if error:
|
|
|
self.presigned_long_tx = None
|
|
|
else:
|
|
|
- self.presigned_long_tx = (long_tx_info, long_oid)
|
|
|
+ # 存储: (tx_info, oid, quantity, price, is_ask)
|
|
|
+ self.presigned_long_tx = (long_tx_info, long_oid, self.trade_quantity, long_price, False)
|
|
|
|
|
|
# 签名做空订单(卖出)
|
|
|
short_tx_info, short_oid, error = await self.create_order_tx(
|
|
|
@@ -231,7 +232,8 @@ class TradingStrategy:
|
|
|
if error:
|
|
|
self.presigned_short_tx = None
|
|
|
else:
|
|
|
- self.presigned_short_tx = (short_tx_info, short_oid)
|
|
|
+ # 存储: (tx_info, oid, quantity, price, is_ask)
|
|
|
+ self.presigned_short_tx = (short_tx_info, short_oid, self.trade_quantity, short_price, True)
|
|
|
|
|
|
# 保存签名时的binance_price
|
|
|
self.presigned_prices = binance_price_float
|
|
|
@@ -456,11 +458,9 @@ class TradingStrategy:
|
|
|
|
|
|
# 获取对应方向的预签名交易
|
|
|
if direction == 'long' and self.presigned_long_tx:
|
|
|
- tx_info, oid = self.presigned_long_tx
|
|
|
- logger.info(f"使用预签名做多交易开仓,oid={oid}")
|
|
|
+ tx_info, oid, quantity, price, is_ask = self.presigned_long_tx
|
|
|
elif direction == 'short' and self.presigned_short_tx:
|
|
|
- tx_info, oid = self.presigned_short_tx
|
|
|
- logger.info(f"使用预签名做空交易开仓,oid={oid}")
|
|
|
+ tx_info, oid, quantity, price, is_ask = self.presigned_short_tx
|
|
|
else:
|
|
|
logger.warning(f"没有可用的预签名{side_desc}交易,回退到普通开仓")
|
|
|
await self._open_position(market_info, binance_price)
|
|
|
@@ -468,7 +468,9 @@ class TradingStrategy:
|
|
|
|
|
|
# 直接发送预签名交易
|
|
|
try:
|
|
|
- logger.info(f"发送预签名{side_desc}交易,oid={oid}")
|
|
|
+ # 在发送前打印订单信息
|
|
|
+ side_type = '卖出' if is_ask else '买入'
|
|
|
+ logger.info(f"发送预签名{side_desc}交易: 方向={side_type}, 数量={quantity}, 价格={price}, oid={oid}")
|
|
|
tx_hash, error = await self.send_order_tx(tx_info)
|
|
|
|
|
|
if error:
|
|
|
@@ -683,11 +685,6 @@ class TradingStrategy:
|
|
|
# 生成客户端订单ID
|
|
|
client_order_index = int(time.time() * 1000)
|
|
|
|
|
|
- # 记录下单参数
|
|
|
- logger.info(f"创建订单 - 市场: {market_info.get('symbol')}(ID:{market_info.get('market_id')})")
|
|
|
- logger.info(f"订单参数 - 数量: {quantity}, 价格: {price}, 方向: {'卖出' if is_ask else '买入'}, 只减仓: {reduce_only}, 订单类型: {order_type}")
|
|
|
- logger.info(f"格式化参数 - base_amount: {base_amount}, price: {formatted_price}, client_order_index: {client_order_index}")
|
|
|
-
|
|
|
# 根据订单类型设置time_in_force与order_expiry的调用方式
|
|
|
if order_type == self.signer_client.ORDER_TYPE_LIMIT:
|
|
|
time_in_force = self.signer_client.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME
|
|
|
@@ -724,7 +721,6 @@ class TradingStrategy:
|
|
|
if error is not None:
|
|
|
return None, None, error
|
|
|
|
|
|
- logger.info(f"订单签名成功,生成tx_info: {tx_info}")
|
|
|
return tx_info, client_order_index, None
|
|
|
except Exception as e:
|
|
|
return None, None, str(e)
|