forked from d-e-s-o/apca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.rs
34 lines (29 loc) · 1.06 KB
/
order.rs
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
// Copyright (C) 2020-2022 The apca Developers
// SPDX-License-Identifier: GPL-3.0-or-later
use apca::api::v2::order;
use apca::ApiInfo;
use apca::Client;
use num_decimal::Num;
#[tokio::main]
async fn main() {
// Requires the following environment variables to be present:
// - APCA_API_KEY_ID -> your API key
// - APCA_API_SECRET_KEY -> your secret key
//
// Optionally, the following variable is honored:
// - APCA_API_BASE_URL -> the API base URL to use (set to
// https://api.alpaca.markets for live trading)
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);
// Create request for a limit order for AAPL with a limit price of USD
// 100.
let request = order::OrderReqInit {
type_: order::Type::Limit,
limit_price: Some(Num::from(100)),
..Default::default()
}
// We want to go long on AAPL, buying a single share.
.init("AAPL", order::Side::Buy, order::Amount::quantity(1));
let order = client.issue::<order::Post>(&request).await.unwrap();
println!("Created order {}", order.id.as_hyphenated());
}