1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Trading primitives and exchange adapters for algorithmic trading workflows.
//!
//! # Project Layers
//!
//! - `model` holds exchange-agnostic trading domain types such as orders, option legs, and
//! account snapshots.
//! - `data` separates direct reads from cache-backed reads through `Source`, `Store`, and
//! `Repository` abstractions.
//! - `exchange` defines the common trading traits and exposes concrete exchange adapters.
//! - `exchange::alpaca` is the current REST trading implementation, including equity, single-leg
//! options, and multi-leg options support.
//! - `exchange::okx` currently covers credential/signature behavior and is the next extension
//! point for shared trading operations.
//! - `strategy/` contains executable crates that consume the shared library.
//!
//! # Examples
//!
//! ```rust,no_run
//! use tradingkit::exchange::alpaca::{Alpaca, AlpacaCredentials};
//! use tradingkit::model::{
//! AssetClass, OrderClass, OrderRequest, OrderSide, OrderType, PositionIntent, TimeInForce,
//! };
//! use tradingkit::trading::TradingApi;
//!
//! async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let api = Alpaca::paper(AlpacaCredentials::new(
//! "your-key".to_string(),
//! "your-secret".to_string(),
//! ));
//!
//! let request = OrderRequest {
//! symbol: Some("AAPL240119C00190000".to_string()),
//! asset_class: Some(AssetClass::UsOption),
//! qty: Some("1".to_string()),
//! notional: None,
//! side: Some(OrderSide::Buy),
//! order_type: OrderType::Market,
//! time_in_force: TimeInForce::Day,
//! order_class: Some(OrderClass::Simple),
//! limit_price: None,
//! stop_price: None,
//! trail_price: None,
//! trail_percent: None,
//! client_order_id: Some("example-order".to_string()),
//! extended_hours: Some(false),
//! position_intent: Some(PositionIntent::BuyToOpen),
//! legs: None,
//! };
//!
//! let _order = api.submit(&request).await?;
//! Ok(())
//! }
//! ```
//!
//! The same client can be created from environment variables instead of inline secrets:
//!
//! ```rust,no_run
//! use tradingkit::exchange::alpaca::{Alpaca, AlpacaCredentials};
//!
//! let _alpaca = Alpaca::paper(AlpacaCredentials::env()?);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```