diff --git a/chromedriver/chromedriver.exe b/chromedriver/chromedriver.exe new file mode 100644 index 0000000..015e261 Binary files /dev/null and b/chromedriver/chromedriver.exe differ diff --git a/src/initialization.rs b/src/initialization.rs index 8bcea77..b143cd5 100644 --- a/src/initialization.rs +++ b/src/initialization.rs @@ -11,11 +11,9 @@ use reqwest::{Client, ClientBuilder}; use rust_decimal::{prelude::FromPrimitive, prelude::ToPrimitive, Decimal, RoundingStrategy}; use rust_decimal_macros::dec; use sqlx::FromRow; -use std::{io, io::Write, process::Stdio}; +use std::{io, io::Write, process::Stdio, path::Path}; use tokio::{fs::*, io::ErrorKind, process::Command, task::JoinHandle, time::*}; -const WEB_DRIVER_PATH: &str = "E:/[Cryptocurrency]/tradingbot/webdriver/chromedriver.exe"; -const WEB_DRIVER_PATH2: &str = "C:/tradingbot_complete/webdriver/chromedriver.exe"; const STRATEGIST_NUMBER: u32 = 16; pub async fn initialization() { @@ -82,24 +80,37 @@ async fn initialize_webdriver() { print!("Open webdriver..."); io::stdout().flush(); let mut output; - - output = Command::new(WEB_DRIVER_PATH) + + let os_type = std::env::consts::OS; + let mut chrome_webdriver_path = std::path::PathBuf::new(); + chrome_webdriver_path.push(std::env::current_dir().unwrap()); + chrome_webdriver_path.push("chromedriver"); + + match os_type { + "linux" => { + chrome_webdriver_path.push("chromedriver"); + }, + "windows" => { + chrome_webdriver_path.push("chromedriver.exe"); + }, + _ => { + eprintln!("\ntradingbot supports only Linux and Windows."); + panic!(); + } + } + + if !chrome_webdriver_path.exists() { + eprintln!("\nCheck if there is chromedriver.exe ({})", chrome_webdriver_path.to_str().unwrap()); + panic!(); + } + + output = Command::new(chrome_webdriver_path) .stdin(Stdio::null()) .stdout(Stdio::null()) .stderr(Stdio::null()) .spawn(); - - if output.is_ok() { - output.unwrap(); - } else { - output = Command::new(WEB_DRIVER_PATH2) - .stdin(Stdio::null()) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .spawn(); - - output.unwrap(); - } + output.expect("\nOpening chromedriver failed!"); + println!("Ok"); }