pub struct UserState { /* private fields */ }Expand description
Open orders, positions and wallet balances of one account.
Plain data (Send + Sync): it can live in any task. It does no I/O.
Implementations§
Source§impl UserState
impl UserState
pub fn new() -> Self
Sourcepub fn set_wallet(&mut self, balance: WalletBalance)
pub fn set_wallet(&mut self, balance: WalletBalance)
Replace the balance of balance.account_type with a REST snapshot.
Sourcepub fn set_orders(
&mut self,
category: Category,
orders: Vec<Order>,
snapshot_time: Timestamp,
)
pub fn set_orders( &mut self, category: Category, orders: Vec<Order>, snapshot_time: Timestamp, )
Merge a REST snapshot of the open orders of category.
snapshot_time is the server time of the response
(Response::time), milliseconds.
- an order from the snapshot replaces the stored one unless the stored one is newer, and is skipped if it was already closed by the stream;
- a stored order missing from the snapshot is removed, unless it was
updated after
snapshot_time(it was opened after the snapshot).
Sourcepub fn set_positions(
&mut self,
category: Category,
positions: Vec<Position>,
snapshot_time: Timestamp,
)
pub fn set_positions( &mut self, category: Category, positions: Vec<Position>, snapshot_time: Timestamp, )
Merge a REST snapshot of the positions of category.
A snapshot position replaces the stored one unless the stored one is
newer. Stored positions missing from the snapshot are kept only if
they were updated after snapshot_time.
Sourcepub fn apply(&mut self, msg: TopicMessage) -> Vec<Change>
pub fn apply(&mut self, msg: TopicMessage) -> Vec<Change>
Apply one private stream message. Topics other than order,
position and wallet are ignored.
Sourcepub fn apply_order(&mut self, msg: OrderMsg) -> Option<Change>
pub fn apply_order(&mut self, msg: OrderMsg) -> Option<Change>
Apply one order stream update. Returns None if it was stale.
Sourcepub fn apply_position(&mut self, msg: PositionMsg) -> Option<Change>
pub fn apply_position(&mut self, msg: PositionMsg) -> Option<Change>
Apply one position stream update. Returns None if it was stale.
Sourcepub fn apply_wallet(&mut self, msg: WalletMsg) -> Change
pub fn apply_wallet(&mut self, msg: WalletMsg) -> Change
Apply one wallet stream update (always a full balance).
pub fn wallet(&self, account_type: AccountType) -> Option<&WalletBalance>
pub fn wallets(&self) -> impl Iterator<Item = &WalletBalance>
pub fn order(&self, category: Category, order_id: &str) -> Option<&Order>
pub fn order_by_link_id( &self, category: Category, order_link_id: &str, ) -> Option<&Order>
Sourcepub fn orders_for<'a>(
&'a self,
category: Category,
symbol: &'a str,
) -> impl Iterator<Item = &'a Order>
pub fn orders_for<'a>( &'a self, category: Category, symbol: &'a str, ) -> impl Iterator<Item = &'a Order>
Open orders of one symbol.
pub fn position( &self, category: Category, symbol: &str, position_idx: PositionIdx, ) -> Option<&Position>
Sourcepub fn positions(&self) -> impl Iterator<Item = (&PositionKey, &Position)>
pub fn positions(&self) -> impl Iterator<Item = (&PositionKey, &Position)>
All known positions, including closed ones (size 0), which still carry the leverage and risk limit settings.
Sourcepub fn open_positions(&self) -> impl Iterator<Item = (&PositionKey, &Position)>
pub fn open_positions(&self) -> impl Iterator<Item = (&PositionKey, &Position)>
Positions with a non-zero size.