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
70
71
72
73
74
75
76
77
//! Write-side trading operations for exchange adapters.
use Error;
use crate;
/// Write-only trading surface for submitting, replacing, and canceling orders.
///
/// # Examples
///
/// ```rust,no_run
/// use tradingkit::exchange::alpaca::{Alpaca, AlpacaCredentials};
/// use tradingkit::model::{
/// AssetClass, OrderClass, OrderRequest, OrderSide, OrderType, PositionIntent,
/// ReplaceOrderRequest, 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::Limit,
/// time_in_force: TimeInForce::Day,
/// order_class: Some(OrderClass::Simple),
/// limit_price: Some("200".to_string()),
/// 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 _submitted = api.submit(&request).await?;
///
/// let replace = ReplaceOrderRequest {
/// qty: Some("2".to_string()),
/// time_in_force: Some(TimeInForce::Gtc),
/// limit_price: Some("201".to_string()),
/// stop_price: None,
/// trail: None,
/// client_order_id: Some("example-order-replaced".to_string()),
/// };
///
/// let _replaced = api.replace("order-id", &replace).await?;
/// api.cancel("order-id").await?;
/// Ok(())
/// }
/// ```