Rebrand product and enhance tradable symbols table with spec columns and K-line links.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -963,6 +963,33 @@ class CtpBridge:
|
||||
logger.debug("estimate_margin_one_lot %s: %s", ths_code, exc)
|
||||
return None
|
||||
|
||||
def lookup_contract_spec(self, ths_code: str) -> Optional[dict]:
|
||||
"""从 CTP 合约信息读取乘数与最小变动价位。"""
|
||||
if not self._engine:
|
||||
return None
|
||||
try:
|
||||
sym, ex_name = ths_to_vnpy_symbol(ths_code)
|
||||
exchange = to_vnpy_exchange(ex_name)
|
||||
vt_symbol = f"{sym}.{exchange.value}"
|
||||
contract = self._engine.get_contract(vt_symbol)
|
||||
if not contract:
|
||||
return None
|
||||
mult = float(getattr(contract, "size", 0) or 0)
|
||||
tick = float(
|
||||
getattr(contract, "pricetick", 0)
|
||||
or getattr(contract, "price_tick", 0)
|
||||
or 0
|
||||
)
|
||||
if mult <= 0:
|
||||
return None
|
||||
out: dict[str, Any] = {"mult": mult}
|
||||
if tick > 0:
|
||||
out["tick_size"] = tick
|
||||
return out
|
||||
except Exception as exc:
|
||||
logger.debug("lookup_contract_spec %s: %s", ths_code, exc)
|
||||
return None
|
||||
|
||||
def _collect_positions(self) -> list[dict[str, Any]]:
|
||||
if not self._engine:
|
||||
return []
|
||||
@@ -1420,6 +1447,17 @@ def ctp_estimate_margin_one_lot(mode: str, ths_code: str, price: float) -> Optio
|
||||
return None
|
||||
|
||||
|
||||
def ctp_lookup_contract_spec(mode: str, ths_code: str) -> Optional[dict]:
|
||||
b = get_bridge()
|
||||
if b.connected_mode != mode or not b.ping():
|
||||
return None
|
||||
try:
|
||||
return b.lookup_contract_spec(ths_code)
|
||||
except Exception as exc:
|
||||
logger.debug("ctp_lookup_contract_spec: %s", exc)
|
||||
return None
|
||||
|
||||
|
||||
def get_ctp_balance(mode: str) -> Optional[float]:
|
||||
try:
|
||||
acc = ctp_get_account(mode)
|
||||
|
||||
Reference in New Issue
Block a user