MFX Hub
SDK reference

Market data

Generated from mfx-sdk-python 0.9.11·rebuilt on every release

Subscriptions to ticks and depth, delivered on the stream.

Types

AliasValues
Idstr | UUID

SubscriptionDegraded

A subscription whose symbol cannot tick, or should be ticking and is not.

Sent once, when it becomes degraded. A closed market is not a degradation, and neither is a terminal that restarts and is back inside a few minutes. reason is the platform's own word and is text, not a closed list: symbol_removed, subscription_refused, terminal_disconnected, report_stale and no_ticks_in_session today, and a platform that learns another will send it. A reason that gives way to another while the subscription stays degraded sends nothing; read the subscription for the one that holds.

FieldTypeDefaultMeaning
subscription_idUUID
broker_idUUID
server_idUUID
symbolstr
reasonstr
sincedt.datetime
last_tick_atdt.datetime | None

The symbol's last tick, or None when it has never ticked.

SubscriptionRecovered

A degraded subscription that is delivering again. Sent once.

reason is what it recovered from and since when it had become degraded, so the two together with recovered_at are the whole gap, without the first message being kept.

FieldTypeDefaultMeaning
subscription_idUUID
broker_idUUID
server_idUUID
symbolstr
reasonstr
sincedt.datetime
recovered_atdt.datetime
last_tick_atdt.datetime | None

Book

A symbol's whole order book as one terminal read it. Replace yours with every one.

Prices and volumes are Decimal, exact as the platform sent them. levels is the most a side the platform reads, so a side shorter than it is the broker's whole side. Not a reconstruction: MFX Hub builds no book from ticks or from several terminals.

FieldTypeDefaultMeaning
channelstr
seqint | None
bidstuple[tuple[Decimal, Decimal], ...]

Buy orders, highest price first: (price, volume).

askstuple[tuple[Decimal, Decimal], ...]

Sell orders, lowest price first.

broker_tsstr

When the terminal read it, on the broker's clock, as a tick's broker_ts.

levelsint
best_bid -> Decimal | None property
best_ask -> Decimal | None property

MarketData

client.md — what this tenant has asked to be streamed.

async subscribe( server_id: Id, symbol: str, *, idempotency_key: str, timeframes: list[str] | None = None, ) -> MdSubscription

Ask for a symbol's ticks on one broker server, and optionally its candles.

ParameterTypeDefaultDescription
server_idIdrequired

The server's id from the catalogue.

symbolstrrequired

The broker's own symbol name, exactly as the catalogue returns it. MFX Hub never renames an instrument.

idempotency_key keywordstrrequired

Required on every write and never defaulted. Retrying with the same key returns the original answer; a fresh key asks for a new action.

timeframes keywordlist[str] | NoneNone

timeframes names the candles to build; none means ticks only.

Returns MdSubscription

symbol is the broker's own name, exactly as the tenant's catalogue lists it (EURUSD.sd, not EURUSD): a broker's suffix is part of the name, and the platform matches what the terminal reports rather than guessing.

timeframes names the candles to build; none means ticks only. Candles arrive on their own channel, candles:{server_id}:{symbol}:{tf}.

Subscribing twice with the same idempotency_key returns the same subscription rather than a second one.

async subscriptions( *, cursor: str | None = None, limit: int | None = None, ) -> Page[MdSubscription]

One page of what this tenant has subscribed, newest first.

ParameterTypeDefaultDescription
cursor keywordstr | NoneNone

Where to continue from; the previous page's next cursor.

limit keywordint | NoneNone

How many to return at most.

Returns Page[MdSubscription]

async all_subscriptions() -> AsyncIterator[MdSubscription]

Every subscription, following the cursor.

Returns AsyncIterator[MdSubscription]

async unsubscribe(subscription_id: Id, *, idempotency_key: str) -> None

Stop streaming this symbol. The channel stops; nothing else is affected.

