Skip to content

Account stream

Instead of reading again and again, open the account’s stream: it pushes every change of the account, in order, right after it happens.

wss://app.proofperps.com/v1/api/accounts/{account_id}/stream
  • The key goes in the Authorization: Bearer ppk_... header of the opening request, never in the address. A key of either scope works: the stream only reads.
  • Opening a stream counts as one call of the key’s budget. A trader may have 2 streams open at once (the terminal’s own screens apart).
  • Browsers cannot set this header on a WebSocket: open the stream from your own program (a script, a bot, a server).

On opening, the stream is subscribed to the account’s five channels and sends their current state. Every message is a JSON object:

{"ch": "orders", "account_id": "ev-...", "seq": 812, "ts": 1792218373000, "data": {}}

seq is the account’s sequence number (the order of events, the same numbers as as_of_seq and next_after_seq of the reads).

ch data When
orders one order, as GET …/orders gives it at opening, then at each change of its status or filled quantity
executions one execution, as GET …/executions gives it at each fill or exit
positions {"positions": [...]}, the whole list (empty: flat) at once when a size or a leg changes; otherwise at most once a second
account the gauges of GET …/risk when the balance, the status, a level or a pending payout changes
equity {"equity", "balance"} at most once a second
system {"kind": "subscribed" | "ping" | "resync" | "error", ...} the subscription’s answer; a ping every 15 seconds; see below
  • ?since_seq=N also replays the executions after N (a reconnection that missed some). Too far back (more than 500 entries): a resync.
  • resync: your client fell behind (or since_seq was too old). Everything you held is stale; the current state follows at once. Rebuild your lists from those messages.
  • ?batch=1 sends each frame as a JSON array of messages, in order.
  • You may send {"op": "ping"}. A client that sends more than 50 messages a second is closed (4430); a message over 4,096 bytes too (1009). A client that does not take a frame within 10 seconds is dropped.
Code Why
4401 no valid key, or the key was revoked while the stream was open (checked every 5 seconds)
4404 the account is not yours (exactly like an unknown one)
4429 the key’s budget is spent, or you already have 2 streams open
4503 the API is switched off for the moment
4400 since_seq is not a whole number
1013 the service cannot answer now: try again later
4430, 1009 too many messages, or one too large

Reconnect after a pause that grows with each failure, with since_seq set to the last seq you processed.

Python, with the websockets package:

import asyncio, json, os
import websockets
URL = f"wss://app.proofperps.com/v1/api/accounts/{os.environ['ACCOUNT']}/stream"
async def main():
headers = {"Authorization": f"Bearer {os.environ['PP_KEY']}"}
async with websockets.connect(URL, additional_headers=headers) as ws:
async for frame in ws:
message = json.loads(frame)
print(message["ch"], message["seq"])
asyncio.run(main())

Node.js, with the ws package:

import WebSocket from 'ws';
const url = `wss://app.proofperps.com/v1/api/accounts/${process.env.ACCOUNT}/stream`;
const ws = new WebSocket(url, { headers: { Authorization: `Bearer ${process.env.PP_KEY}` } });
ws.on('message', (frame) => {
const message = JSON.parse(frame);
console.log(message.ch, message.seq);
});
ws.on('close', (code) => console.log('closed', code));