Skip to main content

rustyschwab_types/
lib.rs

1//! # Schwab Types
2//!
3//! Type definitions for the Charles Schwab Trading and Market Data APIs.
4//!
5//! This crate provides strongly-typed Rust structures for all API request and response
6//! types used by the Schwab APIs. These types are designed to:
7//!
8//! - Provide type safety for API interactions
9//! - Support serialization/deserialization via serde
10//! - Match the official Schwab API documentation
11//!
12//! ## Modules
13//!
14//! - [`market_data`] - Quotes, price history, and market data types
15//! - [`streaming`] - Real-time streaming WebSocket message types
16//! - [`accounts`] - Account information and positions
17//! - [`trading`] - Order types, transactions, and trading operations
18//! - [`common`] - Shared enums and utility types
19//!
20//! ## Example
21//!
22//! Outbound orders use the strict [`trading::OrderRequest`] shape: unknown
23//! fields are rejected and prices/quantities are exact decimals. Build one
24//! with the constructors or deserialize the JSON Schwab documents.
25//!
26//! ```
27//! use rustyschwab_types::Decimal;
28//! use rustyschwab_types::trading::{OrderInstruction, OrderRequest, OrderRequestLeg, OrderType};
29//!
30//! let order = OrderRequest::limit(
31//!     OrderRequestLeg::equity(OrderInstruction::Buy, "AAPL", 10),
32//!     Decimal::new(15025, 2),
33//! );
34//! assert_eq!(order.order_type, Some(OrderType::Limit));
35//! order.validate().unwrap();
36//!
37//! let same: OrderRequest = serde_json::from_value(serde_json::json!({
38//!     "orderStrategyType": "SINGLE",
39//!     "orderType": "LIMIT",
40//!     "session": "NORMAL",
41//!     "duration": "DAY",
42//!     "price": "150.25",
43//!     "orderLegCollection": [{
44//!         "instruction": "BUY",
45//!         "quantity": 10,
46//!         "instrument": { "symbol": "AAPL", "assetType": "EQUITY" }
47//!     }]
48//! }))
49//! .unwrap();
50//! assert_eq!(serde_json::to_value(&same).unwrap(), serde_json::to_value(&order).unwrap());
51//! ```
52
53#![cfg_attr(docsrs, feature(doc_cfg))]
54
55/// Market data types including quotes, price history, and market hours.
56pub mod market_data;
57
58/// Real-time streaming WebSocket message types and subscription management.
59pub mod streaming;
60
61/// Account information, positions, and balances.
62pub mod accounts;
63
64/// Trading types including orders, transactions, and execution reports.
65pub mod trading;
66
67/// Common types shared across multiple modules.
68pub mod common;
69
70/// Typed errors from request validation.
71pub mod validation;
72pub use validation::{ValidationError, ValidationErrorKind};
73
74/// The exact-decimal type prices and quantities use, so callers do not need
75/// their own `rust_decimal` dependency to build orders.
76pub use rust_decimal::Decimal;