pub struct PositionReport;Expand description
Represents a FIX Position Report message (MsgType = AP).
Implementations§
Source§impl PositionReport
impl PositionReport
Sourcepub fn try_from_fix_message(message: &FixMessage) -> Result<Position>
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. directionis Buy ifsize > 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_priceandsettlement_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, andsize_currencyare not provided by this parser and remainNone.
Returns:
- Ok(Position) when parsing succeeds
- Err(DeribitFixError) if the required symbol (tag 55) is missing
Sourcepub fn from_deribit_position(
position: &Position,
sender_comp_id: String,
target_comp_id: String,
msg_seq_num: u32,
) -> Result<String>
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.directionis Buy, withposition.size - 705 (ShortQty): if
position.directionis Sell, withabs(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.