pub struct InsurancePoolUpdate {
pub topic: String,
pub event_type: String,
pub timestamp: u64,
pub data: Vec<InsurancePool>,
}Expand description
Represents a WebSocket insurance pool update event.
Contains real-time updates to insurance pool balances for various symbols. Push frequency: 1 second for USDT contracts, USDC contracts, and inverse contracts.
Fields§
§topic: StringThe WebSocket topic for the event (e.g., “insurance.USDT”, “insurance.USDC”, “insurance.inverse”).
Specifies the data stream for the insurance pool update. Bots use this to determine which contract group the update belongs to.
event_type: StringThe event type (e.g., “snapshot”, “delta”).
Snapshot contains the full current state, delta contains incremental changes. Bots should use snapshot to initialize state and delta to update it.
timestamp: u64The timestamp of the event in milliseconds.
Indicates when the insurance pool update was generated by the system. Bots use this to ensure data freshness and time-based analysis.
data: Vec<InsurancePool>The insurance pool data.
Contains a list of insurance pool entries. Each entry represents the balance for a specific symbol or group of symbols. No event will be published if all insurance pool balances remain unchanged.
Implementations§
Source§impl InsurancePoolUpdate
impl InsurancePoolUpdate
Sourcepub fn contract_group(&self) -> Option<&str>
pub fn contract_group(&self) -> Option<&str>
Returns the contract group from the topic.
Extracts the contract group identifier from the WebSocket topic. Examples:
- “insurance.USDT” -> “USDT”
- “insurance.USDC” -> “USDC”
- “insurance.inverse” -> “inverse”
Sourcepub fn is_snapshot(&self) -> bool
pub fn is_snapshot(&self) -> bool
Returns true if this is a snapshot update.
Snapshot updates contain the full insurance pool state and should replace the local state for the corresponding contract group.
Sourcepub fn is_delta(&self) -> bool
pub fn is_delta(&self) -> bool
Returns true if this is a delta update.
Delta updates contain incremental changes and should be applied to the local insurance pool state.
Sourcepub fn timestamp_datetime(&self) -> DateTime<Utc>
pub fn timestamp_datetime(&self) -> DateTime<Utc>
Returns the timestamp as a chrono DateTime.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no insurance pool entries in this update.
Sourcepub fn find_by_symbol(&self, symbol: &str) -> Option<&InsurancePool>
pub fn find_by_symbol(&self, symbol: &str) -> Option<&InsurancePool>
Finds an insurance pool entry for a specific symbol.
Returns the first matching insurance pool entry for the given symbol. Note: For shared insurance pools, the symbols field may contain multiple symbols or a group identifier, so this may not find all relevant entries.
Sourcepub fn filter_by_coin(&self, coin: &str) -> Vec<&InsurancePool>
pub fn filter_by_coin(&self, coin: &str) -> Vec<&InsurancePool>
Finds all insurance pool entries for a specific coin.
Sourcepub fn total_balance(&self) -> f64
pub fn total_balance(&self) -> f64
Returns the total balance across all insurance pools in this update.
Sums the balances of all insurance pool entries in this update. Useful for monitoring the overall health of a contract group’s insurance.
Sourcepub fn count_positive(&self) -> usize
pub fn count_positive(&self) -> usize
Returns the number of insurance pools with positive balance.
Sourcepub fn count_non_positive(&self) -> usize
pub fn count_non_positive(&self) -> usize
Returns the number of insurance pools with non-positive balance.
These are pools that may be at risk of triggering ADL (Auto-Deleveraging).
Sourcepub fn min_balance(&self) -> Option<f64>
pub fn min_balance(&self) -> Option<f64>
Returns the minimum balance among all insurance pools.
Sourcepub fn max_balance(&self) -> Option<f64>
pub fn max_balance(&self) -> Option<f64>
Returns the maximum balance among all insurance pools.
Sourcepub fn average_balance(&self) -> Option<f64>
pub fn average_balance(&self) -> Option<f64>
Returns the average balance across all insurance pools.
Sourcepub fn stale_pools(&self) -> Vec<&InsurancePool>
pub fn stale_pools(&self) -> Vec<&InsurancePool>
Returns all insurance pools that are stale (older than 5 minutes).
Note: The WebSocket pushes updates every 1 second when changes occur, so stale entries in a fresh update may indicate issues with specific symbols.
Sourcepub fn latest_update_time(&self) -> Option<u64>
pub fn latest_update_time(&self) -> Option<u64>
Returns the time of the most recent update among all insurance pools.
Sourcepub fn earliest_update_time(&self) -> Option<u64>
pub fn earliest_update_time(&self) -> Option<u64>
Returns the time of the oldest update among all insurance pools.
Trait Implementations§
Source§impl Clone for InsurancePoolUpdate
impl Clone for InsurancePoolUpdate
Source§fn clone(&self) -> InsurancePoolUpdate
fn clone(&self) -> InsurancePoolUpdate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more