Skip to main content

CtpPlugin

Struct CtpPlugin 

Source
pub struct CtpPlugin { /* private fields */ }
Expand description

CTP 网关插件(纯生产者 + 自服务)。

Implementations§

Source§

impl CtpPlugin

Source

pub fn new(cfg: CtpConfig) -> Self

纯逻辑构造(native 尚未接传输)。

Source

pub fn with_transport(cfg: CtpConfig, trans: Box<dyn CtpTransport>) -> Self

注入传输层(native 桥或测试桩)。

Source

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 秒,而且变成时间依赖(以后会偶发红)。

Source

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,这里无需动作。

Source

pub fn on_md_event(&self, ev: MdEvent)

原生适配入口(native 桥的回调直接调这四个):MD 回报步进 + 总线上抛。

Source

pub fn on_td_event(&self, ev: TdEvent)

原生适配入口(native 桥的回调直接调这四个):TD 回报步进 + 总线上抛。

Source

pub fn on_timer(&self)

eTimer 一拍(原稿 gateway.process_timer_event)。

0.9.4 分工:每一拍都问驱动 —— TdDriver::on_timer 是三条查询路(合约重发 / 资金轮 / 持仓轮)的唯一协调点,它自己按拍决定这一拍发哪一条、最多发一条。 插件这里保留原稿的 2 秒 gate 只给行情日期刷新(md.update_date 走的是另一条 连接,不占交易前置的查询名额)。

Source

pub fn flush_contract(&self)

发掉不满一批的尾巴(收尾 / 会话复位 / 摘插件时调用)。空则什么都不做。

Source

pub fn status(&self) -> GatewayStatus

状态口(0.9.0 新增;公开与 configure 同级;ask 臂 {gw}.status 走它)。

纪律:只读——不改任何守卫、不触发重连、不写日志(界面按秒级刷, 每次刷都写日志会把 eLog 环冲爆,512 行取证环就是这么饱和的)。

Source

pub fn disconnect(&self) -> DisconnectReply

断开口(0.9.0 新增;裁定 1「断开 = 停会话,实例与订阅保留」)。

放掉:两侧会话(传输层 release + 驱动守卫复位,查询阶段回 Idle)。 保留:插件实例、账号配置、订阅集、断开计数与「最近时刻」、持仓合并缓存、 OrderSysID 映射。恢复走『连接』(= configure 重走全链,登录后自动重订阅)。

Source

pub fn configure(&self, r: &ConfigureReq) -> ConfigureReply

配置口(公开,与 connect 同级的显式控制面;ask 臂 {gw}.configure 走的也是它)。

Source

pub fn credentials_state(&self) -> Vec<CredentialEntry>

凭据档位快照(只读;{gw}.credentials_state ask 臂与运维窗呈现共用, BD-CFG-17 的呈现语义:以文件引用为准)。

Trait Implementations§

Source§

impl Configurable for CtpPlugin

Source§

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

导出(BD-CFG-15):非秘键 plain 出(该键非空才落),秘键只在 引用已登记时出引用形态;内存明文无引用 → 在本次落库登记(保存动作 线程;keyring 写毫秒级可忍)并出引用。值永不落文件(BD-CFG-12)。

Source§

fn config_ns(&self) -> &str

命名空间(全链唯一;add_plugin 期撞名校验)。
Source§

fn config_schema(&self) -> Vec<ConfigField>

参数自描述(「插件即 App」波加项,缺省空 = 老插件零负担)。 Read more
Source§

fn config_view(&self) -> Vec<(String, String)>

当前值视图(缺省走 crate::cfg_face::view_of = dump 形态)。 Read more
Source§

impl Default for CtpPlugin

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Plugin for CtpPlugin

Source§

fn name(&self) -> &str

注册键(D2 校验)。
Source§

fn routes(&self) -> Vec<Cow<'static, str>>

订阅的 type 集合:广播 type(如业务常量 “eTick.”)、 自身的寻址 type(e_req_type(本名)/e_to_type(本名))。 宿主 start() 装配 forwarder → 邮箱 → on_mail。
Source§

fn version(&self) -> Cow<'static, str>

插件版本(约定填 crate 版本)。默认空串 = 「未知版本」。 Read more
Source§

fn services(&self) -> Vec<ServiceDesc>

服务目录自报(纯声明):只在 add_plugin 时被宿主读取一次抽 id 织入路由索引; 之后 ctx.services_of/find_service/ask_service 需要明细时由宿主现场调用本方法取。 Read more
Source§

fn on_init(&self, ctx: &PluginContext)

可选:启动前纯接线(缓存 ctx、读配置)。禁止在此 put/注册 handler(规范)。
Source§

fn on_start(&self)

start() 按依赖拓扑序调用(只一次)。
Source§

fn on_stop(&self)

close/remove 按逆依赖序调用;调用后保证不再收到邮件。
Source§

fn on_mail(&self, event: &Event)

★ 唯一业务入口:永远在本插件 worker 线程上串行执行。 广播事件、寻址请求(eReq.<本名>)、定向通知(eTo.<本名>)都从这里进。
Source§

fn as_configurable(&self) -> Option<&dyn Configurable>

配置托底可选能力(ek-core 0.4.0,BD-CFG):有配置面的插件覆写返回 Some(self);缺省 None = 「无配置面」,宿主探查一行事、视而不见 (存量插件零改动零运行时负担)。 Read more
Source§

fn deps(&self) -> &[&str]

D1 显式依赖清单(宿主注册期校验存在性,start 期拓扑排序)。
Source§

fn mailbox_soft_cap(&self) -> u64

邮箱软顶覆写(D5 改案:缺省 MAILBOX_SOFT_CAP,按插件可大可小)。 Read more
Source§

fn as_any(&self) -> Option<&(dyn Any + 'static)>

向下转型口(0.5.2,「插件即 App」波)。 Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.