feat
This commit is contained in:
14
py-client/sdk/__init__.py
Normal file
14
py-client/sdk/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from .account import AccountMixin
|
||||
from .client import Client as _HTTPClient
|
||||
from .data import DataMixin
|
||||
from .errors import APIError, BusinessError
|
||||
from .misc import MiscMixin
|
||||
from .models import *
|
||||
from .trade import *
|
||||
|
||||
|
||||
class Client(AccountMixin, DataMixin, TradeMixin, MiscMixin, _HTTPClient):
|
||||
"""big-qmt 同步 HTTP 客户端。"""
|
||||
|
||||
|
||||
__all__ = ["Client", "APIError", "BusinessError", "OP_BUY", "OP_SELL", "ORDER_TYPE_VOLUME", "PR_TYPE_LATEST", "QUICK_TRADE_NOW"]
|
||||
BIN
py-client/sdk/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/account.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/account.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/client.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/client.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/data.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/data.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/errors.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/errors.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/misc.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/misc.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/models.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
py-client/sdk/__pycache__/trade.cpython-311.pyc
Normal file
BIN
py-client/sdk/__pycache__/trade.cpython-311.pyc
Normal file
Binary file not shown.
33
py-client/sdk/account.py
Normal file
33
py-client/sdk/account.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from typing import Any
|
||||
|
||||
from .models import Assets, Position
|
||||
|
||||
|
||||
class AccountMixin:
|
||||
account_type: str
|
||||
|
||||
def _positions(self, path: str) -> tuple[list[str], list[Position]]:
|
||||
raw = self._post(path, {"account": self.account_type}) or {}
|
||||
return list(raw), [Position.from_dict(value, code) for code, value in raw.items()]
|
||||
|
||||
def positions(self): return self._positions("/api/v2/positions")
|
||||
def holding(self): return self._positions("/api/holding")
|
||||
|
||||
def assets(self) -> Assets:
|
||||
data = self._post("/api/v2/assets", {"account": self.account_type})
|
||||
return Assets(float(data.get("total", 0)), float(data.get("available", 0)))
|
||||
|
||||
def total_money(self) -> float: return float(self._post("/api/money/total", {"account": self.account_type}).get("total_money", 0))
|
||||
def available_money(self) -> float: return float(self._post("/api/money/available", {"account": self.account_type}).get("available_money", 0))
|
||||
def buy(self, stock: str, price: float, volume: int, pr_type: int = 0): return self._order("/api/order/buy", stock, price, volume, pr_type)
|
||||
def sell(self, stock: str, price: float, volume: int, pr_type: int = 0): return self._order("/api/order/sell", stock, price, volume, pr_type)
|
||||
|
||||
def _order(self, path, stock, price, volume, pr_type):
|
||||
body = {"stock": stock, "price": price, "volume": volume}
|
||||
if pr_type: body["prType"] = pr_type
|
||||
return self._post(path, body)
|
||||
|
||||
def order_status_list(self): return self._post("/api/order/status", {"account": self.account_type}).get("orders", [])
|
||||
def cancel_all(self): return self._post("/api/order/cancel_all", {"account": self.account_type})
|
||||
def cancel_by_rule(self, stock: str, volume: int): return self._post("/api/order/cancel_order", {"stock": stock, "volume": volume, "account": self.account_type})
|
||||
def deals(self): return self._post("/api/order/deal", {"account": self.account_type}).get("deals", [])
|
||||
59
py-client/sdk/client.py
Normal file
59
py-client/sdk/client.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import asdict, is_dataclass
|
||||
from typing import Any
|
||||
from urllib.error import HTTPError
|
||||
from urllib.request import Request, urlopen
|
||||
|
||||
from .errors import APIError, BusinessError
|
||||
|
||||
|
||||
def csv_join(items: list[str]) -> str:
|
||||
return ",".join(item.strip() for item in items if item.strip())
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, base_url: str, token: str, timeout: float = 15.0) -> None:
|
||||
self.base_url = base_url.rstrip("/")
|
||||
self.token = token
|
||||
self.timeout = timeout if timeout > 0 else 15.0
|
||||
self.account_type = "stock"
|
||||
|
||||
def set_account_type(self, account_type: str) -> "Client":
|
||||
if account_type.strip():
|
||||
self.account_type = account_type
|
||||
return self
|
||||
|
||||
def _request(self, method: str, path: str, body: Any = None) -> Any:
|
||||
data = None
|
||||
headers = {"X-Token": self.token, "Accept": "application/json"}
|
||||
if method != "GET":
|
||||
if body is None: body = {}
|
||||
if is_dataclass(body): body = asdict(body)
|
||||
data = json.dumps(body, ensure_ascii=False).encode()
|
||||
headers["Content-Type"] = "application/json"
|
||||
request = Request(self.base_url + path, data=data, headers=headers, method=method)
|
||||
try:
|
||||
with urlopen(request, timeout=self.timeout) as response:
|
||||
raw = response.read()
|
||||
except HTTPError as exc:
|
||||
raw = exc.read()
|
||||
try: message = json.loads(raw).get("error", raw.decode(errors="replace"))
|
||||
except (ValueError, AttributeError): message = raw.decode(errors="replace").strip()
|
||||
raise APIError(exc.code, str(message)) from exc
|
||||
if not raw: return None
|
||||
try: return json.loads(raw)
|
||||
except ValueError as exc: raise ValueError(f"invalid JSON from {path}: {raw[:512]!r}") from exc
|
||||
|
||||
def _get(self, path: str) -> Any: return self._request("GET", path)
|
||||
def _post(self, path: str, body: Any = None) -> Any: return self._request("POST", path, body)
|
||||
|
||||
def _get_field(self, path: str, key: str) -> Any:
|
||||
return self._get(path).get(key)
|
||||
|
||||
def _post_field(self, path: str, body: Any, key: str) -> Any:
|
||||
result = self._post(path, body)
|
||||
if isinstance(result, dict) and result.get("error"):
|
||||
raise BusinessError(result["error"])
|
||||
return result.get(key, result) if key and isinstance(result, dict) else result
|
||||
83
py-client/sdk/data.py
Normal file
83
py-client/sdk/data.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from .client import csv_join
|
||||
from .models import *
|
||||
|
||||
|
||||
class DataMixin:
|
||||
def _one(self, endpoint, arg, value, key): return self._post_field(f"/api/data/{endpoint}", {arg: value}, key)
|
||||
|
||||
def stock_name(self, code): return self._one("stock_name", "stockcode", code, "name")
|
||||
def open_date(self, code): return self._one("open_date", "stockcode", code, "open_date")
|
||||
def last_volume(self, code): return self._one("last_volume", "stockcode", code, "last_volume")
|
||||
def bar_timetag(self, index): return self._one("bar_timetag", "index", index, "timetag")
|
||||
def tick_timetag(self): return self._get_field("/api/data/tick_timetag", "timetag")
|
||||
def sector(self, sector, realtime): return self._post("/api/data/sector", {"sector": sector, "realtime": realtime}).get("stocks", [])
|
||||
def industry(self, industry): return self._post("/api/data/industry", {"industry": industry}).get("stocks", [])
|
||||
def stock_list_in_sector(self, name): return self._post("/api/data/stock_list_in_sector", {"sectorname": name}).get("stocks", [])
|
||||
def weight_in_index(self, indexcode, stockcode): return self._post_field("/api/data/weight_in_index", locals_body(indexcode=indexcode, stockcode=stockcode), "weight")
|
||||
def contract_multiplier(self, code): return self._one("contract_multiplier", "contractcode", code, "multiplier")
|
||||
def risk_free_rate(self, index): return self._one("risk_free_rate", "index", index, "risk_free_rate")
|
||||
def date_location(self, date): return self._one("date_location", "strdate", date, "location")
|
||||
|
||||
def history_data(self, req: HistoryDataRequest):
|
||||
return self._post_field("/api/data/history_data", {"len": req.length or 10, "period": req.period, "field": req.field, "dividend_type": req.dividend_type, "skip_paused": str(req.skip_paused).lower()}, "data")
|
||||
def _market_body(self, req): return {"fields": csv_join(req.fields), "stock_code": csv_join(req.stocks), "start_time": req.start_time, "end_time": req.end_time, "period": req.period, "dividend_type": req.dividend_type, "count": req.count}
|
||||
def market_data(self, req): return self._post_field("/api/data/market_data", self._market_body(req), "data")
|
||||
def market_data_ex(self, req): return self._post_field("/api/data/market_data_ex", self._market_body(req), "data")
|
||||
|
||||
def full_tick(self, stocks):
|
||||
raw = self._post("/api/data/full_tick", {"stocks": stocks}) or {}
|
||||
def number(data, *names):
|
||||
for name in names:
|
||||
try: return float(data[name])
|
||||
except (KeyError, TypeError, ValueError): pass
|
||||
return 0.0
|
||||
return {code: Tick(number(value, "lastPrice", "last_price", "LastPrice"), number(value, "lastClose", "last_close", "LastClose"), value if isinstance(value, dict) else {}) for code, value in raw.items()}
|
||||
|
||||
def divid_factors(self, code): return self._one("divid_factors", "stockcode", code, "factors")
|
||||
def main_contract(self, code): return self._one("main_contract", "codemarket", code, "main_contract")
|
||||
def timetag_to_datetime(self, timetag, format=""):
|
||||
body = {"timetag": timetag}
|
||||
if format: body["format"] = format
|
||||
return self._post_field("/api/data/timetag_to_datetime", body, "datetime")
|
||||
def total_share(self, code): return self._one("total_share", "stockcode", code, "total_share")
|
||||
def trading_dates(self, stockcode, start_date, end_date, period, count=0):
|
||||
body = locals_body(stockcode=stockcode, start_date=start_date, end_date=end_date, period=period)
|
||||
if count: body["count"] = count
|
||||
return self._post("/api/data/trading_dates", body).get("dates", [])
|
||||
def svol(self, code): return self._one("svol", "stockcode", code, "svol")
|
||||
def bvol(self, code): return self._one("bvol", "stockcode", code, "bvol")
|
||||
def longhubang(self, stocks, start, end): return self._post_field("/api/data/longhubang", {"stock_list": csv_join(stocks), "startTime": start, "endTime": end}, "data")
|
||||
def top10_share_holder(self, stocks, name, start, end): return self._post_field("/api/data/top10_share_holder", {"stock_list": csv_join(stocks), "data_name": name, "start_time": start, "end_time": end}, "data")
|
||||
def option_detail(self, code): return self._one("option_detail", "optioncode", code, "detail")
|
||||
def turnover_rate(self, stocks, start, end): return self._post_field("/api/data/turnover_rate", {"stock_list": csv_join(stocks), "startTime": start, "endTime": end}, "data")
|
||||
def etf_info(self, code): return self._one("etf_info", "stockcode", code, "info")
|
||||
def etf_iopv(self, code): return self._one("etf_iopv", "stockcode", code, "iopv")
|
||||
def instrument_detail(self, code): return self._one("instrumentdetail", "stockcode", code, "detail")
|
||||
def contract_expire_date(self, code): return self._one("contract_expire_date", "codemarket", code, "expire_date")
|
||||
def option_undl_data(self, code): return self._one("option_undl_data", "undl_code_ref", code, "data")
|
||||
|
||||
def financial_data(self, req):
|
||||
return self._post_field("/api/data/financial_data", {"tabname": req.tabname, "colname": req.colname, "market": req.market, "code": req.code, "report_type": req.report_type, "barpos": req.barpos, "fieldList": csv_join(req.field_list), "stockList": csv_join(req.stock_list), "startDate": req.start_date, "endDate": req.end_date}, "data")
|
||||
def factor_data(self, req): return self._post_field("/api/data/factor_data", {"fieldList": csv_join(req.field_list), "stockList": csv_join(req.stock_list), "stockCode": req.stock_code, "startDate": req.start_date, "endDate": req.end_date}, "data")
|
||||
def his_st_data(self, code): return self._one("his_st_data", "stockCode", code, "data")
|
||||
def his_index_data(self, index): return self._one("his_index_data", "index", index, "data")
|
||||
def all_subscription(self): return self._get_field("/api/data/all_subscription", "subscriptions")
|
||||
def option_list(self, code, dedate, opttype, available): return self._post_field("/api/data/option_list", {"undl_code": code, "dedate": dedate, "opttype": opttype, "isavailable": str(available).lower()}, "option_list")
|
||||
def his_contract_list(self, market): return self._one("his_contract_list", "market", market, "contracts")
|
||||
def option_iv(self, code): return self._one("option_iv", "optioncode", code, "iv")
|
||||
def bsm_price(self, req):
|
||||
prices = ",".join(str(v) for v in req.object_prices) if isinstance(req.object_prices, list) else req.object_prices
|
||||
return self._post_field("/api/data/bsm_price", {"optionType": req.option_type, "objectPrices": prices, "strikePrice": req.strike_price, "riskFree": req.risk_free, "sigma": req.sigma, "days": req.days, "dividend": req.dividend}, "price")
|
||||
def bsm_iv(self, req): return self._post_field("/api/data/bsm_iv", camel_request(req), "iv")
|
||||
def local_data(self, req): return self._post_field("/api/data/local_data", {"stock_code": req.stock_code, "start_time": req.start_time, "end_time": req.end_time, "period": req.period, "divid_type": req.divid_type, "count": req.count}, "data")
|
||||
def subscribe_quote(self, code, period, dividend_type): return self._post("/api/data/subscribe_quote", {"stock_code": code, "period": period, "dividend_type": dividend_type})
|
||||
def unsubscribe_quote(self, sub_id): return self._post("/api/data/unsubscribe_quote", {"sub_id": sub_id})
|
||||
|
||||
|
||||
def locals_body(**kwargs): return kwargs
|
||||
def camel_request(req):
|
||||
data = asdict(req)
|
||||
return {"optionType": data["option_type"], "objectPrices": data["object_prices"], "strikePrice": data["strike_price"], "optionPrice": data["option_price"], "riskFree": data["risk_free"], "days": data["days"], "dividend": data["dividend"]}
|
||||
14
py-client/sdk/errors.py
Normal file
14
py-client/sdk/errors.py
Normal file
@@ -0,0 +1,14 @@
|
||||
class APIError(RuntimeError):
|
||||
def __init__(self, status_code: int, message: str = "") -> None:
|
||||
self.status_code = status_code
|
||||
self.message = message
|
||||
text = f"qmt api: http {status_code}"
|
||||
super().__init__(f"{text}: {message}" if message else text)
|
||||
|
||||
@property
|
||||
def unauthorized(self) -> bool:
|
||||
return self.status_code == 401
|
||||
|
||||
|
||||
class BusinessError(RuntimeError):
|
||||
pass
|
||||
31
py-client/sdk/misc.py
Normal file
31
py-client/sdk/misc.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from typing import Any
|
||||
|
||||
|
||||
class MiscMixin:
|
||||
def context_period(self): return self._get_field("/api/context/period", "period")
|
||||
def context_barpos(self): return self._get_field("/api/context/barpos", "barpos")
|
||||
def context_time_tick_size(self): return self._get_field("/api/context/time_tick_size", "time_tick_size")
|
||||
def context_stockcode(self): return self._get_field("/api/context/stockcode", "stockcode")
|
||||
def context_dividend_type(self): return self._get_field("/api/context/dividend_type", "dividend_type")
|
||||
def context_market(self): return self._get_field("/api/context/market", "market")
|
||||
def context_do_back_test(self): return self._get_field("/api/context/do_back_test", "do_back_test")
|
||||
def context_benchmark(self): return self._get_field("/api/context/benchmark", "benchmark")
|
||||
def context_capital(self): return self._get_field("/api/context/capital", "capital")
|
||||
def context_universe(self):
|
||||
value = self._get_field("/api/context/universe", "universe")
|
||||
if value is None: return []
|
||||
return [str(v) for v in value if str(v)] if isinstance(value, list) else [str(value)]
|
||||
|
||||
def is_last_bar(self): return self._get_field("/api/check/is_last_bar", "is_last_bar")
|
||||
def is_new_bar(self): return self._get_field("/api/check/is_new_bar", "is_new_bar")
|
||||
def is_suspended_stock(self, stockcode): return self._post_field("/api/check/is_suspended_stock", {"stockcode": stockcode}, "is_suspended")
|
||||
def is_sector_stock(self, sectorname, market, stockcode): return self._post_field("/api/check/is_sector_stock", {"sectorname": sectorname, "market": market, "stockcode": stockcode}, "is_in_sector")
|
||||
def is_typed_stock(self, stocktypenum, market, stockcode): return self._post_field("/api/check/is_typed_stock", {"stocktypenum": stocktypenum, "market": market, "stockcode": stockcode}, "result")
|
||||
def industry_name_of_stock(self, industry_type, stockcode): return self._post_field("/api/check/get_industry_name_of_stock", {"industryType": industry_type, "stockcode": stockcode}, "industry_name")
|
||||
|
||||
def ext_data(self, name, stockcode, deviation): return self._post_field("/api/ext/ext_data", {"extdataname": name, "stockcode": stockcode, "deviation": deviation}, "value")
|
||||
def ext_data_rank(self, name, stockcode, deviation): return self._post_field("/api/ext/ext_data_rank", {"extdataname": name, "stockcode": stockcode, "deviation": deviation}, "rank")
|
||||
def get_factor_value(self, name, stockcode, deviation): return self._post_field("/api/ext/get_factor_value", {"factorname": name, "stockcode": stockcode, "deviation": deviation}, "value")
|
||||
def get_factor_rank(self, name, stockcode, deviation): return self._post_field("/api/ext/get_factor_rank", {"factorname": name, "stockcode": stockcode, "deviation": deviation}, "rank")
|
||||
def python_version(self): return self._get("/api/sys/python_version")
|
||||
def shutdown(self): return self._post("/api/sys/shutdown", {})
|
||||
106
py-client/sdk/models.py
Normal file
106
py-client/sdk/models.py
Normal file
@@ -0,0 +1,106 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _number(value: Any, kind: type = float) -> Any:
|
||||
try:
|
||||
return kind(value or 0)
|
||||
except (TypeError, ValueError):
|
||||
return kind()
|
||||
|
||||
|
||||
@dataclass
|
||||
class Position:
|
||||
stock_code: str = ""
|
||||
stock_name: str = ""
|
||||
direction: Any = None
|
||||
volume: int = 0
|
||||
open_price: float = 0.0
|
||||
float_profit: float = 0.0
|
||||
market_value: float = 0.0
|
||||
stock_holder: str = ""
|
||||
frozen_volume: int = 0
|
||||
can_use_volume: int = 0
|
||||
on_road_volume: int = 0
|
||||
yesterday_volume: int = 0
|
||||
last_price: float = 0.0
|
||||
profit_rate: float = 0.0
|
||||
future_trade_type: Any = None
|
||||
expire_date: str = ""
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any], code: str = "") -> "Position":
|
||||
return cls(
|
||||
stock_code=str(data.get("StockCode") or code), stock_name=str(data.get("StockName") or ""),
|
||||
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 ""),
|
||||
frozen_volume=_number(data.get("FrozenVolume"), int), can_use_volume=_number(data.get("CanUseVolume"), int),
|
||||
on_road_volume=_number(data.get("OnRoadVolume"), int), yesterday_volume=_number(data.get("YesterdayVolume"), int),
|
||||
last_price=_number(data.get("LastPrice")), profit_rate=_number(data.get("ProfitRate")),
|
||||
future_trade_type=data.get("FutureTradeType"), expire_date=str(data.get("ExpireDate") or ""),
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Assets:
|
||||
total: float = 0.0
|
||||
available: float = 0.0
|
||||
|
||||
|
||||
@dataclass
|
||||
class Tick:
|
||||
last_price: float = 0.0
|
||||
last_close: float = 0.0
|
||||
raw: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass
|
||||
class HistoryDataRequest:
|
||||
length: int = 10
|
||||
period: str = ""
|
||||
field: str = ""
|
||||
dividend_type: int = 0
|
||||
skip_paused: bool = True
|
||||
|
||||
|
||||
@dataclass
|
||||
class MarketDataRequest:
|
||||
fields: list[str] = field(default_factory=list)
|
||||
stocks: list[str] = field(default_factory=list)
|
||||
start_time: str = ""
|
||||
end_time: str = ""
|
||||
period: str = ""
|
||||
dividend_type: str = ""
|
||||
count: int = 0
|
||||
|
||||
|
||||
@dataclass
|
||||
class FinancialDataRequest:
|
||||
tabname: str = ""; colname: str = ""; market: str = ""; code: str = ""
|
||||
report_type: str = ""; barpos: int = 0
|
||||
field_list: list[str] = field(default_factory=list); stock_list: list[str] = field(default_factory=list)
|
||||
start_date: str = ""; end_date: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
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
|
||||
class BSMPriceRequest:
|
||||
option_type: str; object_prices: Any; strike_price: float; risk_free: float; sigma: float; days: int; dividend: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class BSMIVRequest:
|
||||
option_type: str; object_prices: float; strike_price: float; option_price: float; risk_free: float; days: int; dividend: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class LocalDataRequest:
|
||||
stock_code: str; start_time: str = ""; end_time: str = ""; period: str = ""; divid_type: str = ""; count: int = 0
|
||||
54
py-client/sdk/trade.py
Normal file
54
py-client/sdk/trade.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from typing import Any
|
||||
|
||||
OP_BUY, OP_SELL = 23, 24
|
||||
ORDER_TYPE_VOLUME, PR_TYPE_LATEST, QUICK_TRADE_NOW = 1101, 5, 2
|
||||
|
||||
|
||||
class TradeMixin:
|
||||
account_type: str
|
||||
|
||||
def passorder(self, op_type, stock, volume, order_type=0, pr_type=0, price=0, quick_trade=0, strategy_name=""):
|
||||
body = {"opType": op_type, "stock": stock, "price": price, "volume": volume}
|
||||
for key, value in (("orderType", order_type), ("prType", pr_type), ("quickTrade", quick_trade), ("strategyName", strategy_name)):
|
||||
if value: body[key] = value
|
||||
return self._post("/api/trade/passorder", body)
|
||||
|
||||
def passorder_latest(self, side, stock, volume): return self.passorder_latest_tagged(side, stock, volume, "")
|
||||
def passorder_latest_tagged(self, side, stock, volume, order_id):
|
||||
return self.passorder(side, stock, volume, ORDER_TYPE_VOLUME, PR_TYPE_LATEST, -1, QUICK_TRADE_NOW, order_id)
|
||||
|
||||
def algo_passorder(self, **kwargs): return self._post("/api/trade/algo_passorder", kwargs)
|
||||
def smart_algo_passorder(self, **kwargs): return self._post("/api/trade/smart_algo_passorder", kwargs)
|
||||
|
||||
def _style_order(self, path, stock, value_key, value, style, price):
|
||||
return self._post(path, {"stock": stock, value_key: value, "style": style, "price": price})
|
||||
def order_lots(self, stock, lots, style, price): return self._style_order("/api/trade/order_lots", stock, "lots", lots, style, price)
|
||||
def order_value(self, stock, value, style, price): return self._style_order("/api/trade/order_value", stock, "value", value, style, price)
|
||||
def order_percent(self, stock, percent, style, price): return self._style_order("/api/trade/order_percent", stock, "percent", percent, style, price)
|
||||
def order_target_value(self, stock, value, style, price): return self._style_order("/api/trade/order_target_value", stock, "tar_value", value, style, price)
|
||||
def order_target_percent(self, stock, percent, style, price): return self._style_order("/api/trade/order_target_percent", stock, "tar_percent", percent, style, price)
|
||||
def order_shares(self, stock, shares, style, price): return self._style_order("/api/trade/order_shares", stock, "shares", shares, style, price)
|
||||
|
||||
def _future(self, action, stock, amount, style, price): return self._style_order(f"/api/trade/futures/{action}", stock, "amount", amount, style, price)
|
||||
def futures_buy_open(self, *args): return self._future("buy_open", *args)
|
||||
def futures_buy_close_tdayfirst(self, *args): return self._future("buy_close_tdayfirst", *args)
|
||||
def futures_buy_close_ydayfirst(self, *args): return self._future("buy_close_ydayfirst", *args)
|
||||
def futures_sell_open(self, *args): return self._future("sell_open", *args)
|
||||
def futures_sell_close_tdayfirst(self, *args): return self._future("sell_close_tdayfirst", *args)
|
||||
def futures_sell_close_ydayfirst(self, *args): return self._future("sell_close_ydayfirst", *args)
|
||||
|
||||
def _task(self, action, task_id): return self._post(f"/api/trade/{action}_task", {"taskId": task_id, "accountType": self.account_type})
|
||||
def cancel_task(self, task_id): return self._task("cancel", task_id)
|
||||
def pause_task(self, task_id): return self._task("pause", task_id)
|
||||
def resume_task(self, task_id): return self._task("resume", task_id)
|
||||
def do_order(self): return self._post("/api/trade/do_order")
|
||||
def trade_detail_data(self, datatype): return self._post("/api/trade/trade_detail_data", {"account": self.account_type, "datatype": datatype}).get("data", [])
|
||||
def value_by_order_id(self, order_id, datatype): return self._post("/api/trade/value_by_order_id", {"orderId": order_id, "accountType": self.account_type, "datatype": datatype}).get("data")
|
||||
def last_order_id(self, datatype): return self._post("/api/trade/last_order_id", {"account": self.account_type, "datatype": datatype}).get("last_order_id")
|
||||
def can_cancel_order(self, order_id): return self._post("/api/trade/can_cancel_order", {"orderId": order_id, "accountType": self.account_type}).get("can_cancel")
|
||||
def debt_contract(self): return self._contract("debt_contract")
|
||||
def assure_contract(self): return self._contract("assure_contract")
|
||||
def enable_short_contract(self): return self._contract("enable_short_contract")
|
||||
def _contract(self, name): return self._post(f"/api/trade/{name}").get("data", [])
|
||||
def ipo_data(self, typ): return self._post_field("/api/trade/ipo_data", {"type": typ}, "data")
|
||||
def new_purchase_limit(self): return self._post_field("/api/trade/new_purchase_limit", None, "data")
|
||||
Reference in New Issue
Block a user