Skip to Content
SDK reference

Python models

The objects the Python client returns.

Level

class Level(NamedTuple)

One order-book level, the [price, size] pair of the contract.

FieldType
priceDecimal
sizeDecimal

Limits

Ceilings of the stream and of trading, as printed by /v1/meta.

commands_per_second is the trading-command rate per listener, workspace_commands_per_second the workspace-command rate, settings_commands_per_second the settings-write rate; each is 0 for a terminal older than the stage that added the limit, which prints none because it accepts no such commands.

FieldType
ws_connections_per_tokenint
subscriptions_per_connectionint
api_only_instrumentsint
exchange_subscriptions_per_secondint
commands_per_secondint
workspace_commands_per_secondint
settings_commands_per_secondint

Meta

GET /v1/meta: API version, terminal build, token scopes, limits, stream topics.

topics is empty when the terminal was built without the market-data tap; the stream and the market operations then answer unsupported.

FieldType
api_versionstr
app_versionstr
build_hashstr
build_envstr
featuresstr
scopeslist[str]
limitsLimits
topicslist[str]

Health

GET /v1/health: listener state and the market-data hub counters.

FieldType
statusstr
uptime_msint
clientsint
streamsint
api_only_instrumentsint
dropped_eventsint
dropped_framesint
overflow_closesint
stream_availablebool

LastEvent

The last record of the connection history: a stage or error code and its time.

FieldType
codestr
tsint

ConnectionStatus

Connection state: disabled, enabled, connecting, connected or failed.

last_event is None when the connection has no history yet.

FieldType
statestr
last_eventLastEvent | None

Connection

One of the terminal's exchange connections. Carries no secrets, not even masked.

FieldType
idint
exchangestr
marketstr
labelstr
enabledbool
read_onlybool
has_credentialsbool
proxy_boundbool
statusConnectionStatus

Instrument

A catalogue entry. Steps and minimums are None when the exchange did not report them.

FieldType
instrumentstr
exchangestr
marketstr
symbolstr
basestr
quotestr
statusstr
tick_sizeDecimal | None
lot_sizeDecimal | None
min_sizeDecimal | None
contract_valueDecimal | None

Page

class Page(Generic[T])

One page of a list: data plus the next_cursor for the following page.

exchange and market name the pair the page was listed for. next_cursor is None on the last page.

FieldType
datalist[T]
next_cursorstr | None
exchangestr
marketstr

Interval

An interval code the terminal knows and its nominal length.

FieldType
idstr
duration_msint

Intervals

GET /v1/market/intervals: candle and cluster intervals.

FieldType
candleslist[Interval]
clusterslist[Interval]

Candle

One bar. ts is the bar open; volume is in the base coin.

FieldType
tsint
openDecimal
highDecimal
lowDecimal
closeDecimal
volumeDecimal
quote_volumeDecimal
closedbool

Candles

GET /v1/market/candles: bars of one instrument and the connection they came through.

FieldType
instrumentstr
connection_idint
intervalstr
datalist[Candle]

Trade

One trade. ts is when it passed through the terminal, exchange_ts the exchange time.

id is always None in v1.

FieldType
idstr | None
priceDecimal
qtyDecimal
sidestr
tsint
exchange_tsint

Trades

GET /v1/market/trades: the latest trades of one instrument, oldest first.

FieldType
instrumentstr
connection_idint
datalist[Trade]

Ticker

The 24h ticker. Fields the exchange does not report are None.

best_bid and best_ask here are prices from the ticker feed, not book levels; the book's top is on Snapshot.

FieldType
priceDecimal
change_24h_pctDecimal | None
volume_24hDecimal | None
high_24hDecimal | None
low_24hDecimal | None
best_bidDecimal | None
best_askDecimal | None
tsint

MarkPrice

A mark_price stream frame: the mark price and its time.

FieldType
mark_priceDecimal
tsint

Snapshot

GET /v1/market/snapshot: the latest the hub knows about one instrument.

best_bid and best_ask are Level pairs from the hub's book, None until a book snapshot has arrived. The other fields are None until their data has arrived.

FieldType
instrumentstr
connection_idint
tsint
best_bidLevel | None
best_askLevel | None
last_tradeTrade | None
mark_priceDecimal | None
tickerTicker | None

BookTop

The top of the book: bids from the best downwards, asks from the best upwards.

This is the data of a book.top stream frame; OrderBook adds the instrument and the connection for the HTTP operation.

FieldType
tsint
depthint
bidslist[Level]
askslist[Level]

