tickerforge (Rust)
Rust library that loads the default tickerforge-spec YAML tree from the tickerforge-spec-data crate (git dependency, same content as the Python tickerforge-spec-data wheel) and generates or parses futures tickers (parity with tickerforge-py). Options tickers are supported for B3 per spec/contracts/b3/options.yaml (see OptionGenerator).
Trading sessions use the bdays crate (B3 BrazilExchange, US USSettlement for CME). Full alignment with Python’s exchange_calendars is not guaranteed; see docs/calendar-strategy.md.
Install
From a git checkout:
Or path dependency:
= { = "../tickerforge-rs" }
Usage
Generating tickers
use TickerForge;
let forge = new.expect;
let ticker = forge.generate.expect;
assert_eq!;
TickerForge::new() loads the bundled default spec from tickerforge-spec-data. Use TickerForge::with_spec_path(path) (and TickerParser::with_spec_path(path)) for a custom spec directory. The default root path is also available as tickerforge::default_spec_root.
Parsing tickers (smart parsing)
The parser accepts full tickers (INDM26) or root symbols (IND).
Full tickers derive year/month directly from the string — no reference date required. Root symbols resolve the front-month contract via the generator; the date defaults to today when omitted.
Four free functions cover every combination of spec / date:
use ;
// Full ticker — default spec, no date needed
let parsed = parse_ticker.expect;
assert_eq!;
assert_eq!;
assert_eq!;
// Root symbol — default spec, explicit date
let parsed = parse_ticker_date.expect;
// Full ticker — custom spec, no date
let spec = load_spec.expect;
let parsed = parse_ticker_spec.expect;
// Root symbol — custom spec, explicit date
let parsed = parse_ticker_date_spec.expect;
TickerParser wraps a loaded spec for repeated calls.
new() loads the bundled spec and panics on failure (the spec is compiled in, so this should never happen).
Use try_new() for a fallible alternative.
use TickerParser;
let parser = new;
let parsed = parser.parse.expect;
let parsed = parser.parse_date.expect;
Builder pattern
TickerParser::builder() provides a fluent API for configuration and one-shot parsing.
The builder uses typestate generics: parse() is only available at compile time after ticker() has been called.
use TickerParser;
// Build a reusable parser (default spec)
let parser = builder.build.expect;
parser.parse.expect;
// Build a reusable parser (custom spec path)
let parser = builder
.spec_path
.build
.expect;
// One-shot parse — full ticker
let parsed = builder
.ticker
.parse
.expect;
// One-shot parse — root symbol with date
let parsed = builder
.ticker
.reference_date
.parse
.expect;
// One-shot parse — custom spec + date
let parsed = builder
.spec_path
.ticker
.reference_date
.parse
.expect;
Contract-centric (tick, session, trading symbol)
load_spec / get_contract yield a ContractSpec with tick size, merged session windows, timezone, and trading-symbol helpers. Default helpers call load_spec() internally; use the *_with_spec variants to reuse an already-loaded SpecRepository:
use load_spec;
let spec = load_spec?;
let dol = spec.get_contract?;
dol.tick_size;
dol.regular_session_start_end;
dol.exchange_timezone;
// `dol.sessions` is `Vec<SessionSegment>` in YAML map key order; map keys become `name`.
// Bundled default spec (no extra `&SpecRepository` argument)
dol.trading_symbol_today?;
dol.trading_symbol_for?;
// Reuse `spec` (e.g. from `load_spec_from_path`)
dol.trading_symbol_today_with_spec?;
dol.trading_symbol_for_with_spec?;
Options (B3)
use OptionGenerator;
let gen = bundled.expect;
let t = gen
.generate_equity
.expect;
assert_eq!;
What is supported
- YAML spec loading (exchanges, contract cycles, expiration rules, futures
contracts/**/*.yaml) - B3-focused futures generation and parsing (same public surface as Python)
- B3 options from
spec/contracts/b3/options.yaml(equity month codes, IBOV month letters A–L, DOL/IDI futures-style month codes) - Unit tests + CSV examples from
spec/tests/(subset wherebdaysmatches golden expectations)
Run tests
Pre-commit (same idea as tickerforge-py):
Spec updates
Copy or sync from tickerforge-spec:
Implementation notes
See docs/ for calendar strategy, options mapping, and CI/tooling.