parent
5dfd1628a2
commit
bd4b3fb8c2
@ -1,16 +1,49 @@
|
||||
extern crate json;
|
||||
extern crate reqwest;
|
||||
|
||||
use std::time::{SystemTime, Duration};
|
||||
use json::JsonValue;
|
||||
use reqwest::{blocking::ClientBuilder, Proxy};
|
||||
|
||||
pub struct Market {
|
||||
pub last_check_time: SystemTime,
|
||||
pub last_cg_data: JsonValue
|
||||
}
|
||||
|
||||
fn get_wow_price() -> String {
|
||||
let url: &str = "https://tradeogre.com/api/v1/ticker/BTC-WOW";
|
||||
let client: reqwest::blocking::Client = reqwest::blocking::ClientBuilder::new()
|
||||
.timeout(std::time::Duration::from_secs(10))
|
||||
.build()
|
||||
.unwrap();
|
||||
let res: String = client.get(url)
|
||||
.send()
|
||||
.unwrap()
|
||||
.json()
|
||||
.unwrap();
|
||||
return res
|
||||
}
|
||||
impl Market {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
last_check_time: SystemTime::now() - Duration::from_secs(600),
|
||||
last_cg_data: json::object!{}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_client(&self, tor_required: bool) -> ClientBuilder {
|
||||
let mut client_builder = ClientBuilder::new();
|
||||
if tor_required {
|
||||
let proxy = Proxy::all("socks5://127.0.0.1:19050").unwrap();
|
||||
client_builder = client_builder.proxy(proxy);
|
||||
}
|
||||
return client_builder;
|
||||
}
|
||||
|
||||
pub fn get_wow_market(&self, tor_required: bool) -> JsonValue {
|
||||
let url = "https://api.coingecko.com/api/v3/coins/wownero?community_data=false&developer_data=false";
|
||||
let client = self.get_client(tor_required);
|
||||
let res: String = client
|
||||
.build()
|
||||
.unwrap()
|
||||
.get(url)
|
||||
.send()
|
||||
.unwrap()
|
||||
.text()
|
||||
.unwrap();
|
||||
|
||||
let j = json::parse(res.as_str());
|
||||
if j.is_ok() {
|
||||
return j.unwrap();
|
||||
} else {
|
||||
return json::object!{};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in new issue