Skip to main content

RuntimeCounters

Struct RuntimeCounters 

Source
pub struct RuntimeCounters { /* private fields */ }

Implementations§

Source§

impl RuntimeCounters

Source

pub fn new() -> Self

Source

pub fn check_limits<'a>( &'a self, key_id: &str, limits: &Limits, ctx: &CheckCtx, now: DateTime<Utc>, commit_rate: bool, ) -> Result<LimitGuard<'a>, LimitOutcome>

v1.4.106 codex 0538 F3 (P2): accepted-quota architecture entry.

跑全部限额检查 (whitelist + per-order cap + rate + daily peek), 但 累加 daily counter — 返 LimitGuard 让 caller 在 backend 成功后 显式 commit_daily().

失败 → drop(guard) 不写 daily counter, 配额自然归还 (与 legacy check_and_commit 在失败前就累加的 attempted-quota 行为相反).

rate 在本函数仍 commit (rate 是节流不是 quota, 失败重试也算消耗).

参数:

  • commit_rate: true = 跑 rate window 累加 (auth middleware 入口); false = 跳过 rate (handler 层重入, 等同 check_full_skip_rate).
Source

pub fn check_and_commit( &self, key_id: &str, limits: &Limits, ctx: &CheckCtx, now: DateTime<Utc>, ) -> LimitOutcome

执行全部限额检查;通过则(若提供 order_value)累加日计数 + 记录速率窗口时间戳

检查顺序:市场 → 品种 → 方向 → 时间窗 → 单笔 → 速率 → 日累计。 前面的便宜检查先跑;日累计放最后是因为它有副作用(累加), 前面 reject 就不该动计数器。

v1.4.106 codex 0538 F3: 此 wrapper 保持 v1.4.105 attempted-quota 行为 (legacy compat). 新代码应迁移到 Self::check_limits + LimitGuard::commit_daily 走 accepted-quota 模型.

Source

pub fn check_full_skip_rate( &self, key_id: &str, limits: &Limits, ctx: &CheckCtx, now: DateTime<Utc>, ) -> LimitOutcome

handler 层细粒度检查:跑 market / symbol / trd_side / hours / per_order / daily 全套,但跳过 rate —— rate 已经在 auth 中间件层(v1.0) commit 过了,handler 再 commit 一次会让 rate 窗口计 2 次。

典型用法:REST /api/order 路由 / gRPC request(2202) 这种 handler 已经知道完整下单参数(market/symbol/value/side),调用方先在 middleware 跑 rate+hours 全局闸门(check_and_commit with empty CheckCtx),过了 再在 handler 里跑这个方法做细粒度检查。

注意:daily 计数器累加 —— 这是必须的,因为 rate 不能算“额度“, daily 才是真实金额额度。

Trait Implementations§

Source§

impl Debug for RuntimeCounters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RuntimeCounters

Source§

fn default() -> RuntimeCounters

Returns the “default value” for a type. 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.

§

impl<T> Instrument for T

§

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

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

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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