Booked values only. The stream carries what fills have booked: quantity, cost, average price, and realized P&L. It has no mark price and no unrealized P&L, so it sends an update when a fill changes a position and not on every price tick. Compute unrealized P&L on the client from the live price stream; see Unrealized P&L.
Request
Authenticate the same way as Stream Prediction Orders. The stream carries only the authenticated user’s own positions: an account you have no positions on streams an empty snapshot and nothing after it.
The first line of the response is
retry: 2000, which tells an EventSource to wait two seconds before it reconnects.
Events
A
: ping comment is sent every 15 seconds to keep idle connections open.
snapshot
positions holds only open positions, those with a non-zero qty. A position that is flat is not in the snapshot.
position
position is the whole row as it stands after the change, not a delta. Replace the row you hold for that symbol when the event’s version is higher than the one you have.
When qty is "0" the position has closed: remove the row.
resync
resync. Reconnect, and the new snapshot brings your view up to date. slow_client means you stopped reading events fast enough to keep up; shutdown means the server is restarting.
Position fields
Decimals are strings:"0.54", not 0.54.
ForecastEx takes buy orders only, so a position holds one outcome at a time. Buying the other outcome of a contract you hold does not open a second position: it nets against the one you have.
Unrealized P&L
Positions carry no mark price and no unrealized P&L. Take the last price for the held outcome from the live price stream, where each contract’ssnapshot has a yes.last and a no.last, and compute:
yes.last when outcome is YES and no.last when it is NO. Do the arithmetic with a decimal type. If that outcome has not traded, last is null: show no unrealized P&L rather than zero.
Ordering
- Every position carries a
versionthat rises with each change. Keep the highestversionyou have seen for eachsymbol, and ignore a position at or below it. The stream already drops older versions, but applying this rule makes your client correct across reconnects too. - Never order by time.
createdAtandupdatedAtare for display. Onlyversionsays which row is newer. snapshotcomes first. Everypositionafter it is newer than the snapshot’s copy of that position.- Changes to one position arrive in the order they happened. Changes to different positions may interleave.
Reconnecting
Events have no IDs and are not replayed, and there is noLast-Event-ID resume. Every connection starts with a fresh snapshot, so after a disconnect or a resync, reconnect and replace all your positions with the new snapshot. A change that happened while you were disconnected is reflected in it, and a position that closed while you were away is no longer in it.
EventSource reconnects on its own after the retry: 2000 delay. A client that reads the stream with fetch has to reconnect itself, as the example below does.
Examples
cURL
EventSource cannot send an Authorization header, so read the stream with fetch:
JavaScript
yes.last and no.last from the live price stream and combine them with the held row:
JavaScript
Number keeps the example short. In production, use a decimal library for money.
Working with the stream
- Prices, quantities, and P&L are decimal strings. Parse them with a decimal type.
- Do not put the stream behind a buffering proxy. Events must reach you as they are sent.