Remove unused imports
This commit is contained in:
parent
a484827a18
commit
0100c36191
75
src/main.rs
75
src/main.rs
|
|
@ -19,11 +19,6 @@ use crate::request_others::{CoinPriceData, ExchangeInfo, TradeFee};
|
|||
use crate::server_health_check_team::ServerHealth;
|
||||
use crate::time_checking_team::UserTime;
|
||||
use crate::value_estimation_team::datapoints::price_data::RealtimePriceData;
|
||||
use crate::value_estimation_team::indicators::bollingerband::BollingerBandData;
|
||||
use crate::value_estimation_team::indicators::ema::EmaData;
|
||||
use crate::value_estimation_team::indicators::rsi::RsiData;
|
||||
use crate::value_estimation_team::indicators::sma::SmaData;
|
||||
use crate::value_estimation_team::indicators::stoch_rsi::StochRsiData;
|
||||
use reqwest::{Client, ClientBuilder};
|
||||
use sqlx::{mysql::*, Connection, Executor, FromRow, Row};
|
||||
use std::{
|
||||
|
|
@ -205,22 +200,34 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let mut rx4_exchange_info_data = rx_exchange_info_data.clone();
|
||||
|
||||
{
|
||||
// initialize candle 1d, 1w and 1mon
|
||||
print!("initialize candle 1d, 1w and 1mon..");
|
||||
if RUNNING_MODE == RunningMode::REAL {
|
||||
println!("*** REAL MODE ***");
|
||||
} else if RUNNING_MODE == RunningMode::TEST {
|
||||
println!("*** TEST MODE ***");
|
||||
} else if RUNNING_MODE == RunningMode::SIMUL {
|
||||
println!("*** SIMULATION MODE ***");
|
||||
}
|
||||
|
||||
// pre-fetching candle data: 30m, 1d, 1w and 1mon
|
||||
print!("pre-fetching candle data: 30m, 1d, 1w and 1mon..");
|
||||
std::io::stdout().flush();
|
||||
let instant = Instant::now();
|
||||
let interval_30m = String::from("30m");
|
||||
let interval_1d = String::from("1d");
|
||||
let interval_1w = String::from("1w");
|
||||
let interval_1mon = String::from("1mon");
|
||||
|
||||
let mut candle_30m_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
||||
let mut candle_1d_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
||||
let mut candle_1w_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
||||
let mut candle_1mon_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
||||
|
||||
request_candles::fetch_candle_parallel(&interval_30m, &mut candle_30m_vec_temp).await;
|
||||
request_candles::fetch_candle_parallel(&interval_1d, &mut candle_1d_vec_temp).await;
|
||||
request_candles::fetch_candle_parallel(&interval_1w, &mut candle_1w_vec_temp).await;
|
||||
request_candles::fetch_candle_parallel(&interval_1mon, &mut candle_1mon_vec_temp).await;
|
||||
|
||||
tx_candle_30m_vec.send_modify(|vec| *vec = candle_30m_vec_temp);
|
||||
tx_candle_1d_vec.send_modify(|vec| *vec = candle_1d_vec_temp);
|
||||
tx_candle_1w_vec.send_modify(|vec| *vec = candle_1w_vec_temp);
|
||||
tx_candle_1mon_vec.send_modify(|vec| *vec = candle_1mon_vec_temp);
|
||||
|
|
@ -228,13 +235,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// sleep as much as the loop recurs per 60 seconds, expecting child threads will have finished within 60 seconds.
|
||||
println!("Ok..");
|
||||
|
||||
// if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL {
|
||||
// let elapsed_time = instant.elapsed().as_secs();
|
||||
// println!("wait for {} seconds till starting tradingbot..", 60 - elapsed_time);
|
||||
// if 60 > elapsed_time {
|
||||
// sleep(Duration::from_secs((60 - elapsed_time) as u64)).await;
|
||||
// }
|
||||
// }
|
||||
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL {
|
||||
let mut elapsed_time = instant.elapsed().as_secs();
|
||||
let mut remaining_time: u64 = 60 - elapsed_time;
|
||||
|
||||
while remaining_time > 0 && 60 > remaining_time {
|
||||
print!("\rstart tradingbot in {} seconds", remaining_time);
|
||||
io::stdout().flush();
|
||||
elapsed_time = instant.elapsed().as_secs();
|
||||
loop {
|
||||
let temp_elapsed_time = instant.elapsed().as_secs();
|
||||
let is_overflowed = remaining_time.overflowing_sub(1).1;
|
||||
|
||||
if is_overflowed == true {
|
||||
break;
|
||||
}
|
||||
if elapsed_time < temp_elapsed_time {
|
||||
remaining_time -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("\nTradingbot is running");
|
||||
}
|
||||
}
|
||||
|
||||
// Task#0: monitoring tasks
|
||||
|
|
@ -736,8 +760,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// sleep as much as the loop recurs per 10 seconds, expecting child threads will have finished within 10 seconds.
|
||||
elapsed_time = instant.elapsed().as_millis();
|
||||
if 10_000 > elapsed_time {
|
||||
sleep(Duration::from_millis((10_000 - elapsed_time) as u64)).await;
|
||||
if 30_000 > elapsed_time { // 10_000 for major trade
|
||||
sleep(Duration::from_millis((30_000 - elapsed_time) as u64)).await;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -750,7 +774,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let instant = Instant::now();
|
||||
let mut candle_30m_vec_temp: Vec<(String, Vec<CandleData>)> = Vec::new();
|
||||
let result =
|
||||
request_candles::fetch_candle_parallel(&interval, &mut candle_30m_vec_temp).await;
|
||||
|
||||
request_candles::fetch_candle_delay(&interval, &mut candle_30m_vec_temp).await;
|
||||
// request_candles::fetch_candle_parallel(&interval, &mut candle_30m_vec_temp).await;
|
||||
|
||||
match result {
|
||||
Ok(T) => {
|
||||
|
|
@ -761,7 +787,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
// sleep as much as the loop recurs per 60 seconds, expecting child threads will have finished within 60 seconds.
|
||||
elapsed_time = instant.elapsed().as_millis();
|
||||
if 60_000 > elapsed_time {
|
||||
if 60_000 > elapsed_time { //60_000
|
||||
sleep(Duration::from_millis((60_000 - elapsed_time) as u64)).await;
|
||||
}
|
||||
}
|
||||
|
|
@ -971,12 +997,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.expect("The mpsc channel has been closed.");
|
||||
}
|
||||
Err(E) => {
|
||||
println!("Task #18 Error");
|
||||
}
|
||||
}
|
||||
|
||||
// sleep as much as the loop recurs per 1 second if all operation finished within 1 second.
|
||||
elapsed_time = instant.elapsed().as_millis();
|
||||
println!("elapsed time: {}", elapsed_time);
|
||||
if 250 > elapsed_time {
|
||||
sleep(Duration::from_millis((250 - elapsed_time) as u64)).await;
|
||||
}
|
||||
|
|
@ -1048,17 +1074,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL || RUNNING_MODE == TEST {
|
||||
tokio::task::spawn(async move {
|
||||
sleep(Duration::from_secs(30)).await;
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let mut elapsed_time = 0;
|
||||
loop {
|
||||
let instant = Instant::now();
|
||||
let exchange_info_vec = rx_exchange_info_data.borrow().clone();
|
||||
let trade_fee_vec = rx_tradefee_vec.borrow().clone();
|
||||
let result = coex::exchange_team::buy_coin(
|
||||
&client,
|
||||
&exchange_info_vec,
|
||||
&trade_fee_vec,
|
||||
)
|
||||
|
|
@ -1084,10 +1106,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
} else {
|
||||
tokio::task::spawn(async move {
|
||||
sleep(Duration::from_secs(15)).await;
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(800))
|
||||
.build()
|
||||
.unwrap();
|
||||
let mut elapsed_time = 0;
|
||||
|
||||
let instant = Instant::now();
|
||||
|
|
@ -1095,7 +1113,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let trade_fee_vec = rx_tradefee_vec.borrow().clone();
|
||||
// let result = coex::exchange_team::buy_coin_for_test(&client, &coin_price_vec, &exchange_info_vec, &trade_fee_vec).await;
|
||||
let result = coex::exchange_team::buy_coin(
|
||||
&client,
|
||||
&exchange_info_vec,
|
||||
&trade_fee_vec,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user