fix bug
This commit is contained in:
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
import yaml
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class SignalConfig:
|
||||
"""单个交易信号的数据源及开仓限制配置。"""
|
||||
|
||||
@@ -21,7 +21,7 @@ class SignalConfig:
|
||||
gt_last_price_is_open: bool = False
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class GlobalConfig:
|
||||
"""所有主机共享的系统配置。"""
|
||||
|
||||
@@ -37,7 +37,7 @@ class GlobalConfig:
|
||||
signals: dict[str, SignalConfig] = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class AccountConfig:
|
||||
"""当前主机所使用的账户及交易策略参数。"""
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,7 @@ class GridState(str, Enum):
|
||||
STEADY = "steady" # 仍处于当前峰值网格,继续持有
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class GridObservation:
|
||||
"""一次网格观察的不可变结果。"""
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import secrets
|
||||
from .http import get_json
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class SignalItem:
|
||||
signal_key: str = ""; code: str = ""; name: str = ""; desc: str = ""; last_close: float = 0
|
||||
tech_indicator: dict[str, float] = field(default_factory=dict)
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class SignalResult:
|
||||
code: str = ""; total: int = 0; updated: str = ""; data: dict[str, SignalItem] = field(default_factory=dict); message: str = ""
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ from strategy.trend.boot import StartTrend
|
||||
from strategy.zt.boot import StartZT
|
||||
from strategy.ipo import AutoBuyIpo
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class StrategyDefinition:
|
||||
mutex_scope: str
|
||||
start_strategy: object
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,7 +11,7 @@ def _number(value: Any, kind: type = float) -> Any:
|
||||
return kind()
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class OrderItem:
|
||||
"""由 QMT 委托明细解析得到的标准订单记录。"""
|
||||
id: str
|
||||
@@ -64,13 +64,14 @@ class OrderItem:
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class PositionItem:
|
||||
stock_code: str = ""
|
||||
stock_name: str = ""
|
||||
trade_id:str = ""
|
||||
direction: Any = None
|
||||
volume: int = 0
|
||||
open_cost: float = 0.0
|
||||
open_price: float = 0.0
|
||||
float_profit: float = 0.0
|
||||
market_value: float = 0.0
|
||||
@@ -88,7 +89,7 @@ class PositionItem:
|
||||
def from_dict(cls, data: dict[str, Any], code: str = "") -> "PositionItem":
|
||||
return cls(
|
||||
stock_code=str(data.get("StockCode") or code), stock_name=str(data.get("StockName") or ""),
|
||||
trade_id=str(data.get("TradeID") or ""),
|
||||
trade_id=str(data.get("TradeID") or ""),open_cost=_number(data.get("OpenCost")),
|
||||
direction=data.get("Direction"), volume=_number(data.get("Volume"), int),
|
||||
open_price=_number(data.get("OpenPrice")), float_profit=_number(data.get("FloatProfit")),
|
||||
market_value=_number(data.get("MarketValue")), stock_holder=str(data.get("StockHolder") or ""),
|
||||
@@ -107,6 +108,7 @@ class PositionItem:
|
||||
trade_id=str(data.get("TradeID") or ""),
|
||||
direction=data.get("Direction"),
|
||||
volume=_number(data.get("Volume"), int),
|
||||
open_cost=_number(data.get("OpenCost")),
|
||||
open_price=_number(data.get("OpenPrice")),
|
||||
float_profit=_number(data.get("FloatProfit")),
|
||||
market_value=_number(data.get("MarketValue")),
|
||||
@@ -122,7 +124,7 @@ class PositionItem:
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class Assets:
|
||||
total: float = 0.0
|
||||
available: float = 0.0
|
||||
@@ -136,7 +138,7 @@ class Assets:
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class Portfolio:
|
||||
assets: Assets
|
||||
positions: dict[str, PositionItem]
|
||||
@@ -152,7 +154,7 @@ def _trade_datetime(data: dict[str, Any]) -> datetime | None:
|
||||
return None
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class Tick:
|
||||
last_price: float = 0.0
|
||||
last_close: float = 0.0
|
||||
@@ -169,7 +171,7 @@ class Tick:
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class HistoryDataRequest:
|
||||
length: int = 10
|
||||
period: str = ""
|
||||
@@ -178,7 +180,7 @@ class HistoryDataRequest:
|
||||
skip_paused: bool = True
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class MarketDataRequest:
|
||||
fields: list[str] = field(default_factory=list)
|
||||
stocks: list[str] = field(default_factory=list)
|
||||
@@ -189,7 +191,7 @@ class MarketDataRequest:
|
||||
count: int = 0
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class FinancialDataRequest:
|
||||
tabname: str = ""; colname: str = ""; market: str = ""; code: str = ""
|
||||
report_type: str = ""; barpos: int = 0
|
||||
@@ -197,22 +199,22 @@ class FinancialDataRequest:
|
||||
start_date: str = ""; end_date: str = ""
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class FactorDataRequest:
|
||||
field_list: list[str] = field(default_factory=list); stock_list: list[str] = field(default_factory=list)
|
||||
stock_code: str = ""; start_date: str = ""; end_date: str = ""
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class BSMPriceRequest:
|
||||
option_type: str; object_prices: Any; strike_price: float; risk_free: float; sigma: float; days: int; dividend: float
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class BSMIVRequest:
|
||||
option_type: str; object_prices: float; strike_price: float; option_price: float; risk_free: float; days: int; dividend: float
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class LocalDataRequest:
|
||||
stock_code: str; start_time: str = ""; end_time: str = ""; period: str = ""; divid_type: str = ""; count: int = 0
|
||||
|
||||
@@ -6,6 +6,14 @@ from .models import Assets, OrderItem, Portfolio, PositionItem
|
||||
|
||||
|
||||
class PortfolioMixin:
|
||||
def org(self, datatype: str) -> list[dict[str, Any]]:
|
||||
"""查询 account、order、deal 或 position,返回原始字段字典列表。"""
|
||||
datatype = str(datatype).strip().lower()
|
||||
if datatype not in {"account", "order", "deal", "position"}:
|
||||
raise ValueError(f"unsupported org datatype: {datatype}")
|
||||
response = self._get_json(f"/api/portfolio/org/{datatype}")
|
||||
return response["data"]
|
||||
|
||||
def portfolio(self) -> Portfolio:
|
||||
data = self._get_json("/api/portfolio") or {}
|
||||
positions = {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -39,7 +39,7 @@ def Overview(assets, positions, account_cfg=None) -> None:
|
||||
for position in positions:
|
||||
if position.volume <= 0:
|
||||
continue
|
||||
log.info("[启动] %s %s,持仓=%d,可用=%d,成本=%.2f,现价=%.2f,盈亏=%.2f%%", position.stock_code, position.stock_name, position.volume, position.can_use_volume, position.open_price, position.last_price, position.profit_rate * 100)
|
||||
log.info("[启动] %s %s %s,持仓=%d,可用=%d,成本=%.2f(%.2f),现价=%.2f,盈亏=%.2f%%",position.trade_id, position.stock_code, position.stock_name, position.volume, position.can_use_volume, position.open_price,position.open_cost, position.last_price, position.profit_rate * 100)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ TRACKED_STATUSES = BUSY_STATUSES | COMPLETED_STATUSES
|
||||
CANCELABLE_STATUSES = {"49", "50", "51", "52"}
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class PlaceOrderRequest:
|
||||
"""``OrderBook.place`` 提交委托所需的全部参数。"""
|
||||
op: int
|
||||
|
||||
@@ -15,7 +15,7 @@ import logging as log
|
||||
LOSS_TIERS = [-50.0]
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class TradeDecision:
|
||||
"""一次止盈或补仓判断的统一结果。"""
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ from .order import OrderBook
|
||||
from .watch import DipWatch
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class Runtime:
|
||||
"""集中保存趋势策略运行期间共享的依赖和状态。
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime, timedelta
|
||||
from threading import Lock
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class _Entry:
|
||||
last_close: float
|
||||
expires_at: datetime
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -11,7 +11,7 @@ from strategy.trend.watch import DipWatch
|
||||
from .state import TState
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class Runtime:
|
||||
client: Client
|
||||
global_cfg: GlobalConfig
|
||||
|
||||
@@ -17,7 +17,7 @@ BUYING = "BUYING"
|
||||
DONE = "DONE"
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@dataclass(slots=True)
|
||||
class TStateItem:
|
||||
code: str
|
||||
base_qty: int = 0
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
from sdk import Client
|
||||
|
||||
@@ -8,8 +9,20 @@ TOKEN = "QMTbyYanweidong"
|
||||
STOCK_CODE = "000021.SZ"
|
||||
VOLUME = 100
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""只读查询四类原始数据,输出 JSON 便于核对字段。"""
|
||||
with Client(BASE_URL, TOKEN) as client:
|
||||
for datatype in ("account", "order", "deal", "position"):
|
||||
print(f"\n=== {datatype} ===")
|
||||
try:
|
||||
result = client.org(datatype)
|
||||
print(f"记录数:{len(result)}")
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2, default=str))
|
||||
except Exception as exc:
|
||||
print(f"查询失败:{exc}")
|
||||
|
||||
|
||||
def main1() -> None:
|
||||
order = {
|
||||
"opType": 23,
|
||||
"orderType": 1101,
|
||||
|
||||
Reference in New Issue
Block a user