Skip to main content

TdDriver

Struct TdDriver 

Source
pub struct TdDriver {
    pub reqid: i64,
    /* private fields */
}
Expand description

TD 状态机。

Fields§

§reqid: i64

请求计数(原稿 reqid;native 层使用)

Implementations§

Source§

impl TdDriver

Source

pub fn new(gw: &str, cfg: TdConfig, contracts: Contracts) -> Self

构造(生产面):单调钟锚定到驱动创建时刻。

Source

pub fn with_clock( gw: &str, cfg: TdConfig, contracts: Contracts, now_ms: Arc<dyn Fn() -> u64 + Send + Sync>, ) -> Self

构造 + 注入单调钟(0.9.6,测试接缝)。

护栏要的是「距上一发过了多久」,不是「过了几拍」。真钟下测试里连续调 on_timer 之间 elapsed≈0,会被护栏全挡 —— 那样所有节律钉都测不到周期本身,而“排队拍挤在一起 处理“这个真实失效模式也永远测不到。所以假钟必须能注入,这不是可选项。

Source

pub fn local_orderid(&self, order_ref: &str) -> String

本地委托号段(front_session_ref 三段下划线,原稿 495/681/850)。

Source

pub fn auth_failed(&self) -> bool

认证失败标志(63 错;原稿 auth_failed 781-782 由 authenticate 的守卫读)。

Source

pub fn product_classes(&self) -> Vec<String>

当前生效的产品类白名单(已归一化;供回包/界面显示)。

Source

pub fn contract_counts(&self) -> (usize, usize, usize)

合约阶段计数快照 (收录, 按勾选丢弃, 未映射)(测试与日志核对用)。

Source

pub fn anomaly_counts(&self) -> AnomalyCounts

入向异常读数(0.12.0 D-ANOMALY-SURFACE;零丢弃矩阵与状态口的判据面)。

Source

pub fn last_anomaly_ms(&self) -> Option<i64>

最近一次入向异常的纪元毫秒(从未发生 = None;界面不得显示“0 秒前“)。

Source

pub fn contract_name(&self, symbol: &str) -> Option<String>

合约表里的名称(0.11.0 第5刀 R6):插件在发单/成交/持仓行上补这一栏。

映射层刻意不吃合约参数(0.7.0 甲的纪律:converter 语义),所以名称不在 map.rs 里填;名称是网关侧的富化:map.rs 只负责“柜台给了什么“, 发之前的这一笔由插件把“共享表里 known 的名字“补上。查不到就留空, 绝不因为缺名字丢行(红线①)。

Source

pub fn login_status(&self) -> bool

登录态(适配层复接用)。

Source

pub fn login_failed(&self) -> bool

登录失败标志(原稿 796-797 的 login 守卫,登录失败不再续发;适配层用)。

Source

pub fn positions_len(&self) -> usize

当前持仓合并缓存键数(测试/适配复接用)。

Source

pub fn front_id(&self) -> i64

FrontID(登录回报;适配层使用)。

Source

pub fn connect_status(&self) -> bool

连接态(原稿 close 401-404 / 889-892 的 if connect_status: exit() 守卫,适配层用)。

Source

pub fn session_id(&self) -> i64

SessionID。

Source

pub fn order_ref(&self) -> i64

已本地报单计数(order_ref;适配层使用)。

Source

pub fn send_order(&mut self, req: &OrderRequest) -> SendOutcome

发单(原稿 send_order 808-854)。 Returns 输出动作 + en_orderid。 校验路径原样(missings log + ""):开平/类型缺者不放行; 方向 miss(NET)→ 空报单方向(原稿 get(…,“”) 行为)。

Source

pub fn flow_path(&self) -> String

流文件目录(原稿 createFtdcTraderApi 767:{gateway_name}\\Td)。

Source

pub fn connect(&mut self) -> Vec<TdOut>

连接(原稿 TD connect 763-777):首次 → 发 ReqConnect;重复调用 → authenticate()(含 auth_failed 守卫)。close 守卫面由 connect_status() getter 提供给适配层(原稿 889-892)。

