RuntimeCounters

Struct RuntimeCounters 

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

运行时限额状态:每 key 的日累计计数器 + 速率窗口

Implementations§

Source§

impl RuntimeCounters

Source

pub fn new() -> Self

Source

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

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

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

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