Move client variable into loop

This commit is contained in:
Sik Yoon 2023-12-02 20:33:35 +09:00
parent c6df1ac360
commit 116edcbe07

View File

@ -396,12 +396,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Task#1: check server time and health // Task#1: check server time and health
tokio::task::spawn(async move { tokio::task::spawn(async move {
let client = ClientBuilder::new()
.timeout(Duration::from_millis(1000))
.build()
.unwrap();
let mut usertime = UserTime::new();
let mut serverhealth = ServerHealth::new();
let mut prev_server_epoch: u128 = 0; let mut prev_server_epoch: u128 = 0;
let mut epoch_difference: f64 = 0.0; let mut epoch_difference: f64 = 0.0;
let mut epoch_mean: f64 = 0.0; let mut epoch_mean: f64 = 0.0;
@ -409,6 +403,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(Duration::from_millis(1000))
.build()
.unwrap();
let mut usertime = UserTime::new();
let mut serverhealth = ServerHealth::new();
let mut epoch_difference_vec: Vec<f64> = Vec::new(); let mut epoch_difference_vec: Vec<f64> = Vec::new();
// let mut usertime_mutex = usertime_arc.lock().await; // let mut usertime_mutex = usertime_arc.lock().await;
// server_health_check_team::execute_server_health_check(&mut usertime_mutex).await; // server_health_check_team::execute_server_health_check(&mut usertime_mutex).await;
@ -493,13 +493,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Task#2: request trade fee // Task#2: request trade fee
tokio::task::spawn(async move { tokio::task::spawn(async move {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let tx1_changed = rx1_1.changed().await; let tx1_changed = rx1_1.changed().await;
let tx2_changed = rx2.changed().await; let tx2_changed = rx2.changed().await;
let local_epoch = *rx1_1.borrow(); let local_epoch = *rx1_1.borrow();
@ -554,11 +554,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Task#3: request lot stepsize and ticksize // Task#3: request lot stepsize and ticksize
tokio::task::spawn(async move { tokio::task::spawn(async move {
let client = ClientBuilder::new() loop {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000)) .timeout(tokio::time::Duration::from_millis(3000))
.build() .build()
.unwrap(); .unwrap();
loop {
let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new(); let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new();
let mut result; let mut result;
loop { loop {
@ -595,13 +595,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// total_price_down_dist_index // total_price_down_dist_index
tokio::task::spawn(async move { tokio::task::spawn(async move {
sleep(Duration::from_secs(10)).await; sleep(Duration::from_secs(10)).await;
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let result = request_others::request_24hr_ticker_price_change_statistics(&client).await; let result = request_others::request_24hr_ticker_price_change_statistics(&client).await;
match result { match result {
Ok(T) => { Ok(T) => {
@ -668,15 +668,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Task#5: price per second // Task#5: price per second
tokio::task::spawn(async move { tokio::task::spawn(async move {
sleep(Duration::from_secs(20)).await; sleep(Duration::from_secs(20)).await;
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(1000))
.build()
.unwrap();
let mut server_epoch = 0; let mut server_epoch = 0;
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(1000))
.build()
.unwrap();
let mut price_vec_temp: Vec<CoinPriceData> = Vec::new(); let mut price_vec_temp: Vec<CoinPriceData> = Vec::new();
let result = request_others::request_all_coin_price(&client, &mut price_vec_temp).await; let result = request_others::request_all_coin_price(&client, &mut price_vec_temp).await;
let mut price_vec_temp_c: Vec<CoinPriceData> = Vec::new(); let mut price_vec_temp_c: Vec<CoinPriceData> = Vec::new();
@ -1241,13 +1240,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else if RUNNING_MODE == TEST { } else if RUNNING_MODE == TEST {
sleep(Duration::from_secs(10)).await; sleep(Duration::from_secs(10)).await;
} }
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let exchange_info_vec = rx3_exchange_info_data.borrow().clone(); let exchange_info_vec = rx3_exchange_info_data.borrow().clone();
let trade_fee_vec = rx2_tradefee_vec.borrow().clone(); let trade_fee_vec = rx2_tradefee_vec.borrow().clone();
let result = coex::order_team::monitoring_open_buy_order( let result = coex::order_team::monitoring_open_buy_order(
@ -1324,13 +1323,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else if RUNNING_MODE == TEST { } else if RUNNING_MODE == TEST {
sleep(Duration::from_secs(10)).await; sleep(Duration::from_secs(10)).await;
} }
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let exchange_info_vec = rx4_exchange_info_data.borrow().clone(); let exchange_info_vec = rx4_exchange_info_data.borrow().clone();
let trade_fee_vec = rx4_tradefee_vec.borrow().clone(); let trade_fee_vec = rx4_tradefee_vec.borrow().clone();
let result = coex::order_team::monitoring_open_sell_order( let result = coex::order_team::monitoring_open_sell_order(
@ -1361,13 +1360,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Task#23: monitoring_filled_sell_order // Task#23: monitoring_filled_sell_order
tokio::task::spawn(async move { tokio::task::spawn(async move {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let result = coex::order_team::monitoring_filled_sell_order(&client).await; let result = coex::order_team::monitoring_filled_sell_order(&client).await;
// send Task#0 a message to notify running on // send Task#0 a message to notify running on
@ -1394,7 +1393,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let mut all_data = AllData::new(); let mut all_data = AllData::new();
// realtime price data // realtime price data
all_data.rt_price_1m_vec = rx4_rt_price_1m_vec.borrow().clone(); all_data.rt_price_1m_vec = rx4_rt_price_1m_vec.borrow().clone();
@ -1420,14 +1419,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Task#25: update current_total_usdt and available_usdt // Task#25: update current_total_usdt and available_usdt
tokio::task::spawn(async move { tokio::task::spawn(async move {
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let mut previous_result = false; let mut previous_result = false;
let mut elapsed_time = 0; let mut elapsed_time = 0;
loop { loop {
let instant = Instant::now(); let instant = Instant::now();
let client = ClientBuilder::new()
.timeout(tokio::time::Duration::from_millis(3000))
.build()
.unwrap();
let result = let result =
coex::assets_managing_team::monitoring_asset_usdt(&mut previous_result, &client) coex::assets_managing_team::monitoring_asset_usdt(&mut previous_result, &client)
.await; .await;