#[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);
}
}