Struct PositionReport

Source
pub struct PositionReport;
Expand description

Represents a FIX Position Report message (MsgType = AP).

Implementations§

Source§

impl PositionReport

Source

pub fn try_from_fix_message(message: &FixMessage) -> Result<Position>

Parse a Position from a FIX message (Position Report-like payload).

This function extracts Deribit position information from a FixMessage by reading standard FIX tags and Deribit extensions. It computes derived fields such as net size and direction, and maps several optional numeric fields into greeks and margin metrics.

Behavior:

  • Instrument name (tag 55) is mandatory; absence results in an error.
  • LongQty (704) and ShortQty (705) are read and netted as size = long - short.
  • direction is Buy if size > 0.0, otherwise Sell.
  • Many numeric fields are optional; if missing or unparsable, they default to:
    • f64 options: None
    • Aggregated numeric values used directly (e.g., average_price) default to 0.0
  • Settlement price (730) is reused as both average_price and settlement_price.

Tag mapping:

  • 55 (Symbol) -> Position.instrument_name
  • 704 (LongQty) and 705 (ShortQty) -> Position.size (long - short)
  • 730 (SettlPx) -> Position.average_price and Position.settlement_price
  • 731 (IndexPx) -> Position.index_price
  • 732 (MarkPx) -> Position.mark_price
  • 898 (MaintenanceMargin) -> Position.maintenance_margin
  • 899 (InitialMargin) -> Position.initial_margin
  • 706 (RealizedPnL) -> Position.realized_profit_loss
  • 707 (UnrealizedPnL) -> Position.floating_profit_loss and Position.unrealized_profit_loss
  • 708 (TotalPnL) -> Position.total_profit_loss
  • 811 (Delta), 812 (Gamma), 813 (Theta), 814 (Vega) -> Position greeks
  • 461 (CFICode) -> Position.kind

Errors:

  • Returns DeribitFixError::Generic when tag 55 (Symbol) is missing.

Note:

  • Fields like average_price_usd, interest_value, leverage, open_orders_margin, realized_funding, and size_currency are not provided by this parser and remain None.

Returns:

  • Ok(Position) when parsing succeeds
  • Err(DeribitFixError) if the required symbol (tag 55) is missing
Source

pub fn from_deribit_position( position: &Position, sender_comp_id: String, target_comp_id: String, msg_seq_num: u32, ) -> Result<String>

Builds a FIX Position Report (MsgType=AP) from a Deribit Position.

This function converts a Deribit position into a FIX message using the provided message metadata (sender/target IDs and sequence number). Only fields present in the input position are included in the resulting message, and position-side determines whether LongQty or ShortQty is used.

FIX tags populated:

  • 35 (MsgType): AP (PositionReport)
  • 49 (SenderCompID): from sender_comp_id
  • 56 (TargetCompID): from target_comp_id
  • 34 (MsgSeqNum): from msg_seq_num
  • 55 (Symbol): from position.instrument_name
  • 730 (SettlPx): from position.average_price
  • 704 (LongQty): if position.direction is Buy, with position.size
  • 705 (ShortQty): if position.direction is Sell, with abs(position.size)
  • 706 (PosAmt Realized PnL): from position.realized_profit_loss (if set)
  • 707 (PosAmt Floating/Unrealized PnL): from position.floating_profit_loss (if set)
  • 708 (PosAmt Total PnL): from position.total_profit_loss (if set)
  • 811 (Delta): from position.delta (if set)
  • 812 (Gamma): from position.gamma (if set)
  • 813 (Theta): from position.theta (if set)
  • 814 (Vega): from position.vega (if set)
  • 731 (IndexPx): from position.index_price (if set)
  • 732 (MarkPx): from position.mark_price (if set)
  • 899 (InitialMargin): from position.initial_margin (if set)
  • 898 (MaintenanceMargin): from position.maintenance_margin (if set)
  • 979 (PosAmtType): constant “FMTM”

Parameters:

  • position: Source Deribit position to translate.
  • sender_comp_id: Value for FIX tag 49 (SenderCompID).
  • target_comp_id: Value for FIX tag 56 (TargetCompID).
  • msg_seq_num: Value for FIX tag 34 (MsgSeqNum).

Returns:

  • Ok(String): The serialized FIX message string when message building succeeds.
  • Err(DeribitFixError): If the underlying builder fails to construct the message.

Notes:

  • Quantity tag selection depends on position.direction:
    • Buy -> 704=LongQty
    • Sell -> 705=ShortQty (absolute value)
  • Optional numeric fields are only included when present in 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,