Wiki Guides
Reading data
How to read candles and ticks back from Mirexa — range queries, paging iterators, newest-first reads, many streams in one round trip, column reads, query-time rollups and listing streams — from Go, the command line and Python.
A read names one stream and a time range [start, end) in Unix nanoseconds, and returns
what the stream holds there: candles, optionally with markers for the empty slots, or
trades. Every read merges the stream's in-memory hot cache with its chunks on disk, so an
acknowledged write is visible to the next read. There is no query language; the options
below are the whole surface.
One range query
resp, err := c.QueryCandles(ctx, client.QueryRequest{
StreamID: stream,
StartTime: start.UnixNano(), // inclusive
EndTime: end.UnixNano(), // exclusive
})
if err != nil {
return err // transport failure or a refusal from the node
}
switch resp.Status {
case client.QueryStatusOK:
case client.QueryStatusStreamNotFound:
case client.QueryStatusInvalidRange:
}
for _, p := range resp.Points {
// p.Candle, p.IsGap, p.Status, p.Reason
}
A query has two failure channels: an error means the transport failed or the node
refused the request; resp.Status is an in-band answer about this request. A missing
stream is a status, not an error.[1]
QueryRequest field |
Meaning |
|---|---|
StreamID |
the stream |
StartTime, EndTime |
[StartTime, EndTime), Unix ns; a start below 0 is an invalid range |
MaxResults |
0 = as many as fit in one response frame; a cap on one response here, a cap on the total for iterators |
Descending |
newest first; with MaxResults: it returns the last N bars of the range |
IncludeGaps |
return a marker for each empty slot (candles only) |
Ticks |
read trades instead of candles |
Rollup |
longer bars made at query time (below) |
Columns |
read only some values (below) |
AllowStale |
cluster only: let an in-sync copy answer (candles only) |
resp.HasMore means the range holds more than one frame can carry: continue from past the
last timestamp (or use an iterator). The latest three bars of a stream:
resp, err := c.QueryCandles(ctx, client.QueryRequest{
StreamID: stream, StartTime: 0, EndTime: math.MaxInt64,
Descending: true, MaxResults: 3,
})
Iterating a long range
QueryCandlesRows pages for you, with the database/sql.Rows contract:
rows := c.QueryCandlesRows(ctx, client.QueryRequest{
StreamID: stream, StartTime: start, EndTime: end, IncludeGaps: true,
})
defer rows.Close()
for rows.Next() {
p := rows.Point()
if p.IsGap {
continue
}
use(p.Candle)
}
if err := rows.Err(); err != nil { // always
return err
}
Always check Err(): an in-band refusal ("no such stream") ends the loop exactly as a
normal finish does, and surfaces only there, as a *QueryStatusError. MaxResults is a
cap on the total. QueryTicksRows is the same for trades (rows.Tick()).[2]
Gap markers
With IncludeGaps, each empty slot in the range comes back as a point with IsGap set and
its Status and Reason — for example GapReasonOffTime for a closed market,
GapStatusOpen for missing data you can still fill. A slot the classifier has not reached
yet reports OPEN / UNKNOWN. A derived bar carrying an INCOMPLETE mark is a bar, not a
marker: test it with p.Incomplete(). Markers are per interval, so a weekend on a 1m
stream is 2,880 points; to get holes as ranges, use ListGaps
(Finding and filling gaps). Trades have no gap markers.
Ticks
resp, err := c.QueryTicks(ctx, client.QueryRequest{StreamID: s, StartTime: a, EndTime: b})
for _, t := range resp.Ticks {
// t.Timestamp, t.Price, t.Volume
}
Reading trades needs READ_TICKS; reading candles needs READ_CANDLES.
Many streams in one round trip
QueryMultiAll sends several sub-queries in one request and returns separate, complete
series in request order; nothing is merged, so the same stream may appear twice with
different windows, and candle and tick sub-queries may mix:[3]
results, err := c.QueryMultiAll(ctx, []client.QueryRequest{
{StreamID: btc, StartTime: start, EndTime: end},
{StreamID: eth, StartTime: start, EndTime: end},
{StreamID: btc, StartTime: earlier, EndTime: start},
})
for i, r := range results { // results[i] answers request i
if r.Status != client.QueryStatusOK {
continue // affects this entry only
}
use(r.Points)
}
Each result carries its own status. A node limits the sub-queries one request may carry
(network.max_subqueries_per_request, default 128; a larger batch is refused whole), and
QueryMultiAll re-asks for whatever did not fit in one frame. QueryMulti is the raw
single-frame form.
Only some columns
QueryColumns asks for the timestamp and only the values you name, decoded on the node and
returned as slices:
cols, err := c.QueryColumns(ctx, client.QueryRequest{
StreamID: s, StartTime: a, EndTime: b,
Columns: client.ColumnClose, // or ColumnOpen | ColumnVolume, ColumnsAll
})
for i, ts := range cols.Timestamp {
use(ts, cols.Close[i]) // columns not asked for are nil
}
A close-only row is 17 bytes on the wire against 49 for a whole bar. It pages like the row
iterator. Column reads carry no gap markers and cannot be combined with IncludeGaps,
Ticks, AllowStale or Rollup; cols.Incomplete(i) reports an INCOMPLETE mark.[4]
Rollups: longer bars at query time
Rollup returns bars of that length computed at query time from the stream's candles, or
with Ticks: true from its trades, and stored nowhere. The answer is candles either way:
hourly, err := c.QueryCandles(ctx, client.QueryRequest{
StreamID: oneMinute, StartTime: from, EndTime: to,
IncludeGaps: true, Rollup: time.Hour,
})
The length must be a whole multiple of the stream's own, at least twice (above a day only
1d and 1w); only closed buckets are answered; and the rules are those of a stored
derivation, so the answers match one. See
Derived streams.
From the command line
./bin/cli query -stream binance:BTCUSDT:1m \
-start 2026-10-20T00:00:00Z -end 2026-10-21T00:00:00Z -gaps
| Flag | Meaning |
|---|---|
-, - |
required; RFC 3339 or Unix ns |
- |
include empty slots as rows: empty values and a trailing gap column |
- |
stop after this many records (default 0: the whole range) |
- |
read trades |
- |
bars of this length (7m, 4h, 24h) made at query time |
- |
several streams over the same range in one round trip; rows are prefixed with the stream |
Output is CSV on standard output, timestamps in RFC 3339 (UTC), paged automatically.[5]
To list streams: ./bin/cli streams (add -stats for record counts, sizes and time
bounds; listing needs LIST_STREAMS). From Go, ListStreams pages by stream id with
filters on exchange, symbol prefix and timeframe; ResilientClient.ListStreamsAll returns
every id.
Things worth knowing
- Precision. With the default codec, a value with more than four decimal places is rounded when its bar is flushed to a chunk; a read before the flush can return the unrounded value. See Candles and ticks.
- One connection, one request at a time on the node. Requests on one
Clientoverlap on the wire, but the node serves a connection's requests in order; one slow query delays those behind it. Use several clients for parallel reads. - A query cache (
query_cache.enabled, off by default) can serve repeated identical queries; writes invalidate it. - In a cluster, a request sent to a node that does not serve the stream is answered with
a redirect; the public Go
clientpackage does not follow redirects by itself. See Partitions and routing and Reads from copies. - Python:
query_candles,query_ticks,query_columns(into NumPy) and pandas/polars results. See Python SDK.
References
Source
Client.QueryCandles,QueryCandlesRows,QueryTicks,QueryMultiAll,QueryColumns,ListStreamswire.QueryRequest,QueryStatus- /client/client.go
- /cmd/cli/main.go —
query,streams.
Tests
Example,Example_rows,Example_multiQuery,Example_errorHandling,ExampleClient_QueryColumnsin /client/example_test.goTestServer_DescendingWithMaxResultsReturnsTheNewestin /internal/network/query_order_test.goTestServer_QueryMultiMatchesSingleQueries,TestServer_QueryMultiPartialSuccess,TestServer_QueryMultiOverCapRefusedByNamein /internal/network/multiquery_server_test.goTestQueryCandles_GapClassificationSurvivesToTheResultin /internal/ingestion/gap_classification_query_test.goTestRollup_AnswersWhatAStoredDerivationWouldin /internal/ingestion/rollup_test.go