pub struct Portfolio { /* private fields */ }
Implementations§
Source§impl Portfolio
impl Portfolio
pub fn new( cache: Rc<RefCell<Cache>>, clock: Rc<RefCell<dyn Clock>>, config: Option<PortfolioConfig>, ) -> Self
pub fn reset(&mut self)
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Returns true
if the portfolio has been initialized.
Sourcepub fn balances_locked(&self, venue: &Venue) -> HashMap<Currency, Money>
pub fn balances_locked(&self, venue: &Venue) -> HashMap<Currency, Money>
Returns the locked balances for the given venue.
Locked balances represent funds reserved for open orders.
Sourcepub fn margins_init(&self, venue: &Venue) -> HashMap<InstrumentId, Money>
pub fn margins_init(&self, venue: &Venue) -> HashMap<InstrumentId, Money>
Returns the initial margin requirements for the given venue.
Only applicable for margin accounts. Returns empty map for cash accounts.
Sourcepub fn margins_maint(&self, venue: &Venue) -> HashMap<InstrumentId, Money>
pub fn margins_maint(&self, venue: &Venue) -> HashMap<InstrumentId, Money>
Returns the maintenance margin requirements for the given venue.
Only applicable for margin accounts. Returns empty map for cash accounts.
Sourcepub fn unrealized_pnls(&mut self, venue: &Venue) -> HashMap<Currency, Money>
pub fn unrealized_pnls(&mut self, venue: &Venue) -> HashMap<Currency, Money>
Returns the unrealized PnLs for all positions at the given venue.
Calculates mark-to-market PnL based on current market prices.
Sourcepub fn realized_pnls(&mut self, venue: &Venue) -> HashMap<Currency, Money>
pub fn realized_pnls(&mut self, venue: &Venue) -> HashMap<Currency, Money>
Returns the realized PnLs for all positions at the given venue.
Calculates total realized profit and loss from closed positions.
pub fn net_exposures(&self, venue: &Venue) -> Option<HashMap<Currency, Money>>
pub fn unrealized_pnl(&mut self, instrument_id: &InstrumentId) -> Option<Money>
pub fn realized_pnl(&mut self, instrument_id: &InstrumentId) -> Option<Money>
pub fn net_exposure(&self, instrument_id: &InstrumentId) -> Option<Money>
pub fn net_position(&self, instrument_id: &InstrumentId) -> Decimal
pub fn is_net_long(&self, instrument_id: &InstrumentId) -> bool
pub fn is_net_short(&self, instrument_id: &InstrumentId) -> bool
pub fn is_flat(&self, instrument_id: &InstrumentId) -> bool
pub fn is_completely_flat(&self) -> bool
Sourcepub fn initialize_orders(&mut self)
pub fn initialize_orders(&mut self)
Initializes account margin based on existing open orders.
§Panics
Panics if updating the cache with a mutated account fails.
Sourcepub fn initialize_positions(&mut self)
pub fn initialize_positions(&mut self)
Initializes account margin based on existing open positions.
§Panics
Panics if calculation of PnL or updating the cache with a mutated account fails.
Sourcepub fn update_quote_tick(&mut self, quote: &QuoteTick)
pub fn update_quote_tick(&mut self, quote: &QuoteTick)
Updates portfolio calculations based on a new quote tick.
Recalculates unrealized PnL for positions affected by the quote update.
Sourcepub fn update_bar(&mut self, bar: &Bar)
pub fn update_bar(&mut self, bar: &Bar)
Updates portfolio calculations based on a new bar.
Updates cached bar close prices and recalculates unrealized PnL.
Sourcepub fn update_account(&mut self, event: &AccountState)
pub fn update_account(&mut self, event: &AccountState)
Updates portfolio with a new account state event.
Sourcepub fn update_order(&mut self, event: &OrderEventAny)
pub fn update_order(&mut self, event: &OrderEventAny)
Updates portfolio calculations based on an order event.
Handles balance updates for order fills and margin calculations for order changes.
Sourcepub fn update_position(&mut self, event: &PositionEvent)
pub fn update_position(&mut self, event: &PositionEvent)
Updates portfolio calculations based on a position event.
Recalculates net positions, unrealized PnL, and margin requirements.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Portfolio
impl !RefUnwindSafe for Portfolio
impl !Send for Portfolio
impl !Sync for Portfolio
impl Unpin for Portfolio
impl !UnwindSafe for Portfolio
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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