pub struct RuntimeCounters { /* private fields */ }Expand description
运行时限额状态:每 key 的日累计计数器 + 速率窗口
Implementations§
Source§impl RuntimeCounters
impl RuntimeCounters
pub fn new() -> Self
Sourcepub fn check_and_commit(
&self,
key_id: &str,
limits: &Limits,
ctx: &CheckCtx,
now: DateTime<Utc>,
) -> LimitOutcome
pub fn check_and_commit( &self, key_id: &str, limits: &Limits, ctx: &CheckCtx, now: DateTime<Utc>, ) -> LimitOutcome
执行全部限额检查;通过则(若提供 order_value)累加日计数 + 记录速率窗口时间戳
检查顺序:市场 → 品种 → 方向 → 时间窗 → 单笔 → 速率 → 日累计。 前面的便宜检查先跑;日累计放最后是因为它有副作用(累加), 前面 reject 就不该动计数器。
Sourcepub fn check_full_skip_rate(
&self,
key_id: &str,
limits: &Limits,
ctx: &CheckCtx,
now: DateTime<Utc>,
) -> LimitOutcome
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
impl Debug for RuntimeCounters
Source§impl Default for RuntimeCounters
impl Default for RuntimeCounters
Source§fn default() -> RuntimeCounters
fn default() -> RuntimeCounters
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RuntimeCounters
impl !RefUnwindSafe for RuntimeCounters
impl Send for RuntimeCounters
impl Sync for RuntimeCounters
impl Unpin for RuntimeCounters
impl UnwindSafe for RuntimeCounters
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more