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 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):先做 1s 轻量判定 (0.7.0 轮转闸门的 3 秒兜底,必须按 1s 计,放进 2s gate 会退化成 4s) → 2s gate 轮转查询 + 行情日期刷新。这样独立出来服务测试与 native 适配。

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 + 驱动守卫复位,轮转闸门关闭)。 保留:插件实例、账号配置、订阅集、断开计数与「最近时刻」、持仓合并缓存、 OrderSysID 映射。恢复走『连接』(= configure 重走全链,登录后自动重订阅)。

Source

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

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

Trait Implementations§

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 deps(&self) -> &[&str]

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

fn mailbox_cap(&self) -> usize

邮箱容量覆写(D5:按插件可小可大,默认 MAILBOX_CAP)。

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.