pub struct CtpPlugin { /* private fields */ }Expand description
CTP 网关插件(纯生产者 + 自服务)。
Implementations§
Source§impl CtpPlugin
impl CtpPlugin
Sourcepub fn with_transport(cfg: CtpConfig, trans: Box<dyn CtpTransport>) -> Self
pub fn with_transport(cfg: CtpConfig, trans: Box<dyn CtpTransport>) -> Self
注入传输层(native 桥或测试桩)。
Sourcepub fn with_transport_and_clock(
cfg: CtpConfig,
trans: Box<dyn CtpTransport>,
now_ms: Arc<dyn Fn() -> u64 + Send + Sync>,
) -> Self
pub fn with_transport_and_clock( cfg: CtpConfig, trans: Box<dyn CtpTransport>, now_ms: Arc<dyn Fn() -> u64 + Send + Sync>, ) -> Self
注入传输层 + 驱动单调钟(0.9.6,测试接缝)。
协调点的护栏按真实时间放行:真钟下测试里连续调 on_timer 之间 elapsed≈0,会被
全挡。驱动级有 TdDriver::with_clock,但插件级钉(plugin_full_bus_roundtrip 那三条)
走的是插件内部自建的驱动 —— 没有这个接缝,它们只能改成真 sleep(1s):网关测试套从
1 秒拖成 6 秒,而且变成时间依赖(以后会偶发红)。
Sourcepub fn connect(&self)
pub fn connect(&self)
连接(原稿 CtpGateway.connect 162-190:先 TD 后 MD;init_query 只是挂秒针)。
连接触发点住在本插件里(不放到核心/公共层,每个插件自持自己的连接):
宿主 start() 会经 Plugin::on_start 调它一次;要显式控制(先配后连、
断线后重连)也可以直接调。幂等由驱动守卫裁决 —— 原稿 MD 重复调用静默,
TD 重复调用转认证(776-777),两者都在 MdDriver::connect/TdDriver::connect。
原稿末尾的 init_query 只是把查询轮转注册到 EVENT_TIMER(237-240);
本 crate 的对应面是宿主 eTimer → CtpPlugin::on_timer,这里无需动作。
Sourcepub fn on_md_event(&self, ev: MdEvent)
pub fn on_md_event(&self, ev: MdEvent)
原生适配入口(native 桥的回调直接调这四个):MD 回报步进 + 总线上抛。
Sourcepub fn on_td_event(&self, ev: TdEvent)
pub fn on_td_event(&self, ev: TdEvent)
原生适配入口(native 桥的回调直接调这四个):TD 回报步进 + 总线上抛。
Sourcepub fn on_timer(&self)
pub fn on_timer(&self)
eTimer 一拍(原稿 gateway.process_timer_event)。
0.9.4 分工:每一拍都问驱动 —— TdDriver::on_timer 是三条查询路(合约重发 /
资金轮 / 持仓轮)的唯一协调点,它自己按拍决定这一拍发哪一条、最多发一条。
插件这里保留原稿的 2 秒 gate 只给行情日期刷新(md.update_date 走的是另一条
连接,不占交易前置的查询名额)。
Sourcepub fn flush_contract(&self)
pub fn flush_contract(&self)
发掉不满一批的尾巴(收尾 / 会话复位 / 摘插件时调用)。空则什么都不做。
Sourcepub fn status(&self) -> GatewayStatus
pub fn status(&self) -> GatewayStatus
状态口(0.9.0 新增;公开与 configure 同级;ask 臂 {gw}.status 走它)。
纪律:只读——不改任何守卫、不触发重连、不写日志(界面按秒级刷, 每次刷都写日志会把 eLog 环冲爆,512 行取证环就是这么饱和的)。
Sourcepub fn disconnect(&self) -> DisconnectReply
pub fn disconnect(&self) -> DisconnectReply
断开口(0.9.0 新增;裁定 1「断开 = 停会话,实例与订阅保留」)。
放掉:两侧会话(传输层 release + 驱动守卫复位,查询阶段回 Idle)。
保留:插件实例、账号配置、订阅集、断开计数与「最近时刻」、持仓合并缓存、
OrderSysID 映射。恢复走『连接』(= configure 重走全链,登录后自动重订阅)。
Sourcepub fn configure(&self, r: &ConfigureReq) -> ConfigureReply
pub fn configure(&self, r: &ConfigureReq) -> ConfigureReply
配置口(公开,与 connect 同级的显式控制面;ask 臂 {gw}.configure
走的也是它)。
Sourcepub fn credentials_state(&self) -> Vec<CredentialEntry>
pub fn credentials_state(&self) -> Vec<CredentialEntry>
凭据档位快照(只读;{gw}.credentials_state ask 臂与运维窗呈现共用,
BD-CFG-17 的呈现语义:以文件引用为准)。
Trait Implementations§
Source§impl Configurable for CtpPlugin
impl Configurable for CtpPlugin
Source§fn apply_config(&self, m: &SectionMap) -> Result<ApplyReport, String>
fn apply_config(&self, m: &SectionMap) -> Result<ApplyReport, String>
键位与段语义(0.10.0 v1;apply 为补丁合入,段缺键 = 沿用现值)。
本方法禁调 secret::get(只被 boot/管理线程调用,BD-CFG-16)——
秘面只登记引用行,解密在 on_start(worker 面)。
Source§fn dump_config(&self) -> SectionMap
fn dump_config(&self) -> SectionMap
导出(BD-CFG-15):非秘键 plain 出(该键非空才落),秘键只在 引用已登记时出引用形态;内存明文无引用 → 在本次落库登记(保存动作 线程;keyring 写毫秒级可忍)并出引用。值永不落文件(BD-CFG-12)。
Source§fn config_schema(&self) -> Vec<ConfigField>
fn config_schema(&self) -> Vec<ConfigField>
Source§fn config_view(&self) -> Vec<(String, String)>
fn config_view(&self) -> Vec<(String, String)>
crate::cfg_face::view_of = dump 形态)。 Read moreSource§impl Plugin for CtpPlugin
impl Plugin for CtpPlugin
Source§fn routes(&self) -> Vec<Cow<'static, str>>
fn routes(&self) -> Vec<Cow<'static, str>>
Source§fn services(&self) -> Vec<ServiceDesc>
fn services(&self) -> Vec<ServiceDesc>
id 织入路由索引;
之后 ctx.services_of/find_service/ask_service 需要明细时由宿主现场调用本方法取。 Read moreSource§fn on_init(&self, ctx: &PluginContext)
fn on_init(&self, ctx: &PluginContext)
Source§fn on_mail(&self, event: &Event)
fn on_mail(&self, event: &Event)
Source§fn as_configurable(&self) -> Option<&dyn Configurable>
fn as_configurable(&self) -> Option<&dyn Configurable>
Some(self);缺省 None = 「无配置面」,宿主探查一行事、视而不见
(存量插件零改动零运行时负担)。 Read moreSource§fn mailbox_soft_cap(&self) -> u64
fn mailbox_soft_cap(&self) -> u64
MAILBOX_SOFT_CAP,按插件可大可小)。 Read more