Skip to main content

Position

Struct Position 

Source
pub struct Position {
Show 50 fields pub account_id: String, pub conid: String, pub symbol: String, pub description: Option<String>, pub asset_category: AssetCategory, pub cusip: Option<String>, pub isin: Option<String>, pub figi: Option<String>, pub security_id: Option<String>, pub security_id_type: Option<SecurityIdType>, pub multiplier: Option<Decimal>, pub strike: Option<Decimal>, pub expiry: Option<NaiveDate>, pub put_call: Option<PutCall>, pub underlying_conid: Option<String>, pub underlying_symbol: Option<String>, pub quantity: Decimal, pub mark_price: Decimal, pub position_value: Decimal, pub side: Option<String>, 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 currency: String, pub fx_rate_to_base: Option<Decimal>, pub report_date: NaiveDate, pub holding_period_date_time: Option<String>, pub open_date_time: Option<String>, pub originating_transaction_id: Option<String>, pub code: Option<String>, pub originating_order_id: Option<String>, pub issuer: Option<String>, pub issuer_country_code: Option<String>, pub sub_category: Option<SubCategory>, pub listing_exchange: Option<String>, pub underlying_listing_exchange: Option<String>, pub underlying_security_id: Option<String>, pub accrued_int: Option<Decimal>, pub principal_adjust_factor: Option<Decimal>, pub serial_number: Option<String>, pub delivery_type: Option<String>, pub commodity_type: Option<String>, pub fineness: Option<Decimal>, pub weight: Option<String>, pub level_of_detail: Option<LevelOfDetail>, pub model: Option<String>, pub acct_alias: Option<String>, pub vesting_date: Option<NaiveDate>,
}
Expand description

An open position snapshot

Represents a single open position at the end of the reporting period. Fields are organized into CORE (essential for tax/portfolio analytics) and EXTENDED (metadata) sections.

§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

§cusip: Option<String>

CUSIP

§isin: Option<String>

ISIN

§figi: Option<String>

FIGI

§security_id: Option<String>

Security ID

§security_id_type: Option<SecurityIdType>

Security ID type

§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

§underlying_conid: Option<String>

Underlying contract ID

§underlying_symbol: Option<String>

Underlying symbol

§quantity: Decimal

Position quantity (negative for short)

§mark_price: Decimal

Mark price (current market price)

§position_value: Decimal

Position value (quantity * mark_price * multiplier)

§side: Option<String>

Side (Long/Short)

§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

§currency: String

Currency

§fx_rate_to_base: Option<Decimal>

FX rate to base currency

§report_date: NaiveDate

Date of this position snapshot

§holding_period_date_time: Option<String>

Holding period date/time (for long-term vs short-term determination)

§open_date_time: Option<String>

When position was opened

§originating_transaction_id: Option<String>

Originating transaction ID

§code: Option<String>

Position code (may contain tax-related codes)

§originating_order_id: Option<String>

Originating order ID (links to opening trade)

§issuer: Option<String>

Issuer

§issuer_country_code: Option<String>

Issuer country code

§sub_category: Option<SubCategory>

Sub-category

§listing_exchange: Option<String>

Listing exchange

§underlying_listing_exchange: Option<String>

Underlying listing exchange

§underlying_security_id: Option<String>

Underlying security ID

§accrued_int: Option<Decimal>

Accrued interest

§principal_adjust_factor: Option<Decimal>

Principal adjust factor

§serial_number: Option<String>

Serial number (for physical delivery)

§delivery_type: Option<String>

Delivery type

§commodity_type: Option<String>

Commodity type

§fineness: Option<Decimal>

Fineness (for precious metals)

§weight: Option<String>

Weight

§level_of_detail: Option<LevelOfDetail>

Level of detail

§model: Option<String>

Model (for model portfolios)

§acct_alias: Option<String>

Account alias

§vesting_date: Option<NaiveDate>

Vesting date (for restricted stock)

Implementations§

Source§

impl Position

Source

pub fn derivative(&self) -> Option<DerivativeInfo>

Constructs structured derivative info from flat fields

Returns Some(DerivativeInfo) if this position is a derivative (option, future, future option, or warrant) and has the required fields populated. Returns None for non-derivative positions or if required fields are missing.

§Example
if let Some(derivative) = position.derivative() {
    match derivative {
        DerivativeInfo::Option { strike, expiry, put_call, .. } => {
            println!("Option: Strike={}, Expiry={}, Type={:?}", strike, expiry, put_call);
        }
        _ => {}
    }
}

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>,