完善下单表单与 CTP 持仓,requirements 加入 vnpy 并更新部署文档
以损定仓/固定张数分栏下单、限价市价、持仓仅读柜台;DEPLOY 补充 SimNow 与 vnpy 安装说明。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+10
-1
@@ -173,12 +173,16 @@ class CtpBridge:
|
||||
elif direction is not None and "空" in str(direction):
|
||||
d = "short"
|
||||
sym = getattr(pos, "symbol", "") or ""
|
||||
exchange = getattr(pos, "exchange", None)
|
||||
ex_name = str(exchange.value if hasattr(exchange, "value") else exchange or "")
|
||||
out.append({
|
||||
"symbol": sym,
|
||||
"exchange": ex_name,
|
||||
"direction": d,
|
||||
"lots": vol,
|
||||
"avg_price": float(getattr(pos, "price", 0) or 0),
|
||||
"pnl": float(getattr(pos, "pnl", 0) or 0),
|
||||
"frozen": int(getattr(pos, "frozen", 0) or 0),
|
||||
})
|
||||
return out
|
||||
|
||||
@@ -190,6 +194,7 @@ class CtpBridge:
|
||||
direction: str,
|
||||
lots: int,
|
||||
price: float,
|
||||
order_type: str = "limit",
|
||||
) -> str:
|
||||
from vnpy.trader.constant import Direction, Offset, OrderType
|
||||
from vnpy.trader.object import OrderRequest
|
||||
@@ -217,11 +222,13 @@ class CtpBridge:
|
||||
else:
|
||||
raise ValueError(f"未知开平: {offset}")
|
||||
|
||||
ot = OrderType.MARKET if (order_type or "limit").lower() == "market" else OrderType.LIMIT
|
||||
|
||||
req = OrderRequest(
|
||||
symbol=sym,
|
||||
exchange=exchange,
|
||||
direction=d,
|
||||
type=OrderType.LIMIT,
|
||||
type=ot,
|
||||
volume=lots,
|
||||
price=price,
|
||||
offset=off,
|
||||
@@ -290,6 +297,7 @@ def execute_order(
|
||||
lots: int,
|
||||
price: float,
|
||||
settings: dict | None = None,
|
||||
order_type: str = "limit",
|
||||
) -> dict[str, Any]:
|
||||
"""统一下单:simulation=SimNow,live=期货公司 CTP。"""
|
||||
del conn, settings
|
||||
@@ -308,6 +316,7 @@ def execute_order(
|
||||
direction=direction,
|
||||
lots=lots,
|
||||
price=price,
|
||||
order_type=order_type,
|
||||
)
|
||||
return {
|
||||
"order_id": order_id,
|
||||
|
||||
Reference in New Issue
Block a user