Bourse.Position (bourse v0.6.0)

Copy Markdown View Source

Unified derivatives position data.

Represents an open position on a derivatives exchange (futures, swaps, options).

Fields

  • id - Position ID
  • symbol - Unified symbol (e.g., "BTC/USDT:USDT")
  • timestamp - Last update time in milliseconds
  • datetime - ISO 8601 datetime string
  • side - "long" or "short"
  • contracts - Number of contracts
  • contract_size - Size of one contract
  • notional - Absolute position value in the venue's own settlement unit. Quote currency on every venue except binancecoinm, whose COIN-M notionalValue is coin-settled (carve C-T610/binancecoinm-inverse-settlement-notional in docs/authored-spec-carves/global.md). Do not sum notional across venues without checking that exception, and do not derive base exposure as notional / mark_price on an inverse market — use base_quantity, or contracts * contract_size / mark_price.
  • base_quantity - Absolute position size in the base currency. Populated for deribit futures, where the venue publishes it directly; nil on every other venue, which state no base-denominated position field.
  • leverage - Current leverage
  • unrealized_pnl - Unrealized profit/loss
  • realized_pnl - Realized profit/loss
  • cumulative_funding - Funding settled for the position
  • pending_funding - Funding not yet settled into cash balance
  • total_fees - Fees paid while opening or changing the position
  • net_settlements - Net USD paid or received from settlements
  • collateral - Collateral amount
  • entry_price - Average entry price
  • mark_price - Current mark price
  • liquidation_price - Estimated liquidation price
  • margin_mode - "cross" or "isolated"
  • isolated - Whether the position uses isolated margin
  • hedged - Whether position is in hedge mode
  • maintenance_margin - Required maintenance margin
  • maintenance_margin_percentage - Maintenance margin as a fraction (0.1 = 10%)
  • initial_margin - Required initial margin
  • initial_margin_percentage - Initial margin as a fraction (0.1 = 10%)
  • margin_ratio - Current margin ratio as a fraction (0.1 = 10%)
  • last_update_timestamp - Last update timestamp
  • last_price - Last traded price
  • stop_loss_price - Stop loss price
  • take_profit_price - Take profit price
  • percentage - PnL in percent points (10 = 10%)
  • margin - Position margin
  • info - Raw exchange response

Summary

Functions

Returns true if the position is long.

Returns true if the position has positive unrealized PnL.

JSON Schema for the Position unified type.

Returns true if the position is short.

Types

t()

@type t() :: %Bourse.Position{
  base_quantity: number() | nil,
  collateral: number() | nil,
  contract_size: number() | nil,
  contracts: number() | nil,
  cumulative_funding: number() | nil,
  datetime: String.t() | nil,
  entry_price: number() | nil,
  hedged: boolean() | nil,
  id: String.t() | nil,
  info: map() | nil,
  initial_margin: number() | nil,
  initial_margin_percentage: number() | nil,
  isolated: boolean() | nil,
  last_price: number() | nil,
  last_update_timestamp: integer() | nil,
  leverage: number() | nil,
  liquidation_price: number() | nil,
  maintenance_margin: number() | nil,
  maintenance_margin_percentage: number() | nil,
  margin: number() | nil,
  margin_mode: String.t() | nil,
  margin_ratio: number() | nil,
  mark_price: number() | nil,
  net_settlements: number() | nil,
  notional: number() | nil,
  pending_funding: number() | nil,
  percentage: number() | nil,
  realized_pnl: number() | nil,
  side: String.t() | nil,
  stop_loss_price: number() | nil,
  symbol: String.t() | nil,
  take_profit_price: number() | nil,
  timestamp: integer() | nil,
  total_fees: number() | nil,
  unrealized_pnl: number() | nil
}

Functions

long?(position)

@spec long?(t()) :: boolean()

Returns true if the position is long.

profitable?(position)

@spec profitable?(t()) :: boolean()

Returns true if the position has positive unrealized PnL.

schema()

@spec schema() :: map()

JSON Schema for the Position unified type.

short?(position)

@spec short?(t()) :: boolean()

Returns true if the position is short.