OrderBook

class OrderBook(BookTop)

GET /v1/market/orderbook: the top of one instrument's book.

FieldType
instrumentstr
connection_idint

ClusterLevel

Volume traded at one price inside a cluster bucket.

FieldType
priceDecimal
volumeDecimal
buy_volumeDecimal
sell_volumeDecimal
buy_tradesint
sell_tradesint

Cluster

One cluster bucket: totals, price range and every level from the lowest price up.

last_trade_ts is 0 for a bucket seeded from history without a trade time. vwap, min_price and max_price are None for a bucket without trades.

FieldType
intervalstr
tsint
end_tsint
volumeDecimal
buy_volumeDecimal
sell_volumeDecimal
tradesint
vwapDecimal | None
min_priceDecimal | None
max_priceDecimal | None
completedbool
last_trade_tsint
levelslist[ClusterLevel]

Clusters

GET /v1/market/clusters: the latest buckets of one instrument, oldest first.

interval is the one selected for the instrument in the terminal.

FieldType
instrumentstr
connection_idint
intervalstr
tsint
datalist[Cluster]

Order

An open order of a connection: pending, open or partially_filled.

key is the terminal's order key (t-...), exchange_id the exchange's id; either is None while unknown. size, filled and remaining are in the base coin; notional is the quote amount the trader entered, None for an order that came from an exchange snapshot. The JSON key type is order_type here.

FieldType
keystr | None
exchange_idstr | None
instrumentstr
sidestr
order_typestr
priceDecimal | None
sizeDecimal
filledDecimal
remainingDecimal
notionalDecimal | None
statusstr
created_tsint

TriggerOrder

A trigger order: stop_loss, take_profit or stop (trigger_type).

rule is price_above_or_equal or price_below_or_equal; status is open, finished, inactive or invalid. size, notional, order_type, client_id and created_ts are None when the venue did not report them.

FieldType
idstr
instrumentstr
trigger_typestr
trigger_priceDecimal
rulestr
sizeDecimal | None
notionalDecimal | None
statusstr
order_typestr | None
client_idstr | None
created_tsint | None

AccountOrders

GET /v1/account/orders: open orders and trigger orders of one connection.

FieldType
connection_idint
datalist[Order]
triggerslist[TriggerOrder]

Position

An open position. size is in the base coin (lots on MOEX, lot_size base units each).

notional is in the quote; unrealized_pnl and mark_price are the terminal's own (best bid for a long, best ask for a short), None until the first book tick.

FieldType
instrumentstr
sidestr
sizeDecimal
lot_sizeDecimal | None
entry_priceDecimal | None
notionalDecimal | None
unrealized_pnlDecimal | None
mark_priceDecimal | None

AccountPositions

GET /v1/account/positions: open positions of one connection.

FieldType
connection_idint
datalist[Position]

Balance

The latest balance of one currency.

available and locked are None when the venue does not report them; ts is the exchange time where there is one, otherwise the receive time.

FieldType
currencystr
totalDecimal
availableDecimal | None
lockedDecimal | None
tsint

AccountBalances

GET /v1/account/balances: per currency, the latest value since the API came on.

FieldType
connection_idint
datalist[Balance]

Fill

One execution. position_side is long/short on hedged venues, else None.

FieldType
trade_idstr | None
order_idstr | None
instrumentstr
sidestr
priceDecimal
qtyDecimal
feeDecimal | None
fee_currencystr | None
position_sidestr | None
tsint

AccountFills

GET /v1/account/fills: the connection's latest fills, oldest first.

FieldType
connection_idint
datalist[Fill]

Accepted

A trading command was accepted by the terminal, not yet by the exchange.

operation_id names the operation in the terminal's operations file; key is the order key (t-...) under which the order will appear in account.orders, None for a cancellation. The exchange's confirmation, fill or rejection arrives through the stream.

FieldType
acceptedbool
operation_idstr
keystr | None
connection_idint
instrumentstr

Leverage

GET /v1/account/leverage: leverage and margin mode of one futures instrument.

Read from the terminal's cache, which the window's instrument selection and set_leverage fill; an instrument the terminal has not touched yet is ApiError not_active. mode is the terminal's leverage mode (manual, max, smart), not the exchange's; margin_mode is cross or isolated.

FieldType
connection_idint
instrumentstr
leverageint
max_leverageint
modestr
margin_modestr

CellPosition

A cell of a tab's grid: column left to right, row top to bottom, cell within the row.