Source

pub fn reconfigure(&mut self, cfg: TdConfig)

换配置并复位连接/认证/登录/合约守卫(0.3.0 configure 面;错密改密 再连的正路)。持仓/订单缓存保留(交易所侧会重报);TD 侧有地址时共享合约表清空 (0.6.0,D-PC-FILTER —— 勾选收窄必须真生效,configure 本就重走全量查询; MD-only 配置不清,因为没有任何东西会把表重新灌满)。

Source

pub fn note_query_send_failure( &mut self, label: &str, code: i32, ) -> Vec<LogData>

Source

pub fn note_instrument_send_failure(&mut self, code: i32) -> Vec<LogData>

合约查询发送被拒(0.9.3 计数,0.9.4 改重发口径): ① 进同一条 query_rejects / query_reject_streak,也进 instrument_rejects 分项 (发送侧被拒同样是“合约一条没到手“的原因,分项不分发送侧还是回报侧); ② 不在这里排重发 —— 重发归 Self::on_timer 的合约状态机,触发条件是 「10 秒里没有合约信息过来」,不是「返回码非 0」。被拒当然也属于没到手, 但那一发已经算进 attempts 了,再排一次就是把同一秒问两遍。

Source

pub fn status_view(&self) -> TdStatusView

0.9.0 状态读数(只读,不改任何状态)。

Source

pub fn reset_session(&mut self)

0.9.0 {gw}.disconnect:停这一侧会话(守卫复位,查询阶段回 Idle)。

不清的东西写明:断开计数、登录/回报「最近时刻」、被拒计数、持仓合并缓存、 OrderSysID 映射 —— 它们是跨会话的历史事实与账本映射,清掉等于抹掉掉线证据、 并让在途撤单的号对不上。auth_failed 也不清(它归 reconfigure 管: 『连接』走 configure,那里才是换凭据的地方)。

Source

pub fn authenticate(&mut self) -> Vec<TdOut>

认证(原稿 779-792;auth_failed 守卫 781-782 静默不重发)。

Source

pub fn login(&mut self) -> Vec<TdOut>

登录(原稿 794-806;login_failed 守卫 796-797 静默不重发)。

Source

pub fn cancel_order(&mut self, req: &CancelRequest) -> Vec<TdOut>

Source

pub fn on_timer(&mut self) -> Vec<TdOut>

周期查询的唯一协调点(0.9.8 改成阶段机):每一拍发不发、发哪一条由这里一次决定。

三个闸,全是墙钟(与驱动的单调毫秒钟同钟同基准): ① 首发合约 —— 距发出结算单确认请求 ≥ INSTRUMENT_FIRST_WAIT_MS; ② 重发合约 / 问满警告 —— 距上一发真发出去 ≥ INSTRUMENT_RETRY_WAIT_MS,同一个数 兼作第三发的回报窗口,窗口走完仍无合约才警告; ③ 资金 / 持仓轮询 —— 距上一发 ≥ QUERY_MIN_INTERVAL_MS,不满就这一拍不发、等下一拍。

阶段(用户定口径):Idle 什么都不发 → Instrument 问合约(最多 3 次)→ 任一合约行 到手 → Rotating 交替轮询;3 次问满仍无合约 → 警告一次 → Halted 什么都不再发。 闸在阶段之前:被挡的这一拍不推进任何计数(挡一格还推进计数,就是把节律改掉一格)。

Source

pub fn instrument_retry(&self) -> (u32, bool, bool)

合约这一路的当前读数(0.9.5;测试用):已问几次、是否已了结、是否已警告。 「已了结」= 阶段已离开 Instrument(到手进 Rotating,问满进 Halted)。

Source

pub fn query_phase(&self) -> QueryPhase

当前查询阶段(0.9.8;状态口与测试用)。

Source

pub fn step(&mut self, ev: TdEvent) -> Vec<TdOut>

步进(原型 CtpTdApi 各回调)。

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more