Settlements Channel
Topic: settlements:{user_id}
Delivers a settlement recorded against your account whenever a trade closes or expires. Money arrives as dollar strings and contract counts as quantity strings; see Wire format.
Settlement object
Section titled “Settlement object”Identity
Section titled “Identity”id: The unique id of the settlement.account_id: The id of the account the settlement is for.market_id: The id of the market the settlement is on.opening_trade_id: The id of the trade that opened the position being settled.closing_trade_id: The id of the trade that closed the position. Null when the position was closed by the market settling rather than by a closing trade.type: What caused the settlement and the position beforehand:closed_short,closed_long,expired_shortorexpired_long.inserted_at: When the settlement was recorded, as an integer of Unix microseconds.
Amounts
Section titled “Amounts”opening_price: The price the opening trade traded at.closing_price: The price the closing trade traded at, or the market’s settlement price for anexpired_*settlement.quantity: The number of contracts settled, as a quantity string. Can be fractional.fee: The fee charged for the settlement.gross_pnl: The profit or loss before fees.realized_pnl: The profit or loss after fees.settled_premium: The amount of premium settled.settled_risk: The amount of risk settled.
Pre-start flags
Section titled “Pre-start flags”opening_placed_pre_start: Whether the opening trade’s order was placed before the event started.closing_placed_pre_start: Whether the closing trade’s order was placed before the event started. Null when there is no closing trade.opening_traded_pre_start: Whether the opening trade executed before the event started.closing_traded_pre_start: Whether the closing trade executed before the event started. Null when there is no closing trade.pre_start: Whether the settlement itself was created before the event started.
Use Cases
Section titled “Use Cases”| Use case | Message to send |
|---|---|
| Join and start receiving settlements | ["3","3","settlements:<user_id>","phx_join",{}] |
| Join filtered to one market (see filtering) | ["3","3","settlements:<user_id>","phx_join",{"market_ids":["<uuid>"]}] |
| Change the market filter without rejoining | ["3","4","settlements:<user_id>","select_market_ids",{"market_ids":null}] |
| Check the connection is alive | ["3","5","settlements:<user_id>","ping",{}] |
Joining
Section titled “Joining”["3","3","settlements:<user_id>","phx_join",{}]{"status":"ok","response":{"selected_market_ids":null}}Nothing follows until a settlement is recorded.
Pushed when a settlement is recorded
Section titled “Pushed when a settlement is recorded”[null, null, "settlements:e6528824-b4e0-4ff8-bd70-36e5904738d1", "new_settlements", { "settlements": [Settlement]}]Settlements are batched into one frame. This event is a delta: when a
market_ids filter is active and none of the settlements match it, no frame is sent
at all rather than one carrying an empty list.
[ null, null, "settlements:e6528824-b4e0-4ff8-bd70-36e5904738d1", "new_settlements", { "settlements": [ { "id": "ca14dee4-c85b-4393-a194-7ca719136e3d", "account_id": "28417940-ecef-40a9-8816-cc055d7d846f", "market_id": "fd6a5668-ffda-4f97-b8fe-7aa6d79d9c5f", "opening_trade_id": "fc70fdcf-5e30-49bc-97a5-cbddeab025f5", "closing_trade_id": null, "type": "expired_long", "inserted_at": 1791596758350791, "opening_price": "0.3600", "closing_price": "1.0000", "quantity": "50.00", "fee": "0.0000", "gross_pnl": "32.0000", "realized_pnl": "32.0000", "settled_premium": "-18.0000", "settled_risk": "18.0000", "opening_placed_pre_start": false, "closing_placed_pre_start": null, "opening_traded_pre_start": false, "closing_traded_pre_start": null, "pre_start": false } ] }]Docs version v1.10.5