FieldType
columnint
rowint
cellint

Stack

A stack — order book with its trade tape and clusters — inside a tab.

widget_id is global for this run of the terminal. instrument and connection_id are None while the stack is empty; position is None for a stack hidden inside a stack group.

FieldType
widget_idint
instrumentstr | None
connection_idint | None
emptybool
frozenbool
positionCellPosition | None

Chart

A chart inside a tab.

owner_widget_id is the stack the chart follows, None when standalone.

FieldType
widget_idint
instrumentstr | None
connection_idint | None
intervalstr
owner_widget_idint | None
positionCellPosition | None

Tab

A tab of a window: id is numbered per window from 1, exactly one tab is active.

FieldType
idint
namestr
activebool
stackslist[Stack]
chartslist[Chart]

Window

A terminal window; main cannot be closed through the API.

chart_window is a torn-off chart window. The geometry is in logical screen pixels; monitor is the OS's monitor name or None.

FieldType
idint
mainbool
chart_windowbool
focusedbool
xint
yint
widthint
heightint
maximizedbool
monitorstr | None
tabslist[Tab]

Workspace

GET /v1/workspace and the workspace stream topic: every window, by ascending id.

The ids are internal numbers of this run of the terminal: do not keep them across restarts, read them again.

FieldType
windowslist[Window]

TabItem

One column of a tab opened or extended through the API.

A stack of instrument on connection_id (the general rule picks one when None) and, with chart, a chart over it.

FieldType
instrumentstr
connection_idint | None
chartbool

WorkspaceOutcome

What the window did for a workspace command.

For an opening: the window, the new tab and its stacks and charts in column order; for columns added to a tab only the added widgets. For closing and activating: the touched ids, the rest None or empty.

FieldType
window_idint | None
tab_idint | None
stackslist[int]
chartslist[int]

SettingRow

One row of the terminal's settings table, as stored.

scope is global or order_book; scope_id is default, an instrument address, or None for hotkeys; connection_id is the owning connection or None. value is the decoded JSON (numbers as written). writable says whether update_settings accepts the key; it is None on a settings stream frame, which carries no such flag.

FieldType
scopestr
scope_idstr | None
connection_idint | None
categorystr
keystr
valueAny
writablebool | None

Settings

GET /v1/settings: rows as stored, without the default ladder.

FieldType
datalist[SettingRow]

OrderbookSetting

One stack setting with the level it was resolved from.

resolved_from is instrument (the pair's row on the connection), connection (the connection's default), app_instrument (the pair's row without a connection) or global.

FieldType
valueAny
resolved_fromstr
writablebool

OrderbookSettings

GET /v1/settings/orderbook: one instrument's stack settings as its stack sees them.

FieldType
connection_idint
instrumentstr
datadict[str, dict[str, OrderbookSetting]]

SettingChange

One change for update_settings.

instrument addresses the pair's row (scope order_book); connection_id with scope="order_book" and no instrument addresses the connection's default; neither addresses the global default. Global settings take no connection.

FieldType
categorystr
keystr
valueAny
scopestr | None
instrumentstr | None
connection_idint | None

SettingsApplied

PATCH /v1/settings: how many changes were applied (all of them, or the call raised).

FieldType
appliedint

OrdersUpdate

An account.orders frame: orders and triggers of one instrument after a change.

FieldType
instrumentstr
orderslist[Order]
triggerslist[TriggerOrder]

PositionUpdate

An account.positions frame: one instrument's position; a close is position=None.

FieldType
instrumentstr
positionPosition | None

Subscribed

Reply to subscribe: the subscription id and the connection chosen for it.

connection_id is None for workspace and settings: neither has a connection.

FieldType
substr
connection_idint | None
request_idstr | None

Unsubscribed

Reply to unsubscribe.

FieldType
substr
request_idstr | None

Event

A data frame of a subscription.

seq grows by one for trades; for conflated topics gaps in the numbering are normal. data is typed by the topic, see parse_event_data.

FieldType
substr
seqint
tsint
dataAny

Gap

Events from_seq..to_seq of a trades subscription were lost.

Arrives before the first frame after the loss; the trades can be re-read with Terminal.trades(..., since_ts=...).

FieldType
substr
from_seqint
to_seqint
reasonstr

SubscriptionError

The server removed a subscription: the venue refused or the pair could not be subscribed.

A new subscribe starts it again.

FieldType
substr
codestr
messagestr

Generated from the code of spectre-terminal at commit 2d1c324.

On this page