Concepts
Events and the stream
One WebSocket, many subscriptions: account, results, market data and candles are channels on the same connection. Events are ordered per terminal with a sequence number, and every payload carries schema_version.
from mfx import Channel
async with client.stream() as stream: # resumes by itself after a reconnect
await stream.subscribe(Channel.EVENTS)
async for msg in stream:
if msg.type == "position.closed":
...const stream = client.stream(); // resumes by itself after a reconnect
await stream.subscribe("events");
for await (const msg of stream) {
if (msg.type === "position.closed") { /* ... */ }
}await using var stream = client.Stream(); // resumes by itself after a reconnect
await stream.SubscribeAsync("events");
await foreach (var msg in stream) {
if (msg.Type == "position.closed") { /* ... */ }
}try (MfxStream stream = client.stream()) { // resumes by itself after a reconnect
stream.subscribe("events");
for (StreamMessage msg : stream) {
if (msg.type().equals("position.closed")) { /* ... */ }
}
}GET wss://ws.mfxhub.com/v1/stream (signed upgrade)
> {"op": "subscribe", "ch": "events"}
< {"op": "msg", "ch": "events", "seq": 184222, "type": "position.closed", "data": {"schema_version": 1, ...}}
> {"op": "resume", "ch": "events", "after_seq": 184222}A gap in seq means a missed event: resume from the last one you processed and the stream replays what it holds, or tells you to resync from a fresh read when it cannot.