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 {
|
impl Market {
|
||||||
let url: &str = "https://tradeogre.com/api/v1/ticker/BTC-WOW";
|
pub fn new() -> Self {
|
||||||
let client: reqwest::blocking::Client = reqwest::blocking::ClientBuilder::new()
|
Self {
|
||||||
.timeout(std::time::Duration::from_secs(10))
|
last_check_time: SystemTime::now() - Duration::from_secs(600),
|
||||||
.build()
|
last_cg_data: json::object!{}
|
||||||
.unwrap();
|
}
|
||||||
let res: String = client.get(url)
|
}
|
||||||
.send()
|
|
||||||
.unwrap()
|
fn get_client(&self, tor_required: bool) -> ClientBuilder {
|
||||||
.json()
|
let mut client_builder = ClientBuilder::new();
|
||||||
.unwrap();
|
if tor_required {
|
||||||
return res
|
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