Skip to content

Commit d692502

Browse files
author
Stephan Dilly
committed
a few more api endpoints
1 parent 5b476f9 commit d692502

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

rest-api/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Support as many flavours and special cases out there in different Rest APIs with
1515
## todo
1616

1717
- [x] proof of concept
18+
- [ ] string results
1819
- [ ] define base url in attribute
1920
- [ ] support url parameters
21+
- [ ] support query parameters
2022
- [ ] support post using json
2123
- [ ] allow serializable types in api

rest-api/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,14 @@ mod tests {
147147

148148
assert_eq!(get_endpoint_attr(a), None);
149149
}
150+
#[test]
151+
fn test_endpoint_some() {
152+
let a: syn::TraitItemMethod = syn::parse2(quote! {
153+
#[endpoint("foo")]
154+
fn foo() {}
155+
})
156+
.unwrap();
157+
158+
assert_eq!(get_endpoint_attr(a), Some("foo".to_owned()));
159+
}
150160
}

src/main.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ use std::env;
44
//TODO: #[api_root("base_url")]
55
#[api]
66
trait AlpacaApi {
7+
/// see https://docs.alpaca.markets/api-documentation/api-v2/account/
78
#[endpoint("account")]
89
fn get_account(&self) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
9-
fn account(&self) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
10+
11+
/// see https://docs.alpaca.markets/api-documentation/api-v2/account-activities/
12+
#[endpoint("account/activities/FILL")]
13+
fn account_activities(
14+
&self, //activity_type: String,
15+
) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
16+
17+
/// see https://docs.alpaca.markets/api-documentation/api-v2/clock/
18+
fn clock(&self) -> Result<serde_json::Value, Box<dyn std::error::Error>>;
1019
}
1120

1221
fn main() {
@@ -30,5 +39,11 @@ fn main() {
3039

3140
println!("{:#?}", acc);
3241

33-
assert_eq!(acc, api.account().unwrap());
42+
let act = api.account_activities().unwrap();
43+
44+
println!("{:#?}", act);
45+
46+
let clc = api.clock().unwrap();
47+
48+
println!("{:#?}", clc);
3449
}

0 commit comments

Comments
 (0)