pub struct RiskModule { /* private fields */ }Implementations§
Source§impl RiskModule
impl RiskModule
Sourcepub fn new(
rest_client: Arc<BinanceRestClient>,
global_rate_limit_per_minute: u32,
endpoint_limits: EndpointRateLimits,
) -> Self
pub fn new( rest_client: Arc<BinanceRestClient>, global_rate_limit_per_minute: u32, endpoint_limits: EndpointRateLimits, ) -> Self
Build a risk module with a per-minute global rate budget.
global_rate_limit_per_minute is clamped to at least 1 to prevent an
always-rejecting configuration.
Sourcepub fn rate_budget_snapshot(&self) -> RateBudgetSnapshot
pub fn rate_budget_snapshot(&self) -> RateBudgetSnapshot
Return current global rate-budget usage.
Use this for UI/telemetry only. It does not reserve capacity.
Sourcepub fn reserve_rate_budget(&mut self) -> bool
pub fn reserve_rate_budget(&mut self) -> bool
Reserve one unit from the global rate budget.
This method resets the rolling minute window when needed and then consumes exactly one request token.
Returns false when the current minute budget is exhausted.
§Usage
Call this once per outbound broker request, after risk approval and immediately before submission.
§Caution
Do not call this speculatively and then skip submission; doing so reduces usable throughput and can cause unnecessary rejections.
pub fn reserve_endpoint_budget(&mut self, group: ApiEndpointGroup) -> bool
pub fn endpoint_budget_snapshot( &self, group: ApiEndpointGroup, ) -> RateBudgetSnapshot
Sourcepub async fn evaluate_intent(
&self,
intent: &OrderIntent,
balances: &HashMap<String, f64>,
) -> Result<RiskDecision>
pub async fn evaluate_intent( &self, intent: &OrderIntent, balances: &HashMap<String, f64>, ) -> Result<RiskDecision>
Evaluate an order intent against risk rules and exchange filters.
This performs:
- price availability validation,
- quantity derivation and normalization by market rules,
- min/max quantity validation,
- spot balance sufficiency checks.
§Returns
Ok(RiskDecision { approved: true, .. })when submission is allowed.Ok(RiskDecision { approved: false, .. })for expected business-rule rejection (insufficient balance, too-small qty, etc).Err(_)when exchange metadata fetch fails or other runtime errors occur.
§Usage
Use as the first gate in an order pipeline:
- Build
OrderIntent. - Call
evaluate_intent. - If approved, call
reserve_rate_budget. - Submit order to broker.
§Caution
balancesshould be recently refreshed. Stale balances can produce false approvals/rejections.- For spot sell, requested size is currently driven by available base
balance and then normalized, not by
order_amount_usdt. - This function does not place orders or mutate state.
Auto Trait Implementations§
impl Freeze for RiskModule
impl !RefUnwindSafe for RiskModule
impl Send for RiskModule
impl Sync for RiskModule
impl Unpin for RiskModule
impl UnsafeUnpin for RiskModule
impl !UnwindSafe for RiskModule
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more