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
pub mod parse;
use async_trait::async_trait;
use cxmr_api_clients_errors::Error;
use cxmr_exchanges::{Exchange, ExchangeInfo};
use cxmr_http_client::{build_request, send_request, BufExt, HttpsClient, RequestParams};
use self::parse::deserialize_exchange_info;
pub static POLONIEX_HOST: &'static str = "poloniex.com";
#[derive(Clone)]
pub struct PublicClient {
client: HttpsClient,
}
impl PublicClient {
pub fn new(client: HttpsClient) -> Self {
PublicClient { client: client }
}
}
#[async_trait]
impl cxmr_api::PublicClient for PublicClient {
type Error = Error;
fn exchange(&self) -> &'static Exchange {
&Exchange::Poloniex
}
async fn exchange_info(&self) -> Result<ExchangeInfo, Self::Error> {
let mut params = RequestParams::new();
params.insert("command".to_string(), "returnTicker".to_string());
let req = build_request(POLONIEX_HOST, "/public", Some(params))?;
let body = send_request(&self.client, req).await?;
Ok(deserialize_exchange_info(body.reader())?)
}
}