mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Merge pull request #22 from whitequark/master
The author of BTC-e was arrested and this broke our exchange rate function
This commit is contained in:
commit
1514a37196
1 changed files with 15 additions and 21 deletions
36
src/btc.rs
36
src/btc.rs
|
@ -9,33 +9,27 @@ use std::io::Read;
|
|||
use std::rc::Rc;
|
||||
use json;
|
||||
|
||||
static URL: &'static str = "https://btc-e.com/api/3/ticker/btc_usd-ltc_usd-nmc_usd-nvc_usd-ppc_usd-eth_usd";
|
||||
static URL: &'static str = "https://blockchain.info/stats?format=json";
|
||||
|
||||
pub fn parse(mut f: File) -> Result<Defs, String> {
|
||||
let mut buf = String::new();
|
||||
try!(f.read_to_string(&mut buf).map_err(|x| format!("{}", x)));
|
||||
let parsed = try!(json::parse(&*buf).map_err(|x| format!("{}", x)));
|
||||
let mut out = vec![];
|
||||
for (k, v) in parsed.entries() {
|
||||
if k.ends_with("_usd") {
|
||||
let name = k[0..k.len()-"_usd".len()].to_uppercase();
|
||||
let avg = v["avg"].as_number();
|
||||
if let Some(avg) = avg {
|
||||
let (sign, mantissa, exp) = avg.as_parts();
|
||||
let integer = format!("{}{}", if sign { "" } else { "-" }, mantissa);
|
||||
if let Ok(num) = ::Number::from_parts(&*integer, None, Some(&*format!("{}", exp))) {
|
||||
out.push(DefEntry {
|
||||
name: name,
|
||||
def: Rc::new(Def::Unit(
|
||||
Expr::Mul(vec![
|
||||
Expr::Const(num),
|
||||
Expr::Unit("USD".to_owned())
|
||||
]))),
|
||||
doc: Some(format!("Sourced from BTC-E exchange.")),
|
||||
category: Some("currencies".to_owned()),
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(price) = parsed["market_price_usd"].as_number() {
|
||||
let (sign, mantissa, exp) = price.as_parts();
|
||||
let integer = format!("{}{}", if sign { "" } else { "-" }, mantissa);
|
||||
if let Ok(price) = ::Number::from_parts(&*integer, None, Some(&*format!("{}", exp))) {
|
||||
out.push(DefEntry {
|
||||
name: "BTC".to_owned(),
|
||||
def: Rc::new(Def::Unit(
|
||||
Expr::Mul(vec![
|
||||
Expr::Const(price),
|
||||
Expr::Unit("USD".to_owned())
|
||||
]))),
|
||||
doc: Some(format!("Sourced from blockchain.info.")),
|
||||
category: Some("currencies".to_owned()),
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(Defs {
|
||||
|
|
Loading…
Reference in a new issue