Skip to main content

RuntimeCounters

Struct RuntimeCounters 

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

Implementations§

Source§

impl RuntimeCounters

Source

pub fn check_limits<'a>( &'a self, key_id: &str, limits: &(impl LimitPolicy + ?Sized), 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§

impl RuntimeCounters

Source

pub fn check_and_commit( &self, key_id: &str, limits: &(impl LimitPolicy + ?Sized), 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: &(impl LimitPolicy + ?Sized), 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 才是真实金额额度。

Source§

impl RuntimeCounters

Source

pub fn check_batch_limits<'a>( &'a self, key_id: &str, limits: &(impl LimitPolicy + ?Sized), contexts: &[CheckCtx], now: DateTime<Utc>, commit_rate: bool, receipt_id: &str, ) -> Result<BatchLimitGuard<'a>, LimitOutcome>

Validate a complete group write and return one atomic daily receipt. receipt_id must be the durable caller+intent identity shared by every transport surface and the gateway writer.

Source

pub fn release_batch_receipt( &self, key_id: &str, receipt_id: &str, contexts: &[CheckCtx], ) -> Result<bool, LimitOutcome>

Release an authoritative explicit-reject reservation exactly once. Unknown/timeout/malformed outcomes must not call this method.

Source

pub fn release_batch_receipt_by_id( &self, key_id: &str, receipt_id: &str, ) -> Result<bool, LimitOutcome>

Release the exact durable caller+intent receipt after an authoritative asynchronous failure. The original request contexts are already bound into the immutable receipt fingerprint and deltas at commit time.

Source§

impl RuntimeCounters

Source

pub fn new() -> Self

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.

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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<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