Mirexa

Wiki Concepts

Streams, symbols and timeframes

What a stream is in Mirexa — its three-part identity, how timeframes are parsed, the time grid bars sit on, the metadata a stream carries, and how streams come into existence.

A stream is the unit Mirexa stores, reads, subscribes to and replicates: one instrument, at one bar length, on one exchange. Every write and every read names exactly one stream (a multi-query names several, but answers each separately). There is no schema to declare and no table to create — a stream exists from its first write.

Identity

A stream is identified by three strings:

Field Meaning Example
Exchange The venue. Free text. binance, nyse
Symbol The instrument. Free text. BTCUSDT, AAPL
Timeframe The bar length, <positive integer><unit>. 1m, 5m, 1h, 1d, 1w

Each component must be 1 to 64 bytes drawn from [0-9A-Za-z._-], and may not be . or ..; the node refuses anything else at the protocol boundary, because components become directory names on disk.[1] Names are case-sensitive: BTCUSDT and btcusdt are two streams.

The command-line tools write a stream as exchange:symbol:timeframe (binance:BTCUSDT:1m). The Go type's String() renders it in a different order, symbol:timeframe:exchange (BTCUSDT:1m:binance); that form is what listing cursors and types.ParseStreamID use.[2] Do not mix the two up when building a cursor by hand.

go
stream := client.NewStreamID("binance", "BTCUSDT", "1m") // exchange, symbol, timeframe

Candles and ticks share an identity

A stream id names a candle half and a tick half. Ticks written to binance:ETHUSDT:1m and candles written to binance:ETHUSDT:1m are stored side by side under one identity; which half a request touches is chosen by the request (the -ticks flag, QueryRequest.Ticks, IngestTicks). A tick stream therefore still carries a timeframe in its name, and that timeframe must parse. The usual reason to use one id for both is a derived stream: trades go into the tick half and the node writes one-minute bars into the candle half.

Partitions

In a cluster, a stream is placed by its partition: a hash of its symbol and exchange (FNV-1a, 64-bit) modulo the cluster's partition count, 4,096 by default. The timeframe is deliberately left out, so every timeframe of one instrument on one exchange lives in the same partition, on the same node — which is what lets one stream be derived from another without crossing the network.[3] The partition count is fixed once a cluster agrees on it. See Partitions and routing.

Timeframes

A timeframe is a positive integer followed by one unit:[4]

Unit Meaning Examples
s seconds 1s, 30s
m minutes 1m, 5m, 15m
h hours 1h, 4h
d days (24 hours) 1d
w weeks (7 days) 1w

Anything else — an empty string, 0m, 1M, 90, a value so large the interval would overflow 64-bit nanoseconds — is refused, never defaulted. (An earlier version defaulted an unparseable timeframe to one minute, which turned five hourly bars into 241 points, 236 of them false gap markers.)

The grid

