Move client variable into loop
This commit is contained in:
parent
c6df1ac360
commit
116edcbe07
73
src/main.rs
73
src/main.rs
|
|
@ -396,12 +396,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// Task#1: check server time and health
|
||||
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 epoch_difference: f64 = 0.0;
|
||||
let mut epoch_mean: f64 = 0.0;
|
||||
|
|
@ -409,6 +403,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
loop {
|
||||
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 usertime_mutex = usertime_arc.lock().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
|
||||
tokio::task::spawn(async move {
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let mut elapsed_time = 0;
|
||||
loop {
|
||||
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 tx2_changed = rx2.changed().await;
|
||||
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
|
||||
tokio::task::spawn(async move {
|
||||
let client = ClientBuilder::new()
|
||||
loop {
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
loop {
|
||||
let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new();
|
||||
let mut result;
|
||||
loop {
|
||||
|
|
@ -595,13 +595,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// total_price_down_dist_index
|
||||
tokio::task::spawn(async move {
|
||||
sleep(Duration::from_secs(10)).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 client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let result = request_others::request_24hr_ticker_price_change_statistics(&client).await;
|
||||
match result {
|
||||
Ok(T) => {
|
||||
|
|
@ -668,15 +668,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
// Task#5: price per second
|
||||
tokio::task::spawn(async move {
|
||||
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 elapsed_time = 0;
|
||||
loop {
|
||||
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 result = request_others::request_all_coin_price(&client, &mut price_vec_temp).await;
|
||||
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 {
|
||||
sleep(Duration::from_secs(10)).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 client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let exchange_info_vec = rx3_exchange_info_data.borrow().clone();
|
||||
let trade_fee_vec = rx2_tradefee_vec.borrow().clone();
|
||||
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 {
|
||||
sleep(Duration::from_secs(10)).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 client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let exchange_info_vec = rx4_exchange_info_data.borrow().clone();
|
||||
let trade_fee_vec = rx4_tradefee_vec.borrow().clone();
|
||||
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
|
||||
tokio::task::spawn(async move {
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let mut elapsed_time = 0;
|
||||
loop {
|
||||
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;
|
||||
|
||||
// send Task#0 a message to notify running on
|
||||
|
|
@ -1420,14 +1419,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// Task#25: update current_total_usdt and available_usdt
|
||||
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 elapsed_time = 0;
|
||||
loop {
|
||||
let instant = Instant::now();
|
||||
let client = ClientBuilder::new()
|
||||
.timeout(tokio::time::Duration::from_millis(3000))
|
||||
.build()
|
||||
.unwrap();
|
||||
let result =
|
||||
coex::assets_managing_team::monitoring_asset_usdt(&mut previous_result, &client)
|
||||
.await;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user