Off-Grid Primitives
off-grid-primitives is a Rust crate that defines the core data structures and logic for the Off-Grid exchange: spot market state (L1/L2/L3), order books, matching engine, and account balances across spot, futures, and options.
Overview
This library provides the primitives used to build Off-Grid trading infrastructure. All types are serializable (e.g. via serde) and suitable for use in runtimes, indexers, and off-chain services.
| Component | Path | Description |
|---|---|---|
| Spot | src/spot/ | Order book, market data (L1/L2/L3), pair state, matching engine, and events |
| Account | src/account/ | Balance interfaces for spot, futures, and option accounts |
| Asset | src/asset/ | Asset types and definitions for spot, futures, and option instruments |
Quick Start
Add to your Cargo.toml:
[]
= { = ".." } # or from git/crates.io
Spot:
use ;
Account:
use ;
Testing
From the repository root, run all tests:
Run tests by component:
# Account primitives
# Spot primitives (L1, L2, L3, orderbook, pair, matching engine)
# Spot sub-components
# Orders (cross-component)
Tests live under tests/ and mirror the crate layout: tests/account.rs, tests/spot/ (with l1.rs, l2.rs, l3.rs, orderbook/, pair/, matching_engine/), and tests/orders.rs.
Dependencies
serde,serde_bytes— Serializationthiserror— Error typesulid— Order idsblake3— Hashingonce_cell— Lazy/static initialization
Issue template
We use GitHub issue templates for bugs and feature requests:
- Bug report — For bugs or incorrect behavior.
- Feature request — For new features or enhancements.
Open an issue and choose the appropriate template.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for:
- How to report bugs and suggest features.
- How to submit pull requests.
- Development setup and project structure.
Changelog
Release history and notable changes are documented in CHANGELOG.md.
License
See LICENSE.