Client and signing
The client signs every request with your private key, applies a retry budget, and opens the stream. Secrets and signing keys render as *** everywhere.
Budget
What the key has left, as of the last answer (X-MFX-Budget-*).
| Field | Type | Default | Meaning |
|---|---|---|---|
| remaining | int | ||
| source | str |
|
MfxClient
A tenant's connection to MFX.
base_url includes the version: https://api.dev.mfxhub.com/v1.
| Parameter | Type | Default | Description |
|---|---|---|---|
| base_url | str | required | The API root, https://api.mfxhub.com/v1. |
| key_id | str | required | Your key id, issued with the key. |
| private_key | SigningKey | Ed25519PrivateKey | str | bytes | required | The private half of your key, shown once at issue. Accepted as a SigningKey or as its text. |
| timeout_s keyword | float | DEFAULT_TIMEOUT_S | |
| read_retries keyword | int | DEFAULT_READ_RETRIES | |
| transport keyword | httpx.AsyncBaseTransport | None | None | |
| sleep keyword | Callable[[float], Awaitable[None]] | None | None | |
| jitter keyword | Callable[[float, float], float] | random.uniform | |
| wall keyword | Callable[[], float] | time.monotonic |
Returns None
What the key had left when MFX last answered; None before the first answer.
The REST base this client was pointed at. The stream's host is derived from it.
The signer, so the WebSocket upgrade is signed by the same code as every REST call.
Jittered exponential backoff for an attempt, with no server-supplied delay in hand.
| Parameter | Type | Default | Description |
|---|---|---|---|
| attempt | int | required |
Returns float
Exposed so the stream's reconnects and the read path's retries lean on this tenant's quota at the same rate; two backoff policies in one client is one policy nobody tuned.
The multiplexed WebSocket stream. Opened with async with.
| Parameter | Type | Default | Description |
|---|---|---|---|
| connect keyword | Connector | None | None |
|
| url keyword | str | None | None | |
| max_reconnects keyword | int | None | None |
Returns MfxStream
connect replaces the transport, which is how a test drives reconnects without a server.
The generated client, for the endpoint modules. Not part of the public surface.
This client's clock, so latency is measured the same way everywhere and can be faked.
Returns float
This client's sleep — the one the retry policy uses, so a test waits for nothing.
| Parameter | Type | Default | Description |
|---|---|---|---|
| seconds | float | required |
Returns None
Raise the typed error for a failed answer, for a caller that wants to catch rather than check. execution uses it to turn a refusal into a result rather than an exception.
| Parameter | Type | Default | Description |
|---|---|---|---|
| response | GeneratedResponse[Any] | required | |
| what | str | required |
Returns None
Run a generated read and return what the generated core parsed.
| Parameter | Type | Default | Description |
|---|---|---|---|
| call | Callable[[], Awaitable[GeneratedResponse[Any]]] | required | |
| what | str | required |
Returns Any
Run a generated read, retrying 429 with the server's own delay.
| Parameter | Type | Default | Description |
|---|---|---|---|
| call | Callable[[], Awaitable[GeneratedResponse[Any]]] | required | Each attempt calls |
| what | str | required |
Returns GeneratedResponse[Any]
Each attempt calls call again, so it is signed again: a retried request is a new request with a new nonce, never the same bytes twice.
Returns the whole answer, for the one caller that must read the body itself while the page schemas generate without their contents.
Run a generated write. Never retried: a retried write is a second order.
| Parameter | Type | Default | Description |
|---|---|---|---|
| call | Callable[[], Awaitable[GeneratedResponse[Any]]] | required | |
| what | str | required |
Returns Any
One attempt, with transport faults and unreadable answers turned into MFX errors.
| Parameter | Type | Default | Description |
|---|---|---|---|
| call | Callable[[], Awaitable[GeneratedResponse[Any]]] | required | |
| what | str | 'the request' |
Returns GeneratedResponse[Any]
Returns None
SigningKey
A tenant's Ed25519 private key, which renders as *** everywhere it could be printed.
Accepts the key as PEM, as the base64 of its 32 raw bytes, or as an already-loaded Ed25519PrivateKey.
| Parameter | Type | Default | Description |
|---|---|---|---|
| key | Ed25519PrivateKey | str | bytes | SigningKey | required |
Returns None
The base64 signature of message.
| Parameter | Type | Default | Description |
|---|---|---|---|
| message | bytes | required | The base64 signature of |
Returns str
MfxSignature (httpx.Auth)
Signs every request as it goes out, with a fresh timestamp and nonce each time.
The four headers for one request, with a fresh timestamp and nonce.
| Parameter | Type | Default | Description |
|---|---|---|---|
| method | str | required | |
| path_with_query | str | required | |
| body | bytes | b'' |
Returns dict[str, str]
The WebSocket upgrade is signed through here too, so the stream and every REST call put the same bytes under the same signature. A second implementation for the upgrade is how the two drift until one of them is a 401 nobody can explain.
| Parameter | Type | Default | Description |
|---|---|---|---|
| request | httpx.Request | required |
Returns Generator[httpx.Request, httpx.Response, None]
signing_message()
The exact bytes an MFX signature covers — one place, so the client and the tests agree.
| Parameter | Type | Default | Description |
|---|---|---|---|
| timestamp | str | required | |
| nonce | str | required | |
| method | str | required | |
| path_with_query | str | required | |
| body | bytes | required |
Returns bytes
Raises when the nonce is not ^[A-Za-z0-9_-]{16,64}$. Refusing here rather than sending it is deliberate: the server answers 401 to a bad nonce, and "auth_error" is a poor way to learn that a custom nonce generator emits something with a newline in it.
Secret
A string that renders as *** everywhere except reveal.
| Parameter | Type | Default | Description |
|---|---|---|---|
| value | str | Secret | required |
Returns None
The value itself. Every call site is a place a secret can escape — keep them few.
Returns str
SyncMfxClient
The MFX client for code with no event loop. Use it as a context manager::
with SyncMfxClient(base_url, key_id, private_key) as mfx: terminal = mfx.get_terminal(terminal_id)
| Parameter | Type | Default | Description |
|---|---|---|---|
| broker_id keyword | Id | required | The broker's id from the catalogue. |
| server_id keyword | Id | required | The server's id from the catalogue. |
| idempotency_key keyword | str | required | Required on every write and never defaulted. Retrying with the same key returns the original answer; a fresh key asks for a new action. |
| farm_id keyword | Id | None | None | Where to place the terminal. Leave it out and the platform chooses; name one to place it deliberately. |
| streaming keyword | bool | False | Whether this terminal streams market data. |
| execution keyword | bool | False | Whether this terminal may trade. |
| instruments keyword | list[str] | None | None | The broker's own symbol names to subscribe on creation. |
| labels keyword | dict[str, str] | None | None | Your own key/value labels on the terminal, for your own filtering. |
| redundancy keyword | Redundancy | 'none' | "none", "active_passive" or "active_active": whether the terminal keeps a warm stand-in. |
Returns TenantTerminal
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
Returns TenantTerminal
Every terminal, following the cursor — as an ordinary iterator.
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit keyword | int | None | None | How many to return at most. |
Returns Iterator[TenantTerminal]
Each page is one call; the walk is not read ahead, so a script that stops early has not paid for the rest.
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
| login keyword | int | required | The broker login. |
| password keyword | Secret | str | required | The broker password, wrapped in Secret. It travels once and is used by reference. |
| server keyword | str | required | The broker server name as the broker publishes it. |
| idempotency_key keyword | str | required | Required on every write and never defaulted. Retrying with the same key returns the original answer; a fresh key asks for a new action. |
| cred_type keyword | CredentialType | 'master' |
Returns CredentialAccepted
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
| idempotency_key keyword | str | required | Required on every write and never defaulted. Retrying with the same key returns the original answer; a fresh key asks for a new action. |
| reason keyword | str | None | None | Your own words, recorded with the action. |
| confirm_open_positions keyword | bool | False |
Returns TenantTerminal
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
| idempotency_key keyword | str | required | Required on every write and never defaulted. Retrying with the same key returns the original answer; a fresh key asks for a new action. |
Returns TenantTerminal
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
| idempotency_key keyword | str | required | Required on every write and never defaulted. Retrying with the same key returns the original answer; a fresh key asks for a new action. |
Returns TenantTerminal
Returns Iterator[TenantBroker]
| Parameter | Type | Default | Description |
|---|---|---|---|
| broker_id | Id | required | The broker's id from the catalogue. |
Returns Iterator[TenantBrokerServer]
| Parameter | Type | Default | Description |
|---|---|---|---|
| broker_id | Id | required | The broker's id from the catalogue. |
Returns Iterator[Symbol]
| Parameter | Type | Default | Description |
|---|---|---|---|
| broker_id | Id | required | The broker's id from the catalogue. |
| symbol | str | required | The broker's own symbol name, exactly as the catalogue returns it. MFX Hub never renames an instrument. |
Returns Symbol
| Parameter | Type | Default | Description |
|---|---|---|---|
| broker_id | Id | required | The broker's id from the catalogue. |
| symbol | str | required | The broker's own symbol name, exactly as the catalogue returns it. MFX Hub never renames an instrument. |
Returns SymbolQuote
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
Returns Account
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
Returns PositionList
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
Returns PendingOrderList
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
| from_ keyword | dt.datetime | required | |
| to keyword | dt.datetime | required |
Returns Iterator[Deal]
| Parameter | Type | Default | Description |
|---|---|---|---|
| terminal_id | Id | required | The terminal to act on. Another customer's id answers 404, never 403. |
Returns SpreadList
Returns Usage
A symbol's bars for a window; see candles.
Returns CandleList
One read of tick history; see ticks.
Returns TickList
Never raises for a refused or failed order — it returns the result, exactly as the async boundary does. A script that treats an exception as "it did not happen" would treat a refusal as a network fault and retry a filled order.
Returns ExecutionResult
Returns ExecutionResult
Returns ExecutionResult
Returns ExecutionResult
Returns ExecutionResult
Returns ExecutionResult
Returns ExecutionResult
Returns ExecutionResult
What the key had left when MFX last answered.
Close the connections, stop the loop and join its thread. Closing twice is harmless.
Returns None
Page
One page, and the cursor for the next. next_cursor is None on the last.
| Field | Type | Default | Meaning |
|---|---|---|---|
| items | list[T] | default_factory=list | |
| next_cursor | str | None | None | |
| returned | int | None | None | How many are in THIS page. Not a total, and never to be shown as one. |