Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/coinnect.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
//! Use this module to create a generic API.


#![allow(new_ret_no_self)]
#![allow(clippy::new_ret_no_self)]

use std::path::PathBuf;

use exchange::{Exchange, ExchangeApi};
use bitstamp::{BitstampApi, BitstampCreds};
use kraken::{KrakenApi, KrakenCreds};
use poloniex::{PoloniexApi, PoloniexCreds};
use bittrex::{BittrexApi, BittrexCreds};
use gdax::{GdaxApi, GdaxCreds};
use error::*;
use exchange::{Exchange, ExchangeApi};
use gdax::{GdaxApi, GdaxCreds};
use kraken::{KrakenApi, KrakenCreds};
use poloniex::{PoloniexApi, PoloniexCreds};

pub trait Credentials {
/// Get an element from the credentials.
Expand All @@ -27,7 +26,7 @@ pub struct Coinnect;

impl Coinnect {
/// Create a new CoinnectApi by providing an API key & API secret
pub fn new<C: Credentials>(exchange: Exchange, creds: C) -> Result<Box<ExchangeApi>> {
pub fn new<C: Credentials>(exchange: Exchange, creds: C) -> Result<Box<dyn ExchangeApi>> {
match exchange {
Exchange::Bitstamp => Ok(Box::new(BitstampApi::new(creds)?)),
Exchange::Kraken => Ok(Box::new(KrakenApi::new(creds)?)),
Expand All @@ -42,26 +41,27 @@ impl Coinnect {
///
/// For this example, you could use load your Bitstamp account with
/// `new_from_file(Exchange::Bitstamp, "account_bitstamp", Path::new("/keys.json"))`
pub fn new_from_file(exchange: Exchange,
name: &str,
path: PathBuf)
-> Result<Box<ExchangeApi>> {
pub fn new_from_file(
exchange: Exchange,
name: &str,
path: PathBuf,
) -> Result<Box<dyn ExchangeApi>> {
match exchange {
Exchange::Bitstamp => {
Ok(Box::new(BitstampApi::new(BitstampCreds::new_from_file(name, path)?)?))
}
Exchange::Kraken => {
Ok(Box::new(KrakenApi::new(KrakenCreds::new_from_file(name, path)?)?))
}
Exchange::Poloniex => {
Ok(Box::new(PoloniexApi::new(PoloniexCreds::new_from_file(name, path)?)?))
}
Exchange::Bittrex => {
Ok(Box::new(BittrexApi::new(BittrexCreds::new_from_file(name, path)?)?))
}
Exchange::Gdax => {
Ok(Box::new(GdaxApi::new(GdaxCreds::new_from_file(name, path)?)?))
}
Exchange::Bitstamp => Ok(Box::new(BitstampApi::new(BitstampCreds::new_from_file(
name, path,
)?)?)),
Exchange::Kraken => Ok(Box::new(KrakenApi::new(KrakenCreds::new_from_file(
name, path,
)?)?)),
Exchange::Poloniex => Ok(Box::new(PoloniexApi::new(PoloniexCreds::new_from_file(
name, path,
)?)?)),
Exchange::Bittrex => Ok(Box::new(BittrexApi::new(BittrexCreds::new_from_file(
name, path,
)?)?)),
Exchange::Gdax => Ok(Box::new(GdaxApi::new(GdaxCreds::new_from_file(
name, path,
)?)?)),
}
}
}
Loading