Expand description
§Schwab Types
Type definitions for the Charles Schwab Trading and Market Data APIs.
This crate provides strongly-typed Rust structures for all API request and response types used by the Schwab APIs. These types are designed to:
- Provide type safety for API interactions
- Support serialization/deserialization via serde
- Match the official Schwab API documentation
§Modules
market_data- Quotes, price history, and market data typesstreaming- Real-time streaming WebSocket message typesaccounts- Account information and positionstrading- Order types, transactions, and trading operationscommon- Shared enums and utility types
§Example
Outbound orders use the strict trading::OrderRequest shape: unknown
fields are rejected and prices/quantities are exact decimals. Build one
with the constructors or deserialize the JSON Schwab documents.
use rustyschwab_types::Decimal;
use rustyschwab_types::trading::{OrderInstruction, OrderRequest, OrderRequestLeg, OrderType};
let order = OrderRequest::limit(
OrderRequestLeg::equity(OrderInstruction::Buy, "AAPL", 10),
Decimal::new(15025, 2),
);
assert_eq!(order.order_type, Some(OrderType::Limit));
order.validate().unwrap();
let same: OrderRequest = serde_json::from_value(serde_json::json!({
"orderStrategyType": "SINGLE",
"orderType": "LIMIT",
"session": "NORMAL",
"duration": "DAY",
"price": "150.25",
"orderLegCollection": [{
"instruction": "BUY",
"quantity": 10,
"instrument": { "symbol": "AAPL", "assetType": "EQUITY" }
}]
}))
.unwrap();
assert_eq!(serde_json::to_value(&same).unwrap(), serde_json::to_value(&order).unwrap());Re-exports§
pub use validation::ValidationError;pub use validation::ValidationErrorKind;
Modules§
- accounts
- Account information, positions, and balances. Account types including balances, positions, and user preferences.
- common
- Common types shared across multiple modules. Common types shared across multiple API modules.
- market_
data - Market data types including quotes, price history, and market hours. Market data types for quotes, price history, options, and instruments.
- streaming
- Real-time streaming WebSocket message types and subscription management. Real-time streaming WebSocket types for the Schwab Streamer API.
- trading
- Trading types including orders, transactions, and execution reports. Trading types including orders, transactions, and execution reports.
- validation
- Typed errors from request validation.
Typed errors for request validation (
OrderRequest::validateand the query-parameter validators).
Structs§
- Decimal
- The exact-decimal type prices and quantities use, so callers do not need
their own
rust_decimaldependency to build orders.Decimalrepresents a 128 bit representation of a fixed-precision decimal number. The finite set of values of typeDecimalare of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.