Skip to main content

CrossPositionCore

Trait CrossPositionCore 

Source
pub trait CrossPositionCore:
    Sealed
    + Send
    + Sync
    + Debug
    + 'static {
Show 20 methods // Required methods fn margin(&self) -> u64; fn leverage(&self) -> CrossLeverage; fn exposure(&self) -> CrossExposure; fn realized_pl(&self) -> i64; fn session_funding_fees(&self) -> i64; fn trading_fees(&self) -> u64; // Provided methods fn quantity(&self) -> i64 { ... } fn entry_price(&self) -> Option<Price> { ... } fn liquidation(&self) -> Option<Price> { ... } fn initial_margin(&self) -> u64 { ... } fn running_margin(&self) -> u64 { ... } fn maintenance_margin(&self) -> u64 { ... } fn est_running_pl(&self, market_price: Price) -> i64 { ... } fn est_net_value(&self, market_price: Price) -> u64 { ... } fn est_free_margin(&self, market_price: Price) -> u64 { ... } fn est_entry_price_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, ) -> Option<Price> { ... } fn est_margin_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, ) -> Option<i64> { ... } fn est_order_fee_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, fee_perc: PercentageCapped, ) -> Option<u64> { ... } fn est_collateral_diff_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, new_liquidation: Price, fee_perc: PercentageCapped, ) -> Option<i64> { ... } fn est_collateral_diff_for_liquidation( &self, market_price: Price, new_liquidation: Price, fee_perc: PercentageCapped, ) -> Option<i64> { ... }
}
Expand description

Generic cross-margin position interface used by both live and simulated positions.

The estimated P/L, NAV, and free-margin helpers take an explicit market price because LN Markets’ live CrossPosition does not expose the reference/mark price used for its own P/L fields. Passing the price explicitly keeps the estimate source clear and lets simulated and live callers use the same formula.

Required Methods§

Source

fn margin(&self) -> u64

Returns the cross account margin/collateral in satoshis.

Source

fn leverage(&self) -> CrossLeverage

Returns the configured cross account leverage.

Source

fn exposure(&self) -> CrossExposure

Returns the active cross-margin exposure, if any.

Source

fn realized_pl(&self) -> i64

Returns cumulative realized cross-position profit/loss in satoshis.

Source

fn session_funding_fees(&self) -> i64

Returns session-local cross funding fees in satoshis.

Positive values are net costs and negative values are net revenue.

Source

fn trading_fees(&self) -> u64

Returns cross order fees.

Provided Methods§

Source

fn quantity(&self) -> i64

Returns the signed cross position quantity in USD notional.

Positive quantities correspond to long positions, negative quantities correspond to short positions, and zero corresponds to a neutral position.

Source

fn entry_price(&self) -> Option<Price>

Returns the cross position entry price, if a position is open.

Source

fn liquidation(&self) -> Option<Price>

Returns the cross position liquidation price, if a position is open.

Source

fn initial_margin(&self) -> u64

Returns the current initial margin allocated to the cross position.

Source

fn running_margin(&self) -> u64

Returns the current running margin for the cross position.

Source

fn maintenance_margin(&self) -> u64

Returns the current maintenance margin for the cross position.

Source

fn est_running_pl(&self, market_price: Price) -> i64

Estimates current cross position running P/L at the supplied market price.

Source

fn est_net_value(&self, market_price: Price) -> u64

Estimates the cross account net asset value at the supplied market price.

Source

fn est_free_margin(&self, market_price: Price) -> u64

Estimates cross free margin at the supplied market price.

Running margin absorbs negative P/L first. When the loss exceeds running margin, the excess loss is deducted from free margin.

Source

fn est_entry_price_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, ) -> Option<Price>

Estimates the entry price that would result from changing this cross position to new_side / new_quantity with one market adjustment at market_price.

Same-side increases aggregate the current entry with the added quantity. Same-side reductions follow the simulator’s current accounting: profitable reductions keep the current entry and losing reductions carry the loss in the remaining entry. Reversals and flat opens use the market price as the new entry.

Source

fn est_margin_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, ) -> Option<i64>

Estimates the raw cross margin that would result from changing this cross position to new_side / new_quantity with one fee-free market adjustment at market_price.

This follows the same realized-P/L margin accounting as est_entry_price_for_exposure: full reversals realize the full current P/L, profitable partial reductions realize reduced-quantity P/L into raw margin, and losing partial reductions carry the loss in the remaining entry instead of deducting it from raw margin.

Source

fn est_order_fee_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, fee_perc: PercentageCapped, ) -> Option<u64>

Estimates the market-order fee for changing this cross position to new_side / new_quantity at market_price.

The estimate uses the absolute USD exposure delta between the current and target net positions. It returns zero when the target exposure already matches the current exposure.

Source

fn est_collateral_diff_for_exposure( &self, new_side: TradeSide, new_quantity: CrossQuantity, market_price: Price, new_liquidation: Price, fee_perc: PercentageCapped, ) -> Option<i64>

Estimates the cross collateral change needed to hold a position of new_side / new_quantity with liquidation at new_liquidation.

The target entry, raw margin, net value, and order fee are derived as though the current exposure were adjusted with one market order at market_price. The returned delta is the larger of:

  • the net-collateral delta needed to put liquidation at new_liquidation, including the target exposure’s maintenance margin; and
  • the raw-margin delta needed to satisfy the SDK cross exposure coherence floor (running_margin + maintenance_margin + 1).

A positive result is collateral that must be deposited; a negative result is collateral that can be withdrawn. Returns None when the target liquidation is not on the liquidatable side of market_price or the target exposure is invalid for the account leverage. If the coherence floor dominates, depositing the returned amount makes the exposure valid but may move liquidation farther from market than new_liquidation.

Source

fn est_collateral_diff_for_liquidation( &self, market_price: Price, new_liquidation: Price, fee_perc: PercentageCapped, ) -> Option<i64>

Estimates the cross collateral change needed to move this position’s liquidation to new_liquidation, keeping its current side, quantity, and entry price.

Convenience wrapper over est_collateral_diff_for_exposure for the current running exposure and configured fee rate. Returns None when the position is neutral.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§