diff --git a/src/cmd/oracle.rs b/src/cmd/oracle.rs index 764ddc1c..5b7bd094 100644 --- a/src/cmd/oracle.rs +++ b/src/cmd/oracle.rs @@ -145,7 +145,7 @@ impl Price { Price::from_str(amount.as_str().ok_or("No USD value found")?) } - fn from_binance() -> Result { + fn from_binance_us() -> Result { let mut response = reqwest::get("https://api.binance.us/api/v3/ticker/price?symbol=HNTUSD")?; let json: serde_json::Value = response.json()?; @@ -153,6 +153,13 @@ impl Price { Price::from_str(amount.as_str().ok_or("No USD value found")?) } + fn from_binance_int() -> Result { + 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() { @@ -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(