Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created March 23, 2021 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/f8ca8de0dd43761d10a664a6f7ac1471 to your computer and use it in GitHub Desktop.
Save cuongld2/f8ca8de0dd43761d10a664a6f7ac1471 to your computer and use it in GitHub Desktop.
source code for simple alert while trading
#[path="models/financevietstock.rs"]
pub mod financevietstock;
use reqwest::header::CONTENT_LENGTH;
use reqwest::header::CONTENT_TYPE;
use reqwest::header::USER_AGENT;
use std::collections::HashMap;
use crate::financevietstock::FinanceResponse;
use std::time::Duration;
use async_std::task;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
loop{
let mut stock_expected_price = HashMap::new();
stock_expected_price.insert(String::from("DAH"), 9000);
stock_expected_price.insert(String::from("VNG"), 16000);
stock_expected_price.insert(String::from("AAM"), 11500);
stock_expected_price.insert(String::from("TNH"), 35000);
stock_expected_price.insert(String::from("VNS"), 10800);
for (key, value) in stock_expected_price.into_iter() {
let body_request = format!("code={stock_price}&s=1",stock_price=key);
let res = client.post("https://finance.vietstock.vn/company/tradinginfo")
.header(CONTENT_LENGTH,body_request.chars().count())
.header(CONTENT_TYPE,"application/x-www-form-urlencoded; charset=UTF-8")
.header(USER_AGENT,"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0")
.body(body_request)
.send()
.await?;
println!("{:?}",res);
let json_value: FinanceResponse = res.json().await?;
println!("{:?}",json_value);
assert_eq!(json_value.LastPrice > value, false);
}
task::sleep(Duration::from_secs(3600)).await;
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment