Position ¶
- class Position ( Instrument instrument , OrderFilled fill ) ¶
-
Bases:
object
Represents a position in a financial 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 :
-
Money
- client_order_ids ¶
-
Return the client order IDs associated with the position.
- Returns :
-
list[VenueOrderId]
Notes
Guaranteed not to contain duplicate IDs.
- 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.
- Returns :
-
list[Money]
- cost_currency ¶
-
The position cost currency (for PnL).
- Returns :
-
Currency
- 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.
- Returns :
-
int
- events ¶
-
Return the order fill events for the position.
- Returns :
-
list[Event]
- id ¶
-
The position ID.
- Returns :
-
PositionId
- info ( self ) unicode ¶
-
Return a summary description of the position.
- Returns :
-
str
- instrument_id ¶
-
The position instrument ID.
- Returns :
-
InstrumentId
- is_closed ¶
-
Return whether the position side is
FLAT
.- Returns :
-
bool
- is_inverse ¶
-
If the quantity is expressed in quote currency.
- Returns :
-
bool
- is_long ¶
-
Return whether the position side is
LONG
.- Returns :
-
bool
- is_open ¶
-
Return whether the position side is not
FLAT
.- Returns :
-
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 :
-
bool – True if side is opposite, else False.
- is_short ¶
-
Return whether the position side is
SHORT
.- Returns :
-
bool
- last_event ¶
-
Return the last order fill event.
- Returns :
-
OrderFilled
- last_trade_id ¶
-
Return the last trade match ID for the position.
- Returns :
-
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 :
-
Money – In quote currency.
- 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
- realized_pnl ¶
-
The current realized PnL for the position (including commissions).
- Returns :
-
Money or
None
- realized_return ¶
-
The current realized return for the position.
- Returns :
-
double
- side ¶
-
The current position side.
- Returns :
-
PositionSide
- static side_from_order_side ( OrderSide side ) ¶
-
Return the position side resulting from the given order side (from
FLAT
).- Parameters :
-
side (OrderSide {
BUY
,SELL
}) – The order side - Returns :
-
PositionSide
- signed_decimal_qty ( self ) ¶
-
Return a signed decimal representation of the position quantity.
-
If the position is LONG, the value is positive (e.g. Decimal(‘10.25’))
-
If the position is SHORT, the value is negative (e.g. Decimal(‘-10.25’))
-
If the position is FLAT, the value is zero (e.g. Decimal(‘0’))
- Returns :
-
Decimal
-
- signed_qty ¶
-
The current signed quantity (positive for position side
LONG
, negative forSHORT
).- Returns :
-
double
- size_precision ¶
-
The size precision for the position.
- Returns :
-
uint8
- strategy_id ¶
-
The strategy ID associated with the position.
- Returns :
-
StrategyId
- symbol ¶
-
Return the positions ticker symbol.
- Returns :
-
Symbol
- to_dict ( self ) dict ¶
-
Return a dictionary representation of this object.
- Returns :
-
dict[str, object]
- total_pnl ( self , Price last ) Money ¶
-
Return the total PnL from the given last quote tick.
Result will be in quote currency for standard instruments, or base currency for inverse instruments.
- Parameters :
-
last ( Price ) – The last price for the calculation.
- Returns :
-
Money
- trade_ids ¶
-
Return the trade match IDs associated with the position.
- Returns :
-
list[TradeId]
- trader_id ¶
-
The trader ID associated with the position.
- Returns :
-
TraderId
- ts_closed ¶
-
The UNIX timestamp (nanoseconds) when the position was closed.
- Returns :
-
uint64_t
- ts_init ¶
-
The UNIX timestamp (nanoseconds) when the object was initialized.
- Returns :
-
uint64_t
- ts_last ¶
-
The UNIX timestamp (nanoseconds) when the last fill occurred.
- Returns :
-
uint64_t
- ts_opened ¶
-
The UNIX timestamp (nanoseconds) when the position was opened.
- Returns :
-
uint64_t
- unrealized_pnl ( self , Price last ) Money ¶
-
Return the unrealized PnL from the given last quote tick.
Result will be in quote currency for standard instruments, or base currency for inverse instruments.
- Parameters :
-
last ( Price ) – The last price for the calculation.
- Returns :
-
Money
- venue ¶
-
Return the positions trading venue.
- Returns :
-
Venue
- venue_order_ids ¶
-
Return the venue order IDs associated with the position.
- Returns :
-
list[VenueOrderId]
Notes
Guaranteed not to contain duplicate IDs.