Position

Struct Position 

Source
pub struct Position {
Show 21 fields pub account_id: String, pub conid: String, pub symbol: String, pub description: Option<String>, pub asset_category: AssetCategory, pub multiplier: Option<Decimal>, pub strike: Option<Decimal>, pub expiry: Option<NaiveDate>, pub put_call: Option<PutCall>, pub quantity: Decimal, pub mark_price: Decimal, pub position_value: Decimal, pub open_price: Option<Decimal>, pub cost_basis_price: Option<Decimal>, pub cost_basis_money: Option<Decimal>, pub fifo_pnl_unrealized: Option<Decimal>, pub percent_of_nav: Option<Decimal>, pub side: Option<String>, pub currency: String, pub fx_rate_to_base: Option<Decimal>, pub report_date: NaiveDate,
}
Expand description

An open position snapshot

Represents a single open position at the end of the reporting period. Includes quantity, current market price, cost basis, and unrealized P&L.

§Example

use ib_flex::parse_activity_flex;
use rust_decimal::Decimal;

let xml = std::fs::read_to_string("activity.xml")?;
let statement = parse_activity_flex(&xml)?;

for position in &statement.positions.items {
    println!("{}: {} shares", position.symbol, position.quantity);
    println!("  Current price: {}", position.mark_price);
    println!("  Position value: {}", position.position_value);

    // Calculate gain/loss percentage
    if let Some(cost_basis) = position.cost_basis_money {
        let current_value = position.position_value;
        let gain_pct = ((current_value - cost_basis) / cost_basis) * Decimal::from(100);
        println!("  Gain: {:.2}%", gain_pct);
    }

    // Show unrealized P&L
    if let Some(pnl) = position.fifo_pnl_unrealized {
        println!("  Unrealized P&L: {}", pnl);
    }

    // Check if short position
    if position.quantity < Decimal::ZERO {
        println!("  SHORT POSITION");
    }
}

Fields§

§account_id: String

IB account number

§conid: String

IB contract ID

§symbol: String

Ticker symbol

§description: Option<String>

Security description

§asset_category: AssetCategory

Asset category

§multiplier: Option<Decimal>

Contract multiplier

§strike: Option<Decimal>

Strike (for options)

§expiry: Option<NaiveDate>

Expiry (for options/futures)

§put_call: Option<PutCall>

Put or Call

§quantity: Decimal

Position quantity (negative for short)

§mark_price: Decimal

Mark price (current market price)

§position_value: Decimal

Position value (quantity * mark_price * multiplier)

§open_price: Option<Decimal>

Open price

§cost_basis_price: Option<Decimal>

Cost basis price per share/contract

§cost_basis_money: Option<Decimal>

Total cost basis

§fifo_pnl_unrealized: Option<Decimal>

FIFO unrealized P&L

§percent_of_nav: Option<Decimal>

Percent of NAV

§side: Option<String>

Side (Long/Short)

§currency: String

Currency

§fx_rate_to_base: Option<Decimal>

FX rate to base currency

§report_date: NaiveDate

Date of this position snapshot

Trait Implementations§

Source§

impl Clone for Position

Source§

fn clone(&self) -> Position

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Position

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Position

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Position

Source§

fn eq(&self, other: &Position) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Position

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Position

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,