Skip to content

Commit d031ea0

Browse files
committed
Fix format
1 parent dc6a1a4 commit d031ea0

File tree

10 files changed

+43
-55
lines changed

10 files changed

+43
-55
lines changed

src/core/api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl Api {
5353

5454
assert!(res.status().is_success());
5555
let response_body = res.text().unwrap();
56-
let v:Value = serde_json::from_str(response_body.as_str()).unwrap();
56+
let v: Value = serde_json::from_str(response_body.as_str()).unwrap();
5757
if v["success"].as_i64().unwrap() == 0 {
5858
let msg = v["error"].as_str().unwrap();
5959
panic!(msg.to_string());
@@ -69,9 +69,9 @@ impl Api {
6969
param.insert("nonce".to_string(), nonce);
7070

7171
let body = &mut String::new();
72-
let param_strs = param
73-
.iter()
74-
.map(|(key, val)| format!("{}={}", key.as_str(), val.as_str()));
72+
let param_strs = param.iter().map(|(key, val)| {
73+
format!("{}={}", key.as_str(), val.as_str())
74+
});
7575
for val in param_strs {
7676
if body.len() != 0 {
7777
body.push('&');

src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() {
3434
match api.exec() {
3535
Ok(res) => {
3636
println!("{}", res);
37-
let json:Value = serde_json::from_str(res.as_str()).unwrap();
37+
let json: Value = serde_json::from_str(res.as_str()).unwrap();
3838
let order_id = json["return"]["order_id"].as_u64().unwrap();
3939
let api = CancelOrderBuilder::new(access_key.clone())
4040
.order_id(order_id)
@@ -43,10 +43,12 @@ fn main() {
4343
let wait_time = time::Duration::from_secs(5);
4444
thread::sleep(wait_time);
4545
println!("{}", api.exec().unwrap());
46-
},
46+
}
4747
_ => return,
4848
}
4949

50-
let api = ActiveOrdersBuilder::new(access_key.clone()).currency_pair("zaif_jpy").finalize();
50+
let api = ActiveOrdersBuilder::new(access_key.clone())
51+
.currency_pair("zaif_jpy")
52+
.finalize();
5153
println!("{}", api.exec().unwrap());
5254
}

src/public_api/currencies.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ pub struct Currencies {
99
impl Currencies {
1010
pub fn exec(&self) -> reqwest::Result<String> {
1111
let api = ApiBuilder::new()
12-
.uri(format!("https://api.zaif.jp/api/1/currencies/{}", self.name).as_str())
12+
.uri(
13+
format!("https://api.zaif.jp/api/1/currencies/{}", self.name).as_str(),
14+
)
1315
.finalize();
1416

1517
api.exec()
@@ -22,17 +24,13 @@ pub struct CurrenciesBuilder {
2224

2325
impl CurrenciesBuilder {
2426
pub fn new() -> CurrenciesBuilder {
25-
CurrenciesBuilder {
26-
name: "all".to_string(),
27-
}
27+
CurrenciesBuilder { name: "all".to_string() }
2828
}
2929
pub fn name(&mut self, name: &str) -> &mut CurrenciesBuilder {
3030
self.name = name.to_string();
3131
self
3232
}
3333
pub fn finalize(&self) -> Currencies {
34-
Currencies {
35-
name: self.name.clone(),
36-
}
34+
Currencies { name: self.name.clone() }
3735
}
3836
}

src/public_api/currency_pairs.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ pub struct CurrencyPairs {
99
impl CurrencyPairs {
1010
pub fn exec(&self) -> reqwest::Result<String> {
1111
let api = ApiBuilder::new()
12-
.uri(format!("https://api.zaif.jp/api/1/currency_pairs/{}", self.currency_pair).as_str())
12+
.uri(
13+
format!(
14+
"https://api.zaif.jp/api/1/currency_pairs/{}",
15+
self.currency_pair
16+
).as_str(),
17+
)
1318
.finalize();
1419

1520
api.exec()
@@ -22,17 +27,13 @@ pub struct CurrencyPairsBuilder {
2227

2328
impl CurrencyPairsBuilder {
2429
pub fn new() -> CurrencyPairsBuilder {
25-
CurrencyPairsBuilder {
26-
currency_pair: "all".to_string(),
27-
}
30+
CurrencyPairsBuilder { currency_pair: "all".to_string() }
2831
}
2932
pub fn currency_pair(&mut self, currency_pair: &str) -> &mut CurrencyPairsBuilder {
3033
self.currency_pair = currency_pair.to_string();
3134
self
3235
}
3336
pub fn finalize(&self) -> CurrencyPairs {
34-
CurrencyPairs {
35-
currency_pair: self.currency_pair.clone(),
36-
}
37+
CurrencyPairs { currency_pair: self.currency_pair.clone() }
3738
}
3839
}

src/public_api/depth.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ impl Depth {
1010
pub fn exec(&self) -> reqwest::Result<String> {
1111
let api = ApiBuilder::new()
1212
.uri(
13-
format!(
14-
"https://api.zaif.jp/api/1/depth/{}",
15-
self.currency_pair
16-
).as_str(),
13+
format!("https://api.zaif.jp/api/1/depth/{}", self.currency_pair).as_str(),
1714
)
1815
.finalize();
1916

@@ -27,17 +24,13 @@ pub struct DepthBuilder {
2724

2825
impl DepthBuilder {
2926
pub fn new() -> DepthBuilder {
30-
DepthBuilder {
31-
currency_pair: "btc_jpy".to_string(),
32-
}
27+
DepthBuilder { currency_pair: "btc_jpy".to_string() }
3328
}
3429
pub fn currency_pair(&mut self, currency_pair: &str) -> &mut DepthBuilder {
3530
self.currency_pair = currency_pair.to_string();
3631
self
3732
}
3833
pub fn finalize(&self) -> Depth {
39-
Depth {
40-
currency_pair: self.currency_pair.clone(),
41-
}
34+
Depth { currency_pair: self.currency_pair.clone() }
4235
}
4336
}

src/public_api/last_price.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@ pub struct LastPriceBuilder {
2727

2828
impl LastPriceBuilder {
2929
pub fn new() -> LastPriceBuilder {
30-
LastPriceBuilder {
31-
currency_pair: "btc_jpy".to_string(),
32-
}
30+
LastPriceBuilder { currency_pair: "btc_jpy".to_string() }
3331
}
3432
pub fn currency_pair(&mut self, currency_pair: &str) -> &mut LastPriceBuilder {
3533
self.currency_pair = currency_pair.to_string();
3634
self
3735
}
3836
pub fn finalize(&self) -> LastPrice {
39-
LastPrice {
40-
currency_pair: self.currency_pair.clone(),
41-
}
37+
LastPrice { currency_pair: self.currency_pair.clone() }
4238
}
4339
}

src/trade_api/active_orders.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ impl ActiveOrders {
1414
let param: &mut HashMap<String, String> = &mut HashMap::new();
1515
param.insert("method".to_string(), "active_orders".to_string());
1616
if let Some(ref currency_pair) = self.currency_pair {
17-
param.insert("currency_pair".to_string(), format!("{}", currency_pair.clone()));
17+
param.insert(
18+
"currency_pair".to_string(),
19+
format!("{}", currency_pair.clone()),
20+
);
1821
}
1922

2023
let api = ApiBuilder::new()
@@ -33,7 +36,7 @@ pub struct ActiveOrdersBuilder {
3336
currency_pair: Option<String>,
3437
}
3538

36-
impl ActiveOrdersBuilder{
39+
impl ActiveOrdersBuilder {
3740
pub fn new(access_key: AccessKey) -> ActiveOrdersBuilder {
3841
ActiveOrdersBuilder {
3942
access_key: access_key,

src/trade_api/cancel_order.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ impl CancelOrder {
1616
param.insert("method".to_string(), "cancel_order".to_string());
1717
param.insert("order_id".to_string(), format!("{}", self.order_id));
1818
if let Some(ref currency_pair) = self.currency_pair {
19-
param.insert("currency_pair".to_string(), format!("{}", currency_pair.clone()));
19+
param.insert(
20+
"currency_pair".to_string(),
21+
format!("{}", currency_pair.clone()),
22+
);
2023
}
2124

2225
let api = ApiBuilder::new()
@@ -36,7 +39,7 @@ pub struct CancelOrderBuilder {
3639
currency_pair: Option<String>,
3740
}
3841

39-
impl CancelOrderBuilder{
42+
impl CancelOrderBuilder {
4043
pub fn new(access_key: AccessKey) -> CancelOrderBuilder {
4144
CancelOrderBuilder {
4245
access_key: access_key,

src/trade_api/get_info2.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ pub struct GetInfo2 {
1010

1111
impl GetInfo2 {
1212
pub fn new(access_key: AccessKey) -> GetInfo2 {
13-
GetInfo2 {
14-
access_key: access_key,
15-
}
13+
GetInfo2 { access_key: access_key }
1614
}
1715
pub fn exec(&self) -> reqwest::Result<String> {
1816
let param: &mut HashMap<String, String> = &mut HashMap::new();
@@ -33,15 +31,11 @@ pub struct GetInfo2Builder {
3331
access_key: AccessKey,
3432
}
3533

36-
impl GetInfo2Builder{
34+
impl GetInfo2Builder {
3735
pub fn new(access_key: AccessKey) -> GetInfo2Builder {
38-
GetInfo2Builder {
39-
access_key: access_key,
40-
}
36+
GetInfo2Builder { access_key: access_key }
4137
}
4238
pub fn finalize(&self) -> GetInfo2 {
43-
GetInfo2 {
44-
access_key: self.access_key.clone(),
45-
}
39+
GetInfo2 { access_key: self.access_key.clone() }
4640
}
4741
}

src/trade_api/trade.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ pub enum TradeAction {
1010
Ask, // 売り
1111
}
1212
impl TradeAction {
13-
fn param_string
14-
(&self) -> String {
13+
fn param_string(&self) -> String {
1514
match *self {
1615
TradeAction::Bid => "bid".to_string(),
1716
TradeAction::Ask => "ask".to_string(),
@@ -65,7 +64,7 @@ pub struct TradeBuilder {
6564
comment: Option<String>,
6665
}
6766

68-
impl TradeBuilder{
67+
impl TradeBuilder {
6968
pub fn new(access_key: AccessKey) -> TradeBuilder {
7069
TradeBuilder {
7170
access_key: access_key,
@@ -113,4 +112,3 @@ impl TradeBuilder{
113112
}
114113
}
115114
}
116-

0 commit comments

Comments
 (0)