qamd-rs
A market data protocol library for the QUANTAXIS project. This library provides standardized structures for interacting with market data sources, with support for snapshots, ticks, daily bars, minute bars, and order book information.
Features
- Standardized representation of market data snapshots with
MDSnapshot - Support for both level 1 (top of book) and level 2 (order book depth) market data
- Simple tick data representation with the
Tickstructure - Unified daily bar structure (
DailyBar) for stocks, futures, indices, and ETFs - Unified minute bar structure (
MinuteBar) with support for stocks, futures, and indices - Serialization and deserialization support via Serde
- Support for optional fields with special handling for market data "no data" values
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0"
Usage Examples
Working with Market Data Snapshots
use MDSnapshot;
use Utc;
// Create a market data snapshot
let snapshot = MDSnapshot ;
// Check order book depth
if snapshot.has_level2_depth
// Calculate the bid-ask spread
let spread = snapshot.bid_ask_spread;
println!;
// Serialize to JSON
let json = to_string_pretty.unwrap;
println!;
Working with Tick Data
use Tick;
use Utc;
// Create a new tick directly
let tick = Tick ;
// Or extract a tick from a market data snapshot
let tick_from_snapshot = from_snapshot;
Working with Daily Market Data
The library provides a unified DailyBar type with factory methods for different instrument types:
use ;
use NaiveDate;
let date = from_ymd_opt.unwrap;
// Create a stock daily bar
let stock = new_stock;
// Create a futures daily bar
let future = new_future;
// Access common data via trait interface
println!;
// Access instrument-specific data via methods
if let Some = future.open_interest
// Check instrument type
if stock.is_stock
// Handle different instruments with a common interface
let instruments: = vec!;
for instr in &instruments
Working with Minute Market Data
The library provides a unified MinuteBar type with factory methods for different instrument types:
use ;
use ;
// Create a stock minute bar
let stock_time = Utc.with_ymd_and_hms.unwrap;
let stock = new_stock;
// Create a futures minute bar with a trading date (useful for night sessions)
let future_time = Utc.with_ymd_and_hms.unwrap;
let trading_date = from_ymd_opt.unwrap;
let future = new_future;
// Access common data via trait interface
println!;
// Access instrument-specific data
println!;
println!;
// Calculate analytics on bars
println!;
println!;
// Handle different instruments with a common interface
let bars: = vec!;
for bar in &bars
License
This project is licensed under the MIT License - see the LICENSE file for details.