Files
big-qmt/py-client/sdk/trade.py

58 lines
1.7 KiB
Python
Raw Normal View History

2026-09-03 11:33:43 +08:00
from __future__ import annotations
2026-08-28 18:52:27 +08:00
from typing import Any
2026-09-03 11:33:43 +08:00
2026-09-02 21:03:45 +08:00
OP_BUY = 23
OP_SELL = 24
2026-09-03 11:33:43 +08:00
ORDER_TYPE_VOLUME = 1101
PR_TYPE_LATEST = 5
QUICK_TRADE_NOW = 2
2026-08-30 00:34:27 +08:00
ORDER_SIDE_BY_OFFSET = {"23": "BUY", "24": "SELL", "48": "BUY", "49": "SELL"}
2026-08-28 18:52:27 +08:00
class TradeMixin:
2026-09-03 11:33:43 +08:00
def passorder(
self,
op_type: int,
2026-09-04 21:04:34 +08:00
stock_code: str = "",
volume: int = 0,
2026-09-03 11:33:43 +08:00
order_type: int = ORDER_TYPE_VOLUME,
pr_type: int = PR_TYPE_LATEST,
price: float = -1,
quick_trade: int = QUICK_TRADE_NOW,
strategy_name: str = "",
order_id: str = "",
2026-09-04 21:04:34 +08:00
stock: str = "",
2026-09-03 11:33:43 +08:00
) -> dict[str, Any]:
2026-09-04 21:04:34 +08:00
# ``stock`` is retained for compatibility with the original IPO client.
stock_code = str(stock_code or stock).strip()
if not stock_code:
raise ValueError("stock_code cannot be empty")
2026-09-03 11:33:43 +08:00
return self._post_json(
"/api/trade/passorder",
{
"opType": op_type,
"orderType": order_type,
"stockCode": stock_code,
"prType": pr_type,
"price": price,
"volume": volume,
"quickTrade": quick_trade,
"strategyName": strategy_name,
"orderId": order_id,
},
)
2026-09-04 21:04:34 +08:00
def ipo_data(self, ipo_type: str = "STOCK") -> list[dict[str, Any]]:
"""Return today's IPO candidates from the QMT REST service."""
response = self._post_json(
"/api/trade/ipo_data",
{"type": str(ipo_type).strip().upper()},
) or []
return response if isinstance(response, list) else []
2026-09-03 11:33:43 +08:00
def cancel_by_id(self, order_id: str) -> dict[str, Any]:
return self._post_json("/api/trade/cancel_by_id", {"order_id": order_id})