1#[macro_use]
4extern crate serde_derive;
5extern crate async_trait;
6extern crate serde;
7
8extern crate cxmr_currency;
9extern crate cxmr_exchanges;
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14
15use cxmr_currency::CurrencyPair;
16use cxmr_exchanges::{
17 AccountInfo, Exchange, ExchangeInfo, ExchangeOrder, MarketOrder, OrderExecution,
18};
19
20#[derive(Deserialize, Serialize, Clone)]
22pub struct Account {
23 pub name: String,
25 pub enabled: bool,
27 pub exchange: Exchange,
29 pub credentials: Credentials,
31}
32
33impl Account {
34 pub fn new(key: String, secret: String, exchange: Exchange) -> Self {
35 let mut name = key.clone();
36 name.truncate(3);
37 Account {
38 name: name,
39 enabled: false,
40 exchange: exchange,
41 credentials: Credentials::new(key, secret),
42 }
43 }
44}
45
46#[derive(Deserialize, Serialize, Clone, Default)]
48pub struct Credentials {
49 pub key: String,
50 pub secret: String,
51}
52
53impl Credentials {
54 pub fn new(key: String, secret: String) -> Self {
55 Credentials {
56 key: key,
57 secret: secret,
58 }
59 }
60}
61
62#[async_trait]
64pub trait PrivateClient: Send + Sync {
65 type Error;
66
67 fn account(&self) -> &Account;
68
69 fn exchange(&self) -> &'static Exchange;
71
72 async fn account_info(&self) -> Result<AccountInfo, Self::Error>;
74
75 async fn open_orders(&self, pair: CurrencyPair) -> Result<Vec<MarketOrder>, Self::Error>;
77
78 async fn create_order(&self, order: &ExchangeOrder) -> Result<OrderExecution, Self::Error>;
80
81 async fn user_data_stream(&self, key: Option<String>) -> Result<String, Self::Error>;
83}
84
85#[async_trait]
87pub trait PublicClient: Send + Sync {
88 type Error;
89
90 fn exchange(&self) -> &'static Exchange;
92
93 async fn exchange_info(&self) -> Result<ExchangeInfo, Self::Error>;
95}
96
97pub type SharedPublicClient<E> = Arc<dyn PublicClient<Error = E>>;
99
100pub type SharedPrivateClient<E> = Arc<dyn PrivateClient<Error = E>>;