Skip to content

Commit 40e79bd

Browse files
authored
Merge pull request #28 from ainestal/doc_test_utils
Doc test utils
2 parents f6cd84b + 5572777 commit 40e79bd

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

src/bitstamp/utils.rs

+31
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ pub fn parse_result(response: &Map<String, Value>) -> Result<Map<String, Value>>
119119
/// Return the currency enum associated with the
120120
/// string used by Bitstamp. If no currency is found,
121121
/// return None
122+
/// # Examples
123+
///
124+
/// ```
125+
/// use coinnect::bitstamp::utils::get_currency_enum;
126+
/// use coinnect::currency::Currency;
127+
///
128+
/// let currency = get_currency_enum("usd_balance");
129+
/// assert_eq!(Some(Currency::USD), currency);
130+
/// ```
122131
pub fn get_currency_enum(currency: &str) -> Option<Currency> {
123132
match currency {
124133
"usd_balance" => Some(Currency::USD),
@@ -128,3 +137,25 @@ pub fn get_currency_enum(currency: &str) -> Option<Currency> {
128137
_ => None,
129138
}
130139
}
140+
141+
/// Return the currency string associated with the
142+
/// enum used by Bitstamp. If no currency is found,
143+
/// return None
144+
/// # Examples
145+
///
146+
/// ```
147+
/// use coinnect::bitstamp::utils::get_currency_string;
148+
/// use coinnect::currency::Currency;
149+
///
150+
/// let currency = get_currency_string(Currency::USD);
151+
/// assert_eq!(currency, Some("USD".to_string()));
152+
/// ```
153+
pub fn get_currency_string(currency: Currency) -> Option<String> {
154+
match currency {
155+
Currency::USD => Some("USD".to_string()),
156+
Currency::BTC => Some("BTC".to_string()),
157+
Currency::EUR => Some("EUR".to_string()),
158+
Currency::XRP => Some("XRP".to_string()),
159+
_ => None,
160+
}
161+
}

src/kraken/utils.rs

+49
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,18 @@ pub fn parse_result(response: &Map<String, Value>) -> Result<Map<String, Value>>
140140
}
141141
}
142142

143+
/// Return the currency enum associated with the
144+
/// string used by Kraken. If no currency is found,
143145
/// return None
146+
/// # Examples
147+
///
148+
/// ```
149+
/// use coinnect::kraken::utils::get_currency_enum;
150+
/// use coinnect::currency::Currency;
151+
///
152+
/// let currency = get_currency_enum("ZUSD");
153+
/// assert_eq!(Some(Currency::USD), currency);
154+
/// ```
144155
pub fn get_currency_enum(currency: &str) -> Option<Currency> {
145156
match currency {
146157
"ZEUR" => Some(Currency::EUR),
@@ -166,3 +177,41 @@ pub fn get_currency_enum(currency: &str) -> Option<Currency> {
166177
_ => None,
167178
}
168179
}
180+
181+
/// Return the currency String associated with the
182+
/// string used by Kraken. If no currency is found,
183+
/// return None
184+
/// # Examples
185+
///
186+
/// ```
187+
/// use coinnect::kraken::utils::get_currency_string;
188+
/// use coinnect::currency::Currency;
189+
///
190+
/// let currency = get_currency_string(Currency::BTC);
191+
/// assert_eq!(currency, Some("XXBT".to_string()));
192+
/// ```
193+
pub fn get_currency_string(currency: Currency) -> Option<String> {
194+
match currency {
195+
Currency::EUR => Some("ZEUR".to_string()),
196+
Currency::CAD => Some("ZCAD".to_string()),
197+
Currency::GBP => Some("ZGBP".to_string()),
198+
Currency::JPY => Some("ZJPY".to_string()),
199+
Currency::USD => Some("ZUSD".to_string()),
200+
Currency::DASH => Some("XDASH".to_string()),
201+
Currency::ETC => Some("XETC".to_string()),
202+
Currency::ETH => Some("XETH".to_string()),
203+
Currency::GNO => Some("XGNO".to_string()),
204+
Currency::ICN => Some("XICN".to_string()),
205+
Currency::LTC => Some("XLTC".to_string()),
206+
Currency::MLN => Some("XMLN".to_string()),
207+
Currency::REP => Some("XREP".to_string()),
208+
Currency::USDT => Some("XUSDT".to_string()),
209+
Currency::BTC => Some("XXBT".to_string()),
210+
Currency::XDG => Some("XXDG".to_string()),
211+
Currency::XLM => Some("XXLM".to_string()),
212+
Currency::XMR => Some("XXMR".to_string()),
213+
Currency::XRP => Some("XXRP".to_string()),
214+
Currency::ZEC => Some("XZEC".to_string()),
215+
_ => None,
216+
}
217+
}

src/poloniex/utils.rs

+38
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ pub fn parse_result(response: &Map<String, Value>) -> Result<Map<String, Value>>
153153
/// Return the currency enum associated with the
154154
/// string used by Poloniex. If no currency is found,
155155
/// return None
156+
/// # Examples
157+
///
158+
/// ```
159+
/// use coinnect::poloniex::utils::get_currency_enum;
160+
/// use coinnect::currency::Currency;
161+
///
162+
/// let currency = get_currency_enum("BTC").unwrap();
163+
/// assert_eq!(currency, Currency::BTC);
164+
/// ```
156165
pub fn get_currency_enum(currency: &str) -> Option<Currency> {
157166
match currency {
158167
"AMP" => Some(Currency::AMP),
@@ -169,3 +178,32 @@ pub fn get_currency_enum(currency: &str) -> Option<Currency> {
169178
_ => None,
170179
}
171180
}
181+
182+
/// Return the currency string associated with the
183+
/// enum used by Poloniex. If no currency is found,
184+
/// return None
185+
/// # Examples
186+
///
187+
/// ```
188+
/// use coinnect::poloniex::utils::get_currency_string;
189+
/// use coinnect::currency::Currency;
190+
///
191+
/// let currency = get_currency_string(Currency::BTC);
192+
/// assert_eq!(currency, Some("BTC".to_string()));
193+
/// ```
194+
pub fn get_currency_string(currency: Currency) -> Option<String> {
195+
match currency {
196+
Currency::AMP => Some("AMP".to_string()),
197+
Currency::BTC => Some("BTC".to_string()),
198+
Currency::ARDR => Some("ARDR".to_string()),
199+
Currency::ETH => Some("ETH".to_string()),
200+
Currency::ETC => Some("ETC".to_string()),
201+
Currency::LBC => Some("LBC".to_string()),
202+
Currency::XMR => Some("XMR".to_string()),
203+
Currency::XPM => Some("XPM".to_string()),
204+
Currency::XRP => Some("XRP".to_string()),
205+
Currency::XVC => Some("XVC".to_string()),
206+
Currency::ZEC => Some("ZEC".to_string()),
207+
_ => None,
208+
}
209+
}

0 commit comments

Comments
 (0)