|
1 | | -extern crate reqwest; |
| 1 | +extern crate serde; |
| 2 | +extern crate serde_json; |
2 | 3 |
|
3 | 4 | use std::collections::HashMap; |
4 | 5 |
|
5 | | -use core::*; |
| 6 | +use trade_api::TradeApi; |
| 7 | +use core::AccessKey; |
6 | 8 |
|
7 | 9 | builder!(ActiveOrdersBuilder => ActiveOrders { |
8 | 10 | access_key: AccessKey = AccessKey::new("", ""), |
9 | 11 | currency_pair: Option<String> = None |
10 | 12 | }); |
11 | 13 |
|
12 | 14 | impl ActiveOrders { |
13 | | - pub fn exec(&self) -> reqwest::Result<String> { |
14 | | - let param: &mut HashMap<String, String> = &mut HashMap::new(); |
15 | | - param.insert("method".to_string(), "active_orders".to_string()); |
| 15 | + pub fn exec(&self) -> serde_json::Result<HashMap<u64, ActiveOrdersResponse>> { |
| 16 | + serde_json::from_value(<Self as TradeApi>::exec(&self)?) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +impl TradeApi for ActiveOrders { |
| 21 | + fn method(&self) -> &str { |
| 22 | + "active_orders" |
| 23 | + } |
| 24 | + fn parameters(&self) -> HashMap<String, String> { |
| 25 | + let mut param = HashMap::new(); |
16 | 26 | if let Some(ref currency_pair) = self.currency_pair { |
17 | 27 | param.insert( |
18 | 28 | "currency_pair".to_string(), |
19 | 29 | format!("{}", currency_pair.clone()), |
20 | 30 | ); |
21 | 31 | } |
22 | | - |
23 | | - let api = ApiBuilder::new() |
24 | | - .access_key(self.access_key.clone()) |
25 | | - .uri("https://api.zaif.jp/tapi") |
26 | | - .method(Method::Post) |
27 | | - .param(param.clone()) |
28 | | - .finalize(); |
29 | | - |
30 | | - api.exec() |
| 32 | + param |
| 33 | + } |
| 34 | + fn access_key(&self) -> &AccessKey { |
| 35 | + &self.access_key |
31 | 36 | } |
32 | 37 | } |
33 | 38 |
|
| 39 | +#[derive(Deserialize)] |
| 40 | +pub struct ActiveOrdersResponse { |
| 41 | + pub currency_pair: String, |
| 42 | + pub action: String, |
| 43 | + pub amount: f64, |
| 44 | + pub price: f64, |
| 45 | + pub timestamp: String, |
| 46 | + pub comment: String, |
| 47 | +} |
0 commit comments