gmo_coin/
lib.rs

1extern crate hex;
2#[macro_use]
3extern crate lazy_static;
4extern crate ring;
5extern crate serde;
6extern crate serde_json;
7extern crate time;
8extern crate ureq;
9
10pub mod endpoint;
11pub mod private;
12pub mod public;
13
14use serde::{Deserialize, Serialize};
15use std::fmt;
16
17/// ## Symbol
18/// validなsymbol
19#[derive(Debug)]
20#[allow(non_camel_case_types)]
21pub enum Symbol {
22    BTC,
23    ETH,
24    BCH,
25    LTC,
26    XRP,
27    BTC_JPY,
28    ETH_JPY,
29    BCH_JPY,
30    LTC_JPY,
31    XRP_JPY,
32}
33
34impl fmt::Display for self::Symbol {
35    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36        match self {
37            Symbol::BTC => write!(f, "BTC"),
38            Symbol::ETH => write!(f, "ETH"),
39            Symbol::BCH => write!(f, "BCH"),
40            Symbol::LTC => write!(f, "LTC"),
41            Symbol::XRP => write!(f, "XRP"),
42            Symbol::BTC_JPY => write!(f, "BTC_JPY"),
43            Symbol::ETH_JPY => write!(f, "ETH_JPY"),
44            Symbol::BCH_JPY => write!(f, "BCH_JPY"),
45            Symbol::LTC_JPY => write!(f, "LTC_JPY"),
46            Symbol::XRP_JPY => write!(f, "XRP_JPY"),
47        }
48    }
49}
50
51#[derive(Debug)]
52pub enum SymbolError {
53    SymbolParseError
54}
55
56impl fmt::Display for self::SymbolError {
57    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58        match self {
59            SymbolError::SymbolParseError => write!(f, "Can't parse symbol"),
60        }
61    }
62}
63
64impl std::str::FromStr for self::Symbol {
65    type Err = self::SymbolError;
66    fn from_str(s: &str) -> Result<Self, Self::Err> {
67        match s {
68            "BTC" | "btc" => Ok(Symbol::BTC),
69            "ETH" | "etc" => Ok(Symbol::ETH),
70            "BCH" | "bch" => Ok(Symbol::BCH),
71            "LTC" | "ltc" => Ok(Symbol::LTC),
72            "XRP" | "xrp" => Ok(Symbol::XRP),
73            "BTC_JPY" | "btc_jpy" => Ok(Symbol::BTC_JPY),
74            "ETH_JPY" | "eth_jpy" => Ok(Symbol::ETH_JPY),
75            "BCH_JPY" | "bch_jpy" => Ok(Symbol::BCH_JPY),
76            "LTC_JPY" | "ltc_jpy" => Ok(Symbol::LTC_JPY),
77            "XRP_JPY" | "xrp_jpy" => Ok(Symbol::XRP_JPY),
78            _ => Err(SymbolError::SymbolParseError),
79        }
80    }
81}
82
83impl Symbol {
84    pub fn from_str(s: &str) -> Result<Symbol, SymbolError> {
85        s.parse() 
86    }
87}
88
89/// ## LevarageSymbol
90/// levarageのvalidなsymbol
91#[derive(Debug)]
92#[allow(non_camel_case_types)]
93pub enum LeverageSymbol {
94    BTC_JPY,
95    ETH_JPY,
96    BCH_JPY,
97    LTC_JPY,
98    XRP_JPY,
99}
100
101impl fmt::Display for self::LeverageSymbol {
102    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
103        match self {
104            LeverageSymbol::BTC_JPY => write!(f, "BTC_JPY"),
105            LeverageSymbol::ETH_JPY => write!(f, "ETH_JPY"),
106            LeverageSymbol::BCH_JPY => write!(f, "BCH_JPY"),
107            LeverageSymbol::LTC_JPY => write!(f, "LTC_JPY"),
108            LeverageSymbol::XRP_JPY => write!(f, "XRP_JPY"),
109        }
110    }
111}
112
113impl std::str::FromStr for self::LeverageSymbol {
114    type Err = self::SymbolError;
115    fn from_str(s: &str) -> Result<Self, Self::Err> {
116        match s {
117            "BTC_JPY" | "btc_jpy" => Ok(LeverageSymbol::BTC_JPY),
118            "ETH_JPY" | "eth_jpy" => Ok(LeverageSymbol::ETH_JPY),
119            "BCH_JPY" | "bch_jpy" => Ok(LeverageSymbol::BCH_JPY),
120            "LTC_JPY" | "ltc_jpy" => Ok(LeverageSymbol::LTC_JPY),
121            "XRP_JPY" | "xrp_jpy" => Ok(LeverageSymbol::XRP_JPY),
122            _ => Err(SymbolError::SymbolParseError),
123        }
124    }
125}
126
127impl LeverageSymbol {
128    pub fn from_str(s: &str) -> Result<Self, SymbolError> {
129        s.parse()
130    }
131}
132
133/// ## Side
134/// 売買
135#[derive(Debug, Serialize, Deserialize)]
136#[allow(non_camel_case_types)]
137pub enum Side {
138    BUY,
139    SELL,
140}
141
142impl fmt::Display for self::Side {
143    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
144        match self {
145            Side::BUY => write!(f, "BUY"),
146            Side::SELL => write!(f, "SELL"),
147        }
148    }
149}
150
151#[derive(Debug)]
152pub enum SideError {
153    SideParseError
154}
155
156impl fmt::Display for self::SideError {
157    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
158        match self {
159            SideError::SideParseError => write!(f, "SideParseError"),
160        }
161    }
162}
163
164impl std::str::FromStr for self::Side {
165    type Err = self::SideError;
166    fn from_str(s: &str) -> Result<Self, Self::Err> {
167        match s {
168            "BUY" | "buy" => Ok(Side::BUY),
169            "SELL"|"sell" => Ok(Side::SELL),
170            _ => Err(SideError::SideParseError),
171        }
172    }
173}
174
175impl Side {
176    pub fn from_str(s: &str) -> Result<Side, SideError> {
177        s.parse()
178    }
179}
180
181/// ## Pagenation
182/// ページ形式で返ってくるレスポンス用の構造体
183///
184///  - currentPage
185///  - count
186#[derive(Debug, Serialize, Deserialize)]
187#[serde(rename_all = "camelCase")]
188pub struct Pagenation {
189    pub current_page: usize,
190    pub count: usize,
191}
192
193/// ## Response
194///
195/// Response
196#[derive(Debug, Serialize, Deserialize)]
197pub struct Response<T> {
198    pub status: usize,
199    pub data: T,
200    pub responsetime: String
201}
202
203/// ## ResponsePage
204///
205/// Response
206#[derive(Debug, Serialize, Deserialize)]
207pub struct ResponsePage<T> {
208    pub status: usize,
209    pub data: DataPage<T>,
210    pub responsetime: String
211}
212
213#[derive(Debug, Serialize, Deserialize)]
214pub struct DataPage<T> {
215    pub pagination: Pagenation,
216    pub list: Vec<T>
217}
218
219/// ## ResponseList
220///
221/// Response
222#[derive(Debug, Serialize, Deserialize)]
223pub struct ResponseList<T> {
224    pub status: usize,
225    pub data: List<T>,
226    pub responsetime: String
227}
228
229#[derive(Debug, Serialize, Deserialize)]
230pub struct List<T> {
231    pub list: Vec<T>
232}
233