Skip to main content

binary_option_tools_core/pocketoption/utils/
basic.rs

1use chrono::{Duration, Utc};
2use rand::{thread_rng, Rng};
3
4use crate::pocketoption::error::{PocketOptionError, PocketResult};
5
6pub fn get_index() -> PocketResult<u64> {
7    // rand = str(random.randint(10, 99))
8    // cu = int(time.time())
9    // t = str(cu + (2 * 60 * 60))
10    // index = int(t + rand)
11    let mut rng = thread_rng();
12
13    let rand = rng.gen_range(10..99);
14    let time = (Utc::now() + Duration::hours(2)).timestamp();
15    format!("{}{}", time, rand)
16        .parse::<u64>()
17        .map_err(|e| PocketOptionError::GeneralParsingError(e.to_string()))
18}
19
20pub fn is_otc(symbol: &str) -> bool {
21    symbol.ends_with("otc")
22}