跳转至

xtquant_manager.manager

XtQuantManager — 多账号注册表 + 请求分发(单例)

职责: - 维护多个 XtQuantAccount 实例的注册表 - 提供统一的请求分发接口 - 单例模式,全局唯一实例

XtQuantManager

XtQuantManager()

多账号管理器,线程安全单例。

Usage

manager = XtQuantManager.get_instance() manager.register_account(AccountConfig(...)) order_id = manager.order_stock("55009640", ...)

get_instance classmethod

get_instance() -> XtQuantManager

获取全局单例

reset_instance classmethod

reset_instance() -> None

重置单例(仅用于测试)

register_account

register_account(config: AccountConfig) -> bool

注册账号并建立连接。 如果 account_id 已存在,先断开旧实例再覆盖。

参数:

名称 类型 描述 默认
config AccountConfig

账号配置

必需

返回:

类型 描述
bool

True = 注册并连接成功,False = 连接失败(账号仍被注册)

unregister_account

unregister_account(account_id: str) -> bool

断开并移除账号。

参数:

名称 类型 描述 默认
account_id str

账号 ID

必需

返回:

类型 描述
bool

True = 成功移除,False = 账号不存在

get_account

get_account(account_id: str) -> XtQuantAccount

获取账号对象。

引发:

类型 描述
AccountNotFoundError

账号不存在

list_accounts

list_accounts() -> List[str]

返回所有已注册账号 ID 列表

shutdown

shutdown() -> None

断开所有账号连接

order_stock

order_stock(account_id: str, stock_code: str, order_type: int, order_volume: int, price_type: int, price: float, strategy_name: str = '', order_remark: str = '') -> int

下单,失败返回 -1

cancel_order

cancel_order(account_id: str, order_id: int) -> int

撤单

query_positions

query_positions(account_id: str) -> List[dict]

查询持仓

query_asset

query_asset(account_id: str) -> dict

查询资产

query_orders

query_orders(account_id: str) -> List[dict]

查询委托

query_trades

query_trades(account_id: str) -> List[dict]

查询成交

get_full_tick

get_full_tick(account_id: str, stock_codes: List[str]) -> dict

获取全推行情

get_market_data_ex

get_market_data_ex(account_id: str, fields: list, stock_list: List[str], period: str = '1d', start_time: str = '20200101', end_time: str = '') -> dict

获取历史行情

download_history_data

download_history_data(account_id: str, stock_code: str, period: str = '1d', start_time: str = '20200101', end_time: str = '') -> bool

下载历史数据

get_all_states

get_all_states() -> Dict[str, dict]

返回所有账号状态快照

get_all_metrics

get_all_metrics() -> Dict[str, dict]

返回所有账号指标快照

get_account_state

get_account_state(account_id: str) -> dict

返回指定账号状态

get_account_metrics

get_account_metrics(account_id: str) -> dict

返回指定账号指标