ParameterTypeDefaultDescription
subscription_idIdrequired
idempotency_key keywordstrrequired

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 None

async candles( broker: Id, symbol: str, timeframe: str, *, from_: dt.datetime, to: dt.datetime, limit: int | None = None, server_id: Id | None = None, ) -> CandleList

A symbol's bars for a window, oldest first: at most 1,000 a call.

ParameterTypeDefaultDescription
brokerIdrequired
symbolstrrequired

The broker's own symbol name, exactly as the catalogue returns it. MFX Hub never renames an instrument.

timeframestrrequired

One of M1, M5, M15, M30, H1, H4, D1, W1, MN1.

from_ keyworddt.datetimerequired
to keyworddt.datetimerequired

When the window holds more than limit bars the answer is the newest of them, so a chart asking for "up to now" gets the bars nearest now; ask again with an earlier to for the ones before.

limit keywordint | NoneNone

How many to return at most.

server_id keywordId | NoneNone

The server's id from the catalogue.

Returns CandleList

The bars are the ones the broker's server shows the tenant's own account, read through one of its ACTIVE terminals on that server. When the window holds more than limit bars the answer is the newest of them, so a chart asking for "up to now" gets the bars nearest now; ask again with an earlier to for the ones before. The bar still forming is included when the window reaches it: its close is the last price.

timeframe is one of M1, M5, M15, M30, H1, H4, D1, W1, MN1; any other is a ValueError here, before the wire. Each bar's ts is its open time as a true instant: a daily bar opens at the broker's midnight, which is not UTC midnight. symbol is the broker's own name. With terminals on more than one of the broker's servers, name server_id. No bar in the window is an empty answer, not an error.

async ticks( broker: Id, symbol: str, *, from_: dt.datetime, to: dt.datetime | None = None, limit: int | None = None, server_id: Id | None = None, ) -> TickList

One read of tick history: the first limit ticks at or after from_, oldest first.

ParameterTypeDefaultDescription
brokerIdrequired
symbolstrrequired

The broker's own symbol name, exactly as the catalogue returns it. MFX Hub never renames an instrument.

from_ keyworddt.datetimerequired

One read of tick history: the first limit ticks at or after from_, oldest first.

to keyworddt.datetime | NoneNone

to leaves out ticks after it.

limit keywordint | NoneNone

How many to return at most.

server_id keywordId | NoneNone

The server's id from the catalogue.

Returns TickList

The ticks are the ones the broker's server keeps for the tenant's own account, read through one of its ACTIVE terminals on that server; MFX keeps no tick store of its own, so how far back they go is the broker's to say. At most 1,000 a call, which is also the default. to leaves out ticks after it. more on the answer is true when the window holds ticks beyond the ones returned - all_ticks follows it.

symbol is the broker's own name. With terminals on more than one of the broker's servers, name server_id.

async all_ticks( broker: Id, symbol: str, *, from_: dt.datetime, to: dt.datetime | None = None, page_size: int | None = None, server_id: Id | None = None, ) -> AsyncIterator[Tick]

Every tick of a window, in order, each once, a call at a time.

ParameterTypeDefaultDescription
brokerIdrequired
symbolstrrequired

The broker's own symbol name, exactly as the catalogue returns it. MFX Hub never renames an instrument.

from_ keyworddt.datetimerequired
to keyworddt.datetime | NoneNone
page_size keywordint | NoneNone
server_id keywordId | NoneNone

The server's id from the catalogue.

Returns AsyncIterator[Tick]

The contract's way to continue is to ask again from the last tick's time, and several ticks can share one millisecond, so the next answer begins with ticks already held. This drops exactly those and yields the rest, which is easy to get subtly wrong by hand: drop by time alone and ticks are lost, drop nothing and they are doubled.

Every call is a round trip to capacity (a busy symbol passes 100,000 ticks a day): this is for reading history. The stream is the way to follow ticks as they happen.