-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from yajamon/response_struct_for_trade
Response struct for trade Fix #19
- Loading branch information
Showing
6 changed files
with
174 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
extern crate reqwest; | ||
extern crate serde; | ||
extern crate serde_json; | ||
|
||
use std::collections::HashMap; | ||
|
||
use core::*; | ||
use trade_api::TradeApi; | ||
use core::AccessKey; | ||
|
||
builder!(ActiveOrdersBuilder => ActiveOrders { | ||
access_key: AccessKey = AccessKey::new("", ""), | ||
currency_pair: Option<String> = None | ||
}); | ||
|
||
impl ActiveOrders { | ||
pub fn exec(&self) -> reqwest::Result<String> { | ||
let param: &mut HashMap<String, String> = &mut HashMap::new(); | ||
param.insert("method".to_string(), "active_orders".to_string()); | ||
pub fn exec(&self) -> serde_json::Result<HashMap<u64, ActiveOrdersResponse>> { | ||
serde_json::from_value(<Self as TradeApi>::exec(&self)?) | ||
} | ||
} | ||
|
||
impl TradeApi for ActiveOrders { | ||
fn method(&self) -> &str { | ||
"active_orders" | ||
} | ||
fn parameters(&self) -> HashMap<String, String> { | ||
let mut param = HashMap::new(); | ||
if let Some(ref currency_pair) = self.currency_pair { | ||
param.insert( | ||
"currency_pair".to_string(), | ||
format!("{}", currency_pair.clone()), | ||
); | ||
} | ||
|
||
let api = ApiBuilder::new() | ||
.access_key(self.access_key.clone()) | ||
.uri("https://api.zaif.jp/tapi") | ||
.method(Method::Post) | ||
.param(param.clone()) | ||
.finalize(); | ||
|
||
api.exec() | ||
param | ||
} | ||
fn access_key(&self) -> &AccessKey { | ||
&self.access_key | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct ActiveOrdersResponse { | ||
pub currency_pair: String, | ||
pub action: String, | ||
pub amount: f64, | ||
pub price: f64, | ||
pub timestamp: String, | ||
pub comment: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
extern crate reqwest; | ||
extern crate serde; | ||
extern crate serde_json; | ||
|
||
use std::collections::HashMap; | ||
|
||
use core::*; | ||
use trade_api::TradeApi; | ||
use core::AccessKey; | ||
|
||
builder!(GetInfo2Builder => GetInfo2 { | ||
access_key: AccessKey = AccessKey::new("", "") | ||
}); | ||
|
||
impl GetInfo2 { | ||
pub fn new(access_key: AccessKey) -> GetInfo2 { | ||
GetInfo2 { access_key: access_key } | ||
pub fn exec(&self) -> serde_json::Result<GetInfo2Response> { | ||
serde_json::from_value(<Self as TradeApi>::exec(&self)?) | ||
} | ||
pub fn exec(&self) -> reqwest::Result<String> { | ||
let param: &mut HashMap<String, String> = &mut HashMap::new(); | ||
param.insert("method".to_string(), "get_info2".to_string()); | ||
|
||
let api = ApiBuilder::new() | ||
.access_key(self.access_key.clone()) | ||
.uri("https://api.zaif.jp/tapi") | ||
.method(Method::Post) | ||
.param(param.clone()) | ||
.finalize(); | ||
} | ||
|
||
api.exec() | ||
impl TradeApi for GetInfo2 { | ||
fn method(&self) -> &str { | ||
"get_info2" | ||
} | ||
fn parameters(&self) -> HashMap<String, String> { | ||
HashMap::new() | ||
} | ||
fn access_key(&self) -> &AccessKey { | ||
&self.access_key | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct GetInfo2Response { | ||
pub funds: HashMap<String, f64>, | ||
pub deposit: HashMap<String, f64>, | ||
pub rights: HashMap<String, i64>, | ||
pub open_orders: i64, | ||
pub server_time: i64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters