Position
class Position
Bases: object
Position(Instrument instrument, OrderFilled fill) -> None Represents a position in a market.
The position ID may be assigned at the trading venue, or can be system generated depending on a strategies OMS (Order Management System) settings.
- Parameters:
- instrument (Instrument) – The trading instrument for the position.
- fill (OrderFilled) – The order fill event which opened the position.
- Raises:
- ValueError – If instrument.id is not equal to fill.instrument_id.
- ValueError – If event.position_id is
None
.
account_id
The account ID associated with the position.
- Returns: AccountId
apply(self, OrderFilled fill) → void
Applies the given order fill event to the position.
- Parameters: fill (OrderFilled) – The order fill event to apply.
- Raises: KeyError – If fill.trade_id already applied to the position.
avg_px_close
The average close price.
- Returns: double
avg_px_open
The average open price.
- Returns: double
base_currency
The position base currency (if applicable).
- Returns:
Currency or
None
calculate_pnl(self, double avg_px_open, double avg_px_close, Quantity quantity) → Money
Return a calculated PnL.
Result will be in quote currency for standard instruments, or base currency for inverse instruments.
- Parameters:
- avg_px_open (double) – The average open price.
- avg_px_close (double) – The average close price.
- quantity (Quantity) – The quantity for the calculation.
- Returns: In settlement currency.
- Return type: Money
client_order_ids
Return the client order IDs associated with the position.
- Return type: list[VenueOrderId]
closing_order_id
The client order ID for the order which closed the position.
- Returns:
ClientOrderId or
None
commissions(self) → list
Return the total commissions generated by the position.
- Return type: list[Money]
duration_ns
The total open duration (nanoseconds).
- Returns: uint64_t
entry
The position entry order side.
- Returns: OrderSide
event_count
Return the count of order fill events applied to the position.
- Return type: int
events
Return the order fill events for the position.
- Return type: list[Event]
id
The position ID.
- Returns: PositionId
info(self) → str
Return a summary description of the position.
- Return type: str
instrument_id
The position instrument ID.
- Returns: InstrumentId
is_closed
Return whether the position side is FLAT
.
- Return type: bool
is_inverse
If the quantity is expressed in quote currency.
- Returns: bool
is_long
Return whether the position side is LONG
.
- Return type: bool
is_open
Return whether the position side is not FLAT
.
- Return type: bool
is_opposite_side(self, OrderSide side) → bool
Return a value indicating whether the given order side is opposite to the current position side.
- Parameters:
side (OrderSide {
BUY
,SELL
}) - Returns: True if side is opposite, else False.
- Return type: bool
is_short
Return whether the position side is SHORT
.
- Return type: bool
last_event
Return the last order fill event.
- Return type: OrderFilled
last_trade_id
Return the last trade match ID for the position.
- Return type: TradeId
multiplier
The multiplier for the positions instrument.
- Returns: Quantity
notional_value(self, Price last) → Money
Return the current notional value of the position.
- Parameters: last (Price) – The last close price for the position.
- Returns: In quote currency.
- Return type: Money
opening_order_id
The client order ID for the order which opened the position.
- Returns: ClientOrderId
peak_qty
The peak directional quantity reached by the position.
- Returns: Quantity
price_precision
The price precision for the position.
- Returns: uint8
quantity
The current open quantity.
- Returns: Quantity
quote_currency
The position quote currency.
- Returns: Currency