Every candle in a stream must be stamped on the stream's grid: the multiples of its interval counted from an origin. The origin is the Unix epoch (1970-01-01 00:00 UTC) for every interval except a whole number of weeks, whose grid counts from Monday 1970-01-05 00:00 UTC — so a weekly bar is the Monday-start week, stamped Monday 00:00 UTC.[5]

  • A 1m bar is stamped on a whole minute, a 1h bar on a whole hour UTC, a 1d bar at 00:00 UTC.
  • A 1w bar is stamped on a Monday at 00:00 UTC. A Thursday-stamped weekly bar (the epoch's weekday) is refused as unaligned.
  • A bar's timestamp is the start of its interval, in Unix nanoseconds.

A write with a timestamp off the grid is refused as a bad batch ("a timestamp is not aligned to the stream's timeframe"), before anything is stored. Truncating your timestamps to the interval — in Go, t.Truncate(time.Minute) for a minute stream — keeps them on the grid for every interval below a week.

A daily bar is stamped 00:00 UTC whatever the market's timezone. Bars Mirexa derives follow the same rule: a derived daily bar holds the local trading date in the stream's calendar timezone and is stamped 00:00 UTC of that date. See Derived streams.

Metadata

Besides its data, each stream carries a small metadata record, kept in the node's catalog (streams.meta) and shipped to every copy in a cluster:[6]

Field What it does Set with
Working hours Weekly trading windows in an IANA timezone. Gaps outside them are closures, not missing data. mirexa-cli calendar set, SetStreamMetadata
Closures Specific closed ranges: holidays, halts, a known maintenance window (at most 10,000). mirexa-cli calendar add-closure / remove-closure, AddStreamClosure / RemoveStreamClosure
Gap thresholds GapThresholdHigh: on a stream with no working hours, a gap at least this long is a closure. GapThresholdLow: stored, but see the note below. mirexa-cli calendar set -threshold-high/-threshold-low
Lineage That this stream's candles are derived from another stream, and how. mirexa-cli lineage set, SetStreamLineage
Cache capacity An override of how many slots the stream's hot cache holds. mirexa-cli cache set
Custom fields Free key–value pairs. Stored; no effect on behaviour. —

The calendar fields are explained in Gaps and trading calendars and the lineage in Derived streams. Each kind of change has its own call, and a calendar update keeps the stream's lineage and cache override rather than erasing them.[7]

GapThresholdLow is accepted, stored and returned, and the CLI describes it as the "minimum gap duration recorded", but at this commit nothing in the write or flush path reads it: a gap shorter than it is recorded and classified like any other. The only code that would act on it (storage.ClassifyGap) has no production caller. Treat it as inert.

The hot-cache size

Recent bars of each stream live in an in-memory hot cache before they are flushed to disk. Its size, in slots, is derived from the timeframe: enough slots to cover ingestion.live_candle.cache_span, at least 2,048 and at most cache_arena_capacity (50,000). With the defaults, 1m and shorter streams get 50,000 slots, 5m gets 10,000 and 30m or longer get 2,048. A slot costs 40 bytes whether or not a bar fills it.[8]

The size matters to a writer because it is also the widest batch the live path accepts: a batch spanning more slots than the stream's cache is refused and must be split (or sent through the history route). An operator can override the size for one stream with mirexa-cli cache set -slots N (16 to 8,388,608); the running stream takes the change at once without losing data. See The hot cache.

How a stream comes into existence

There is no create call you must make first:[9]

  • The first write registers it. A candle or tick write to an unknown id creates the stream with default metadata (no calendar, no lineage) and its directories on disk.
  • Setting metadata can register it. mirexa-cli calendar set and cache set register a stream the node does not yet know; through the SDK, SetStreamMetadata does so when the request sets Create: true.
  • Listing shows every stream a node holds (mirexa-cli streams, ListStreams), paged by stream id, with optional per-stream statistics.

Registration lands whole or not at all: the stream's storage is created before its metadata is recorded, so a stream that lists as present always has somewhere to put its data.

There is no way to delete a stream's data through the clients. The control API's DeleteStream removes a stream from the catalog only: its stored data stays on disk, and the next write to the id registers it again. See the control-plane API.

On disk

A stream lives in <data_dir>/partition_<N>/<exchange>@<symbol>_<timeframe>/, holding its chunk files, its stream index (stream.idx) and its gap index (gap.idx). The name carries all three parts of the stream's identity, so two streams that differ only in exchange (binance:BTCUSDT:1m and kraken:BTCUSDT:1m) never share a directory, even in the same partition. Until 2026-10-30 the name was <symbol>_<timeframe> and they did; a node renames directories in the old form at startup. See Indexes and the on-disk layout.

References

Source

Tests

Further reading


  1. wire.validateStreamID; TestPayload_RejectsUnparseableTimeframe. ↩︎

  2. StreamID.String and ParseStreamID; the CLI's parser is commonFlags.streamID in /cmd/cli/main.go. ↩︎

  3. StreamID.PartitionKey, AssignPartition; TestAssignPartition_DistributionIsUniform. ↩︎

  4. ParseTimeframe; TestParseTimeframe_RejectsOverflowingValues. ↩︎

  5. /internal/types/grid.go; TestGrid_AWeekStartsOnMondayEveryOtherIntervalAtTheEpoch, TestIngest_AWeeklyStreamIsOnTheMondayGrid. ↩︎

  6. types.StreamMetadata; closure limit MaxClosures in /internal/types/closure.go. ↩︎

  7. TestSetStreamLineage_OnlyItWritesTheLineage. ↩︎

  8. The CLI's cache help text and cache.Sizing; TestStreamCache_AdmissionPredictsTheArenaAPendingSizeGives. ↩︎

  9. TestRegisterStream_ImplicitOnFirstWriteUsesDefaults, TestRegisterStream_LandsWhollyOrNotAtAll. ↩︎