tickerforge (Rust)
Rust library that loads the default tickerforge-spec YAML tree from the tickerforge-spec-data crate on crates.io (same content as the PyPI tickerforge-spec-data wheel) and generates or parses futures, options, and cash equities tickers from all supported markets (parity with tickerforge-py). Option and equity rules are loaded automatically from all spec/contracts/**/*.yaml and spec/equities/**/*.yaml files.
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 crates.io:
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 — futures, options, and equities (parse_any_ticker*)
parse_any_ticker* parses futures, options, and cash equities in a single call and returns an AnyParsedTicker enum.
use ;
// Cash equity
match parse_any_ticker.unwrap
// Futures ticker
match parse_any_ticker.unwrap
// B3 equity option (PETR4, January call, strike 30)
match parse_any_ticker.unwrap
// CME futures
match parse_any_ticker.unwrap
// B3 index option
match parse_any_ticker.unwrap
// Exchange filter (returns Err if ticker doesn't match that exchange)
let any = parse_any_ticker_exchange.unwrap;
Five free functions cover every combination:
| Function | Spec | Date | Exchange |
|---|---|---|---|
parse_any_ticker(ticker) |
bundled | today | — |
parse_any_ticker_date(ticker, date) |
bundled | explicit | — |
parse_any_ticker_spec(ticker, spec) |
custom | today | — |
parse_any_ticker_date_spec(ticker, date, spec) |
custom | explicit | — |
parse_any_ticker_exchange(ticker, exchange) |
bundled | today | explicit |
Parsing tickers — futures only (legacy API)
The parse_ticker* free functions remain available and return ParsedFuturesTicker directly:
use ;
let parsed = parse_ticker.expect;
let parsed = parse_ticker_date.expect;
let spec = load_spec.expect;
let parsed = parse_ticker_spec.expect;
let parsed = parse_ticker_date_spec.expect;
TickerParser — stateful parsing (futures + options)
TickerParser wraps a loaded spec for repeated calls. Methods now return AnyParsedTicker.
use ;
let parser = new;
// Parse any ticker (futures or option)
let any = parser.parse.expect;
let any = parser.parse_exchange.expect;
let any = 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 ;
// Build a reusable parser (default spec)
let parser = builder.build.expect;
parser.parse.expect;
// One-shot parse — full futures ticker
let any = builder
.ticker
.parse
.expect;
// One-shot parse — option with exchange filter
let any = builder
.ticker
.exchange
.parse
.expect;
// One-shot parse — root symbol with date
let any = builder
.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 — parsing
use ;
// B3 equity option
match parse_any_ticker.unwrap
// DOL option vs future — no ambiguity
assert!;
assert!;
Options — generation (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, options, and equities from the spec tree)
- Multi-market futures generation and parsing: B3 (IND, DOL, WIN, …) and CME (ES, NQ, …)
- Multi-market options parsing via
parse_any_ticker*andOptionParser: B3 equity, index (IBOV), dollar (DOL), interest-rate (IDI); more markets added automatically from spec - B3 options generation via
OptionGenerator(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): format, clippy, then llvm-cov with a 80% line coverage minimum. Install the subcommand first: cargo install cargo-llvm-cov (or cargo binstall cargo-llvm-cov). Full detail: docs/coverage-and-quality-gates.md.
To skip only the coverage hook: SKIP=cargo-llvm-cov git commit ...
Spec updates
Copy or sync from tickerforge-spec:
Implementation notes
See docs/ for calendar strategy, options mapping, and CI/tooling.