mod account_data;
mod apply;
mod market_data;
mod sync;
mod views;
use std::collections::BTreeMap;
use crate::account::history::{Fill, LedgerUpdate};
use crate::account::{Abstraction, ClearinghouseState, FrontendOrder};
use crate::client::Network;
use crate::live::store::Account;
use crate::live::store::interest::Interests;
use crate::live::store::market::Markets;
use crate::live::{Limits, Refused, Subscription};
use crate::markets::perps::{MetaAndAssetCtxs, UserFunding};
use crate::markets::spot::{SpotMeta, SpotMetaAndAssetCtxs};
use crate::markets::{Book, Candle, Mids, Trade};
use crate::utils::Address;
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
pub enum Read<'a> {
Book(&'a Book),
Trades(&'a [Trade]),
Candles(&'a [Candle]),
Mids {
dex: &'a str,
mids: &'a Mids,
},
Perps(&'a MetaAndAssetCtxs),
Dex {
dex: &'a str,
read: &'a MetaAndAssetCtxs,
},
Dexes(&'a crate::markets::dexes::Dexes),
Spot(&'a SpotMetaAndAssetCtxs),
SpotMeta(&'a SpotMeta),
Clearinghouse {
user: Address,
dex: &'a str,
state: &'a ClearinghouseState,
},
SpotState {
user: Address,
state: &'a crate::account::SpotState,
},
Mode {
user: Address,
mode: &'a Abstraction,
},
Orders {
user: Address,
dex: &'a str,
orders: &'a [FrontendOrder],
},
Fills {
user: Address,
fills: &'a [Fill],
},
MoreFills {
user: Address,
fills: &'a [Fill],
},
Fundings {
user: Address,
fundings: &'a [UserFunding],
},
Ledger {
user: Address,
rows: &'a [LedgerUpdate],
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Folded {
Changed,
Same,
Dropped,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct Synced {
pub frames: Vec<String>,
pub refused: Vec<(Subscription, Refused)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("this store is on {store} and the session on {session}; one store is one network")]
#[non_exhaustive]
pub struct OtherNetwork {
pub store: Network,
pub session: Network,
}
#[derive(Debug)]
pub struct Store {
network: Network,
interests: Interests,
markets: Markets,
accounts: BTreeMap<Address, Account>,
}
impl Store {
#[must_use]
pub fn new(network: Network) -> Store {
Store {
network,
interests: Interests::new(Limits::VENUE),
markets: Markets::default(),
accounts: BTreeMap::new(),
}
}
#[must_use]
pub fn with_limits(mut self, limits: Limits) -> Store {
self.interests.set_limits(limits);
self
}
#[must_use]
pub const fn network(&self) -> Network {
self.network
}
}
impl Folded {
const fn of(changed: bool) -> Folded {
match changed {
true => Folded::Changed,
false => Folded::Same,
}
}
const fn or(self, other: Folded) -> Folded {
match (self, other) {
(Folded::Changed, _) | (_, Folded::Changed) => Folded::Changed,
(Folded::Same, _) | (_, Folded::Same) => Folded::Same,
_ => Folded::Dropped,
}
}
}
fn book(coin: &str) -> Subscription {
Subscription::L2Book { coin: coin.to_owned(), n_sig_figs: None, mantissa: None, fast: false }
}