Skip to content

Commit

Permalink
Merge pull request #58 from helium/lthiery/oracle-improvements
Browse files Browse the repository at this point in the history
Add Binance International
  • Loading branch information
madninja committed Nov 19, 2020
2 parents ade2510 + a6503ac commit 7a40d99
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cmd/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,21 @@ impl Price {
Price::from_str(amount.as_str().ok_or("No USD value found")?)
}

fn from_binance() -> Result<Self> {
fn from_binance_us() -> Result<Self> {
let mut response =
reqwest::get("https://api.binance.us/api/v3/ticker/price?symbol=HNTUSD")?;
let json: serde_json::Value = response.json()?;
let amount = &json["price"];
Price::from_str(amount.as_str().ok_or("No USD value found")?)
}

fn from_binance_int() -> Result<Self> {
let mut response = reqwest::get("https://api.binance.us/api/v3/avgPrice?symbol=HNTUSDT")?;
let json: serde_json::Value = response.json()?;
let amount = &json["price"];
Price::from_str(amount.as_str().ok_or("No USD value found")?)
}

fn to_millis(self) -> u64 {
if let Some(scaled_dec) = self.0.checked_mul(USD_TO_PRICE_SCALAR.into()) {
if let Some(num) = scaled_dec.to_u64() {
Expand All @@ -178,7 +185,10 @@ impl FromStr for Price {
match s {
"coingecko" => Price::from_coingecko(),
"bilaxy" => Price::from_bilaxy(),
"binance" => Price::from_binance(),
// don't break old interface so maintain "binance" to Binance US
"binance" => Price::from_binance_us(),
"binance-us" => Price::from_binance_us(),
"binance-int" => Price::from_binance_int(),
_ => {
let data = Decimal::from_str(s).or_else(|_| Decimal::from_scientific(s))?;
Ok(Price(
Expand Down

0 comments on commit 7a40d99

Please sign in to comment.