-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgdax.rs
152 lines (141 loc) · 5.46 KB
/
gdax.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#[cfg(test)]
mod gdax_tests {
extern crate coinnect;
extern crate bigdecimal;
use self::bigdecimal::BigDecimal;
use std::str::FromStr;
use self::coinnect::gdax::utils;
use self::coinnect::gdax::{GdaxApi, GdaxCreds};
use self::coinnect::bitstamp::BitstampCreds;
use self::coinnect::exchange::ExchangeApi;
use self::coinnect::types::Pair;
#[test]
fn build_url_should_return_the_a_url() {
assert_eq!(utils::build_url("ticker", "btc-usd"),
"https://api.gdax.com/products/btc-usd/ticker");
}
#[test]
fn build_url_should_return_the_url_for_transactions_for_btc_usd() {
assert_eq!(utils::build_url("transactions", "btc-usd"),
"https://api.gdax.com/accounts/btc-usd/ledger");
}
#[test]
fn fail_with_invalid_creds() {
let creds = BitstampCreds::new("", "", "", "");
let res = GdaxApi::new(creds);
assert_eq!(res.unwrap_err().to_string(),
"Invalid config: \nExpected: Gdax\nFind: Bitstamp");
}
#[test]
fn can_get_real_gdax_tick() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
api.ticker(Pair::BTC_USD).unwrap();
}
#[test]
fn ticker_should_have_the_correct_last() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
let result = api.ticker(Pair::BTC_USD);
assert_ne!(result.unwrap().last_trade_price,
BigDecimal::from_str("0.0").unwrap());
}
#[test]
fn ticker_should_have_the_correct_high() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
let result = api.ticker(Pair::BTC_USD);
assert_ne!(result.unwrap().highest_bid,
BigDecimal::from_str("0.0").unwrap());
}
#[test]
fn ticker_should_have_the_correct_low() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
let result = api.ticker(Pair::BTC_USD);
assert_ne!(result.unwrap().lowest_ask,
BigDecimal::from_str("0.0").unwrap());
}
#[test]
fn ticker_should_have_the_correct_volume() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
let result = api.ticker(Pair::BTC_USD);
assert_ne!(result.unwrap().volume.unwrap(),
BigDecimal::from_str("0.0").unwrap());
}
#[test]
fn should_return_an_order_book() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
let result = api.return_order_book(Pair::BTC_USD);
assert_eq!(result.is_ok(), true);
}
#[test]
fn order_book_should_have_a_timestamp() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
let result = api.return_order_book(Pair::BTC_USD);
assert!(result.unwrap().contains_key("sequence"));
}
#[test]
fn order_book_should_have_asks_for_btcusd() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
assert!(api.return_order_book(Pair::BTC_USD)
.unwrap()
.contains_key("asks"));
}
#[test]
fn order_book_should_have_asks_for_btceur() {
let creds = GdaxCreds::new("", "", "", "");
let mut api = GdaxApi::new(creds).unwrap();
assert!(api.return_order_book(Pair::BTC_USD)
.unwrap()
.contains_key("asks"));
}
#[test]
fn should_create_a_fixed_nonce_when_requested() {
assert_eq!(utils::generate_nonce(Some("1".to_string())), "1");
}
#[test]
fn should_create_a_nonce_bigger_than_2017() {
assert!(utils::generate_nonce(None).parse::<i64>().unwrap() > 1483228800);
}
// #[test]
// fn should_create_a_correct_signature() {
// let nonce = "1483228800";
// let passphrase = "123456";
// let api_key = "1234567890ABCDEF1234567890ABCDEF";
// let api_secret = "1234567890ABCDEF1234567890ABCDEF";
// let expected_signature = "7D7C4168D49CBC2620A45EF00EAA228C1287561F1C1F94172272E1231A8ADF6B"
// .to_string();
// assert_eq!(utils::build_signature(nonce, passphrase, api_key, api_secret).unwrap(),
// expected_signature);
// }
//
// #[test]
// fn should_return_the_trade_history_for_btc_usd() {
// let creds = GdaxCreds::new("", "", "", "");
// let mut api = GdaxApi::new(creds).unwrap();
// let result = api.return_trade_history(Pair::BTC_USD);
//
// assert_eq!(result.is_ok(), false);
// }
//
// // IMPORTANT: Real keys are needed in order to retrieve the balance
// #[test]
//// #[cfg_attr(not(feature = "gdax_private_tests"), ignore)]
// fn balance_should_have_usd_and_btc_balance() {
// use std::path::PathBuf;
// let path = PathBuf::from("./keys_real.json");
// let creds = GdaxCreds::new_from_file("account_gdax", path).unwrap();
// let mut api = GdaxApi::new(creds).unwrap();
// let result = api.return_balances().unwrap();
// let result_looking_for_usd = result.clone();
// let result_looking_for_btc = result.clone();
//
// assert!(result_looking_for_usd.contains_key("usd_balance"));
// assert!(result_looking_for_btc.contains_key("btc_balance"));
// }
}