添加市价单
This commit is contained in:
parent
97920a0ede
commit
c94f226fbc
@ -150,7 +150,11 @@ class RealTraderManager:
|
||||
)
|
||||
|
||||
# 立即更新一次订单状态
|
||||
self.check_and_retry(order_id, strategy_name, code, direction, amount, 1)
|
||||
threading.Thread(
|
||||
target=self.check_and_retry,
|
||||
args=(order_id, strategy_name, code, direction, amount, 1),
|
||||
name=f"CheckOrder-{order_id}"
|
||||
).start()
|
||||
|
||||
return {"success": True, "order_id": order_id}
|
||||
|
||||
@ -180,7 +184,11 @@ class RealTraderManager:
|
||||
new_order_id = new_order.get("order_id")
|
||||
if new_order.get("success") and new_order_id:
|
||||
# 立即检查新市价单
|
||||
self.check_and_retry(new_order_id, strategy_name, code, direction, left_amount)
|
||||
threading.Thread(
|
||||
target=self.check_and_retry,
|
||||
args=(new_order_id, strategy_name, code, direction, left_amount),
|
||||
name=f"CheckMarketOrder-{new_order_id}"
|
||||
).start()
|
||||
return True
|
||||
else:
|
||||
logger.error(f"补单失败: {new_order}")
|
||||
@ -249,7 +257,7 @@ class RealTraderManager:
|
||||
time.sleep(3)
|
||||
updated_order = self.trader.get_order(order_id)
|
||||
if not updated_order:
|
||||
logger.error(f"获取订单失败: {order_id}")
|
||||
logger.error(f"获取订单失败, 订单可能正在报单: {order_id}")
|
||||
return None
|
||||
|
||||
# 根据委托状态更新订单状态
|
||||
|
@ -273,6 +273,7 @@ def buy():
|
||||
strategy_name = data.get(
|
||||
"strategy_name", "default_strategy"
|
||||
) # 新增策略名称参数,默认为空
|
||||
order_type = data.get("order_type", ORDER_TYPE_LIMIT)
|
||||
|
||||
try:
|
||||
if not all([code, price_str, amount_str]):
|
||||
@ -281,7 +282,7 @@ def buy():
|
||||
price = float(price_str)
|
||||
amount = int(amount_str)
|
||||
|
||||
if price <= 0 or amount <= 0:
|
||||
if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0):
|
||||
raise ValueError("Price and amount must be positive")
|
||||
|
||||
# 检查交易系统是否可用
|
||||
@ -310,16 +311,16 @@ def buy():
|
||||
)
|
||||
rtm = get_real_trader_manager()
|
||||
result = rtm.place_order(
|
||||
strategy_name, code, ORDER_DIRECTION_BUY, amount, price
|
||||
strategy_name, code, ORDER_DIRECTION_BUY, amount, price, order_type
|
||||
)
|
||||
else:
|
||||
result = trader.buy(code, price, amount, strategy_name)
|
||||
|
||||
if result.get("success"):
|
||||
logger.info(f"买入成功: {result}")
|
||||
logger.info(f"买入下单成功: {result}")
|
||||
return jsonify({"success": True, "order_id": result.get("order_id")}), 200
|
||||
else:
|
||||
logger.error(f"买入失败: {result}")
|
||||
logger.error(f"买入下单失败: {result}")
|
||||
return jsonify({"success": False, "error": result}), 400
|
||||
|
||||
except ValueError as e:
|
||||
@ -341,6 +342,7 @@ def sell():
|
||||
price_str = data.get("price")
|
||||
amount_str = data.get("amount")
|
||||
strategy_name = data.get("strategy_name", "") # 新增策略名称参数,默认为空
|
||||
order_type = data.get("order_type", ORDER_TYPE_LIMIT)
|
||||
|
||||
try:
|
||||
if not all([code, price_str, amount_str]):
|
||||
@ -349,7 +351,7 @@ def sell():
|
||||
price = float(price_str)
|
||||
amount = int(amount_str)
|
||||
|
||||
if price <= 0 or amount <= 0:
|
||||
if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0):
|
||||
raise ValueError("Price and amount must be positive")
|
||||
|
||||
# 检查交易系统是否可用
|
||||
@ -378,19 +380,19 @@ def sell():
|
||||
)
|
||||
rtm = get_real_trader_manager()
|
||||
result = rtm.place_order(
|
||||
strategy_name, code, ORDER_DIRECTION_SELL, amount, price
|
||||
strategy_name, code, ORDER_DIRECTION_SELL, amount, price, order_type
|
||||
)
|
||||
else:
|
||||
result = trader.sell(code, price, amount)
|
||||
result = trader.sell(code, price, amount, strategy_name)
|
||||
|
||||
if result.get("success"):
|
||||
logger.info(f"卖出成功: {result}")
|
||||
logger.info(f"卖出下单成功: {result}")
|
||||
return jsonify({"success": True, "order_id": result.get("order_id")}), 200
|
||||
elif "error" in result:
|
||||
logger.error(f"卖出失败: {result}")
|
||||
logger.error(f"卖出下单失败: {result}")
|
||||
return jsonify({"success": False, "error": result["error"]}), 400
|
||||
else:
|
||||
logger.error(f"卖出失败: {result}")
|
||||
logger.error(f"卖出下单失败: {result}")
|
||||
return jsonify({"success": False, "error": result}), 400
|
||||
|
||||
except ValueError as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user