diff --git a/src/coex/order_team.rs b/src/coex/order_team.rs index a779d3c..d487fe3 100644 --- a/src/coex/order_team.rs +++ b/src/coex/order_team.rs @@ -441,7 +441,7 @@ pub async fn monitoring_filled_buy_order( if !filled_buy_orders.is_empty() { // 심볼들을 2개씩 청스로 나누어 테스크를 생성하고 각 태스크 별로 병렬로 처리한다. // update real-time current price to each record through chunks - let chunks = filled_buy_orders.chunks(2); + let chunks: std::slice::Chunks<'_, BuyOrderedCoinList> = filled_buy_orders.chunks(2); let mut task_vec = Vec::new(); for chunk in chunks { @@ -536,7 +536,7 @@ pub async fn monitoring_filled_buy_order( // let target_profit_percent = average_amplitude + (standard_deviation_amplitude * (average_ratio_amp_body)); let target_profit_percent = - (average_amplitude / 2.0) + (standard_deviation_amplitude * 2.0); // 2.0 sigma (recommand: 0.5 ~ 2.0(patient & greedy)) + (average_amplitude / 2.0) + (standard_deviation_amplitude * 1.0); // 2.0 sigma (recommand: 0.5 ~ 2.0(patient & greedy)) // if scoreboard_list.first().unwrap().pos_liquidation_signal == 1 // || scoreboard_list.first().unwrap().neg_liquidation_signal == 1 diff --git a/src/coex/strategy_team.rs b/src/coex/strategy_team.rs index cc6d7d9..1c25cb9 100644 --- a/src/coex/strategy_team.rs +++ b/src/coex/strategy_team.rs @@ -2,6 +2,7 @@ use crate::coex::exchange_team::*; use crate::coex::order_team::*; use crate::coin_health_check_team::request_others::CoinPriceData; use crate::database_control::*; +use crate::value_estimation_team; 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; @@ -39,83 +40,82 @@ pub struct AllData { pub rt_price_1d_vec: Vec<(String, Vec)>, pub rt_price_1w_vec: Vec<(String, Vec)>, pub rt_price_1mon_vec: Vec<(String, Vec)>, + // pub sma3_1m_data: Vec<(String, Vec)>, + // pub sma3_30m_data: Vec<(String, Vec)>, + // pub sma3_1d_data: Vec<(String, Vec)>, + // pub sma3_1w_data: Vec<(String, Vec)>, + // pub sma3_1mon_data: Vec<(String, Vec)>, - pub sma3_1m_data: Vec<(String, Vec)>, - pub sma3_30m_data: Vec<(String, Vec)>, - pub sma3_1d_data: Vec<(String, Vec)>, - pub sma3_1w_data: Vec<(String, Vec)>, - pub sma3_1mon_data: Vec<(String, Vec)>, + // pub sma10_1m_data: Vec<(String, Vec)>, + // pub sma10_30m_data: Vec<(String, Vec)>, + // pub sma10_1d_data: Vec<(String, Vec)>, + // pub sma10_1w_data: Vec<(String, Vec)>, + // pub sma10_1mon_data: Vec<(String, Vec)>, - pub sma10_1m_data: Vec<(String, Vec)>, - pub sma10_30m_data: Vec<(String, Vec)>, - pub sma10_1d_data: Vec<(String, Vec)>, - pub sma10_1w_data: Vec<(String, Vec)>, - pub sma10_1mon_data: Vec<(String, Vec)>, + // pub sma30_1m_data: Vec<(String, Vec)>, + // pub sma30_30m_data: Vec<(String, Vec)>, + // pub sma30_1d_data: Vec<(String, Vec)>, + // pub sma30_1w_data: Vec<(String, Vec)>, + // pub sma30_1mon_data: Vec<(String, Vec)>, - pub sma30_1m_data: Vec<(String, Vec)>, - pub sma30_30m_data: Vec<(String, Vec)>, - pub sma30_1d_data: Vec<(String, Vec)>, - pub sma30_1w_data: Vec<(String, Vec)>, - pub sma30_1mon_data: Vec<(String, Vec)>, + // pub ema3_1m_data: Vec<(String, Vec)>, + // pub ema3_30m_data: Vec<(String, Vec)>, + // pub ema3_1d_data: Vec<(String, Vec)>, + // pub ema3_1w_data: Vec<(String, Vec)>, + // pub ema3_1mon_data: Vec<(String, Vec)>, - pub ema3_1m_data: Vec<(String, Vec)>, - pub ema3_30m_data: Vec<(String, Vec)>, - pub ema3_1d_data: Vec<(String, Vec)>, - pub ema3_1w_data: Vec<(String, Vec)>, - pub ema3_1mon_data: Vec<(String, Vec)>, + // pub ema10_1m_data: Vec<(String, Vec)>, + // pub ema10_30m_data: Vec<(String, Vec)>, + // pub ema10_1d_data: Vec<(String, Vec)>, + // pub ema10_1w_data: Vec<(String, Vec)>, + // pub ema10_1mon_data: Vec<(String, Vec)>, - pub ema10_1m_data: Vec<(String, Vec)>, - pub ema10_30m_data: Vec<(String, Vec)>, - pub ema10_1d_data: Vec<(String, Vec)>, - pub ema10_1w_data: Vec<(String, Vec)>, - pub ema10_1mon_data: Vec<(String, Vec)>, + // pub ema30_1m_data: Vec<(String, Vec)>, + // pub ema30_30m_data: Vec<(String, Vec)>, + // pub ema30_1d_data: Vec<(String, Vec)>, + // pub ema30_1w_data: Vec<(String, Vec)>, + // pub ema30_1mon_data: Vec<(String, Vec)>, - pub ema30_1m_data: Vec<(String, Vec)>, - pub ema30_30m_data: Vec<(String, Vec)>, - pub ema30_1d_data: Vec<(String, Vec)>, - pub ema30_1w_data: Vec<(String, Vec)>, - pub ema30_1mon_data: Vec<(String, Vec)>, + // pub rsi3_1m_data: Vec<(String, Vec)>, + // pub rsi3_30m_data: Vec<(String, Vec)>, + // pub rsi3_1d_data: Vec<(String, Vec)>, + // pub rsi3_1w_data: Vec<(String, Vec)>, + // pub rsi3_1mon_data: Vec<(String, Vec)>, - pub rsi3_1m_data: Vec<(String, Vec)>, - pub rsi3_30m_data: Vec<(String, Vec)>, - pub rsi3_1d_data: Vec<(String, Vec)>, - pub rsi3_1w_data: Vec<(String, Vec)>, - pub rsi3_1mon_data: Vec<(String, Vec)>, + // pub rsi10_1m_data: Vec<(String, Vec)>, + // pub rsi10_30m_data: Vec<(String, Vec)>, + // pub rsi10_1d_data: Vec<(String, Vec)>, + // pub rsi10_1w_data: Vec<(String, Vec)>, + // pub rsi10_1mon_data: Vec<(String, Vec)>, - pub rsi10_1m_data: Vec<(String, Vec)>, - pub rsi10_30m_data: Vec<(String, Vec)>, - pub rsi10_1d_data: Vec<(String, Vec)>, - pub rsi10_1w_data: Vec<(String, Vec)>, - pub rsi10_1mon_data: Vec<(String, Vec)>, + // pub rsi30_1m_data: Vec<(String, Vec)>, + // pub rsi30_30m_data: Vec<(String, Vec)>, + // pub rsi30_1d_data: Vec<(String, Vec)>, + // pub rsi30_1w_data: Vec<(String, Vec)>, + // pub rsi30_1mon_data: Vec<(String, Vec)>, - pub rsi30_1m_data: Vec<(String, Vec)>, - pub rsi30_30m_data: Vec<(String, Vec)>, - pub rsi30_1d_data: Vec<(String, Vec)>, - pub rsi30_1w_data: Vec<(String, Vec)>, - pub rsi30_1mon_data: Vec<(String, Vec)>, + // pub stoch_rsi3_1m_3_k_data: Vec<(String, Vec)>, + // pub stoch_rsi3_1m_3_d_data: Vec<(String, Vec)>, + // pub stoch_rsi30_1m_30_k_data: Vec<(String, Vec)>, + // pub stoch_rsi30_1m_30_d_data: Vec<(String, Vec)>, - pub stoch_rsi3_1m_3_k_data: Vec<(String, Vec)>, - pub stoch_rsi3_1m_3_d_data: Vec<(String, Vec)>, - pub stoch_rsi30_1m_30_k_data: Vec<(String, Vec)>, - pub stoch_rsi30_1m_30_d_data: Vec<(String, Vec)>, + // pub bb3_1m_data: Vec<(String, Vec)>, + // pub bb3_30m_data: Vec<(String, Vec)>, + // pub bb3_1d_data: Vec<(String, Vec)>, + // pub bb3_1w_data: Vec<(String, Vec)>, + // pub bb3_1mon_data: Vec<(String, Vec)>, - pub bb3_1m_data: Vec<(String, Vec)>, - pub bb3_30m_data: Vec<(String, Vec)>, - pub bb3_1d_data: Vec<(String, Vec)>, - pub bb3_1w_data: Vec<(String, Vec)>, - pub bb3_1mon_data: Vec<(String, Vec)>, + // pub bb10_1m_data: Vec<(String, Vec)>, + // pub bb10_30m_data: Vec<(String, Vec)>, to be deleted + // pub bb10_1d_data: Vec<(String, Vec)>, + // pub bb10_1w_data: Vec<(String, Vec)>, + // pub bb10_1mon_data: Vec<(String, Vec)>, - pub bb10_1m_data: Vec<(String, Vec)>, - pub bb10_30m_data: Vec<(String, Vec)>, - pub bb10_1d_data: Vec<(String, Vec)>, - pub bb10_1w_data: Vec<(String, Vec)>, - pub bb10_1mon_data: Vec<(String, Vec)>, - - pub bb30_1m_data: Vec<(String, Vec)>, - pub bb30_30m_data: Vec<(String, Vec)>, - pub bb30_1d_data: Vec<(String, Vec)>, - pub bb30_1w_data: Vec<(String, Vec)>, - pub bb30_1mon_data: Vec<(String, Vec)>, + // pub bb30_1m_data: Vec<(String, Vec)>, + // pub bb30_30m_data: Vec<(String, Vec)>, + // pub bb30_1d_data: Vec<(String, Vec)>, + // pub bb30_1w_data: Vec<(String, Vec)>, + // pub bb30_1mon_data: Vec<(String, Vec)>, } impl AllData { pub fn new() -> AllData { @@ -127,83 +127,82 @@ impl AllData { rt_price_1d_vec: Vec::new(), rt_price_1w_vec: Vec::new(), rt_price_1mon_vec: Vec::new(), + // sma3_1m_data: Vec::new(), + // sma3_30m_data: Vec::new(), + // sma3_1d_data: Vec::new(), + // sma3_1w_data: Vec::new(), + // sma3_1mon_data: Vec::new(), - sma3_1m_data: Vec::new(), - sma3_30m_data: Vec::new(), - sma3_1d_data: Vec::new(), - sma3_1w_data: Vec::new(), - sma3_1mon_data: Vec::new(), + // sma10_1m_data: Vec::new(), + // sma10_30m_data: Vec::new(), + // sma10_1d_data: Vec::new(), + // sma10_1w_data: Vec::new(), + // sma10_1mon_data: Vec::new(), - sma10_1m_data: Vec::new(), - sma10_30m_data: Vec::new(), - sma10_1d_data: Vec::new(), - sma10_1w_data: Vec::new(), - sma10_1mon_data: Vec::new(), + // sma30_1m_data: Vec::new(), + // sma30_30m_data: Vec::new(), + // sma30_1d_data: Vec::new(), + // sma30_1w_data: Vec::new(), + // sma30_1mon_data: Vec::new(), - sma30_1m_data: Vec::new(), - sma30_30m_data: Vec::new(), - sma30_1d_data: Vec::new(), - sma30_1w_data: Vec::new(), - sma30_1mon_data: Vec::new(), + // ema3_1m_data: Vec::new(), + // ema3_30m_data: Vec::new(), + // ema3_1d_data: Vec::new(), + // ema3_1w_data: Vec::new(), + // ema3_1mon_data: Vec::new(), - ema3_1m_data: Vec::new(), - ema3_30m_data: Vec::new(), - ema3_1d_data: Vec::new(), - ema3_1w_data: Vec::new(), - ema3_1mon_data: Vec::new(), + // ema10_1m_data: Vec::new(), + // ema10_30m_data: Vec::new(), + // ema10_1d_data: Vec::new(), + // ema10_1w_data: Vec::new(), + // ema10_1mon_data: Vec::new(), - ema10_1m_data: Vec::new(), - ema10_30m_data: Vec::new(), - ema10_1d_data: Vec::new(), - ema10_1w_data: Vec::new(), - ema10_1mon_data: Vec::new(), + // ema30_1m_data: Vec::new(), + // ema30_30m_data: Vec::new(), + // ema30_1d_data: Vec::new(), + // ema30_1w_data: Vec::new(), + // ema30_1mon_data: Vec::new(), - ema30_1m_data: Vec::new(), - ema30_30m_data: Vec::new(), - ema30_1d_data: Vec::new(), - ema30_1w_data: Vec::new(), - ema30_1mon_data: Vec::new(), + // rsi3_1m_data: Vec::new(), + // rsi3_30m_data: Vec::new(), + // rsi3_1d_data: Vec::new(), + // rsi3_1w_data: Vec::new(), + // rsi3_1mon_data: Vec::new(), - rsi3_1m_data: Vec::new(), - rsi3_30m_data: Vec::new(), - rsi3_1d_data: Vec::new(), - rsi3_1w_data: Vec::new(), - rsi3_1mon_data: Vec::new(), + // rsi10_1m_data: Vec::new(), + // rsi10_30m_data: Vec::new(), + // rsi10_1d_data: Vec::new(), + // rsi10_1w_data: Vec::new(), + // rsi10_1mon_data: Vec::new(), - rsi10_1m_data: Vec::new(), - rsi10_30m_data: Vec::new(), - rsi10_1d_data: Vec::new(), - rsi10_1w_data: Vec::new(), - rsi10_1mon_data: Vec::new(), + // rsi30_1m_data: Vec::new(), + // rsi30_30m_data: Vec::new(), + // rsi30_1d_data: Vec::new(), + // rsi30_1w_data: Vec::new(), + // rsi30_1mon_data: Vec::new(), - rsi30_1m_data: Vec::new(), - rsi30_30m_data: Vec::new(), - rsi30_1d_data: Vec::new(), - rsi30_1w_data: Vec::new(), - rsi30_1mon_data: Vec::new(), + // stoch_rsi3_1m_3_k_data: Vec::new(), + // stoch_rsi3_1m_3_d_data: Vec::new(), + // stoch_rsi30_1m_30_k_data: Vec::new(), + // stoch_rsi30_1m_30_d_data: Vec::new(), - stoch_rsi3_1m_3_k_data: Vec::new(), - stoch_rsi3_1m_3_d_data: Vec::new(), - stoch_rsi30_1m_30_k_data: Vec::new(), - stoch_rsi30_1m_30_d_data: Vec::new(), + // bb3_1m_data: Vec::new(), + // bb3_30m_data: Vec::new(), + // bb3_1d_data: Vec::new(), + // bb3_1w_data: Vec::new(), + // bb3_1mon_data: Vec::new(), - bb3_1m_data: Vec::new(), - bb3_30m_data: Vec::new(), - bb3_1d_data: Vec::new(), - bb3_1w_data: Vec::new(), - bb3_1mon_data: Vec::new(), + // bb10_1m_data: Vec::new(), + // bb10_30m_data: Vec::new(), to be deleted + // bb10_1d_data: Vec::new(), + // bb10_1w_data: Vec::new(), + // bb10_1mon_data: Vec::new(), - bb10_1m_data: Vec::new(), - bb10_30m_data: Vec::new(), - bb10_1d_data: Vec::new(), - bb10_1w_data: Vec::new(), - bb10_1mon_data: Vec::new(), - - bb30_1m_data: Vec::new(), - bb30_30m_data: Vec::new(), - bb30_1d_data: Vec::new(), - bb30_1w_data: Vec::new(), - bb30_1mon_data: Vec::new(), + // bb30_1m_data: Vec::new(), + // bb30_30m_data: Vec::new(), + // bb30_1d_data: Vec::new(), + // bb30_1w_data: Vec::new(), + // bb30_1mon_data: Vec::new(), }; a } @@ -276,7 +275,7 @@ pub async fn execute_strategists( // strategist_015(all_data).await; // strategist_016(all_data).await; - execute_strategist_for_test(all_data).await; + execute_strategist_for_test_temp(all_data).await; // execute_strategist_for_test1(all_data).await; // execute_strategist_for_test2(all_data).await; Ok(()) @@ -711,7 +710,221 @@ pub async fn execute_strategists( // Ok(()) // } -pub async fn execute_strategist_for_test( +// pub async fn execute_strategist_for_test( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // 1st filtering: supertrend(ATR period 10, multiplier: 1.3, 30m close price), the area should be in SELL area. +// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut supertrend_vec: Vec = Vec::new(); +// for symbol in &alldata.valid_symbol_vec { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let supertrend_option_30m = +// supertrend(&symbol, &alldata.rt_price_30m_vec, 10, 1.3, true).await; + +// if opclo_30m_option.is_some() && supertrend_option_30m.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// supertrend_vec = supertrend_option_30m.unwrap(); + +// if opclo_30m_vec.len() >= 3 && supertrend_vec.len() >= 3 { +// let supertrend_search_result = supertrend_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |SupertrendData { +// band_value, +// signal, +// area, +// close_time, +// }| *close_time, +// ); +// if supertrend_search_result.is_ok() { +// if supertrend_vec[supertrend_search_result.unwrap()] +// .area +// .contains("DOWN") +// { +// filtered_2nd_symbols +// .push((symbol.clone(), opclo_30m_vec.last().unwrap().close_time)); +// } +// } +// } +// } +// } + +// // 2nd filtering: lookup tables if the tradepair is already there +// let inspect_table_name_1 = String::from("buy_ordered_coin_list"); +// let inspect_table_name_2 = String::from("sell_ordered_coin_list"); +// let inspect_table_name_3 = String::from("pre_suggested_coin_list"); +// let inspect_table_name_4 = String::from("suggested_coin_list"); +// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) + +// for element in filtered_2nd_symbols { +// let mut exists_condition_build = String::from("symbol=\'"); +// exists_condition_build.push_str(element.0.as_str()); +// exists_condition_build.push_str("\' AND close_time="); +// exists_condition_build.push_str(element.1.to_string().as_str()); +// let exists_condition = Some(exists_condition_build); + +// let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; +// let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; +// let inspect_result_3 = exists_record(&inspect_table_name_3, &exists_condition).await; +// let inspect_result_4 = exists_record(&inspect_table_name_4, &exists_condition).await; + +// if inspect_result_1 == false +// && inspect_result_2 == false +// && inspect_result_3 == false +// && inspect_result_4 == false +// { +// filtered_3rd_symbols.push(element); +// } +// } + +// // 3rd filtering: BollingerBand (length 10, stddev: 3.0, 30m close price) the current price should be under the lowerband of BB. +// let mut bb10_30m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for element in filtered_3rd_symbols { +// let bb10_30m_option = alldata.bb10_30m_data.iter().position(|x| *x.0 == element.0); + +// if bb10_30m_option.is_some() { +// bb10_30m_vec = alldata.bb10_30m_data[bb10_30m_option.unwrap()].1.clone(); + +// if bb10_30m_vec.len() >= 3 { +// let bb_search_result = bb10_30m_vec.binary_search_by_key( +// &element.1, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// if bb_search_result.is_ok() { +// let current_price = get_current_price(&element.0, &alldata.price_vec) +// .await +// .unwrap(); +// if bb10_30m_vec[bb_search_result.unwrap()].lowerband > current_price { +// filtered_4th_symbols.push(element); +// } +// } +// } +// } +// } + +// // 4th filtering: RSI (length: 10, 30m close price) the current index should be lower than 30. +// let mut rsi10_30m_vec: Vec = Vec::new(); +// let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for element in filtered_4th_symbols { +// let rsi10_30m_option = alldata +// .rsi10_30m_data +// .iter() +// .position(|x| *x.0 == element.0); + +// if rsi10_30m_option.is_some() { +// rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); + +// if rsi10_30m_vec.len() >= 3 { +// let rsi_search_result = rsi10_30m_vec.binary_search_by_key( +// &element.1, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// if rsi_search_result.is_ok() { +// if rsi10_30m_vec[rsi_search_result.unwrap()].rsi_value <= 30.0 { +// filtered_5th_symbols.push(element); +// } +// } +// } +// } +// } + +// // 5th filtering: heatmap volume(MA length 10, std length 10, 30m close price), the current candle should be over than high at least. +// let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for element in filtered_5th_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == element.0); +// if opclo_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if opclo_30m_vec.len() >= 3 { +// let heatmap_volume_option = heatmap_volume( +// &element.0, +// &alldata.rt_price_30m_vec, +// 10, +// 10, +// 4.0, +// 2.5, +// 1.0, +// -0.5, +// ) +// .await; +// if heatmap_volume_option.is_some() { +// let heatmap_volume_vec = heatmap_volume_option.unwrap(); +// let heatmap_search_result = heatmap_volume_vec.binary_search_by_key( +// &element.1, +// |HeatmapVolumeData { +// heatmap_value, +// heatmap_level, +// close_time, +// }| *close_time, +// ); +// if heatmap_search_result.is_ok() { +// if heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level +// == HeatMapLevel::Medium +// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level +// == HeatMapLevel::High +// || heatmap_volume_vec[heatmap_search_result.unwrap()].heatmap_level +// == HeatMapLevel::ExtraHigh +// { +// filtered_6th_symbols.push(element); +// } +// } +// } +// } +// } +// } + +// // 6th filtering condition: MACD +// // let mut opclo_30m_vec: Vec = Vec::new(); +// // let mut ema3_1d_vec: &Vec = &Vec::new(); +// // let mut ema10_1d_vec: &Vec = &Vec::new(); + +// // let mut filtered_7th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// // for element in filtered_6th_symbols { +// // let ema3_1d_option = alldata.ema3_1d_data.iter().position(|x| *x.0 == *element.0); +// // let ema10_1d_option = alldata.ema10_1d_data.iter().position(|x| *x.0 == *element.0); + +// // if ema3_1d_option.is_some() && ema10_1d_option.is_some() { +// // ema3_1d_vec = &alldata.ema3_1d_data[ema3_1d_option.unwrap()].1; +// // ema10_1d_vec = &alldata.ema10_1d_data[ema10_1d_option.unwrap()].1; + +// // if ema3_1d_vec.len() > 20 && ema10_1d_vec.len() > 20 { +// // let macd_vec = ema_macd(&ema3_1d_vec, &ema10_1d_vec, 10).await?; +// // // let macd_search_result = macd_vec.binary_search_by_key(&element.1, |&EmaMacd{macd_value, close_time}|close_time); + +// // // if macd_search_result.is_ok() { +// // if macd_vec.last().unwrap().macd_value - macd_vec[macd_vec.len() -2].macd_value >= 0.0 { +// // filtered_7th_symbols.push(element); +// // } +// // // } +// // } +// // } +// // } + +// insert_pre_suggested_coins(1, &filtered_6th_symbols, alldata).await; + +// Ok(()) +// } + +pub async fn execute_strategist_for_test_temp( alldata: &AllData, ) -> Result<(), Box> { // 1st filtering: supertrend(ATR period 10, multiplier: 1.3, 30m close price), the area should be in SELL area. @@ -784,13 +997,31 @@ pub async fn execute_strategist_for_test( } // 3rd filtering: BollingerBand (length 10, stddev: 3.0, 30m close price) the current price should be under the lowerband of BB. + let mut sma_30m_data: Vec<(String, Vec)> = Vec::new(); + value_estimation_team::indicators::sma::sma( + 30, + &alldata.rt_price_30m_vec, + &mut sma_30m_data, + &alldata.valid_symbol_vec, + ) + .await?; + let mut bb10_30m_data: Vec<(String, Vec)> = Vec::new(); let mut bb10_30m_vec: Vec = Vec::new(); + value_estimation_team::indicators::bollingerband::bollingerband( + 10, + 3.0, + &sma_30m_data, + &alldata.rt_price_1m_vec, + &mut bb10_30m_data, + &alldata.valid_symbol_vec, + ) + .await?; let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) for element in filtered_3rd_symbols { - let bb10_30m_option = alldata.bb10_30m_data.iter().position(|x| *x.0 == element.0); + let bb10_30m_option = bb10_30m_data.iter().position(|x| *x.0 == element.0); if bb10_30m_option.is_some() { - bb10_30m_vec = alldata.bb10_30m_data[bb10_30m_option.unwrap()].1.clone(); + bb10_30m_vec = bb10_30m_data[bb10_30m_option.unwrap()].1.clone(); if bb10_30m_vec.len() >= 3 { let bb_search_result = bb10_30m_vec.binary_search_by_key( @@ -815,16 +1046,21 @@ pub async fn execute_strategist_for_test( } // 4th filtering: RSI (length: 10, 30m close price) the current index should be lower than 30. + let mut rsi10_30m_data: Vec<(String, Vec)> = Vec::new(); + value_estimation_team::indicators::rsi::rsi( + 10, + &alldata.rt_price_30m_vec, + &mut rsi10_30m_data, + &alldata.valid_symbol_vec, + ) + .await?; let mut rsi10_30m_vec: Vec = Vec::new(); let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) for element in filtered_4th_symbols { - let rsi10_30m_option = alldata - .rsi10_30m_data - .iter() - .position(|x| *x.0 == element.0); + let rsi10_30m_option = rsi10_30m_data.iter().position(|x| *x.0 == element.0); if rsi10_30m_option.is_some() { - rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); + rsi10_30m_vec = rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); if rsi10_30m_vec.len() >= 3 { let rsi_search_result = rsi10_30m_vec.binary_search_by_key( @@ -925,1314 +1161,1315 @@ pub async fn execute_strategist_for_test( Ok(()) } -pub async fn execute_strategist_for_test1( - alldata: &AllData, -) -> Result<(), Box> { - let inspect_table_name_1 = String::from("buy_ordered_coin_list"); - let inspect_table_name_2 = String::from("sell_ordered_coin_list"); - let inspect_table_name_3 = String::from("pre_suggested_coin_list"); - let inspect_table_name_4 = String::from("suggested_coin_list"); +// pub async fn execute_strategist_for_test1( +// alldata: &AllData, +// ) -> Result<(), Box> { +// let inspect_table_name_1 = String::from("buy_ordered_coin_list"); +// let inspect_table_name_2 = String::from("sell_ordered_coin_list"); +// let inspect_table_name_3 = String::from("pre_suggested_coin_list"); +// let inspect_table_name_4 = String::from("suggested_coin_list"); - let market_cap_index = select_marketcap().await; +// let market_cap_index = select_marketcap().await; - let mut filtered_symbols: Vec = Vec::new(); - // filtered_symbols.push(String::from("BNBUSDT")); - filtered_symbols.push(String::from("BTCUSDT")); - // filtered_symbols.push(String::from("ETHUSDT")); - // filtered_symbols.push(String::from("LTCUSDT")); - // filtered_symbols.push(String::from("XRPUSDT")); - // filtered_symbols.push(String::from("TRXUSDT")); - // let current_price = get_current_price(&filtered_symbols.first().unwrap(), &alldata.price_vec).await.unwrap(); +// let mut filtered_symbols: Vec = Vec::new(); +// // filtered_symbols.push(String::from("BNBUSDT")); +// filtered_symbols.push(String::from("BTCUSDT")); +// // filtered_symbols.push(String::from("ETHUSDT")); +// // filtered_symbols.push(String::from("LTCUSDT")); +// // filtered_symbols.push(String::from("XRPUSDT")); +// // filtered_symbols.push(String::from("TRXUSDT")); +// // let current_price = get_current_price(&filtered_symbols.first().unwrap(), &alldata.price_vec).await.unwrap(); - let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - let mut ema3_1m_vec: &Vec = &Vec::new(); - let mut ema3_30m_vec: &Vec = &Vec::new(); - let mut ema10_1m_vec: &Vec = &Vec::new(); - let mut ema30_1m_vec: &Vec = &Vec::new(); - let mut sma10_1m_vec: &Vec = &Vec::new(); - let mut sma3_30m_vec: &Vec = &Vec::new(); - let mut sma30_1m_vec: &Vec = &Vec::new(); - let mut rsi3_1m_vec: &Vec = &Vec::new(); - let mut rsi30_1m_vec: &Vec = &Vec::new(); - let mut stoch_rsi3_1m_k_vec: &Vec = &Vec::new(); - let mut stoch_rsi3_1m_d_vec: &Vec = &Vec::new(); - let mut stoch_rsi30_1m_k_vec: &Vec = &Vec::new(); - let mut stoch_rsi30_1m_d_vec: &Vec = &Vec::new(); - let mut rt_price_1m_vec: &Vec = &Vec::new(); - let mut is_filtering_passed: bool = false; +// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// let mut ema3_1m_vec: &Vec = &Vec::new(); +// let mut ema3_30m_vec: &Vec = &Vec::new(); +// let mut ema10_1m_vec: &Vec = &Vec::new(); +// let mut ema30_1m_vec: &Vec = &Vec::new(); +// let mut sma10_1m_vec: &Vec = &Vec::new(); +// let mut sma3_30m_vec: &Vec = &Vec::new(); +// let mut sma30_1m_vec: &Vec = &Vec::new(); +// let mut rsi3_1m_vec: &Vec = &Vec::new(); +// let mut rsi30_1m_vec: &Vec = &Vec::new(); +// let mut stoch_rsi3_1m_k_vec: &Vec = &Vec::new(); +// let mut stoch_rsi3_1m_d_vec: &Vec = &Vec::new(); +// let mut stoch_rsi30_1m_k_vec: &Vec = &Vec::new(); +// let mut stoch_rsi30_1m_d_vec: &Vec = &Vec::new(); +// let mut rt_price_1m_vec: &Vec = &Vec::new(); +// let mut is_filtering_passed: bool = false; - let mut cnt = 0; - let exists_condition = Some(String::from("used_usdt >= 10.0 AND registerer = 1")); - let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; - let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; - let mut is_buy_period_30m = false; +// let mut cnt = 0; +// let exists_condition = Some(String::from("used_usdt >= 10.0 AND registerer = 1")); +// let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; +// let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; +// let mut is_buy_period_30m = false; - if inspect_result_1 == false && inspect_result_2 == false { - for symbol in filtered_symbols { - is_filtering_passed = false; - let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); - let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); - let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); - let ema30_1m_option = alldata.ema30_1m_data.iter().position(|x| *x.0 == *symbol); - let sma10_1m_option = alldata.sma10_1m_data.iter().position(|x| *x.0 == *symbol); - let sma3_30m_option = alldata.sma3_30m_data.iter().position(|x| *x.0 == *symbol); - let sma30_1m_option = alldata.sma30_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi30_1m_option = alldata.rsi30_1m_data.iter().position(|x| *x.0 == *symbol); - let stoch_rsi3_1m_k_option = alldata - .stoch_rsi3_1m_3_k_data - .iter() - .position(|x| *x.0 == *symbol); - let stoch_rsi3_1m_d_option = alldata - .stoch_rsi3_1m_3_d_data - .iter() - .position(|x| *x.0 == *symbol); - let stoch_rsi30_1m_k_option = alldata - .stoch_rsi30_1m_30_k_data - .iter() - .position(|x| *x.0 == *symbol); - let stoch_rsi30_1m_d_option = alldata - .stoch_rsi30_1m_30_d_data - .iter() - .position(|x| *x.0 == *symbol); - let rt_price_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// if inspect_result_1 == false && inspect_result_2 == false { +// for symbol in filtered_symbols { +// is_filtering_passed = false; +// let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); +// let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); +// let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); +// let ema30_1m_option = alldata.ema30_1m_data.iter().position(|x| *x.0 == *symbol); +// let sma10_1m_option = alldata.sma10_1m_data.iter().position(|x| *x.0 == *symbol); +// let sma3_30m_option = alldata.sma3_30m_data.iter().position(|x| *x.0 == *symbol); +// let sma30_1m_option = alldata.sma30_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi30_1m_option = alldata.rsi30_1m_data.iter().position(|x| *x.0 == *symbol); +// let stoch_rsi3_1m_k_option = alldata +// .stoch_rsi3_1m_3_k_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let stoch_rsi3_1m_d_option = alldata +// .stoch_rsi3_1m_3_d_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let stoch_rsi30_1m_k_option = alldata +// .stoch_rsi30_1m_30_k_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let stoch_rsi30_1m_d_option = alldata +// .stoch_rsi30_1m_30_d_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let rt_price_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let supertrend_option_30m = - supertrend(&symbol, &alldata.rt_price_30m_vec, 3, 0.5, true).await; +// let supertrend_option_30m = +// supertrend(&symbol, &alldata.rt_price_30m_vec, 3, 0.5, true).await; - if supertrend_option_30m.is_some() { - let supertrend_vec = supertrend_option_30m.unwrap(); - if supertrend_vec.last().unwrap().area.contains("UP") { - is_buy_period_30m = true; - } - } +// if supertrend_option_30m.is_some() { +// let supertrend_vec = supertrend_option_30m.unwrap(); +// if supertrend_vec.last().unwrap().area.contains("UP") { +// is_buy_period_30m = true; +// } +// } - if is_buy_period_30m == true - && ema3_1m_option.is_some() - && ema3_30m_option.is_some() - && ema10_1m_option.is_some() - && ema30_1m_option.is_some() - && sma10_1m_option.is_some() - && sma3_30m_option.is_some() - && sma30_1m_option.is_some() - && rsi3_1m_option.is_some() - && rsi30_1m_option.is_some() - && stoch_rsi3_1m_k_option.is_some() - && stoch_rsi3_1m_d_option.is_some() - && stoch_rsi30_1m_k_option.is_some() - && stoch_rsi30_1m_d_option.is_some() - && rt_price_1m_option.is_some() - { - ema3_1m_vec = &alldata.ema3_1m_data[ema3_1m_option.unwrap()].1; - ema3_30m_vec = &alldata.ema3_30m_data[ema3_30m_option.unwrap()].1; - ema10_1m_vec = &alldata.ema10_1m_data[ema10_1m_option.unwrap()].1; - ema30_1m_vec = &alldata.ema30_1m_data[ema30_1m_option.unwrap()].1; - sma10_1m_vec = &alldata.sma10_1m_data[sma10_1m_option.unwrap()].1; - sma3_30m_vec = &alldata.sma3_30m_data[sma3_30m_option.unwrap()].1; - sma30_1m_vec = &alldata.sma30_1m_data[sma30_1m_option.unwrap()].1; - rsi3_1m_vec = &alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1; - rsi30_1m_vec = &alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1; - stoch_rsi3_1m_k_vec = - &alldata.stoch_rsi3_1m_3_k_data[stoch_rsi3_1m_k_option.unwrap()].1; - stoch_rsi3_1m_d_vec = - &alldata.stoch_rsi3_1m_3_d_data[stoch_rsi3_1m_d_option.unwrap()].1; - stoch_rsi30_1m_k_vec = - &alldata.stoch_rsi30_1m_30_k_data[stoch_rsi30_1m_k_option.unwrap()].1; - stoch_rsi30_1m_d_vec = - &alldata.stoch_rsi30_1m_30_d_data[stoch_rsi30_1m_d_option.unwrap()].1; - rt_price_1m_vec = &alldata.rt_price_1m_vec[rt_price_1m_option.unwrap()].1; +// if is_buy_period_30m == true +// && ema3_1m_option.is_some() +// && ema3_30m_option.is_some() +// && ema10_1m_option.is_some() +// && ema30_1m_option.is_some() +// && sma10_1m_option.is_some() +// && sma3_30m_option.is_some() +// && sma30_1m_option.is_some() +// && rsi3_1m_option.is_some() +// && rsi30_1m_option.is_some() +// && stoch_rsi3_1m_k_option.is_some() +// && stoch_rsi3_1m_d_option.is_some() +// && stoch_rsi30_1m_k_option.is_some() +// && stoch_rsi30_1m_d_option.is_some() +// && rt_price_1m_option.is_some() +// { +// ema3_1m_vec = &alldata.ema3_1m_data[ema3_1m_option.unwrap()].1; +// ema3_30m_vec = &alldata.ema3_30m_data[ema3_30m_option.unwrap()].1; +// ema10_1m_vec = &alldata.ema10_1m_data[ema10_1m_option.unwrap()].1; +// ema30_1m_vec = &alldata.ema30_1m_data[ema30_1m_option.unwrap()].1; +// sma10_1m_vec = &alldata.sma10_1m_data[sma10_1m_option.unwrap()].1; +// sma3_30m_vec = &alldata.sma3_30m_data[sma3_30m_option.unwrap()].1; +// sma30_1m_vec = &alldata.sma30_1m_data[sma30_1m_option.unwrap()].1; +// rsi3_1m_vec = &alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1; +// rsi30_1m_vec = &alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1; +// stoch_rsi3_1m_k_vec = +// &alldata.stoch_rsi3_1m_3_k_data[stoch_rsi3_1m_k_option.unwrap()].1; +// stoch_rsi3_1m_d_vec = +// &alldata.stoch_rsi3_1m_3_d_data[stoch_rsi3_1m_d_option.unwrap()].1; +// stoch_rsi30_1m_k_vec = +// &alldata.stoch_rsi30_1m_30_k_data[stoch_rsi30_1m_k_option.unwrap()].1; +// stoch_rsi30_1m_d_vec = +// &alldata.stoch_rsi30_1m_30_d_data[stoch_rsi30_1m_d_option.unwrap()].1; +// rt_price_1m_vec = &alldata.rt_price_1m_vec[rt_price_1m_option.unwrap()].1; - // filtering condition: data are ready - if ema3_1m_vec.len() >= 3 - && ema3_30m_vec.len() >= 3 - && ema10_1m_vec.len() >= 3 - && ema30_1m_vec.len() >= 3 - && sma10_1m_vec.len() >= 3 - && sma3_30m_vec.len() >= 3 - && sma30_1m_vec.len() >= 3 - && rsi3_1m_vec.len() >= 3 - && rsi30_1m_vec.len() >= 3 - && stoch_rsi3_1m_k_vec.len() >= 5 - && stoch_rsi3_1m_d_vec.len() >= 5 - && stoch_rsi30_1m_k_vec.len() >= 5 - && stoch_rsi30_1m_d_vec.len() >= 5 - && rt_price_1m_vec.len() >= 50 - { - is_filtering_passed = true; - } +// // filtering condition: data are ready +// if ema3_1m_vec.len() >= 3 +// && ema3_30m_vec.len() >= 3 +// && ema10_1m_vec.len() >= 3 +// && ema30_1m_vec.len() >= 3 +// && sma10_1m_vec.len() >= 3 +// && sma3_30m_vec.len() >= 3 +// && sma30_1m_vec.len() >= 3 +// && rsi3_1m_vec.len() >= 3 +// && rsi30_1m_vec.len() >= 3 +// && stoch_rsi3_1m_k_vec.len() >= 5 +// && stoch_rsi3_1m_d_vec.len() >= 5 +// && stoch_rsi30_1m_k_vec.len() >= 5 +// && stoch_rsi30_1m_d_vec.len() >= 5 +// && rt_price_1m_vec.len() >= 50 +// { +// is_filtering_passed = true; +// } - // // filtering condition: SuperTrend & EMA & SMA - // if is_filtering_passed == true { - // let supertrend_option = supertrend(&symbol, &alldata.rt_price_1m_vec, 10, 1.0, false).await; - // if supertrend_option.is_some() { - // let supertrend_vec = supertrend_option.unwrap(); - // let supertrend_result = supertrend_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |SupertrendData{band_value, signal, area, close_time}| *close_time); - // let ema3_result = ema3_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); - // let sma10_result = sma10_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&SmaData{sma_value, close_time}|close_time); +// // // filtering condition: SuperTrend & EMA & SMA +// // if is_filtering_passed == true { +// // let supertrend_option = supertrend(&symbol, &alldata.rt_price_1m_vec, 10, 1.0, false).await; +// // if supertrend_option.is_some() { +// // let supertrend_vec = supertrend_option.unwrap(); +// // let supertrend_result = supertrend_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |SupertrendData{band_value, signal, area, close_time}| *close_time); +// // let ema3_result = ema3_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); +// // let sma10_result = sma10_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&SmaData{sma_value, close_time}|close_time); - // if supertrend_vec.last().unwrap().signal.is_some() && ema3_result.is_ok() && sma10_result.is_ok() { - // if (((supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) && rt_price_1m_vec.last().unwrap().close_price <= supertrend_vec[supertrend_vec.len()-2].band_value * 1.0005) - // || (supertrend_vec.last().unwrap().area.contains("UP") && ema3_1m_vec[ema3_result.unwrap()-1].ema_value < sma10_1m_vec[sma10_result.unwrap()-1].sma_value && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value)) - // && sma10_1m_vec[sma10_result.unwrap()-2].sma_value < sma10_1m_vec[sma10_result.unwrap()].sma_value { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } else { is_filtering_passed = false; } - // } else { is_filtering_passed = false; } - // } +// // if supertrend_vec.last().unwrap().signal.is_some() && ema3_result.is_ok() && sma10_result.is_ok() { +// // if (((supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) && rt_price_1m_vec.last().unwrap().close_price <= supertrend_vec[supertrend_vec.len()-2].band_value * 1.0005) +// // || (supertrend_vec.last().unwrap().area.contains("UP") && ema3_1m_vec[ema3_result.unwrap()-1].ema_value < sma10_1m_vec[sma10_result.unwrap()-1].sma_value && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value)) +// // && sma10_1m_vec[sma10_result.unwrap()-2].sma_value < sma10_1m_vec[sma10_result.unwrap()].sma_value { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } else { is_filtering_passed = false; } +// // } else { is_filtering_passed = false; } +// // } - // filtering condition: SuperTrend - if is_filtering_passed == true { - let supertrend_option = - supertrend(&symbol, &alldata.rt_price_1m_vec, 30, 1.5, false).await; - if supertrend_option.is_some() { - let supertrend_vec = supertrend_option.unwrap(); - let supertrend_result = supertrend_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |SupertrendData { - band_value, - signal, - area, - close_time, - }| *close_time, - ); +// // filtering condition: SuperTrend +// if is_filtering_passed == true { +// let supertrend_option = +// supertrend(&symbol, &alldata.rt_price_1m_vec, 30, 1.5, false).await; +// if supertrend_option.is_some() { +// let supertrend_vec = supertrend_option.unwrap(); +// let supertrend_result = supertrend_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |SupertrendData { +// band_value, +// signal, +// area, +// close_time, +// }| *close_time, +// ); - if supertrend_result.is_ok() { - if supertrend_vec[supertrend_result.unwrap()] - .signal - .as_ref() - .is_some() - { - if supertrend_vec[supertrend_result.unwrap()] - .signal - .as_ref() - .unwrap() - .contains("BUY") - && supertrend_vec[supertrend_result.unwrap() - 1].band_value - + ((rt_price_1m_vec[rt_price_1m_vec.len() - 2].high_price - - rt_price_1m_vec[rt_price_1m_vec.len() - 2].low_price) - * 0.1) - > rt_price_1m_vec.last().unwrap().close_price - { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// if supertrend_result.is_ok() { +// if supertrend_vec[supertrend_result.unwrap()] +// .signal +// .as_ref() +// .is_some() +// { +// if supertrend_vec[supertrend_result.unwrap()] +// .signal +// .as_ref() +// .unwrap() +// .contains("BUY") +// && supertrend_vec[supertrend_result.unwrap() - 1].band_value +// + ((rt_price_1m_vec[rt_price_1m_vec.len() - 2].high_price +// - rt_price_1m_vec[rt_price_1m_vec.len() - 2].low_price) +// * 0.1) +// > rt_price_1m_vec.last().unwrap().close_price +// { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: SMA & EMA - if is_filtering_passed == true { - let sma10_1m_result = sma10_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - let sma30_1m_result = sma30_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - let ema3_1m_result = ema3_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - let ema3_30m_result = ema3_30m_vec.binary_search_by_key( - &sma3_30m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - let ema10_1m_result = ema10_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - let ema30_1m_result = ema30_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - if sma10_1m_result.is_ok() - && sma30_1m_result.is_ok() - && ema3_1m_result.is_ok() - && ema10_1m_result.is_ok() - && ema30_1m_result.is_ok() - && ema3_30m_result.is_ok() - { - if ema3_1m_vec[ema3_1m_result.unwrap()].ema_value - >= ema10_1m_vec[ema10_1m_result.unwrap()].ema_value - { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// // filtering condition: SMA & EMA +// if is_filtering_passed == true { +// let sma10_1m_result = sma10_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// let sma30_1m_result = sma30_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// let ema3_1m_result = ema3_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// let ema3_30m_result = ema3_30m_vec.binary_search_by_key( +// &sma3_30m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// let ema10_1m_result = ema10_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// let ema30_1m_result = ema30_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// if sma10_1m_result.is_ok() +// && sma30_1m_result.is_ok() +// && ema3_1m_result.is_ok() +// && ema10_1m_result.is_ok() +// && ema30_1m_result.is_ok() +// && ema3_30m_result.is_ok() +// { +// if ema3_1m_vec[ema3_1m_result.unwrap()].ema_value +// >= ema10_1m_vec[ema10_1m_result.unwrap()].ema_value +// { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: current price limitation - // if is_filtering_passed == true { - // if rt_price_1m_vec[rt_price_1m_vec.len()-2].close_price + ((rt_price_1m_vec[rt_price_1m_vec.len()-2].high_price - rt_price_1m_vec[rt_price_1m_vec.len()-2].low_price) * 0.1) > rt_price_1m_vec.last().unwrap().close_price { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } +// // filtering condition: current price limitation +// // if is_filtering_passed == true { +// // if rt_price_1m_vec[rt_price_1m_vec.len()-2].close_price + ((rt_price_1m_vec[rt_price_1m_vec.len()-2].high_price - rt_price_1m_vec[rt_price_1m_vec.len()-2].low_price) * 0.1) > rt_price_1m_vec.last().unwrap().close_price { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } - // filtering condition: Heatmap Volume - // if is_filtering_passed == true { - // let heatmap_volume_option = heatmap_volume(&symbol, &alldata.rt_price_1m_vec, 30, 30, 4.0, 2.5, 1.0, -0.5).await; - // if heatmap_volume_option.is_some() { - // let heatmap_volume_vec = heatmap_volume_option.unwrap(); - // let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |HeatmapVolumeData{heatmap_value, heatmap_level, close_time}|*close_time); - // if heatmap_search_result.is_ok() { - // let heatmap_volume_trunc_vec_option = heatmap_volume_vec.get(heatmap_search_result.unwrap()-11..heatmap_search_result.unwrap()-1); - // if heatmap_volume_trunc_vec_option.is_some() { - // let heatmap_volume_trunc_vec = heatmap_volume_trunc_vec_option.unwrap(); - // let mut heat_value_summation = 0.0; - // for element in heatmap_volume_trunc_vec { - // if element.heatmap_level == HeatMapLevel::ExtraHigh { - // heat_value_summation += 2.0; - // } else if element.heatmap_level == HeatMapLevel::High { - // heat_value_summation += 1.5; - // } else if element.heatmap_level == HeatMapLevel::Medium { - // heat_value_summation += 1.0; - // } else if element.heatmap_level == HeatMapLevel::Normal { - // heat_value_summation += 0.5; - // } else { - // heat_value_summation += 0.0; - // } - // } - // if heat_value_summation >= 2.0 { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } - // } - // } else { is_filtering_passed = false; } - // } +// // filtering condition: Heatmap Volume +// // if is_filtering_passed == true { +// // let heatmap_volume_option = heatmap_volume(&symbol, &alldata.rt_price_1m_vec, 30, 30, 4.0, 2.5, 1.0, -0.5).await; +// // if heatmap_volume_option.is_some() { +// // let heatmap_volume_vec = heatmap_volume_option.unwrap(); +// // let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |HeatmapVolumeData{heatmap_value, heatmap_level, close_time}|*close_time); +// // if heatmap_search_result.is_ok() { +// // let heatmap_volume_trunc_vec_option = heatmap_volume_vec.get(heatmap_search_result.unwrap()-11..heatmap_search_result.unwrap()-1); +// // if heatmap_volume_trunc_vec_option.is_some() { +// // let heatmap_volume_trunc_vec = heatmap_volume_trunc_vec_option.unwrap(); +// // let mut heat_value_summation = 0.0; +// // for element in heatmap_volume_trunc_vec { +// // if element.heatmap_level == HeatMapLevel::ExtraHigh { +// // heat_value_summation += 2.0; +// // } else if element.heatmap_level == HeatMapLevel::High { +// // heat_value_summation += 1.5; +// // } else if element.heatmap_level == HeatMapLevel::Medium { +// // heat_value_summation += 1.0; +// // } else if element.heatmap_level == HeatMapLevel::Normal { +// // heat_value_summation += 0.5; +// // } else { +// // heat_value_summation += 0.0; +// // } +// // } +// // if heat_value_summation >= 2.0 { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } +// // } +// // } else { is_filtering_passed = false; } +// // } - // filtering condition: Stoch RSI - if is_filtering_passed == true { - // let sample_length: usize = 5; - // stoch_rsi10_1m_k_vec.reverse(); - // stoch_rsi10_1m_k_vec.truncate(5); - // stoch_rsi10_1m_k_vec.reverse(); - // stoch_rsi10_1m_d_vec.reverse(); - // stoch_rsi10_1m_d_vec.truncate(5); - // stoch_rsi10_1m_d_vec.reverse(); - let rsi3_k_result = stoch_rsi3_1m_k_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&StochRsiKData { - stoch_rsi_k_value, - close_time, - }| close_time, - ); - let rsi3_d_result = stoch_rsi3_1m_d_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&StochRsiDData { - stoch_rsi_d_value, - close_time, - }| close_time, - ); - let rsi30_k_result = stoch_rsi30_1m_k_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&StochRsiKData { - stoch_rsi_k_value, - close_time, - }| close_time, - ); - let rsi30_d_result = stoch_rsi30_1m_d_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&StochRsiDData { - stoch_rsi_d_value, - close_time, - }| close_time, - ); - if rsi30_k_result.is_ok() - && rsi30_d_result.is_ok() - && rsi3_k_result.is_ok() - && rsi3_d_result.is_ok() - { - if stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value - >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value - && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap() - 1].stoch_rsi_k_value - >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap() - 1] - .stoch_rsi_d_value - && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value - <= 50.0 - // (stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value - // && stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value > stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - // || - // && (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= 60.0 - // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-2].stoch_rsi_k_value >= stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value - // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi3_1m_d_vec[rsi3_d_result.unwrap()-1].stoch_rsi_d_value - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value) - // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - // || (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 - // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// // filtering condition: Stoch RSI +// if is_filtering_passed == true { +// // let sample_length: usize = 5; +// // stoch_rsi10_1m_k_vec.reverse(); +// // stoch_rsi10_1m_k_vec.truncate(5); +// // stoch_rsi10_1m_k_vec.reverse(); +// // stoch_rsi10_1m_d_vec.reverse(); +// // stoch_rsi10_1m_d_vec.truncate(5); +// // stoch_rsi10_1m_d_vec.reverse(); +// let rsi3_k_result = stoch_rsi3_1m_k_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&StochRsiKData { +// stoch_rsi_k_value, +// close_time, +// }| close_time, +// ); +// let rsi3_d_result = stoch_rsi3_1m_d_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&StochRsiDData { +// stoch_rsi_d_value, +// close_time, +// }| close_time, +// ); +// let rsi30_k_result = stoch_rsi30_1m_k_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&StochRsiKData { +// stoch_rsi_k_value, +// close_time, +// }| close_time, +// ); +// let rsi30_d_result = stoch_rsi30_1m_d_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&StochRsiDData { +// stoch_rsi_d_value, +// close_time, +// }| close_time, +// ); +// if rsi30_k_result.is_ok() +// && rsi30_d_result.is_ok() +// && rsi3_k_result.is_ok() +// && rsi3_d_result.is_ok() +// { +// if stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value +// >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value +// && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap() - 1].stoch_rsi_k_value +// >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap() - 1] +// .stoch_rsi_d_value +// && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value +// <= 50.0 +// // (stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value +// // && stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value > stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// // || +// // && (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= 60.0 +// // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-2].stoch_rsi_k_value >= stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value +// // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi3_1m_d_vec[rsi3_d_result.unwrap()-1].stoch_rsi_d_value +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value) +// // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// // || (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 +// // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: MACD - if is_filtering_passed == true { - let macd_vec = ema_macd(&ema3_1m_vec, &ema10_1m_vec, 10).await?; - let macd_search_result = macd_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaMacd { - macd_value, - close_time, - }| close_time, - ); +// // filtering condition: MACD +// if is_filtering_passed == true { +// let macd_vec = ema_macd(&ema3_1m_vec, &ema10_1m_vec, 10).await?; +// let macd_search_result = macd_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaMacd { +// macd_value, +// close_time, +// }| close_time, +// ); - if macd_search_result.is_ok() { - if macd_vec[macd_search_result.unwrap()].macd_value - > macd_vec[macd_search_result.unwrap() - 1].macd_value - { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// if macd_search_result.is_ok() { +// if macd_vec[macd_search_result.unwrap()].macd_value +// > macd_vec[macd_search_result.unwrap() - 1].macd_value +// { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: Ratio between amplitude and body of candles - if is_filtering_passed == true { - let sample_length: usize = 5; // 5 candle samsples - let rt_price_1m_partial_vec_option = rt_price_1m_vec - .get(rt_price_1m_vec.len() - sample_length - 1..rt_price_1m_vec.len() - 1); - if rt_price_1m_partial_vec_option.is_some() { - let rt_price_1m_partial_vec = rt_price_1m_partial_vec_option.unwrap(); +// // filtering condition: Ratio between amplitude and body of candles +// if is_filtering_passed == true { +// let sample_length: usize = 5; // 5 candle samsples +// let rt_price_1m_partial_vec_option = rt_price_1m_vec +// .get(rt_price_1m_vec.len() - sample_length - 1..rt_price_1m_vec.len() - 1); +// if rt_price_1m_partial_vec_option.is_some() { +// let rt_price_1m_partial_vec = rt_price_1m_partial_vec_option.unwrap(); - let mut sum_ratio_amp_body = 0.0; - for element in rt_price_1m_partial_vec { - sum_ratio_amp_body += (element.close_price - element.open_price).abs() - / (element.high_price - element.low_price); - } - let average_ratio_amp_body = sum_ratio_amp_body / sample_length as f64; - if average_ratio_amp_body > 0.3 { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// let mut sum_ratio_amp_body = 0.0; +// for element in rt_price_1m_partial_vec { +// sum_ratio_amp_body += (element.close_price - element.open_price).abs() +// / (element.high_price - element.low_price); +// } +// let average_ratio_amp_body = sum_ratio_amp_body / sample_length as f64; +// if average_ratio_amp_body > 0.3 { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // check all filterings are passed - if is_filtering_passed == true { - filtered_2nd_symbols.push((symbol, rt_price_1m_vec.last().unwrap().close_time)); - } +// // check all filterings are passed +// if is_filtering_passed == true { +// filtered_2nd_symbols.push((symbol, rt_price_1m_vec.last().unwrap().close_time)); +// } - // if ema3_1m_vec.len() >= 3 && ema10_1m_vec.len() >= 3 && ema30_1m_vec.len() >= 3 && sma10_1m_vec.len() >= 3 && rsi3_1m_vec.len() >= 3 && stoch_rsi10_1m_k_vec.len() >= 5 && stoch_rsi10_1m_d_vec.len() >= 5 && stoch_rsi30_1m_k_vec.len() >= 5 && stoch_rsi30_1m_d_vec.len() >= 5 && rt_price_1m_vec.len() >= 10 { - // stoch_rsi10_1m_k_vec.reverse(); - // stoch_rsi10_1m_k_vec.truncate(5); - // stoch_rsi10_1m_k_vec.reverse(); - // stoch_rsi10_1m_d_vec.reverse(); - // stoch_rsi10_1m_d_vec.truncate(5); - // stoch_rsi10_1m_d_vec.reverse(); - // stoch_rsi30_1m_k_vec.reverse(); - // stoch_rsi30_1m_k_vec.truncate(5); - // stoch_rsi30_1m_k_vec.reverse(); - // stoch_rsi30_1m_d_vec.reverse(); - // stoch_rsi30_1m_d_vec.truncate(5); - // stoch_rsi30_1m_d_vec.reverse(); - // let supertrend_option = supertrend(&symbol, &alldata.rt_price_1m_vec, 10, 1.0, false).await; - // let heatmap_volume_option = heatmap_volume(&symbol, &alldata.rt_price_1m_vec, 30, 30, 4.0, 2.5, 1.0, -0.5).await; - // let macd_vec = ema_macd(&ema10_1m_vec, &ema30_1m_vec, 30).await?; +// // if ema3_1m_vec.len() >= 3 && ema10_1m_vec.len() >= 3 && ema30_1m_vec.len() >= 3 && sma10_1m_vec.len() >= 3 && rsi3_1m_vec.len() >= 3 && stoch_rsi10_1m_k_vec.len() >= 5 && stoch_rsi10_1m_d_vec.len() >= 5 && stoch_rsi30_1m_k_vec.len() >= 5 && stoch_rsi30_1m_d_vec.len() >= 5 && rt_price_1m_vec.len() >= 10 { +// // stoch_rsi10_1m_k_vec.reverse(); +// // stoch_rsi10_1m_k_vec.truncate(5); +// // stoch_rsi10_1m_k_vec.reverse(); +// // stoch_rsi10_1m_d_vec.reverse(); +// // stoch_rsi10_1m_d_vec.truncate(5); +// // stoch_rsi10_1m_d_vec.reverse(); +// // stoch_rsi30_1m_k_vec.reverse(); +// // stoch_rsi30_1m_k_vec.truncate(5); +// // stoch_rsi30_1m_k_vec.reverse(); +// // stoch_rsi30_1m_d_vec.reverse(); +// // stoch_rsi30_1m_d_vec.truncate(5); +// // stoch_rsi30_1m_d_vec.reverse(); +// // let supertrend_option = supertrend(&symbol, &alldata.rt_price_1m_vec, 10, 1.0, false).await; +// // let heatmap_volume_option = heatmap_volume(&symbol, &alldata.rt_price_1m_vec, 30, 30, 4.0, 2.5, 1.0, -0.5).await; +// // let macd_vec = ema_macd(&ema10_1m_vec, &ema30_1m_vec, 30).await?; - // if supertrend_option.is_some() && heatmap_volume_option.is_some() { - // let supertrend_vec = supertrend_option.unwrap(); - // let heatmap_volume_vec = heatmap_volume_option.unwrap(); - // let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |HeatmapVolumeData{heatmap_value, heatmap_level, close_time}|*close_time); - // let macd_search_result = macd_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaMacd{macd_value, close_time}|close_time); - // let ema3_result = ema3_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); - // let ema10_result = ema10_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); - // let ema30_result = ema30_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); - // let sma10_result = sma10_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&SmaData{sma_value, close_time}|close_time); +// // if supertrend_option.is_some() && heatmap_volume_option.is_some() { +// // let supertrend_vec = supertrend_option.unwrap(); +// // let heatmap_volume_vec = heatmap_volume_option.unwrap(); +// // let heatmap_search_result = heatmap_volume_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |HeatmapVolumeData{heatmap_value, heatmap_level, close_time}|*close_time); +// // let macd_search_result = macd_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaMacd{macd_value, close_time}|close_time); +// // let ema3_result = ema3_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); +// // let ema10_result = ema10_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); +// // let ema30_result = ema30_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); +// // let sma10_result = sma10_1m_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&SmaData{sma_value, close_time}|close_time); - // if supertrend_vec.last().unwrap().signal.is_some() && heatmap_search_result.is_ok() && macd_search_result.is_ok() && ema3_result.is_ok() && ema10_result.is_ok() && ema30_result.is_ok() && sma10_result.is_ok() { - // // if supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") - // // && macd_vec[macd_search_result.unwrap()].macd_value > macd_vec[macd_search_result.unwrap()-1].macd_value { - // // { - // if ((supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) && current_price <= supertrend_vec[supertrend_vec.len()-2].band_value * 1.0005) - // || (supertrend_vec.last().unwrap().area.contains("UP") && ema3_1m_vec[ema3_result.unwrap()-1].ema_value < sma10_1m_vec[sma10_result.unwrap()-1].sma_value && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) - // // && current_price >= ema30_1m_vec[ema30_result.unwrap()].ema_value - // // && ema10_1m_vec[ema10_result.unwrap()-1].ema_value < ema10_1m_vec[ema10_result.unwrap()].ema_value +// // if supertrend_vec.last().unwrap().signal.is_some() && heatmap_search_result.is_ok() && macd_search_result.is_ok() && ema3_result.is_ok() && ema10_result.is_ok() && ema30_result.is_ok() && sma10_result.is_ok() { +// // // if supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") +// // // && macd_vec[macd_search_result.unwrap()].macd_value > macd_vec[macd_search_result.unwrap()-1].macd_value { +// // // { +// // if ((supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) && current_price <= supertrend_vec[supertrend_vec.len()-2].band_value * 1.0005) +// // || (supertrend_vec.last().unwrap().area.contains("UP") && ema3_1m_vec[ema3_result.unwrap()-1].ema_value < sma10_1m_vec[sma10_result.unwrap()-1].sma_value && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) +// // // && current_price >= ema30_1m_vec[ema30_result.unwrap()].ema_value +// // // && ema10_1m_vec[ema10_result.unwrap()-1].ema_value < ema10_1m_vec[ema10_result.unwrap()].ema_value - // // && ema10_1m_vec[ema10_result.unwrap()].ema_value >= ema30_1m_vec[ema30_result.unwrap()].ema_value - // { - // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // if k_result.is_ok() && d_result.is_ok() { - // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value { - // let heatmap_volume_trunc_vec_option = heatmap_volume_vec.get(heatmap_search_result.unwrap()-11..heatmap_search_result.unwrap()-1); - // if heatmap_volume_trunc_vec_option.is_some() { - // let heatmap_volume_trunc_vec = heatmap_volume_trunc_vec_option.unwrap(); - // let mut heat_value_summation = 0.0; - // for element in heatmap_volume_trunc_vec { - // if element.heatmap_level == HeatMapLevel::ExtraHigh { - // heat_value_summation += 2.0; - // } else if element.heatmap_level == HeatMapLevel::High { - // heat_value_summation += 1.5; - // } else if element.heatmap_level == HeatMapLevel::Medium { - // heat_value_summation += 1.0; - // } else if element.heatmap_level == HeatMapLevel::Normal { - // heat_value_summation += 0.5; - // } else { - // heat_value_summation += 0.0; - // } - // } - // if heat_value_summation >= 3.0 { - // filtered_2nd_symbols.push((symbol, supertrend_vec.last().unwrap().close_time)); - // } - // } - // } - // } - // } - // // } - // } - // } - // // if macd_search_result.is_ok() { - // // if macd_vec[macd_search_result.unwrap()].macd_value > 0.0 { - // // //check duplicate records - // // let mut exists_condition_build = String::from("symbol=\'"); - // // exists_condition_build.push_str(symbol.as_str()); - // // exists_condition_build.push_str("\' AND close_time="); - // // exists_condition_build.push_str(opclo_1m_vec.last().unwrap().close_time.to_string().as_str()); - // // let exists_condition = Some(exists_condition_build); +// // // && ema10_1m_vec[ema10_result.unwrap()].ema_value >= ema30_1m_vec[ema30_result.unwrap()].ema_value +// // { +// // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&supertrend_vec.last().unwrap().close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // if k_result.is_ok() && d_result.is_ok() { +// // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value { +// // let heatmap_volume_trunc_vec_option = heatmap_volume_vec.get(heatmap_search_result.unwrap()-11..heatmap_search_result.unwrap()-1); +// // if heatmap_volume_trunc_vec_option.is_some() { +// // let heatmap_volume_trunc_vec = heatmap_volume_trunc_vec_option.unwrap(); +// // let mut heat_value_summation = 0.0; +// // for element in heatmap_volume_trunc_vec { +// // if element.heatmap_level == HeatMapLevel::ExtraHigh { +// // heat_value_summation += 2.0; +// // } else if element.heatmap_level == HeatMapLevel::High { +// // heat_value_summation += 1.5; +// // } else if element.heatmap_level == HeatMapLevel::Medium { +// // heat_value_summation += 1.0; +// // } else if element.heatmap_level == HeatMapLevel::Normal { +// // heat_value_summation += 0.5; +// // } else { +// // heat_value_summation += 0.0; +// // } +// // } +// // if heat_value_summation >= 3.0 { +// // filtered_2nd_symbols.push((symbol, supertrend_vec.last().unwrap().close_time)); +// // } +// // } +// // } +// // } +// // } +// // // } +// // } +// // } +// // // if macd_search_result.is_ok() { +// // // if macd_vec[macd_search_result.unwrap()].macd_value > 0.0 { +// // // //check duplicate records +// // // let mut exists_condition_build = String::from("symbol=\'"); +// // // exists_condition_build.push_str(symbol.as_str()); +// // // exists_condition_build.push_str("\' AND close_time="); +// // // exists_condition_build.push_str(opclo_1m_vec.last().unwrap().close_time.to_string().as_str()); +// // // let exists_condition = Some(exists_condition_build); - // // let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; - // // let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; - // // let inspect_result_3 = exists_record(&inspect_table_name_3, &exists_condition).await; - // // let inspect_result_4 = exists_record(&inspect_table_name_4, &exists_condition).await; +// // // let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; +// // // let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; +// // // let inspect_result_3 = exists_record(&inspect_table_name_3, &exists_condition).await; +// // // let inspect_result_4 = exists_record(&inspect_table_name_4, &exists_condition).await; - // // if inspect_result_1 == false && inspect_result_2 == false && inspect_result_3 == false && inspect_result_4 == false { - // // let mut sum_stoch_rsi30_1m_k = 0.0; - // // for element in &stoch_rsi30_1m_k_vec { - // // sum_stoch_rsi30_1m_k += element.stoch_rsi_k_value; - // // } - // // let average_stoch_rsi30_1m_k = sum_stoch_rsi30_1m_k / 5.0; +// // // if inspect_result_1 == false && inspect_result_2 == false && inspect_result_3 == false && inspect_result_4 == false { +// // // let mut sum_stoch_rsi30_1m_k = 0.0; +// // // for element in &stoch_rsi30_1m_k_vec { +// // // sum_stoch_rsi30_1m_k += element.stoch_rsi_k_value; +// // // } +// // // let average_stoch_rsi30_1m_k = sum_stoch_rsi30_1m_k / 5.0; - // // let ema3_3_result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&EmaData{ema_value, close_time}|close_time); - // // let ema3_2_result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&EmaData{ema_value, close_time}|close_time); - // // let ema3_1_result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[0].close_time, |&EmaData{ema_value, close_time}|close_time); - // // let ema10_result = ema10_1m_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&EmaData{ema_value, close_time}|close_time); - // // let sma10_result = sma10_1m_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&SmaData{sma_value, close_time}|close_time); - // // if ema3_3_result.is_ok() && ema3_2_result.is_ok() && ema3_1_result.is_ok() && ema10_result.is_ok() && sma10_result.is_ok() { - // // if sma10_1m_vec[sma10_result.unwrap()].sma_value < ema3_1m_vec[ema3_3_result.unwrap()].ema_value { - // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // // if k_result.is_ok() && k_prev_result.is_ok() { - // // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value - // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value > 5.0 - // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value < 80.0 - // // && stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value < 96.0 - // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value > 5.0 { - // // if current_price <= opclo_1m_vec[1].opclo_price * ((((opclo_1m_vec[1].high_price / opclo_1m_vec[1].low_price) - 1.0) / 2.0) + 1.0) { - // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // } - // // } - // // } - // // } +// // // let ema3_3_result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&EmaData{ema_value, close_time}|close_time); +// // // let ema3_2_result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&EmaData{ema_value, close_time}|close_time); +// // // let ema3_1_result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[0].close_time, |&EmaData{ema_value, close_time}|close_time); +// // // let ema10_result = ema10_1m_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&EmaData{ema_value, close_time}|close_time); +// // // let sma10_result = sma10_1m_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&SmaData{sma_value, close_time}|close_time); +// // // if ema3_3_result.is_ok() && ema3_2_result.is_ok() && ema3_1_result.is_ok() && ema10_result.is_ok() && sma10_result.is_ok() { +// // // if sma10_1m_vec[sma10_result.unwrap()].sma_value < ema3_1m_vec[ema3_3_result.unwrap()].ema_value { +// // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // // if k_result.is_ok() && k_prev_result.is_ok() { +// // // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value +// // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value > 5.0 +// // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value < 80.0 +// // // && stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value < 96.0 +// // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value > 5.0 { +// // // if current_price <= opclo_1m_vec[1].opclo_price * ((((opclo_1m_vec[1].high_price / opclo_1m_vec[1].low_price) - 1.0) / 2.0) + 1.0) { +// // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // } +// // // } +// // // } +// // // } - // // // if ema10_1m_vec[ema10_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value { - // // // if ema3_1m_vec[ema3_3_result.unwrap()].ema_value > ema10_1m_vec[ema10_result.unwrap()].ema_value { - // // // if ema3_1m_vec[ema3_3_result.unwrap()].ema_value > ema3_1m_vec[ema3_2_result.unwrap()].ema_value - // // // && ema3_1m_vec[ema3_2_result.unwrap()].ema_value > ema3_1m_vec[ema3_1_result.unwrap()].ema_value - // // // { - // // // if average_stoch_rsi30_1m_k < 80.0 { - // // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let k_prev2_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[0].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // // // if k_result.is_ok() && d_result.is_ok() && k_prev_result.is_ok() && k_prev2_result.is_ok() { - // // // if - // // // (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) - // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) > 3.0 - // // // && stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value < 96.0 - // // // && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_k_vec[k_prev2_result.unwrap()].stoch_rsi_k_value) - // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) < 25.0 - // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) > 3.0 - // // // // && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value > 5.0) - // // // // (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value > 5.0) && - // // // // ((stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value <= 80.0) - // // // // || (((opclo_1m_vec[1].open_price - opclo_1m_vec[1].close_price).abs() / (opclo_1m_vec[1].high_price - opclo_1m_vec[1].low_price) > 60.0 && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > 80.0) && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value))) - // // // { - // // // // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > 80.0 { - // // // // if (opclo_1m_vec[1].open_price - opclo_1m_vec[1].close_price).abs() / (opclo_1m_vec[1].high_price - opclo_1m_vec[1].low_price) > 60.0 - // // // // { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // // } else { - // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // if opclo_1m_vec[1].candle_type == "DOWN" && opclo_1m_vec[1].opclo_price >= opclo_1m_vec[2].close_price { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } else if opclo_1m_vec[1].candle_type == "UP" { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // } - // // // // else { - // // // // let result = rsi3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&RsiData{rsi_value, close_time}|close_time); - // // // // if result.is_ok() { - // // // // if rsi3_1m_vec[result.unwrap()].rsi_value < 20.0 && cnt >= 2 && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // // } - // // // // } +// // // // if ema10_1m_vec[ema10_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value { +// // // // if ema3_1m_vec[ema3_3_result.unwrap()].ema_value > ema10_1m_vec[ema10_result.unwrap()].ema_value { +// // // // if ema3_1m_vec[ema3_3_result.unwrap()].ema_value > ema3_1m_vec[ema3_2_result.unwrap()].ema_value +// // // // && ema3_1m_vec[ema3_2_result.unwrap()].ema_value > ema3_1m_vec[ema3_1_result.unwrap()].ema_value +// // // // { +// // // // if average_stoch_rsi30_1m_k < 80.0 { +// // // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let k_prev2_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[0].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // // // if k_result.is_ok() && d_result.is_ok() && k_prev_result.is_ok() && k_prev2_result.is_ok() { +// // // // if +// // // // (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) +// // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) > 3.0 +// // // // && stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value < 96.0 +// // // // && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_k_vec[k_prev2_result.unwrap()].stoch_rsi_k_value) +// // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) < 25.0 +// // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) > 3.0 +// // // // // && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value > 5.0) +// // // // // (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value > 5.0) && +// // // // // ((stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value <= 80.0) +// // // // // || (((opclo_1m_vec[1].open_price - opclo_1m_vec[1].close_price).abs() / (opclo_1m_vec[1].high_price - opclo_1m_vec[1].low_price) > 60.0 && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > 80.0) && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value))) +// // // // { +// // // // // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > 80.0 { +// // // // // if (opclo_1m_vec[1].open_price - opclo_1m_vec[1].close_price).abs() / (opclo_1m_vec[1].high_price - opclo_1m_vec[1].low_price) > 60.0 +// // // // // { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // // } else { +// // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // if opclo_1m_vec[1].candle_type == "DOWN" && opclo_1m_vec[1].opclo_price >= opclo_1m_vec[2].close_price { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } else if opclo_1m_vec[1].candle_type == "UP" { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // } +// // // // // else { +// // // // // let result = rsi3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&RsiData{rsi_value, close_time}|close_time); +// // // // // if result.is_ok() { +// // // // // if rsi3_1m_vec[result.unwrap()].rsi_value < 20.0 && cnt >= 2 && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // // } +// // // // // } - // // // // } else { - // // // // if cnt >= 2 { +// // // // // } else { +// // // // // if cnt >= 2 { - // // // // let result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&EmaData{ema_value, close_time}|close_time); - // // // // match result { - // // // // Ok(T) => { - // // // // if ema3_1m_vec[T].ema_value > opclo_1m_vec[1].opclo_price { - // // // // let result = rsi3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&RsiData{rsi_value, close_time}|close_time); - // // // // match result { - // // // // Ok(T) => { - // // // // if rsi3_1m_vec[T].rsi_value < 15.0 { - // // // // let k_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // // let d_result = stoch_rsi10_1m_d_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // // // // let result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&EmaData{ema_value, close_time}|close_time); +// // // // // match result { +// // // // // Ok(T) => { +// // // // // if ema3_1m_vec[T].ema_value > opclo_1m_vec[1].opclo_price { +// // // // // let result = rsi3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&RsiData{rsi_value, close_time}|close_time); +// // // // // match result { +// // // // // Ok(T) => { +// // // // // if rsi3_1m_vec[T].rsi_value < 15.0 { +// // // // // let k_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // // let d_result = stoch_rsi10_1m_d_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // // // // if k_result.is_ok() && d_result.is_ok() { - // // // // if stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value <= stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value { - // // // // if current_price < opclo_1m_vec[1].opclo_price { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // // } - // // // // } - // // // // } - // // // // }, - // // // // Err(E) => {} - // // // // } - // // // // } - // // // // }, - // // // // Err(E) => {} - // // // // } - // // // // } - // // // // } - // // // } - // // // } else { - // // // let k_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let k_prev_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let k_prev2_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[0].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let d_result = stoch_rsi10_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // // // if k_result.is_ok() && d_result.is_ok() && k_prev_result.is_ok() && k_prev2_result.is_ok() { - // // // if (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) - // // // && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) > 3.0 - // // // && stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_k_vec[k_prev2_result.unwrap()].stoch_rsi_k_value - // // // && stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value - // // // && stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi10_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value < 30.0 - // // // && stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value < 95.0 - // // // { - // // // // if stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > 80.0 { - // // // // if (opclo_1m_vec[1].open_price - opclo_1m_vec[1].close_price).abs() / (opclo_1m_vec[1].high_price - opclo_1m_vec[1].low_price) > 60.0 - // // // // { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // // } else { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } - // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // } - // // // } - // // // } - // // // } - // // // } - // // // // else { - // // // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // // // // if k_result.is_ok() && k_prev_result.is_ok() { - // // // // if (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) - // // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) > 5.0 - // // // // { - // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // } +// // // // // if k_result.is_ok() && d_result.is_ok() { +// // // // // if stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value <= stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value { +// // // // // if current_price < opclo_1m_vec[1].opclo_price { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // // } +// // // // // } +// // // // // } +// // // // // }, +// // // // // Err(E) => {} +// // // // // } +// // // // // } +// // // // // }, +// // // // // Err(E) => {} +// // // // // } +// // // // // } +// // // // // } +// // // // } +// // // // } else { +// // // // let k_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let k_prev_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let k_prev2_result = stoch_rsi10_1m_k_vec.binary_search_by_key(&opclo_1m_vec[0].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let d_result = stoch_rsi10_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // // // if k_result.is_ok() && d_result.is_ok() && k_prev_result.is_ok() && k_prev2_result.is_ok() { +// // // // if (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) +// // // // && (stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) > 3.0 +// // // // && stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_k_vec[k_prev2_result.unwrap()].stoch_rsi_k_value +// // // // && stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi10_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value +// // // // && stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi10_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value < 30.0 +// // // // && stoch_rsi10_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value < 95.0 +// // // // { +// // // // // if stoch_rsi10_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > 80.0 { +// // // // // if (opclo_1m_vec[1].open_price - opclo_1m_vec[1].close_price).abs() / (opclo_1m_vec[1].high_price - opclo_1m_vec[1].low_price) > 60.0 +// // // // // { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // // } else { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } +// // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // } +// // // // } +// // // // } +// // // // } +// // // // } +// // // // // else { +// // // // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // // // // if k_result.is_ok() && k_prev_result.is_ok() { +// // // // // if (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) +// // // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value) > 5.0 +// // // // // { +// // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // } - // // // // // if ema3_1m_vec[ema3_3_result.unwrap()].ema_value < ema3_1m_vec[ema3_2_result.unwrap()].ema_value { - // // // // // if opclo_1m_vec[1].candle_type == "DOWN" && opclo_1m_vec[1].open_price > ema3_1m_vec[ema3_2_result.unwrap()].ema_value - // // // // // && opclo_1m_vec[2].open_price < ema3_1m_vec[ema3_3_result.unwrap()].ema_value - // // // // // && opclo_1m_vec[2].high_price < ema3_1m_vec[ema3_3_result.unwrap()].ema_value - // // // // // && opclo_1m_vec[2].candle_type == "UP" { - // // // // // if (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value < stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) - // // // // // { - // // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // // } - // // // // // } - // // // // // } else if ema3_1m_vec[ema3_3_result.unwrap()].ema_value > ema3_1m_vec[ema3_2_result.unwrap()].ema_value - // // // // // { - // // // // // if opclo_1m_vec[1].candle_type == "UP" - // // // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) { - // // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // // // } - // // // // // } - // // // // } - // // // // } - // // // } - // // } - // // } - // // } - // // // else if macd_vec[macd_search_result.unwrap()].macd_value > macd_vec[macd_search_result.unwrap()-1].macd_value && macd_vec[macd_search_result.unwrap()].macd_value > -3.0{ - // // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // // // if k_result.is_ok() && k_prev_result.is_ok() && d_result.is_ok() { - // // // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value - // // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value - // // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value > 5.0{ - // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // // // } - // // // } - // // // } - // // } +// // // // // // if ema3_1m_vec[ema3_3_result.unwrap()].ema_value < ema3_1m_vec[ema3_2_result.unwrap()].ema_value { +// // // // // // if opclo_1m_vec[1].candle_type == "DOWN" && opclo_1m_vec[1].open_price > ema3_1m_vec[ema3_2_result.unwrap()].ema_value +// // // // // // && opclo_1m_vec[2].open_price < ema3_1m_vec[ema3_3_result.unwrap()].ema_value +// // // // // // && opclo_1m_vec[2].high_price < ema3_1m_vec[ema3_3_result.unwrap()].ema_value +// // // // // // && opclo_1m_vec[2].candle_type == "UP" { +// // // // // // if (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value < stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) +// // // // // // { +// // // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // // } +// // // // // // } +// // // // // // } else if ema3_1m_vec[ema3_3_result.unwrap()].ema_value > ema3_1m_vec[ema3_2_result.unwrap()].ema_value +// // // // // // { +// // // // // // if opclo_1m_vec[1].candle_type == "UP" +// // // // // // && (stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value) { +// // // // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // // // } +// // // // // // } +// // // // // } +// // // // // } +// // // // } +// // // } +// // // } +// // // } +// // // // else if macd_vec[macd_search_result.unwrap()].macd_value > macd_vec[macd_search_result.unwrap()-1].macd_value && macd_vec[macd_search_result.unwrap()].macd_value > -3.0{ +// // // // let k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let k_prev_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // // // let d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // // // if k_result.is_ok() && k_prev_result.is_ok() && d_result.is_ok() { +// // // // if stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_k_vec[k_prev_result.unwrap()].stoch_rsi_k_value +// // // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value > stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value +// // // // && stoch_rsi30_1m_k_vec[k_result.unwrap()].stoch_rsi_k_value - stoch_rsi30_1m_d_vec[d_result.unwrap()].stoch_rsi_d_value > 5.0{ +// // // // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // // // } +// // // // } +// // // // } +// // // } - // } - } - } - } +// // } +// } +// } +// } - // let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - // if market_cap_index.first().unwrap().negative_buy_signal == 1 || (market_cap_index.first().unwrap().liquidation_signal == 0 && market_cap_index.first().unwrap().market_cap_index <= 20.0 && market_cap_index.first().unwrap().market_cap_index >= 0.0) { - // let mut rsi3_1m_vec: Vec = Vec::new(); - // let mut opclo_1m_vec: Vec = Vec::new(); - // let mut ema3_1m_vec: Vec = Vec::new(); - // let mut cnt = 0; - // for symbol in filtered_symbols { - // let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - // let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - // let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); +// // let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// // if market_cap_index.first().unwrap().negative_buy_signal == 1 || (market_cap_index.first().unwrap().liquidation_signal == 0 && market_cap_index.first().unwrap().market_cap_index <= 20.0 && market_cap_index.first().unwrap().market_cap_index >= 0.0) { +// // let mut rsi3_1m_vec: Vec = Vec::new(); +// // let mut opclo_1m_vec: Vec = Vec::new(); +// // let mut ema3_1m_vec: Vec = Vec::new(); +// // let mut cnt = 0; +// // for symbol in filtered_symbols { +// // let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// // let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// // let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); - // if rsi3_1m_option.is_some() && opclo_1m_option.is_some() && ema3_1m_option.is_some() { - // rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - // opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - // ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); +// // if rsi3_1m_option.is_some() && opclo_1m_option.is_some() && ema3_1m_option.is_some() { +// // rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// // opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// // ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); - // if rsi3_1m_vec.len() >= 3 && opclo_1m_vec.len() >= 3 && ema3_1m_vec.len() >= 3 { - // opclo_1m_vec.reverse(); - // opclo_1m_vec.truncate(3); - // opclo_1m_vec.reverse(); +// // if rsi3_1m_vec.len() >= 3 && opclo_1m_vec.len() >= 3 && ema3_1m_vec.len() >= 3 { +// // opclo_1m_vec.reverse(); +// // opclo_1m_vec.truncate(3); +// // opclo_1m_vec.reverse(); - // if opclo_1m_vec.last().unwrap().candle_type == "UP" { - // cnt = 0; - // for element in &opclo_1m_vec { - // if element.candle_type == "DOWN" { - // cnt += 1; - // } - // } +// // if opclo_1m_vec.last().unwrap().candle_type == "UP" { +// // cnt = 0; +// // for element in &opclo_1m_vec { +// // if element.candle_type == "DOWN" { +// // cnt += 1; +// // } +// // } - // if cnt >= 2 { - // let result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&EmaData{ema_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if ema3_1m_vec[T].ema_value > opclo_1m_vec[1].opclo_price { - // let result = rsi3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi3_1m_vec[T].rsi_value < 30.0 { - // if current_price < opclo_1m_vec[1].opclo_price { - // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); - // } - // } - // }, - // Err(E) => {} - // } - // } - // }, - // Err(E) => {} - // } - // } +// // if cnt >= 2 { +// // let result = ema3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&EmaData{ema_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if ema3_1m_vec[T].ema_value > opclo_1m_vec[1].opclo_price { +// // let result = rsi3_1m_vec.binary_search_by_key(&opclo_1m_vec[1].close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi3_1m_vec[T].rsi_value < 30.0 { +// // if current_price < opclo_1m_vec[1].opclo_price { +// // filtered_2nd_symbols.push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } - // } +// // } - // } - // } - // } - // } else if market_cap_index.first().unwrap().liquidation_signal == 1 && market_cap_index.first().unwrap().market_cap_index < - 10.0 { - // let mut rsi3_1m_vec: Vec = Vec::new(); - // let mut rsi10_1m_vec: Vec = Vec::new(); - // let mut rsi30_1m_vec: Vec = Vec::new(); - // let mut op_low_1m_vec: Vec = Vec::new(); - // let mut ema3_1m_vec: Vec = Vec::new(); - // let mut bb30_1m_vec: Vec = Vec::new(); - // let mut cnt = 0; - // for symbol in filtered_symbols { - // let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - // let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - // let rsi30_1m_option = alldata.rsi30_1m_data.iter().position(|x| *x.0 == *symbol); - // let op_low_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - // let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); - // let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); +// // } +// // } +// // } +// // } else if market_cap_index.first().unwrap().liquidation_signal == 1 && market_cap_index.first().unwrap().market_cap_index < - 10.0 { +// // let mut rsi3_1m_vec: Vec = Vec::new(); +// // let mut rsi10_1m_vec: Vec = Vec::new(); +// // let mut rsi30_1m_vec: Vec = Vec::new(); +// // let mut op_low_1m_vec: Vec = Vec::new(); +// // let mut ema3_1m_vec: Vec = Vec::new(); +// // let mut bb30_1m_vec: Vec = Vec::new(); +// // let mut cnt = 0; +// // for symbol in filtered_symbols { +// // let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// // let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); +// // let rsi30_1m_option = alldata.rsi30_1m_data.iter().position(|x| *x.0 == *symbol); +// // let op_low_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// // let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); +// // let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); - // if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() && rsi30_1m_option.is_some() && op_low_1m_option.is_some() && ema3_1m_option.is_some() && bb30_1m_option.is_some() { - // rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - // rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - // rsi30_1m_vec = alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1.clone(); - // op_low_1m_vec = alldata.rt_price_1m_vec[op_low_1m_option.unwrap()].1.clone(); - // ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); - // bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); +// // if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() && rsi30_1m_option.is_some() && op_low_1m_option.is_some() && ema3_1m_option.is_some() && bb30_1m_option.is_some() { +// // rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// // rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); +// // rsi30_1m_vec = alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1.clone(); +// // op_low_1m_vec = alldata.rt_price_1m_vec[op_low_1m_option.unwrap()].1.clone(); +// // ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); +// // bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); - // if rsi3_1m_vec.len() >= 3 && rsi10_1m_vec.len() >= 3 && rsi30_1m_vec.len() >= 3 && op_low_1m_vec.len() >= 3 && ema3_1m_vec.len() >= 3 && bb30_1m_vec.len() >= 3 { - // op_low_1m_vec.reverse(); - // op_low_1m_vec.truncate(5); - // op_low_1m_vec.reverse(); +// // if rsi3_1m_vec.len() >= 3 && rsi10_1m_vec.len() >= 3 && rsi30_1m_vec.len() >= 3 && op_low_1m_vec.len() >= 3 && ema3_1m_vec.len() >= 3 && bb30_1m_vec.len() >= 3 { +// // op_low_1m_vec.reverse(); +// // op_low_1m_vec.truncate(5); +// // op_low_1m_vec.reverse(); - // if op_low_1m_vec.last().unwrap().candle_type == "DOWN" { - // cnt = 0; - // for element in &op_low_1m_vec { - // if element.candle_type == "DOWN" { - // cnt += 1; - // } - // } +// // if op_low_1m_vec.last().unwrap().candle_type == "DOWN" { +// // cnt = 0; +// // for element in &op_low_1m_vec { +// // if element.candle_type == "DOWN" { +// // cnt += 1; +// // } +// // } - // if cnt >= 4 { - // let result = ema3_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if ema3_1m_vec[T].ema_value > (op_low_1m_vec.last().unwrap().open_price + op_low_1m_vec.last().unwrap().low_price) / 2.0 { - // let result = rsi3_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi3_1m_vec[T].rsi_value < 10.0 { - // let result = rsi10_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi10_1m_vec[T].rsi_value < 15.0 { - // let result = rsi30_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi30_1m_vec[T].rsi_value < 35.0 { - // let result = bb30_1m_vec.binary_search_by_key(&op_low_1m_vec.first().unwrap().close_time, |&BollingerBandData{sma, upperband, lowerband, close_time}|close_time); - // match result { - // Ok(T) => { - // if bb30_1m_vec[T].lowerband > (op_low_1m_vec.last().unwrap().open_price + op_low_1m_vec.last().unwrap().low_price) / 2.0 { - // filtered_2nd_symbols.push((symbol, op_low_1m_vec.last().unwrap().close_time)); - // } - // }, - // Err(E) => {}, - // } - // } - // }, - // Err(E) => {} - // } - // } - // }, - // Err(E) => {} - // } - // } - // }, - // Err(E) => {} - // } - // } - // }, - // Err(E) => {} - // } - // } +// // if cnt >= 4 { +// // let result = ema3_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if ema3_1m_vec[T].ema_value > (op_low_1m_vec.last().unwrap().open_price + op_low_1m_vec.last().unwrap().low_price) / 2.0 { +// // let result = rsi3_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi3_1m_vec[T].rsi_value < 10.0 { +// // let result = rsi10_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi10_1m_vec[T].rsi_value < 15.0 { +// // let result = rsi30_1m_vec.binary_search_by_key(&op_low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi30_1m_vec[T].rsi_value < 35.0 { +// // let result = bb30_1m_vec.binary_search_by_key(&op_low_1m_vec.first().unwrap().close_time, |&BollingerBandData{sma, upperband, lowerband, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if bb30_1m_vec[T].lowerband > (op_low_1m_vec.last().unwrap().open_price + op_low_1m_vec.last().unwrap().low_price) / 2.0 { +// // filtered_2nd_symbols.push((symbol, op_low_1m_vec.last().unwrap().close_time)); +// // } +// // }, +// // Err(E) => {}, +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } - // } +// // } - // } - // } - // } - // } +// // } +// // } +// // } +// // } - insert_pre_suggested_coins(1, &filtered_2nd_symbols, alldata).await; +// insert_pre_suggested_coins(1, &filtered_2nd_symbols, alldata).await; - Ok(()) -} +// Ok(()) +// } // Supertrend UP area에서 이득보기 -pub async fn execute_strategist_for_test2( - alldata: &AllData, -) -> Result<(), Box> { - let inspect_table_name_1 = String::from("buy_ordered_coin_list"); - let inspect_table_name_2 = String::from("sell_ordered_coin_list"); - let inspect_table_name_3 = String::from("pre_suggested_coin_list"); - let inspect_table_name_4 = String::from("suggested_coin_list"); +// pub async fn execute_strategist_for_test2( +// alldata: &AllData, +// ) -> Result<(), Box> { +// let inspect_table_name_1 = String::from("buy_ordered_coin_list"); +// let inspect_table_name_2 = String::from("sell_ordered_coin_list"); +// let inspect_table_name_3 = String::from("pre_suggested_coin_list"); +// let inspect_table_name_4 = String::from("suggested_coin_list"); - let market_cap_index = select_marketcap().await; +// let market_cap_index = select_marketcap().await; - let mut filtered_symbols: Vec = Vec::new(); +// let mut filtered_symbols: Vec = Vec::new(); - filtered_symbols.push(String::from("BTCUSDT")); +// filtered_symbols.push(String::from("BTCUSDT")); - let current_price = get_current_price(&filtered_symbols.first().unwrap(), &alldata.price_vec) - .await - .unwrap(); +// let current_price = get_current_price(&filtered_symbols.first().unwrap(), &alldata.price_vec) +// .await +// .unwrap(); - let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - let mut ema3_1m_vec: &Vec = &Vec::new(); - let mut ema3_30m_vec: &Vec = &Vec::new(); - let mut ema10_1m_vec: &Vec = &Vec::new(); - let mut ema30_1m_vec: &Vec = &Vec::new(); - let mut sma3_1m_vec: &Vec = &Vec::new(); - let mut sma10_1m_vec: &Vec = &Vec::new(); - let mut sma3_30m_vec: &Vec = &Vec::new(); - let mut sma30_1m_vec: &Vec = &Vec::new(); - let mut rsi3_1m_vec: &Vec = &Vec::new(); - let mut rsi30_1m_vec: &Vec = &Vec::new(); - let mut stoch_rsi3_1m_k_vec: &Vec = &Vec::new(); - let mut stoch_rsi3_1m_d_vec: &Vec = &Vec::new(); - let mut stoch_rsi30_1m_k_vec: &Vec = &Vec::new(); - let mut stoch_rsi30_1m_d_vec: &Vec = &Vec::new(); - let mut rt_price_1m_vec: &Vec = &Vec::new(); - let mut is_filtering_passed: bool = false; +// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// let mut ema3_1m_vec: &Vec = &Vec::new(); +// let mut ema3_30m_vec: &Vec = &Vec::new(); +// let mut ema10_1m_vec: &Vec = &Vec::new(); +// let mut ema30_1m_vec: &Vec = &Vec::new(); +// let mut sma3_1m_vec: &Vec = &Vec::new(); +// let mut sma10_1m_vec: &Vec = &Vec::new(); +// let mut sma3_30m_vec: &Vec = &Vec::new(); +// let mut sma30_1m_vec: &Vec = &Vec::new(); +// let mut rsi3_1m_vec: &Vec = &Vec::new(); +// let mut rsi30_1m_vec: &Vec = &Vec::new(); +// let mut stoch_rsi3_1m_k_vec: &Vec = &Vec::new(); +// let mut stoch_rsi3_1m_d_vec: &Vec = &Vec::new(); +// let mut stoch_rsi30_1m_k_vec: &Vec = &Vec::new(); +// let mut stoch_rsi30_1m_d_vec: &Vec = &Vec::new(); +// let mut rt_price_1m_vec: &Vec = &Vec::new(); +// let mut is_filtering_passed: bool = false; - let mut cnt = 0; - let exists_condition = Some(String::from("used_usdt >= 10.0 AND registerer = 2")); - let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; - let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; - let inspect_result_4 = exists_record(&inspect_table_name_4, &None).await; - let mut is_buy_period_30m = false; +// let mut cnt = 0; +// let exists_condition = Some(String::from("used_usdt >= 10.0 AND registerer = 2")); +// let inspect_result_1 = exists_record(&inspect_table_name_1, &exists_condition).await; +// let inspect_result_2 = exists_record(&inspect_table_name_2, &exists_condition).await; +// let inspect_result_4 = exists_record(&inspect_table_name_4, &None).await; +// let mut is_buy_period_30m = false; - if inspect_result_1 == false && inspect_result_2 == false && inspect_result_4 == false { - for symbol in filtered_symbols { - is_filtering_passed = false; - let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); - let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); - let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); - let ema30_1m_option = alldata.ema30_1m_data.iter().position(|x| *x.0 == *symbol); - let sma3_1m_option = alldata.sma3_1m_data.iter().position(|x| *x.0 == *symbol); - let sma10_1m_option = alldata.sma10_1m_data.iter().position(|x| *x.0 == *symbol); - let sma3_30m_option = alldata.sma3_30m_data.iter().position(|x| *x.0 == *symbol); - let sma30_1m_option = alldata.sma30_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi30_1m_option = alldata.rsi30_1m_data.iter().position(|x| *x.0 == *symbol); - let stoch_rsi3_1m_k_option = alldata - .stoch_rsi3_1m_3_k_data - .iter() - .position(|x| *x.0 == *symbol); - let stoch_rsi3_1m_d_option = alldata - .stoch_rsi3_1m_3_d_data - .iter() - .position(|x| *x.0 == *symbol); - let stoch_rsi30_1m_k_option = alldata - .stoch_rsi30_1m_30_k_data - .iter() - .position(|x| *x.0 == *symbol); - let stoch_rsi30_1m_d_option = alldata - .stoch_rsi30_1m_30_d_data - .iter() - .position(|x| *x.0 == *symbol); - let rt_price_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// if inspect_result_1 == false && inspect_result_2 == false && inspect_result_4 == false { +// for symbol in filtered_symbols { +// is_filtering_passed = false; +// let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); +// let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); +// let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); +// let ema30_1m_option = alldata.ema30_1m_data.iter().position(|x| *x.0 == *symbol); +// let sma3_1m_option = alldata.sma3_1m_data.iter().position(|x| *x.0 == *symbol); +// let sma10_1m_option = alldata.sma10_1m_data.iter().position(|x| *x.0 == *symbol); +// let sma3_30m_option = alldata.sma3_30m_data.iter().position(|x| *x.0 == *symbol); +// let sma30_1m_option = alldata.sma30_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi30_1m_option = alldata.rsi30_1m_data.iter().position(|x| *x.0 == *symbol); +// let stoch_rsi3_1m_k_option = alldata +// .stoch_rsi3_1m_3_k_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let stoch_rsi3_1m_d_option = alldata +// .stoch_rsi3_1m_3_d_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let stoch_rsi30_1m_k_option = alldata +// .stoch_rsi30_1m_30_k_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let stoch_rsi30_1m_d_option = alldata +// .stoch_rsi30_1m_30_d_data +// .iter() +// .position(|x| *x.0 == *symbol); +// let rt_price_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - if ema3_1m_option.is_some() - && ema3_30m_option.is_some() - && ema10_1m_option.is_some() - && ema30_1m_option.is_some() - && sma3_1m_option.is_some() - && sma10_1m_option.is_some() - && sma3_30m_option.is_some() - && sma30_1m_option.is_some() - && rsi3_1m_option.is_some() - && rsi30_1m_option.is_some() - && stoch_rsi3_1m_k_option.is_some() - && stoch_rsi3_1m_d_option.is_some() - && stoch_rsi30_1m_k_option.is_some() - && stoch_rsi30_1m_d_option.is_some() - && rt_price_1m_option.is_some() - { - ema3_1m_vec = &alldata.ema3_1m_data[ema3_1m_option.unwrap()].1; - ema3_30m_vec = &alldata.ema3_30m_data[ema3_30m_option.unwrap()].1; - ema10_1m_vec = &alldata.ema10_1m_data[ema10_1m_option.unwrap()].1; - ema30_1m_vec = &alldata.ema30_1m_data[ema30_1m_option.unwrap()].1; - sma3_1m_vec = &alldata.sma3_1m_data[sma3_1m_option.unwrap()].1; - sma10_1m_vec = &alldata.sma10_1m_data[sma10_1m_option.unwrap()].1; - sma3_30m_vec = &alldata.sma3_30m_data[sma3_30m_option.unwrap()].1; - sma30_1m_vec = &alldata.sma30_1m_data[sma30_1m_option.unwrap()].1; - rsi3_1m_vec = &alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1; - rsi30_1m_vec = &alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1; - stoch_rsi3_1m_k_vec = - &alldata.stoch_rsi3_1m_3_k_data[stoch_rsi3_1m_k_option.unwrap()].1; - stoch_rsi3_1m_d_vec = - &alldata.stoch_rsi3_1m_3_d_data[stoch_rsi3_1m_d_option.unwrap()].1; - stoch_rsi30_1m_k_vec = - &alldata.stoch_rsi30_1m_30_k_data[stoch_rsi30_1m_k_option.unwrap()].1; - stoch_rsi30_1m_d_vec = - &alldata.stoch_rsi30_1m_30_d_data[stoch_rsi30_1m_d_option.unwrap()].1; - rt_price_1m_vec = &alldata.rt_price_1m_vec[rt_price_1m_option.unwrap()].1; +// if ema3_1m_option.is_some() +// && ema3_30m_option.is_some() +// && ema10_1m_option.is_some() +// && ema30_1m_option.is_some() +// && sma3_1m_option.is_some() +// && sma10_1m_option.is_some() +// && sma3_30m_option.is_some() +// && sma30_1m_option.is_some() +// && rsi3_1m_option.is_some() +// && rsi30_1m_option.is_some() +// && stoch_rsi3_1m_k_option.is_some() +// && stoch_rsi3_1m_d_option.is_some() +// && stoch_rsi30_1m_k_option.is_some() +// && stoch_rsi30_1m_d_option.is_some() +// && rt_price_1m_option.is_some() +// { +// ema3_1m_vec = &alldata.ema3_1m_data[ema3_1m_option.unwrap()].1; +// ema3_30m_vec = &alldata.ema3_30m_data[ema3_30m_option.unwrap()].1; +// ema10_1m_vec = &alldata.ema10_1m_data[ema10_1m_option.unwrap()].1; +// ema30_1m_vec = &alldata.ema30_1m_data[ema30_1m_option.unwrap()].1; +// sma3_1m_vec = &alldata.sma3_1m_data[sma3_1m_option.unwrap()].1; +// sma10_1m_vec = &alldata.sma10_1m_data[sma10_1m_option.unwrap()].1; +// sma3_30m_vec = &alldata.sma3_30m_data[sma3_30m_option.unwrap()].1; +// sma30_1m_vec = &alldata.sma30_1m_data[sma30_1m_option.unwrap()].1; +// rsi3_1m_vec = &alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1; +// rsi30_1m_vec = &alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1; +// stoch_rsi3_1m_k_vec = +// &alldata.stoch_rsi3_1m_3_k_data[stoch_rsi3_1m_k_option.unwrap()].1; +// stoch_rsi3_1m_d_vec = +// &alldata.stoch_rsi3_1m_3_d_data[stoch_rsi3_1m_d_option.unwrap()].1; +// stoch_rsi30_1m_k_vec = +// &alldata.stoch_rsi30_1m_30_k_data[stoch_rsi30_1m_k_option.unwrap()].1; +// stoch_rsi30_1m_d_vec = +// &alldata.stoch_rsi30_1m_30_d_data[stoch_rsi30_1m_d_option.unwrap()].1; +// rt_price_1m_vec = &alldata.rt_price_1m_vec[rt_price_1m_option.unwrap()].1; - // filtering condition: data are ready - if ema3_1m_vec.len() >= 3 - && ema3_30m_vec.len() >= 3 - && ema10_1m_vec.len() >= 3 - && ema30_1m_vec.len() >= 3 - && sma3_1m_vec.len() >= 3 - && sma10_1m_vec.len() >= 3 - && sma3_30m_vec.len() >= 3 - && sma30_1m_vec.len() >= 3 - && rsi3_1m_vec.len() >= 3 - && rsi30_1m_vec.len() >= 3 - && stoch_rsi3_1m_k_vec.len() >= 5 - && stoch_rsi3_1m_d_vec.len() >= 5 - && stoch_rsi30_1m_k_vec.len() >= 5 - && stoch_rsi30_1m_d_vec.len() >= 5 - && rt_price_1m_vec.len() >= 50 - { - is_filtering_passed = true; - } +// // filtering condition: data are ready +// if ema3_1m_vec.len() >= 3 +// && ema3_30m_vec.len() >= 3 +// && ema10_1m_vec.len() >= 3 +// && ema30_1m_vec.len() >= 3 +// && sma3_1m_vec.len() >= 3 +// && sma10_1m_vec.len() >= 3 +// && sma3_30m_vec.len() >= 3 +// && sma30_1m_vec.len() >= 3 +// && rsi3_1m_vec.len() >= 3 +// && rsi30_1m_vec.len() >= 3 +// && stoch_rsi3_1m_k_vec.len() >= 5 +// && stoch_rsi3_1m_d_vec.len() >= 5 +// && stoch_rsi30_1m_k_vec.len() >= 5 +// && stoch_rsi30_1m_d_vec.len() >= 5 +// && rt_price_1m_vec.len() >= 50 +// { +// is_filtering_passed = true; +// } - // // filtering condition: SuperTrend & EMA & SMA - // if is_filtering_passed == true { - // let supertrend_option = supertrend(&symbol, &alldata.rt_price_1m_vec, 10, 1.0, false).await; - // if supertrend_option.is_some() { - // let supertrend_vec = supertrend_option.unwrap(); - // let supertrend_result = supertrend_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |SupertrendData{band_value, signal, area, close_time}| *close_time); - // let ema3_result = ema3_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); - // let sma10_result = sma10_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&SmaData{sma_value, close_time}|close_time); +// // // filtering condition: SuperTrend & EMA & SMA +// // if is_filtering_passed == true { +// // let supertrend_option = supertrend(&symbol, &alldata.rt_price_1m_vec, 10, 1.0, false).await; +// // if supertrend_option.is_some() { +// // let supertrend_vec = supertrend_option.unwrap(); +// // let supertrend_result = supertrend_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |SupertrendData{band_value, signal, area, close_time}| *close_time); +// // let ema3_result = ema3_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&EmaData{ema_value, close_time}|close_time); +// // let sma10_result = sma10_1m_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&SmaData{sma_value, close_time}|close_time); - // if supertrend_vec.last().unwrap().signal.is_some() && ema3_result.is_ok() && sma10_result.is_ok() { - // if (((supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) && rt_price_1m_vec.last().unwrap().close_price <= supertrend_vec[supertrend_vec.len()-2].band_value * 1.0005) - // || (supertrend_vec.last().unwrap().area.contains("UP") && ema3_1m_vec[ema3_result.unwrap()-1].ema_value < sma10_1m_vec[sma10_result.unwrap()-1].sma_value && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value)) - // && sma10_1m_vec[sma10_result.unwrap()-2].sma_value < sma10_1m_vec[sma10_result.unwrap()].sma_value { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } else { is_filtering_passed = false; } - // } else { is_filtering_passed = false; } - // } +// // if supertrend_vec.last().unwrap().signal.is_some() && ema3_result.is_ok() && sma10_result.is_ok() { +// // if (((supertrend_vec.last().unwrap().signal.as_ref().unwrap().contains("BUY") && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value) && rt_price_1m_vec.last().unwrap().close_price <= supertrend_vec[supertrend_vec.len()-2].band_value * 1.0005) +// // || (supertrend_vec.last().unwrap().area.contains("UP") && ema3_1m_vec[ema3_result.unwrap()-1].ema_value < sma10_1m_vec[sma10_result.unwrap()-1].sma_value && ema3_1m_vec[ema3_result.unwrap()].ema_value > sma10_1m_vec[sma10_result.unwrap()].sma_value)) +// // && sma10_1m_vec[sma10_result.unwrap()-2].sma_value < sma10_1m_vec[sma10_result.unwrap()].sma_value { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } else { is_filtering_passed = false; } +// // } else { is_filtering_passed = false; } +// // } - // filtering condition: SuperTrend - if is_filtering_passed == true { - let supertrend_option = - supertrend(&symbol, &alldata.rt_price_1m_vec, 3, 1.0, false).await; - if supertrend_option.is_some() { - let supertrend_vec = supertrend_option.unwrap(); - let supertrend_result = supertrend_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |SupertrendData { - band_value, - signal, - area, - close_time, - }| *close_time, - ); +// // filtering condition: SuperTrend +// if is_filtering_passed == true { +// let supertrend_option = +// supertrend(&symbol, &alldata.rt_price_1m_vec, 3, 1.0, false).await; +// if supertrend_option.is_some() { +// let supertrend_vec = supertrend_option.unwrap(); +// let supertrend_result = supertrend_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |SupertrendData { +// band_value, +// signal, +// area, +// close_time, +// }| *close_time, +// ); - if supertrend_result.is_ok() { - if supertrend_vec[supertrend_result.unwrap()] - .signal - .as_ref() - .is_some() - { - if supertrend_vec[supertrend_result.unwrap()] - .signal - .as_ref() - .unwrap() - .contains("BUY") - { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// if supertrend_result.is_ok() { +// if supertrend_vec[supertrend_result.unwrap()] +// .signal +// .as_ref() +// .is_some() +// { +// if supertrend_vec[supertrend_result.unwrap()] +// .signal +// .as_ref() +// .unwrap() +// .contains("BUY") +// { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: SMA & EMA - if is_filtering_passed == true { - let sma3_1m_result = sma3_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - let sma10_1m_result = sma10_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - let sma30_1m_result = sma30_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - let ema3_1m_result = ema3_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - let ema3_30m_result = ema3_30m_vec.binary_search_by_key( - &sma3_30m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - let ema10_1m_result = ema10_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - let ema30_1m_result = ema30_1m_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - if sma10_1m_result.is_ok() - && sma30_1m_result.is_ok() - && ema3_1m_result.is_ok() - && ema10_1m_result.is_ok() - && ema30_1m_result.is_ok() - && ema3_30m_result.is_ok() - { - if sma3_1m_vec[sma3_1m_result.unwrap()].sma_value - > sma3_1m_vec[sma3_1m_result.unwrap() - 1].sma_value - && sma3_1m_vec[sma3_1m_result.unwrap()].sma_value - > sma3_1m_vec[sma3_1m_result.unwrap() - 2].sma_value - && sma3_1m_vec[sma3_1m_result.unwrap() - 1].sma_value - > sma3_1m_vec[sma3_1m_result.unwrap() - 2].sma_value - && sma30_1m_vec[sma30_1m_result.unwrap()].sma_value - > rt_price_1m_vec.last().unwrap().close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 1].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 2].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 2].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 3].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 3].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 4].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 4].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 5].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 5].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 6].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 6].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 7].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 7].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 8].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 8].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 9].close_price - && sma30_1m_vec[sma30_1m_result.unwrap() - 9].sma_value - > rt_price_1m_vec[rt_price_1m_vec.len() - 10].close_price - // ema10_1m_vec[ema10_1m_result.unwrap()].ema_value > sma10_1m_vec[sma10_1m_result.unwrap()].sma_value - // ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value <= sma10_1m_vec[sma10_1m_result.unwrap()-1].sma_value - // (sma10_1m_vec[sma10_1m_result.unwrap()].sma_value - ema10_1m_vec[ema10_1m_result.unwrap()].ema_value).abs() >= (sma10_1m_vec[sma10_1m_result.unwrap()-1].sma_value - ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value).abs() +// // filtering condition: SMA & EMA +// if is_filtering_passed == true { +// let sma3_1m_result = sma3_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// let sma10_1m_result = sma10_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// let sma30_1m_result = sma30_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// let ema3_1m_result = ema3_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// let ema3_30m_result = ema3_30m_vec.binary_search_by_key( +// &sma3_30m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// let ema10_1m_result = ema10_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// let ema30_1m_result = ema30_1m_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// if sma10_1m_result.is_ok() +// && sma30_1m_result.is_ok() +// && ema3_1m_result.is_ok() +// && ema10_1m_result.is_ok() +// && ema30_1m_result.is_ok() +// && ema3_30m_result.is_ok() +// { +// if sma3_1m_vec[sma3_1m_result.unwrap()].sma_value +// > sma3_1m_vec[sma3_1m_result.unwrap() - 1].sma_value +// && sma3_1m_vec[sma3_1m_result.unwrap()].sma_value +// > sma3_1m_vec[sma3_1m_result.unwrap() - 2].sma_value +// && sma3_1m_vec[sma3_1m_result.unwrap() - 1].sma_value +// > sma3_1m_vec[sma3_1m_result.unwrap() - 2].sma_value +// && sma30_1m_vec[sma30_1m_result.unwrap()].sma_value +// > rt_price_1m_vec.last().unwrap().close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 1].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 2].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 2].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 3].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 3].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 4].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 4].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 5].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 5].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 6].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 6].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 7].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 7].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 8].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 8].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 9].close_price +// && sma30_1m_vec[sma30_1m_result.unwrap() - 9].sma_value +// > rt_price_1m_vec[rt_price_1m_vec.len() - 10].close_price +// // ema10_1m_vec[ema10_1m_result.unwrap()].ema_value > sma10_1m_vec[sma10_1m_result.unwrap()].sma_value +// // ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value <= sma10_1m_vec[sma10_1m_result.unwrap()-1].sma_value +// // (sma10_1m_vec[sma10_1m_result.unwrap()].sma_value - ema10_1m_vec[ema10_1m_result.unwrap()].ema_value).abs() >= (sma10_1m_vec[sma10_1m_result.unwrap()-1].sma_value - ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value).abs() - // && ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value < ema10_1m_vec[ema10_1m_result.unwrap()].ema_value - // && ema10_1m_vec[ema10_1m_result.unwrap()-2].ema_value < ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value +// // && ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value < ema10_1m_vec[ema10_1m_result.unwrap()].ema_value +// // && ema10_1m_vec[ema10_1m_result.unwrap()-2].ema_value < ema10_1m_vec[ema10_1m_result.unwrap()-1].ema_value - // && sma10_1m_vec[sma10_1m_result.unwrap()].sma_value > ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-1].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-2].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-3].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-4].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-5].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-2].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-1].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-3].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-2].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-4].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-3].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-5].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-4].ema_value - // && ema30_1m_vec[ema30_1m_result.unwrap()-5].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - // && rt_price_1m_vec.last().unwrap().close_price > ema30_1m_vec[ema30_1m_result.unwrap()].ema_value - { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// // && sma10_1m_vec[sma10_1m_result.unwrap()].sma_value > ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-1].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-2].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-3].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-4].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-5].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-2].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-1].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-3].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-2].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-4].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-3].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-5].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()-4].ema_value +// // && ema30_1m_vec[ema30_1m_result.unwrap()-5].ema_value < ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// // && rt_price_1m_vec.last().unwrap().close_price > ema30_1m_vec[ema30_1m_result.unwrap()].ema_value +// { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: current price limitation - // if is_filtering_passed == true { - // if rt_price_1m_vec[rt_price_1m_vec.len()-2].close_price + ((rt_price_1m_vec[rt_price_1m_vec.len()-2].high_price - rt_price_1m_vec[rt_price_1m_vec.len()-2].low_price) * 0.5) > rt_price_1m_vec.last().unwrap().close_price { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } +// // filtering condition: current price limitation +// // if is_filtering_passed == true { +// // if rt_price_1m_vec[rt_price_1m_vec.len()-2].close_price + ((rt_price_1m_vec[rt_price_1m_vec.len()-2].high_price - rt_price_1m_vec[rt_price_1m_vec.len()-2].low_price) * 0.5) > rt_price_1m_vec.last().unwrap().close_price { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } - // filtering condition: Heatmap Volume - if is_filtering_passed == true { - let heatmap_volume_option = heatmap_volume( - &symbol, - &alldata.rt_price_1m_vec, - 30, - 30, - 4.0, - 2.5, - 1.0, - -0.5, - ) - .await; - if heatmap_volume_option.is_some() { - let heatmap_volume_vec = heatmap_volume_option.unwrap(); - let heatmap_search_result = heatmap_volume_vec.binary_search_by_key( - &rt_price_1m_vec.last().unwrap().close_time, - |HeatmapVolumeData { - heatmap_value, - heatmap_level, - close_time, - }| *close_time, - ); - if heatmap_search_result.is_ok() { - let heatmap_volume_trunc_vec_option = heatmap_volume_vec.get( - heatmap_search_result.unwrap() - 11 - ..heatmap_search_result.unwrap() - 1, - ); - if heatmap_volume_trunc_vec_option.is_some() { - let heatmap_volume_trunc_vec = - heatmap_volume_trunc_vec_option.unwrap(); - let mut heat_value_summation = 0.0; - for element in heatmap_volume_trunc_vec { - if element.heatmap_level == HeatMapLevel::ExtraHigh { - heat_value_summation += 2.0; - } else if element.heatmap_level == HeatMapLevel::High { - heat_value_summation += 1.5; - } else if element.heatmap_level == HeatMapLevel::Medium { - heat_value_summation += 1.0; - } else if element.heatmap_level == HeatMapLevel::Normal { - heat_value_summation += 0.5; - } else { - heat_value_summation += 0.0; - } - } - if heat_value_summation >= 1.5 { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } - } - } else { - is_filtering_passed = false; - } - } +// // filtering condition: Heatmap Volume +// if is_filtering_passed == true { +// let heatmap_volume_option = heatmap_volume( +// &symbol, +// &alldata.rt_price_1m_vec, +// 30, +// 30, +// 4.0, +// 2.5, +// 1.0, +// -0.5, +// ) +// .await; +// if heatmap_volume_option.is_some() { +// let heatmap_volume_vec = heatmap_volume_option.unwrap(); +// let heatmap_search_result = heatmap_volume_vec.binary_search_by_key( +// &rt_price_1m_vec.last().unwrap().close_time, +// |HeatmapVolumeData { +// heatmap_value, +// heatmap_level, +// close_time, +// }| *close_time, +// ); +// if heatmap_search_result.is_ok() { +// let heatmap_volume_trunc_vec_option = heatmap_volume_vec.get( +// heatmap_search_result.unwrap() - 11 +// ..heatmap_search_result.unwrap() - 1, +// ); +// if heatmap_volume_trunc_vec_option.is_some() { +// let heatmap_volume_trunc_vec = +// heatmap_volume_trunc_vec_option.unwrap(); +// let mut heat_value_summation = 0.0; +// for element in heatmap_volume_trunc_vec { +// if element.heatmap_level == HeatMapLevel::ExtraHigh { +// heat_value_summation += 2.0; +// } else if element.heatmap_level == HeatMapLevel::High { +// heat_value_summation += 1.5; +// } else if element.heatmap_level == HeatMapLevel::Medium { +// heat_value_summation += 1.0; +// } else if element.heatmap_level == HeatMapLevel::Normal { +// heat_value_summation += 0.5; +// } else { +// heat_value_summation += 0.0; +// } +// } +// if heat_value_summation >= 1.5 { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } +// } +// } else { +// is_filtering_passed = false; +// } +// } - // filtering condition: Stoch RSI - // if is_filtering_passed == true { - // // let sample_length: usize = 5; - // // stoch_rsi10_1m_k_vec.reverse(); - // // stoch_rsi10_1m_k_vec.truncate(5); - // // stoch_rsi10_1m_k_vec.reverse(); - // // stoch_rsi10_1m_d_vec.reverse(); - // // stoch_rsi10_1m_d_vec.truncate(5); - // // stoch_rsi10_1m_d_vec.reverse(); - // let rsi3_k_result = stoch_rsi3_1m_k_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // let rsi3_d_result = stoch_rsi3_1m_d_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // let rsi30_k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); - // let rsi30_d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); - // if rsi30_k_result.is_ok() && rsi30_d_result.is_ok() && rsi3_k_result.is_ok() && rsi3_d_result.is_ok() { - // if - // // stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value <= 80.0 || stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value <= 80.0 - // // (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi3_1m_d_vec[rsi3_d_result.unwrap()].stoch_rsi_d_value) - // (stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()-1].stoch_rsi_k_value - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// // filtering condition: Stoch RSI +// // if is_filtering_passed == true { +// // // let sample_length: usize = 5; +// // // stoch_rsi10_1m_k_vec.reverse(); +// // // stoch_rsi10_1m_k_vec.truncate(5); +// // // stoch_rsi10_1m_k_vec.reverse(); +// // // stoch_rsi10_1m_d_vec.reverse(); +// // // stoch_rsi10_1m_d_vec.truncate(5); +// // // stoch_rsi10_1m_d_vec.reverse(); +// // let rsi3_k_result = stoch_rsi3_1m_k_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // let rsi3_d_result = stoch_rsi3_1m_d_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // let rsi30_k_result = stoch_rsi30_1m_k_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiKData{stoch_rsi_k_value, close_time}|close_time); +// // let rsi30_d_result = stoch_rsi30_1m_d_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&StochRsiDData{stoch_rsi_d_value, close_time}|close_time); +// // if rsi30_k_result.is_ok() && rsi30_d_result.is_ok() && rsi3_k_result.is_ok() && rsi3_d_result.is_ok() { +// // if +// // // stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value <= 80.0 || stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value <= 80.0 +// // // (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi3_1m_d_vec[rsi3_d_result.unwrap()].stoch_rsi_d_value) +// // (stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()-1].stoch_rsi_k_value +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - // // (stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value - // // && stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value > stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value - // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - // // || - // || (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= 60.0 - // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-2].stoch_rsi_k_value >= stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value - // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi3_1m_d_vec[rsi3_d_result.unwrap()-1].stoch_rsi_d_value - // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value) - // // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - // // || (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 - // // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 - // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value - // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) - // { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } else { is_filtering_passed = false; } - // } +// // // (stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value +// // // && stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value > stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value +// // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// // // || +// // || (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= 60.0 +// // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-2].stoch_rsi_k_value >= stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value +// // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi3_1m_d_vec[rsi3_d_result.unwrap()-1].stoch_rsi_d_value +// // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()-1].stoch_rsi_k_value <= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()-1].stoch_rsi_d_value) +// // // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// // // || (stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 +// // // && stoch_rsi3_1m_k_vec[rsi3_k_result.unwrap()].stoch_rsi_k_value == 100.0 +// // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value >= stoch_rsi30_1m_d_vec[rsi30_d_result.unwrap()].stoch_rsi_d_value +// // // && stoch_rsi30_1m_k_vec[rsi30_k_result.unwrap()].stoch_rsi_k_value < 80.0) +// // { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } else { is_filtering_passed = false; } +// // } - // // filtering condition: MACD - // if is_filtering_passed == true { - // let macd_vec = ema_macd(&ema3_1m_vec, &ema10_1m_vec, 10).await?; - // let macd_search_result = macd_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&EmaMacd{macd_value, close_time}|close_time); +// // // filtering condition: MACD +// // if is_filtering_passed == true { +// // let macd_vec = ema_macd(&ema3_1m_vec, &ema10_1m_vec, 10).await?; +// // let macd_search_result = macd_vec.binary_search_by_key(&rt_price_1m_vec.last().unwrap().close_time, |&EmaMacd{macd_value, close_time}|close_time); - // if macd_search_result.is_ok() { - // if macd_vec[macd_search_result.unwrap()].macd_value > macd_vec[macd_search_result.unwrap()-1].macd_value { - // is_filtering_passed = true; - // } else { is_filtering_passed = false; } - // } else { is_filtering_passed = false; } - // } +// // if macd_search_result.is_ok() { +// // if macd_vec[macd_search_result.unwrap()].macd_value > macd_vec[macd_search_result.unwrap()-1].macd_value { +// // is_filtering_passed = true; +// // } else { is_filtering_passed = false; } +// // } else { is_filtering_passed = false; } +// // } - // filtering condition: Ratio between amplitude and body of candles - if is_filtering_passed == true { - let sample_length: usize = 5; // 5 candle samsples - let rt_price_1m_partial_vec_option = rt_price_1m_vec - .get(rt_price_1m_vec.len() - sample_length - 1..rt_price_1m_vec.len() - 1); - if rt_price_1m_partial_vec_option.is_some() { - let rt_price_1m_partial_vec = rt_price_1m_partial_vec_option.unwrap(); +// // filtering condition: Ratio between amplitude and body of candles +// if is_filtering_passed == true { +// let sample_length: usize = 5; // 5 candle samsples +// let rt_price_1m_partial_vec_option = rt_price_1m_vec +// .get(rt_price_1m_vec.len() - sample_length - 1..rt_price_1m_vec.len() - 1); +// if rt_price_1m_partial_vec_option.is_some() { +// let rt_price_1m_partial_vec = rt_price_1m_partial_vec_option.unwrap(); - let mut sum_ratio_amp_body = 0.0; - for element in rt_price_1m_partial_vec { - sum_ratio_amp_body += (element.close_price - element.open_price).abs() - / (element.high_price - element.low_price); - } - let average_ratio_amp_body = sum_ratio_amp_body / sample_length as f64; - if average_ratio_amp_body > 0.3 { - is_filtering_passed = true; - } else { - is_filtering_passed = false; - } - } else { - is_filtering_passed = false; - } - } +// let mut sum_ratio_amp_body = 0.0; +// for element in rt_price_1m_partial_vec { +// sum_ratio_amp_body += (element.close_price - element.open_price).abs() +// / (element.high_price - element.low_price); +// } +// let average_ratio_amp_body = sum_ratio_amp_body / sample_length as f64; +// if average_ratio_amp_body > 0.3 { +// is_filtering_passed = true; +// } else { +// is_filtering_passed = false; +// } +// } else { +// is_filtering_passed = false; +// } +// } - // check all filterings are passed - if is_filtering_passed == true { - filtered_2nd_symbols.push((symbol, rt_price_1m_vec.last().unwrap().close_time)); - } - } - } - } +// // check all filterings are passed +// if is_filtering_passed == true { +// filtered_2nd_symbols.push((symbol, rt_price_1m_vec.last().unwrap().close_time)); +// } +// } +// } +// } + +// insert_pre_suggested_coins(2, &filtered_2nd_symbols, alldata).await; +// Ok(()) +// } - insert_pre_suggested_coins(2, &filtered_2nd_symbols, alldata).await; - Ok(()) -} // pub async fn strategist_001 (alldata: &AllData) -> Result<(), Box> { // // [strategist_001 procedure] // // 1. retrieve all usdttrade symbols @@ -2488,893 +2725,893 @@ pub async fn execute_strategist_for_test2( // Ok(()) // } -pub async fn strategist_002( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_002 procedure] - // 1. retrieve all usdttrade symbols - // 2. 1st filtering symbols (opclo_1m price avg < opclo_30m price avg) - // 3. 2nd filtering symbols (sma30 price > opclo_30m price, check if the middle sample among 5 sample from the latest price is the lowest price and then check if RSI30 is lower than 0.3 of the middle sample) - // 4. if the two conditions are right, upload the filtered symbols into [strategist_002_table] - // 5. monitor price of symbols in [strategist_002_table], and upload them into [suggested_coin_list] when price seems to become high - let signal_decision = select_signal_decision().await; - - if signal_decision[0].decision.contains("UP") { - // 2. 1st filtering symbols: candle 1m price avg < candle 30m price avg - let mut opclo_1m_vec: Vec = Vec::new(); - let mut opclo_1m_price_avg = 0.0; - let mut opclo_30m_vec: Vec = Vec::new(); - let mut opclo_30m_price_avg = 0.0; - let mut filtered_1st_symbols: Vec = Vec::new(); - for symbol in &alldata.valid_symbol_vec { - // initialize avgs - opclo_1m_price_avg = 0.0; - opclo_30m_price_avg = 0.0; - - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - // read 1d csv file - if opclo_1m_option.is_some() && opclo_30m_option.is_some() { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if opclo_1m_vec.len() >= 10 && opclo_30m_vec.len() >= 4 { - opclo_1m_vec.reverse(); - opclo_1m_vec.split_off(10); - opclo_30m_vec.reverse(); - opclo_30m_vec.split_off(4); - - // calculate opclo 1m price average - for element in &opclo_1m_vec { - opclo_1m_price_avg += element.opclo_price; - } - opclo_1m_price_avg /= opclo_1m_vec.len() as f64; - - // calculate opclo 30m price average - for element in &opclo_30m_vec { - opclo_30m_price_avg += element.opclo_price; - } - opclo_30m_price_avg /= opclo_30m_vec.len() as f64; - - // campare both prices - if opclo_1m_price_avg < opclo_30m_price_avg * 0.97 { - filtered_1st_symbols.push(symbol.clone()); - } - } - } - } - - // 3. 2nd filtering symbols: check if the middle sample among 5 sample from the latest price of SMA30 is the lowest price and then check if RSI30 is lower than 0.2 of the middle sample - let mut sma10_30m_vec: Vec = Vec::new(); - let mut rsi30_30m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_1st_symbols { - // read 30m opclo, SMA30, rsi30 csv file - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let sma10_30m_option = alldata.sma10_30m_data.iter().position(|x| *x.0 == *symbol); - let rsi30_30m_option = alldata.rsi30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() - && sma10_30m_option.is_some() - && rsi30_30m_option.is_some() - { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - sma10_30m_vec = alldata.sma10_30m_data[sma10_30m_option.unwrap()].1.clone(); - rsi30_30m_vec = alldata.rsi30_30m_data[rsi30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 5 && sma10_30m_vec.len() >= 5 && rsi30_30m_vec.len() >= 5 - { - opclo_30m_vec.pop(); - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(5); - - // 2nd filtering symbols - let result = sma10_30m_vec.binary_search_by_key( - &opclo_30m_vec.first().unwrap().close_time, - |SmaData { - sma_value, - close_time, - }| *close_time, - ); - match result { - Ok(T) => { - if sma10_30m_vec[T].sma_value > opclo_30m_vec[0].opclo_price { - let index_of_min: Option = opclo_30m_vec - .iter() - .enumerate() - .min_by(|(_, a), (_, b)| { - a.opclo_price - .partial_cmp(&b.opclo_price) - .expect("Nan was forbidden.") - }) - .map(|(index, _)| index); - - // index 1 means the middle index of 5 element in a vec, assuming the latest price is included but removed in the vec. - if index_of_min == Some(0) { - let result = rsi30_30m_vec.binary_search_by_key( - &opclo_30m_vec[0].close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi30_30m_vec[T].rsi_value < 20.0 { - filtered_2nd_symbols.push(( - symbol, - opclo_30m_vec.last().unwrap().close_time, - )); - } - } - Err(e) => {} - } - } - } - } - Err(E) => {} - } - } - } - } - // 4. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(2, &filtered_2nd_symbols, alldata).await; - } - // println!("strategist_002 완료"); - Ok(()) -} - -pub async fn strategist_003( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_003 procedure] - // 1. retrieve all usdttrade symbols - // 2. 1st filtering symbols (opclo_1m price avg < opclo_30m price avg) - // 3. 2nd filtering symbols (opclo_30m price at the previous candle < bb_sma30_30m lowerband) - // 4. 3rd filtering symbols (check if the middle sample among 5 sample from the latest price is the lowest price and then check if RSI30 is lower than 0.25 of the middle sample) - // 5. if the two conditions are right, upload the filtered symbols into [suggested_coin_list] - let signal_decision = select_signal_decision().await; - - if signal_decision[0].decision.contains("UP") { - // 1. retrieve all usdttrade symbols - - // 2. 1st filtering symbols: yesterday and today's candle 1d opclo price < EMA10 - let mut opclo_1d_vec: Vec = Vec::new(); - let mut ema10_1d_vec: Vec = Vec::new(); - let mut rsi10_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - for symbol in &alldata.valid_symbol_vec { - // read 1d csv file - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let ema10_1d_option = alldata.ema10_1d_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1d_option = alldata.rsi10_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && ema10_1d_option.is_some() && rsi10_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - ema10_1d_vec = alldata.ema10_1d_data[ema10_1d_option.unwrap()].1.clone(); - rsi10_vec = alldata.rsi10_1d_data[rsi10_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && ema10_1d_vec.len() >= 2 && rsi10_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.split_off(2); - ema10_1d_vec.reverse(); - ema10_1d_vec.split_off(2); - rsi10_vec.reverse(); - rsi10_vec.split_off(2); - - let result = ema10_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |EmaData { - ema_value, - close_time, - }| *close_time, - ); - match result { - Ok(T) => { - if ema10_1d_vec[T].ema_value > opclo_1d_vec[1].opclo_price { - let result = rsi10_vec.binary_search_by_key( - &opclo_1d_vec[1].close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_vec[T].rsi_value < 20.0 { - let result = ema10_1d_vec.binary_search_by_key(&opclo_1d_vec.first().unwrap().close_time, |EmaData{ema_value, close_time}| *close_time); - match result { - Ok(T) => { - if ema10_1d_vec[T].ema_value - > opclo_1d_vec[0].opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(e) => {} - } - } - } - Err(e) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 3. 2nd filtering symbols: lower band in bollingerband of sma30 > candle 30m price - let mut opclo_30m_vec: Vec = Vec::new(); - let mut read_bb_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); // (symbol, closetime) - for symbol in filtered_1st_symbols { - // read 30m csv file - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && bb30_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - read_bb_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 1 && read_bb_vec.len() >= 1 { - let result = read_bb_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if read_bb_vec[T].lowerband > opclo_30m_vec.last().unwrap().opclo_price - { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - } - - // 4. 3rd filtering symbols: check if the middle sample among 5 sample from the latest price of SMA30 is the lowest price and then check if RSI30 is lower than 0.3 of the middle sample - let mut low_1m_vec: Vec = Vec::new(); - let mut bb30_1m_vec: Vec = Vec::new(); - let mut rsi3_vec: Vec = Vec::new(); - let mut rsi10_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_2nd_symbols { - let low_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - - if low_1m_option.is_some() - && bb30_1m_option.is_some() - && rsi3_1m_option.is_some() - && rsi10_1m_option.is_some() - { - low_1m_vec = alldata.rt_price_1m_vec[low_1m_option.unwrap()].1.clone(); - bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); - rsi3_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - - if low_1m_vec.len() >= 1 - && bb30_1m_vec.len() >= 1 - && rsi3_vec.len() >= 1 - && rsi10_vec.len() >= 1 - { - let result = bb30_1m_vec.binary_search_by_key( - &low_1m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1m_vec[T].lowerband > low_1m_vec.last().unwrap().low_price { - let result = rsi3_vec.binary_search_by_key( - &low_1m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_vec[T].rsi_value < 15.0 { - let result = rsi10_vec.binary_search_by_key(&low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - match result { - Ok(T) => { - if rsi10_vec[T].rsi_value < 20.0 { - filtered_3rd_symbols.push(( - symbol, - low_1m_vec.last().unwrap().close_time, - )); - } - } - Err(e) => {} - } - } - } - Err(e) => {} - } - } - } - Err(E) => {} - } - } - } - } - // 4. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(3, &filtered_3rd_symbols, alldata).await; - } - - // println!("strategist_003 완료"); - Ok(()) -} - -pub async fn strategist_004( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_004 procedure] - // 1st filtering: opclo_30m price < bb30_30m lowerband - // 2nd filtering: opclo_1m price < bb30_1m lowerband - // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 - - let signal_decision = select_signal_decision().await; - if signal_decision[0].decision.contains("UP") { - // 1st filtering: (opclo_30m price < bb30 lowerband) - let mut opclo_30m_vec: Vec = Vec::new(); - let mut bb30_30m_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - for symbol in &alldata.valid_symbol_vec { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && bb30_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 1 && bb30_30m_vec.len() >= 1 { - let result = bb30_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_30m_vec[T].lowerband > opclo_30m_vec.last().unwrap().opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - } - - // 2nd filtering: (opclo_1m price < bb30_1m lowerband) - let mut opclo_1m_vec: Vec = Vec::new(); - let mut bb30_1m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - for symbol in filtered_1st_symbols { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1m_option.is_some() && bb30_1m_option.is_some() { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); - - if opclo_1m_vec.len() >= 1 && bb30_1m_vec.len() >= 1 { - let result = bb30_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1m_vec[T].lowerband > opclo_1m_vec.last().unwrap().opclo_price { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - } - - // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 - let mut opclo_1m_vec: Vec = Vec::new(); - let mut rsi3_1m_vec: Vec = Vec::new(); - let mut rsi10_1m_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_2nd_symbols { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1m_option.is_some() && rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - } - - if opclo_1m_vec.len() >= 1 && rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { - let result = rsi3_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_1m_vec[T].rsi_value < 10.0 { - let result = rsi10_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_1m_vec[T].rsi_value < 25.0 { - filtered_3rd_symbols.push(( - symbol, - opclo_1m_vec.last().unwrap().close_time, - )); - } - } - Err(e) => {} - } - } - } - Err(e) => {} - } - } - } - // 4. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(4, &filtered_3rd_symbols, alldata).await; - } - // println!("strategist_004 완료"); - Ok(()) -} - -// for ultra-short -pub async fn strategist_005( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_005 procedure] - // 1st filtering: sampling the least 1m 5 tickers, check DOWN ticker at least 2, check the quote vol of the last ticker > 2X the counterpart of the previous 2 tickers. - // 2nd filtering: opclo_1m price < sma3_1m - // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 - // 4th filtering: check the latest and previous 30m candles are UPs - - let signal_decision = select_signal_decision().await; - if signal_decision[0].decision.contains("UP") { - // 1st filtering: sampling the least 1m 5 tickers, check DOWN ticker at least 2, check the quote vol of the last ticker > 2X the counterpart of the previous 2 tickers. - let mut opclo_1m_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - for symbol in &alldata.valid_symbol_vec { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - - if opclo_1m_option.is_some() { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - if opclo_1m_vec.len() >= 5 { - opclo_1m_vec.reverse(); - opclo_1m_vec.truncate(5); - opclo_1m_vec.reverse(); - - let mut cnt = 0; - for element in &opclo_1m_vec { - if element.candle_type == "DOWN" - && element.opclo_price > opclo_1m_vec.last().unwrap().opclo_price - { - cnt += 1; - } - } - - if cnt >= 2 && opclo_1m_vec.last().unwrap().candle_type == "DOWN" { - let mut vec_cmp = opclo_1m_vec.to_vec(); - vec_cmp.pop(); - vec_cmp.reverse(); - let mut vec_iter = vec_cmp.iter(); - - for _ in 0..2 { - let temp = vec_iter.next(); - if temp.is_some() { - if (temp.unwrap().quote_asset_volume != 0.0) - && (temp.unwrap().quote_asset_volume * 2.0 - < opclo_1m_vec.last().unwrap().quote_asset_volume) - { - filtered_1st_symbols.push(symbol.clone()); - break; - } - } - } - } - } - } - } - - // 2nd filtering: opclo_1m price < sma3_1m - let mut sma3_1m_vec: Vec = Vec::new(); - let mut opclo_1m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - for symbol in filtered_1st_symbols { - let sma3_1m_option = alldata.sma3_1m_data.iter().position(|x| *x.0 == *symbol); - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - - if sma3_1m_option.is_some() && opclo_1m_option.is_some() { - sma3_1m_vec = alldata.sma3_1m_data[sma3_1m_option.unwrap()].1.clone(); - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - - if sma3_1m_vec.len() >= 1 && opclo_1m_vec.len() >= 1 { - let result = sma3_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma3_1m_vec[T].sma_value > opclo_1m_vec.last().unwrap().opclo_price { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - } - - // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 - let mut opclo_1m_vec: Vec = Vec::new(); - let mut rsi3_1m_vec: Vec = Vec::new(); - let mut rsi10_1m_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec = Vec::new(); - for symbol in filtered_2nd_symbols { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1m_option.is_some() && rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - - if opclo_1m_vec.len() >= 1 && rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { - let result = rsi3_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_1m_vec[T].rsi_value < 10.0 { - let result = rsi10_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_1m_vec[T].rsi_value < 25.0 { - filtered_3rd_symbols.push(symbol); - } - } - Err(e) => {} - } - } - } - Err(e) => {} - } - } - } - } - - // 4th filtering: check the latest and previous 30m candles are UPs - let mut opclo_30m_vec: Vec = Vec::new(); - let mut opclo_1m_vec: Vec = Vec::new(); - let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_3rd_symbols { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && opclo_1m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 2 && opclo_1m_vec.len() >= 1 { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(2); - opclo_30m_vec.reverse(); - - if opclo_30m_vec.first().unwrap().candle_type == "UP" - && opclo_30m_vec.last().unwrap().candle_type == "UP" - { - filtered_4th_symbols - .push((symbol, opclo_1m_vec.last().unwrap().close_time)); - } - } - } - } - - // 4. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(5, &filtered_4th_symbols, alldata).await; - } - // println!("strategist_005 완료"); - Ok(()) -} - -pub async fn strategist_006( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_006 procedure] - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 3, the latest opclo_30m < SMA3_30m - // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 - // 4th filtering: the latest 30m quote vol > 2X the previous quote vol - - // 1st filtering symbols: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - let mut opclo_1d_vec: Vec = Vec::new(); - let mut bb30_1d_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - let mut current_price: Option; - for symbol in &alldata.valid_symbol_vec { - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && bb30_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.truncate(2); - opclo_1d_vec.reverse(); - bb30_1d_vec.reverse(); - bb30_1d_vec.truncate(2); - bb30_1d_vec.reverse(); - - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.first().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - current_price = get_current_price(&symbol, &alldata.price_vec).await; - - if current_price.is_some() { - if current_price.unwrap().is_normal() { - if (bb30_1d_vec[T].upperband - > opclo_1d_vec.first().unwrap().opclo_price) - && (opclo_1d_vec.first().unwrap().opclo_price - > current_price.unwrap()) - { - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1d_vec[T].upperband - > opclo_1d_vec.last().unwrap().opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - } - } - Err(E) => {} - } - } - } - } - - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 3, the latest opclo_30m < SMA3_30m - let mut opclo_30m_vec: Vec = Vec::new(); - let mut sma3_30m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - let mut cnt = 0; - for symbol in filtered_1st_symbols { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let sma3_30m_option = alldata.sma3_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && sma3_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - sma3_30m_vec = alldata.sma3_30m_data[sma3_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 5 && sma3_30m_vec.len() >= 1 { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(5); - opclo_30m_vec.reverse(); - - cnt = 0; - for element in &opclo_30m_vec { - if element.candle_type == "DOWN" { - cnt += 1; - } - } - - if cnt >= 3 { - let result = sma3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma3_30m_vec[T].sma_value > opclo_30m_vec.last().unwrap().opclo_price - { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - } - } - - // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 - let mut rsi3_30m_vec: Vec = Vec::new(); - let mut rsi10_30m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec = Vec::new(); - for symbol in filtered_2nd_symbols { - let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { - rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); - rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - let result = rsi3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_30m_vec[T].rsi_value < 15.0 { - let result = rsi10_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_30m_vec[T].rsi_value < 35.0 { - filtered_3rd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 4th filtering: the latest 30m quote vol > 2X the previous quote vol - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_3rd_symbols { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if opclo_30m_vec.len() >= 2 { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(2); - opclo_30m_vec.reverse(); - - if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume - < opclo_30m_vec.last().unwrap().quote_asset_volume - && opclo_30m_vec.last().unwrap().candle_type == "DOWN" - { - filtered_4th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); - } - } - } - } - - // 7. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(6, &filtered_4th_symbols, alldata).await; - Ok(()) -} +// pub async fn strategist_002( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_002 procedure] +// // 1. retrieve all usdttrade symbols +// // 2. 1st filtering symbols (opclo_1m price avg < opclo_30m price avg) +// // 3. 2nd filtering symbols (sma30 price > opclo_30m price, check if the middle sample among 5 sample from the latest price is the lowest price and then check if RSI30 is lower than 0.3 of the middle sample) +// // 4. if the two conditions are right, upload the filtered symbols into [strategist_002_table] +// // 5. monitor price of symbols in [strategist_002_table], and upload them into [suggested_coin_list] when price seems to become high +// let signal_decision = select_signal_decision().await; + +// if signal_decision[0].decision.contains("UP") { +// // 2. 1st filtering symbols: candle 1m price avg < candle 30m price avg +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut opclo_1m_price_avg = 0.0; +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_price_avg = 0.0; +// let mut filtered_1st_symbols: Vec = Vec::new(); +// for symbol in &alldata.valid_symbol_vec { +// // initialize avgs +// opclo_1m_price_avg = 0.0; +// opclo_30m_price_avg = 0.0; + +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// // read 1d csv file +// if opclo_1m_option.is_some() && opclo_30m_option.is_some() { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if opclo_1m_vec.len() >= 10 && opclo_30m_vec.len() >= 4 { +// opclo_1m_vec.reverse(); +// opclo_1m_vec.split_off(10); +// opclo_30m_vec.reverse(); +// opclo_30m_vec.split_off(4); + +// // calculate opclo 1m price average +// for element in &opclo_1m_vec { +// opclo_1m_price_avg += element.opclo_price; +// } +// opclo_1m_price_avg /= opclo_1m_vec.len() as f64; + +// // calculate opclo 30m price average +// for element in &opclo_30m_vec { +// opclo_30m_price_avg += element.opclo_price; +// } +// opclo_30m_price_avg /= opclo_30m_vec.len() as f64; + +// // campare both prices +// if opclo_1m_price_avg < opclo_30m_price_avg * 0.97 { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// } +// } + +// // 3. 2nd filtering symbols: check if the middle sample among 5 sample from the latest price of SMA30 is the lowest price and then check if RSI30 is lower than 0.2 of the middle sample +// let mut sma10_30m_vec: Vec = Vec::new(); +// let mut rsi30_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_1st_symbols { +// // read 30m opclo, SMA30, rsi30 csv file +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let sma10_30m_option = alldata.sma10_30m_data.iter().position(|x| *x.0 == *symbol); +// let rsi30_30m_option = alldata.rsi30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() +// && sma10_30m_option.is_some() +// && rsi30_30m_option.is_some() +// { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// sma10_30m_vec = alldata.sma10_30m_data[sma10_30m_option.unwrap()].1.clone(); +// rsi30_30m_vec = alldata.rsi30_30m_data[rsi30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 5 && sma10_30m_vec.len() >= 5 && rsi30_30m_vec.len() >= 5 +// { +// opclo_30m_vec.pop(); +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(5); + +// // 2nd filtering symbols +// let result = sma10_30m_vec.binary_search_by_key( +// &opclo_30m_vec.first().unwrap().close_time, +// |SmaData { +// sma_value, +// close_time, +// }| *close_time, +// ); +// match result { +// Ok(T) => { +// if sma10_30m_vec[T].sma_value > opclo_30m_vec[0].opclo_price { +// let index_of_min: Option = opclo_30m_vec +// .iter() +// .enumerate() +// .min_by(|(_, a), (_, b)| { +// a.opclo_price +// .partial_cmp(&b.opclo_price) +// .expect("Nan was forbidden.") +// }) +// .map(|(index, _)| index); + +// // index 1 means the middle index of 5 element in a vec, assuming the latest price is included but removed in the vec. +// if index_of_min == Some(0) { +// let result = rsi30_30m_vec.binary_search_by_key( +// &opclo_30m_vec[0].close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi30_30m_vec[T].rsi_value < 20.0 { +// filtered_2nd_symbols.push(( +// symbol, +// opclo_30m_vec.last().unwrap().close_time, +// )); +// } +// } +// Err(e) => {} +// } +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// // 4. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(2, &filtered_2nd_symbols, alldata).await; +// } +// // println!("strategist_002 완료"); +// Ok(()) +// } + +// pub async fn strategist_003( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_003 procedure] +// // 1. retrieve all usdttrade symbols +// // 2. 1st filtering symbols (opclo_1m price avg < opclo_30m price avg) +// // 3. 2nd filtering symbols (opclo_30m price at the previous candle < bb_sma30_30m lowerband) +// // 4. 3rd filtering symbols (check if the middle sample among 5 sample from the latest price is the lowest price and then check if RSI30 is lower than 0.25 of the middle sample) +// // 5. if the two conditions are right, upload the filtered symbols into [suggested_coin_list] +// let signal_decision = select_signal_decision().await; + +// if signal_decision[0].decision.contains("UP") { +// // 1. retrieve all usdttrade symbols + +// // 2. 1st filtering symbols: yesterday and today's candle 1d opclo price < EMA10 +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut ema10_1d_vec: Vec = Vec::new(); +// let mut rsi10_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// for symbol in &alldata.valid_symbol_vec { +// // read 1d csv file +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let ema10_1d_option = alldata.ema10_1d_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1d_option = alldata.rsi10_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && ema10_1d_option.is_some() && rsi10_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// ema10_1d_vec = alldata.ema10_1d_data[ema10_1d_option.unwrap()].1.clone(); +// rsi10_vec = alldata.rsi10_1d_data[rsi10_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && ema10_1d_vec.len() >= 2 && rsi10_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.split_off(2); +// ema10_1d_vec.reverse(); +// ema10_1d_vec.split_off(2); +// rsi10_vec.reverse(); +// rsi10_vec.split_off(2); + +// let result = ema10_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |EmaData { +// ema_value, +// close_time, +// }| *close_time, +// ); +// match result { +// Ok(T) => { +// if ema10_1d_vec[T].ema_value > opclo_1d_vec[1].opclo_price { +// let result = rsi10_vec.binary_search_by_key( +// &opclo_1d_vec[1].close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_vec[T].rsi_value < 20.0 { +// let result = ema10_1d_vec.binary_search_by_key(&opclo_1d_vec.first().unwrap().close_time, |EmaData{ema_value, close_time}| *close_time); +// match result { +// Ok(T) => { +// if ema10_1d_vec[T].ema_value +// > opclo_1d_vec[0].opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(e) => {} +// } +// } +// } +// Err(e) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 3. 2nd filtering symbols: lower band in bollingerband of sma30 > candle 30m price +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut read_bb_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); // (symbol, closetime) +// for symbol in filtered_1st_symbols { +// // read 30m csv file +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && bb30_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// read_bb_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 1 && read_bb_vec.len() >= 1 { +// let result = read_bb_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if read_bb_vec[T].lowerband > opclo_30m_vec.last().unwrap().opclo_price +// { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 4. 3rd filtering symbols: check if the middle sample among 5 sample from the latest price of SMA30 is the lowest price and then check if RSI30 is lower than 0.3 of the middle sample +// let mut low_1m_vec: Vec = Vec::new(); +// let mut bb30_1m_vec: Vec = Vec::new(); +// let mut rsi3_vec: Vec = Vec::new(); +// let mut rsi10_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_2nd_symbols { +// let low_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); + +// if low_1m_option.is_some() +// && bb30_1m_option.is_some() +// && rsi3_1m_option.is_some() +// && rsi10_1m_option.is_some() +// { +// low_1m_vec = alldata.rt_price_1m_vec[low_1m_option.unwrap()].1.clone(); +// bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); +// rsi3_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); + +// if low_1m_vec.len() >= 1 +// && bb30_1m_vec.len() >= 1 +// && rsi3_vec.len() >= 1 +// && rsi10_vec.len() >= 1 +// { +// let result = bb30_1m_vec.binary_search_by_key( +// &low_1m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1m_vec[T].lowerband > low_1m_vec.last().unwrap().low_price { +// let result = rsi3_vec.binary_search_by_key( +// &low_1m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_vec[T].rsi_value < 15.0 { +// let result = rsi10_vec.binary_search_by_key(&low_1m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// match result { +// Ok(T) => { +// if rsi10_vec[T].rsi_value < 20.0 { +// filtered_3rd_symbols.push(( +// symbol, +// low_1m_vec.last().unwrap().close_time, +// )); +// } +// } +// Err(e) => {} +// } +// } +// } +// Err(e) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// // 4. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(3, &filtered_3rd_symbols, alldata).await; +// } + +// // println!("strategist_003 완료"); +// Ok(()) +// } + +// pub async fn strategist_004( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_004 procedure] +// // 1st filtering: opclo_30m price < bb30_30m lowerband +// // 2nd filtering: opclo_1m price < bb30_1m lowerband +// // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 + +// let signal_decision = select_signal_decision().await; +// if signal_decision[0].decision.contains("UP") { +// // 1st filtering: (opclo_30m price < bb30 lowerband) +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut bb30_30m_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// for symbol in &alldata.valid_symbol_vec { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && bb30_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 1 && bb30_30m_vec.len() >= 1 { +// let result = bb30_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_30m_vec[T].lowerband > opclo_30m_vec.last().unwrap().opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 2nd filtering: (opclo_1m price < bb30_1m lowerband) +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut bb30_1m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// for symbol in filtered_1st_symbols { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1m_option.is_some() && bb30_1m_option.is_some() { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); + +// if opclo_1m_vec.len() >= 1 && bb30_1m_vec.len() >= 1 { +// let result = bb30_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1m_vec[T].lowerband > opclo_1m_vec.last().unwrap().opclo_price { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut rsi3_1m_vec: Vec = Vec::new(); +// let mut rsi10_1m_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_2nd_symbols { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1m_option.is_some() && rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); +// } + +// if opclo_1m_vec.len() >= 1 && rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { +// let result = rsi3_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_1m_vec[T].rsi_value < 10.0 { +// let result = rsi10_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_1m_vec[T].rsi_value < 25.0 { +// filtered_3rd_symbols.push(( +// symbol, +// opclo_1m_vec.last().unwrap().close_time, +// )); +// } +// } +// Err(e) => {} +// } +// } +// } +// Err(e) => {} +// } +// } +// } +// // 4. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(4, &filtered_3rd_symbols, alldata).await; +// } +// // println!("strategist_004 완료"); +// Ok(()) +// } + +// // for ultra-short +// pub async fn strategist_005( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_005 procedure] +// // 1st filtering: sampling the least 1m 5 tickers, check DOWN ticker at least 2, check the quote vol of the last ticker > 2X the counterpart of the previous 2 tickers. +// // 2nd filtering: opclo_1m price < sma3_1m +// // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 +// // 4th filtering: check the latest and previous 30m candles are UPs + +// let signal_decision = select_signal_decision().await; +// if signal_decision[0].decision.contains("UP") { +// // 1st filtering: sampling the least 1m 5 tickers, check DOWN ticker at least 2, check the quote vol of the last ticker > 2X the counterpart of the previous 2 tickers. +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); + +// if opclo_1m_option.is_some() { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// if opclo_1m_vec.len() >= 5 { +// opclo_1m_vec.reverse(); +// opclo_1m_vec.truncate(5); +// opclo_1m_vec.reverse(); + +// let mut cnt = 0; +// for element in &opclo_1m_vec { +// if element.candle_type == "DOWN" +// && element.opclo_price > opclo_1m_vec.last().unwrap().opclo_price +// { +// cnt += 1; +// } +// } + +// if cnt >= 2 && opclo_1m_vec.last().unwrap().candle_type == "DOWN" { +// let mut vec_cmp = opclo_1m_vec.to_vec(); +// vec_cmp.pop(); +// vec_cmp.reverse(); +// let mut vec_iter = vec_cmp.iter(); + +// for _ in 0..2 { +// let temp = vec_iter.next(); +// if temp.is_some() { +// if (temp.unwrap().quote_asset_volume != 0.0) +// && (temp.unwrap().quote_asset_volume * 2.0 +// < opclo_1m_vec.last().unwrap().quote_asset_volume) +// { +// filtered_1st_symbols.push(symbol.clone()); +// break; +// } +// } +// } +// } +// } +// } +// } + +// // 2nd filtering: opclo_1m price < sma3_1m +// let mut sma3_1m_vec: Vec = Vec::new(); +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// for symbol in filtered_1st_symbols { +// let sma3_1m_option = alldata.sma3_1m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); + +// if sma3_1m_option.is_some() && opclo_1m_option.is_some() { +// sma3_1m_vec = alldata.sma3_1m_data[sma3_1m_option.unwrap()].1.clone(); +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); + +// if sma3_1m_vec.len() >= 1 && opclo_1m_vec.len() >= 1 { +// let result = sma3_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma3_1m_vec[T].sma_value > opclo_1m_vec.last().unwrap().opclo_price { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 3rd filtering: RSI3_1m < 10, RSI10_1m < 25 +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut rsi3_1m_vec: Vec = Vec::new(); +// let mut rsi10_1m_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec = Vec::new(); +// for symbol in filtered_2nd_symbols { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1m_option.is_some() && rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); + +// if opclo_1m_vec.len() >= 1 && rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { +// let result = rsi3_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_1m_vec[T].rsi_value < 10.0 { +// let result = rsi10_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_1m_vec[T].rsi_value < 25.0 { +// filtered_3rd_symbols.push(symbol); +// } +// } +// Err(e) => {} +// } +// } +// } +// Err(e) => {} +// } +// } +// } +// } + +// // 4th filtering: check the latest and previous 30m candles are UPs +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_3rd_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && opclo_1m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 2 && opclo_1m_vec.len() >= 1 { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(2); +// opclo_30m_vec.reverse(); + +// if opclo_30m_vec.first().unwrap().candle_type == "UP" +// && opclo_30m_vec.last().unwrap().candle_type == "UP" +// { +// filtered_4th_symbols +// .push((symbol, opclo_1m_vec.last().unwrap().close_time)); +// } +// } +// } +// } + +// // 4. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(5, &filtered_4th_symbols, alldata).await; +// } +// // println!("strategist_005 완료"); +// Ok(()) +// } + +// pub async fn strategist_006( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_006 procedure] +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 3, the latest opclo_30m < SMA3_30m +// // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 +// // 4th filtering: the latest 30m quote vol > 2X the previous quote vol + +// // 1st filtering symbols: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut bb30_1d_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// let mut current_price: Option; +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && bb30_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.truncate(2); +// opclo_1d_vec.reverse(); +// bb30_1d_vec.reverse(); +// bb30_1d_vec.truncate(2); +// bb30_1d_vec.reverse(); + +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.first().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// current_price = get_current_price(&symbol, &alldata.price_vec).await; + +// if current_price.is_some() { +// if current_price.unwrap().is_normal() { +// if (bb30_1d_vec[T].upperband +// > opclo_1d_vec.first().unwrap().opclo_price) +// && (opclo_1d_vec.first().unwrap().opclo_price +// > current_price.unwrap()) +// { +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1d_vec[T].upperband +// > opclo_1d_vec.last().unwrap().opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 3, the latest opclo_30m < SMA3_30m +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut sma3_30m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// let mut cnt = 0; +// for symbol in filtered_1st_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let sma3_30m_option = alldata.sma3_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && sma3_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// sma3_30m_vec = alldata.sma3_30m_data[sma3_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 5 && sma3_30m_vec.len() >= 1 { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(5); +// opclo_30m_vec.reverse(); + +// cnt = 0; +// for element in &opclo_30m_vec { +// if element.candle_type == "DOWN" { +// cnt += 1; +// } +// } + +// if cnt >= 3 { +// let result = sma3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma3_30m_vec[T].sma_value > opclo_30m_vec.last().unwrap().opclo_price +// { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } + +// // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 +// let mut rsi3_30m_vec: Vec = Vec::new(); +// let mut rsi10_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec = Vec::new(); +// for symbol in filtered_2nd_symbols { +// let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); +// rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// let result = rsi3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_30m_vec[T].rsi_value < 15.0 { +// let result = rsi10_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_30m_vec[T].rsi_value < 35.0 { +// filtered_3rd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 4th filtering: the latest 30m quote vol > 2X the previous quote vol +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_3rd_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if opclo_30m_vec.len() >= 2 { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(2); +// opclo_30m_vec.reverse(); + +// if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume +// < opclo_30m_vec.last().unwrap().quote_asset_volume +// && opclo_30m_vec.last().unwrap().candle_type == "DOWN" +// { +// filtered_4th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); +// } +// } +// } +// } + +// // 7. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(6, &filtered_4th_symbols, alldata).await; +// Ok(()) +// } // pub async fn strategist_006 () -> Result<(), Box> { // // [strategist_006 procedure] @@ -4777,1510 +5014,1510 @@ pub async fn strategist_006( // Ok(()) // } -pub async fn strategist_013( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_013 procedure] - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - // 3rd filtering: low price 30m < BB30_30m lowerband - // 4th filtering: RSI3_30m < 15, RSI10_30m < 35 - // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 - // 6th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m - - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - let mut opclo_1d_vec: Vec = Vec::new(); - let mut bb30_1d_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - let mut current_price: Option; - for symbol in &alldata.valid_symbol_vec { - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && bb30_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.truncate(2); - opclo_1d_vec.reverse(); - bb30_1d_vec.reverse(); - bb30_1d_vec.truncate(2); - bb30_1d_vec.reverse(); - - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.first().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - current_price = get_current_price(&symbol, &alldata.price_vec).await; - - if current_price.is_some() { - if current_price.unwrap().is_normal() { - if (bb30_1d_vec[T].upperband - > opclo_1d_vec.first().unwrap().opclo_price) - && (opclo_1d_vec.first().unwrap().opclo_price - > current_price.unwrap()) - { - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1d_vec[T].upperband - > opclo_1d_vec.last().unwrap().opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - } - } - Err(E) => {} - } - } - } - } - - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - let mut opclo_30m_vec: Vec = Vec::new(); - let mut ema3_30m_vec: Vec = Vec::new(); - let mut sma30_30m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - let mut cnt = 0; - for symbol in filtered_1st_symbols { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); - let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && ema3_30m_option.is_some() && sma30_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); - sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 5 && ema3_30m_vec.len() >= 1 && sma30_30m_vec.len() >= 1 { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(5); - opclo_30m_vec.reverse(); - - cnt = 0; - for element in &opclo_30m_vec { - if element.candle_type == "DOWN" { - cnt += 1; - } - } - - if cnt >= 4 { - let result = ema3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema3_30m_vec[T].ema_value > opclo_30m_vec.last().unwrap().opclo_price - { - let result = sma30_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma30_30m_vec[T].sma_value - > opclo_30m_vec.last().unwrap().opclo_price - { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - } - - // 3rd filtering: low price 30m < BB30_30m lowerband - let mut low_30m_vec: Vec = Vec::new(); - let mut bb30_30m_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec = Vec::new(); - for symbol in filtered_2nd_symbols { - let low_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); - - if low_30m_option.is_some() && bb30_30m_option.is_some() { - low_30m_vec = alldata.rt_price_30m_vec[low_30m_option.unwrap()].1.clone(); - bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); - - if low_30m_vec.len() >= 1 && bb30_30m_vec.len() >= 1 { - let result = bb30_30m_vec.binary_search_by_key( - &low_30m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_30m_vec[T].lowerband > low_30m_vec.last().unwrap().low_price { - filtered_3rd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - } - - // 4th filtering: 30m RSI 3 < 15, 30m RSI 10 < 35 - let mut rsi3_30m_vec: Vec = Vec::new(); - let mut rsi10_30m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_4th_symbols: Vec = Vec::new(); - for symbol in filtered_3rd_symbols { - let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { - rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); - rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - let result = rsi3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_30m_vec[T].rsi_value < 15.0 { - let result = rsi10_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_30m_vec[T].rsi_value < 35.0 { - filtered_4th_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 - let mut rsi3_1m_vec: Vec = Vec::new(); - let mut rsi10_1m_vec: Vec = Vec::new(); - let mut filtered_5th_symbols: Vec = Vec::new(); // (symbol, closetime) - for symbol in filtered_4th_symbols { - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - - if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { - rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - - if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { - if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 - && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 - { - filtered_5th_symbols.push(symbol); - } - } - } - } - - // 6th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m, clo_1m < BB30_1m lowerband - let mut opclo_1m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut ema3_1m_vec: Vec = Vec::new(); - let mut ema10_1m_vec: Vec = Vec::new(); - let mut bb30_1m_vec: Vec = Vec::new(); - let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_5th_symbols { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); - let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); - let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1m_option.is_some() - && opclo_30m_option.is_some() - && ema3_1m_option.is_some() - && ema10_1m_option.is_some() - && bb30_1m_option.is_some() - { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); - ema10_1m_vec = alldata.ema10_1m_data[ema10_1m_option.unwrap()].1.clone(); - bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); - - if opclo_1m_vec.len() >= 1 - && opclo_30m_vec.len() >= 1 - && ema3_1m_vec.len() >= 1 - && ema10_1m_vec.len() >= 1 - && bb30_1m_vec.len() >= 1 - { - let result = ema3_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema3_1m_vec[T].ema_value > opclo_1m_vec.last().unwrap().opclo_price { - let result = ema10_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema10_1m_vec[T].ema_value - > opclo_1m_vec.last().unwrap().opclo_price - { - let result = bb30_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| { - close_time - }, - ); - match result { - Ok(T) => { - if bb30_1m_vec[T].lowerband - > opclo_1d_vec.last().unwrap().close_price - { - filtered_6th_symbols.push(( - symbol, - opclo_30m_vec.last().unwrap().close_time, - )); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - insert_pre_suggested_coins(13, &filtered_6th_symbols, alldata).await; - - Ok(()) -} - -pub async fn strategist_014( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_014 procedure] - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d, - // 2nd filtering: the latest 2 opclo_1d < SMA3_1d (apply this filtering if 5days angle of marketcap is negative and marketcap opinion is DOWN or KEEP) - // 3rd filtering: RSI3_1d < 20, RSI10_1d < 35, RSI30_1d < 45 (if 5days angle of marketcap is negative and marketcap opinion is UP, this filtering will be passed) - // 4th filtering: - // 1) check the latest candle is DOWN (common) - // 2) DOWN candles having 0.3% below change is not counted - // 3) check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - // 4) OR, check 5 samples of candle 30m has DOWN candles at least 3, the latest clo_30m < BB30_30m lowerband - // 5th filtering: RSI3_30m < 20, RSI10_30m < 35 - // 6th filtering: RSI3_1m < 10, RSI10_1m < 25 - // 7th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m, clo_1m < BB30_1m lowerband - // 8th filtering: check the latest candle is DOWN and check 5 samples of candle 1m has DOWN candles at least 3 - - let signal_opinions = select_signal_association_opinion().await; - let market_cap_index = select_marketcap().await; - - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band and SMA3_1d, current price < previous opclo_1d, - let mut opclo_1d_vec: Vec = Vec::new(); - let mut bb30_1d_vec: Vec = Vec::new(); - let mut sma3_1d_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - let mut current_price: Option; - for symbol in &alldata.valid_symbol_vec { - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); - let sma3_1d_option = alldata.sma3_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && bb30_1d_option.is_some() && sma3_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); - sma3_1d_vec = alldata.sma3_1d_data[sma3_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 && sma3_1d_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.truncate(2); - opclo_1d_vec.reverse(); - bb30_1d_vec.reverse(); - bb30_1d_vec.truncate(2); - bb30_1d_vec.reverse(); - sma3_1d_vec.reverse(); - sma3_1d_vec.truncate(2); - sma3_1d_vec.reverse(); - - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.first().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - current_price = get_current_price(&symbol, &alldata.price_vec).await; - - if current_price.is_some() { - if current_price.unwrap().is_normal() { - if (bb30_1d_vec[T].upperband - > opclo_1d_vec.first().unwrap().opclo_price) - && (opclo_1d_vec.first().unwrap().opclo_price - > current_price.unwrap()) - { - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1d_vec[T].upperband - > opclo_1d_vec.last().unwrap().opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - } - } - Err(E) => {} - } - } - } - } - - // 2nd filtering: the latest 2 opclo_1d < SMA3_1d (apply this filtering if 5days angle of marketcap is negative and marketcap opinion is DOWN or KEEP) - let mut opclo_1d_vec: Vec = Vec::new(); - let mut sma3_1d_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - if (signal_opinions[0].opinion.contains("DOWN") || signal_opinions[0].opinion.contains("KEEP")) - && market_cap_index[1].market_cap_index.is_sign_negative() - { - for symbol in &alldata.valid_symbol_vec { - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let sma3_1d_option = alldata.sma3_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && sma3_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - sma3_1d_vec = alldata.sma3_1d_data[sma3_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && sma3_1d_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.truncate(2); - opclo_1d_vec.reverse(); - sma3_1d_vec.reverse(); - sma3_1d_vec.truncate(2); - sma3_1d_vec.reverse(); - - let result = sma3_1d_vec.binary_search_by_key( - &opclo_1d_vec.first().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma3_1d_vec[T].sma_value > opclo_1d_vec.first().unwrap().opclo_price - { - let result = sma3_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma3_1d_vec[T].sma_value - > opclo_1d_vec.last().unwrap().opclo_price - { - filtered_2nd_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - } else { - filtered_2nd_symbols = filtered_1st_symbols; - } - - // 3rd filtering: RSI3_1d < 20, RSI10_1d < 35, RSI30_1d < 45 (if 5days angle of marketcap is negative and marketcap opinion is UP, this filtering will be passed) - let mut rsi3_1d_vec: Vec = Vec::new(); - let mut rsi10_1d_vec: Vec = Vec::new(); - let mut rsi30_1d_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec = Vec::new(); - if signal_opinions[0].opinion.contains("UP") - && market_cap_index[1].market_cap_index.is_sign_negative() - { - filtered_3rd_symbols = filtered_2nd_symbols; - } else { - for symbol in filtered_2nd_symbols { - let rsi3_1d_option = alldata.rsi3_1d_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1d_option = alldata.rsi10_1d_data.iter().position(|x| *x.0 == *symbol); - let rsi30_1d_option = alldata.rsi30_1d_data.iter().position(|x| *x.0 == *symbol); - - if rsi3_1d_option.is_some() && rsi10_1d_option.is_some() && rsi30_1d_option.is_some() { - rsi3_1d_vec = alldata.rsi3_1d_data[rsi3_1d_option.unwrap()].1.clone(); - rsi10_1d_vec = alldata.rsi10_1d_data[rsi10_1d_option.unwrap()].1.clone(); - rsi30_1d_vec = alldata.rsi30_1d_data[rsi30_1d_option.unwrap()].1.clone(); - - if rsi3_1d_vec.len() >= 1 && rsi10_1d_vec.len() >= 1 && rsi30_1d_vec.len() >= 1 { - if rsi3_1d_vec.last().unwrap().rsi_value < 20.0 - && rsi10_1d_vec.last().unwrap().rsi_value < 35.0 - && rsi30_1d_vec.last().unwrap().rsi_value < 45.0 - { - filtered_3rd_symbols.push(symbol); - } - } - } - } - } - - // 4th filtering: - // 1) check the latest candle is DOWN (common) - // 2) DOWN candles having 0.3% below change is not counted - // 3) check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - // 4) OR, check 5 samples of candle 30m has DOWN candles at least 3, the latest clo_30m < BB30_30m lowerband - - let mut opclo_30m_vec: Vec = Vec::new(); - let mut ema3_30m_vec: Vec = Vec::new(); - let mut sma30_30m_vec: Vec = Vec::new(); - let mut bb30_30m_vec: Vec = Vec::new(); - let mut filtered_4th_symbols: Vec = Vec::new(); - let mut cnt = 0; - for symbol in filtered_3rd_symbols { - let mut is_filtering_passed: bool = false; - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); - let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); - let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() - && ema3_30m_option.is_some() - && sma30_30m_option.is_some() - && bb30_30m_option.is_some() - { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); - sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); - bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 5 - && ema3_30m_vec.len() >= 1 - && sma30_30m_vec.len() >= 1 - && bb30_30m_vec.len() >= 1 - { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(5); - opclo_30m_vec.reverse(); - - if opclo_30m_vec.last().unwrap().candle_type == "DOWN" { - cnt = 0; - for element in &opclo_30m_vec { - if element.candle_type == "DOWN" { - if (element.open_price / element.close_price) - 1.0 > 0.003 { - cnt += 1; - } - } - } - - if cnt >= 4 { - let result = ema3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema3_30m_vec[T].ema_value - > opclo_30m_vec.last().unwrap().opclo_price - { - let result = sma30_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma30_30m_vec[T].sma_value - > opclo_30m_vec.last().unwrap().opclo_price - { - is_filtering_passed = true; - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } else if cnt == 3 { - let result = bb30_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_30m_vec[T].lowerband - > opclo_30m_vec.last().unwrap().close_price - { - is_filtering_passed = true; - } - } - Err(E) => {} - } - } - } - } - } - if is_filtering_passed == true { - filtered_4th_symbols.push(symbol); - } - } - - // 5th filtering: RSI3_30m < 20, RSI10_30m < 35 - let mut rsi3_30m_vec: Vec = Vec::new(); - let mut rsi10_30m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_5th_symbols: Vec = Vec::new(); - for symbol in filtered_4th_symbols { - let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { - rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); - rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - let result = rsi3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_30m_vec[T].rsi_value < 20.0 { - let result = rsi10_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_30m_vec[T].rsi_value < 35.0 { - filtered_5th_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 6th filtering: RSI3_1m < 10, RSI10_1m < 25 - let mut rsi3_1m_vec: Vec = Vec::new(); - let mut rsi10_1m_vec: Vec = Vec::new(); - let mut filtered_6th_symbols: Vec = Vec::new(); - for symbol in filtered_5th_symbols { - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - - if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { - rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - - if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { - if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 - && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 - { - filtered_6th_symbols.push(symbol); - } - } - } - } - - // // 6. 5th filtering symbols: 30m current vol > 30m previous vol * 2 - // let mut opclo_30m_vec: Vec = Vec::new(); - // let mut filtered_4th_symbols: Vec<(String, u64)> = Vec::new(); // (symbol, closetime) - // for element in filtered_3rd_symbols { - // let opclo_30m_result = read_price_into_vector("30m", &element).await; - - // if opclo_30m_result.is_ok() { - // let opclo_30m_option = opclo_30m_result?; - // if opclo_30m_option.is_some() { - // opclo_30m_vec = opclo_30m_option.unwrap(); - - // if opclo_30m_vec.len() >= 2 { - // opclo_30m_vec.reverse(); - // opclo_30m_vec.truncate(2); - // opclo_30m_vec.reverse(); - - // if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume < opclo_30m_vec.last().unwrap().quote_asset_volume && opclo_30m_vec.last().unwrap().candle_type == "DOWN" { - // filtered_4th_symbols.push((element, opclo_30m_vec.last().unwrap().close_time)); - // } - // } - // } - // } - // } - - // 7th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m, clo_1m < BB30_1m lowerband - let mut opclo_1m_vec: Vec = Vec::new(); - let mut ema3_1m_vec: Vec = Vec::new(); - let mut ema10_1m_vec: Vec = Vec::new(); - let mut bb30_1m_vec: Vec = Vec::new(); - let mut filtered_7th_symbols: Vec = Vec::new(); - for symbol in filtered_6th_symbols { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); - let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); - let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1m_option.is_some() - && ema3_1m_option.is_some() - && ema10_1m_option.is_some() - && bb30_1m_option.is_some() - { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); - ema10_1m_vec = alldata.ema10_1m_data[ema10_1m_option.unwrap()].1.clone(); - bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); - - if opclo_1m_vec.len() >= 1 - && ema3_1m_vec.len() >= 1 - && ema10_1m_vec.len() >= 1 - && bb30_1m_vec.len() >= 1 - { - let result = ema3_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema3_1m_vec[T].ema_value > opclo_1m_vec.last().unwrap().opclo_price { - let result = ema10_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema10_1m_vec[T].ema_value - > opclo_1m_vec.last().unwrap().opclo_price - { - let result = bb30_1m_vec.binary_search_by_key( - &opclo_1m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| { - close_time - }, - ); - match result { - Ok(T) => { - if bb30_1m_vec[T].lowerband - > opclo_1d_vec.last().unwrap().close_price - { - filtered_7th_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 8th filtering: - // check the latest candle is DOWN and check 5 samples of candle 30m has DOWN candles at least 3 - let mut opclo_1m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_8th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - - let mut cnt = 0; - for symbol in filtered_7th_symbols { - let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && opclo_1m_option.is_some() { - opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if opclo_1m_vec.len() >= 5 && opclo_30m_vec.len() >= 5 { - opclo_1m_vec.reverse(); - opclo_1m_vec.truncate(5); - opclo_1m_vec.reverse(); - - if opclo_1m_vec.last().unwrap().candle_type == "DOWN" { - cnt = 0; - for element in &opclo_1m_vec { - if element.candle_type == "DOWN" { - cnt += 1; - } - } - - if cnt >= 3 { - filtered_8th_symbols - .push((symbol, opclo_30m_vec.last().unwrap().close_time)); - } - } - } - } - } - - insert_pre_suggested_coins(14, &filtered_8th_symbols, alldata).await; - - Ok(()) -} - -pub async fn strategist_015( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_015 procedure] - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - // 3rd filtering: low price 30m < BB30_30m lowerband - // 4th filtering: RSI3_30m < 15, RSI10_30m < 35 - // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 - - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - let mut opclo_1d_vec: Vec = Vec::new(); - let mut bb30_1d_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - let mut current_price: Option; - for symbol in &alldata.valid_symbol_vec { - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && bb30_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.truncate(2); - opclo_1d_vec.reverse(); - bb30_1d_vec.reverse(); - bb30_1d_vec.truncate(2); - bb30_1d_vec.reverse(); - - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.first().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - current_price = get_current_price(&symbol, &alldata.price_vec).await; - - if current_price.is_some() { - if current_price.unwrap().is_normal() { - if (bb30_1d_vec[T].upperband - > opclo_1d_vec.first().unwrap().opclo_price) - && (opclo_1d_vec.first().unwrap().opclo_price - > current_price.unwrap()) - { - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1d_vec[T].upperband - > opclo_1d_vec.last().unwrap().opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - } - } - Err(E) => {} - } - } - } - } - - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - let mut opclo_30m_vec: Vec = Vec::new(); - let mut ema3_30m_vec: Vec = Vec::new(); - let mut sma30_30m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - let mut cnt = 0; - for symbol in filtered_1st_symbols { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); - let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && ema3_30m_option.is_some() && sma30_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); - sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 5 && ema3_30m_vec.len() >= 1 && sma30_30m_vec.len() >= 1 { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(5); - opclo_30m_vec.reverse(); - - cnt = 0; - for element in &opclo_30m_vec { - if element.candle_type == "DOWN" { - cnt += 1; - } - } - - if cnt >= 4 { - let result = ema3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema3_30m_vec[T].ema_value > opclo_30m_vec.last().unwrap().opclo_price - { - let result = sma30_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma30_30m_vec[T].sma_value - > opclo_30m_vec.last().unwrap().opclo_price - { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - } - - // 3rd filtering: low price 30m < BB30_30m lowerband - let mut low_30m_vec: Vec = Vec::new(); - let mut bb30_30m_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec = Vec::new(); - for symbol in filtered_2nd_symbols { - let low_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); - - if low_30m_option.is_some() && bb30_30m_option.is_some() { - low_30m_vec = alldata.rt_price_30m_vec[low_30m_option.unwrap()].1.clone(); - bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); - - if low_30m_vec.len() >= 1 && bb30_30m_vec.len() >= 1 { - let result = bb30_30m_vec.binary_search_by_key( - &low_30m_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_30m_vec[T].lowerband > low_30m_vec.last().unwrap().low_price { - filtered_3rd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - } - - // 4th filtering: 30m RSI 3 < 15, 30m RSI 10 < 35 - let mut rsi3_30m_vec: Vec = Vec::new(); - let mut rsi10_30m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_4th_symbols: Vec = Vec::new(); - for symbol in filtered_3rd_symbols { - let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { - rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); - rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - let result = rsi3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_30m_vec[T].rsi_value < 15.0 { - let result = rsi10_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_30m_vec[T].rsi_value < 35.0 { - filtered_4th_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 - let mut rsi3_1m_vec: Vec = Vec::new(); - let mut rsi10_1m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_4th_symbols { - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() && opclo_30m_option.is_some() { - rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 - && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 - { - filtered_5th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); - } - } - - // if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - // let result = rsi3_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi3_1m_vec[T].rsi_value < 10.0 { - // let result = rsi10_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi10_1m_vec[T].rsi_value < 25.0 { - // filtered_5th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); - // } - // }, - // Err(E) => {} - // } - // } - // }, - // Err(E) => {} - // } - // } - } - } - // // 6. 5th filtering symbols: 30m current vol > 30m previous vol * 2 - // let mut opclo_30m_vec: Vec = Vec::new(); - // let mut filtered_5th_symbols: Vec<(String, u64)> = Vec::new(); // (symbol, closetime) - // for element in filtered_4th_symbols { - // let opclo_30m_result = read_price_into_vector("30m", &element).await; - - // if opclo_30m_result.is_ok() { - // let opclo_30m_option = opclo_30m_result?; - // if opclo_30m_option.is_some() { - // opclo_30m_vec = opclo_30m_option.unwrap(); - - // if opclo_30m_vec.len() >= 2 { - // opclo_30m_vec.reverse(); - // opclo_30m_vec.truncate(2); - // opclo_30m_vec.reverse(); - - // if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume < opclo_30m_vec.last().unwrap().quote_asset_volume && opclo_30m_vec.last().unwrap().candle_type == "DOWN" { - // filtered_5th_symbols.push((element, opclo_30m_vec.last().unwrap().close_time)); - // } - // } - // } - // } - // } - // println!("5: {:?}", filtered_5th_symbols); - // 7. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(15, &filtered_5th_symbols, alldata).await; - - Ok(()) -} - -pub async fn strategist_016( - alldata: &AllData, -) -> Result<(), Box> { - // [strategist_016 procedure] - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 - // 4th filtering: RSI3_1m < 10, RSI10_1m < 25 - - // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d - let mut opclo_1d_vec: Vec = Vec::new(); - let mut bb30_1d_vec: Vec = Vec::new(); - let mut filtered_1st_symbols: Vec = Vec::new(); - let mut current_price: Option; - for symbol in &alldata.valid_symbol_vec { - let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); - let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); - - if opclo_1d_option.is_some() && bb30_1d_option.is_some() { - opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); - bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); - - if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { - opclo_1d_vec.reverse(); - opclo_1d_vec.truncate(2); - opclo_1d_vec.reverse(); - bb30_1d_vec.reverse(); - bb30_1d_vec.truncate(2); - bb30_1d_vec.reverse(); - - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.first().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - current_price = get_current_price(&symbol, &alldata.price_vec).await; - - if current_price.is_some() { - if current_price.unwrap().is_normal() { - if (bb30_1d_vec[T].upperband - > opclo_1d_vec.first().unwrap().opclo_price) - && (opclo_1d_vec.first().unwrap().opclo_price - > current_price.unwrap()) - { - let result = bb30_1d_vec.binary_search_by_key( - &opclo_1d_vec.last().unwrap().close_time, - |&BollingerBandData { - sma, - upperband, - lowerband, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if bb30_1d_vec[T].upperband - > opclo_1d_vec.last().unwrap().opclo_price - { - filtered_1st_symbols.push(symbol.clone()); - } - } - Err(E) => {} - } - } - } - } - } - Err(E) => {} - } - } - } - } - - // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m - let mut opclo_30m_vec: Vec = Vec::new(); - let mut ema3_30m_vec: Vec = Vec::new(); - let mut sma30_30m_vec: Vec = Vec::new(); - let mut filtered_2nd_symbols: Vec = Vec::new(); - let mut cnt = 0; - for symbol in filtered_1st_symbols { - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); - let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); - - if opclo_30m_option.is_some() && ema3_30m_option.is_some() && sma30_30m_option.is_some() { - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); - sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); - - if opclo_30m_vec.len() >= 5 && ema3_30m_vec.len() >= 1 && sma30_30m_vec.len() >= 1 { - opclo_30m_vec.reverse(); - opclo_30m_vec.truncate(5); - opclo_30m_vec.reverse(); - - cnt = 0; - for element in &opclo_30m_vec { - if element.candle_type == "DOWN" { - cnt += 1; - } - } - - if cnt >= 4 { - let result = ema3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&EmaData { - ema_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if ema3_30m_vec[T].ema_value > opclo_30m_vec.last().unwrap().opclo_price - { - let result = sma30_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&SmaData { - sma_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if sma30_30m_vec[T].sma_value - > opclo_30m_vec.last().unwrap().opclo_price - { - filtered_2nd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - } - - // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 - let mut rsi3_30m_vec: Vec = Vec::new(); - let mut rsi10_30m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_3rd_symbols: Vec = Vec::new(); - for symbol in filtered_2nd_symbols { - let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { - rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); - rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - let result = rsi3_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi3_30m_vec[T].rsi_value < 15.0 { - let result = rsi10_30m_vec.binary_search_by_key( - &opclo_30m_vec.last().unwrap().close_time, - |&RsiData { - rsi_value, - close_time, - }| close_time, - ); - match result { - Ok(T) => { - if rsi10_30m_vec[T].rsi_value < 35.0 { - filtered_3rd_symbols.push(symbol); - } - } - Err(E) => {} - } - } - } - Err(E) => {} - } - } - } - } - - // 4th filtering: RSI3_1m < 10, RSI10_1m < 25 - let mut rsi3_1m_vec: Vec = Vec::new(); - let mut rsi10_1m_vec: Vec = Vec::new(); - let mut opclo_30m_vec: Vec = Vec::new(); - let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) - for symbol in filtered_3rd_symbols { - let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); - let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); - let opclo_30m_option = alldata - .rt_price_30m_vec - .iter() - .position(|x| *x.0 == *symbol); - - if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() && opclo_30m_option.is_some() { - rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); - rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); - opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] - .1 - .clone(); - - if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 - && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 - { - filtered_4th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); - } - } - - // if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { - // let result = rsi3_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi3_1m_vec[T].rsi_value < 10.0 { - // let result = rsi10_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); - // match result { - // Ok(T) => { - // if rsi10_1m_vec[T].rsi_value < 25.0 { - // filtered_5th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); - // } - // }, - // Err(E) => {} - // } - // } - // }, - // Err(E) => {} - // } - // } - } - } - - // // 6. 5th filtering symbols: 30m current vol > 30m previous vol * 2 - // let mut opclo_30m_vec: Vec = Vec::new(); - // let mut filtered_4th_symbols: Vec<(String, u64)> = Vec::new(); // (symbol, closetime) - // for element in filtered_3rd_symbols { - // let opclo_30m_result = read_price_into_vector("30m", &element).await; - - // if opclo_30m_result.is_ok() { - // let opclo_30m_option = opclo_30m_result?; - // if opclo_30m_option.is_some() { - // opclo_30m_vec = opclo_30m_option.unwrap(); - - // if opclo_30m_vec.len() >= 2 { - // opclo_30m_vec.reverse(); - // opclo_30m_vec.truncate(2); - // opclo_30m_vec.reverse(); - - // if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume < opclo_30m_vec.last().unwrap().quote_asset_volume && opclo_30m_vec.last().unwrap().candle_type == "DOWN" { - // filtered_4th_symbols.push((element, opclo_30m_vec.last().unwrap().close_time)); - // } - // } - // } - // } - // } - // println!("4: {:?}", filtered_4th_symbols); - // 7. insert record into [pre_suggested_coin_list] - insert_pre_suggested_coins(16, &filtered_4th_symbols, alldata).await; - - Ok(()) -} +// pub async fn strategist_013( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_013 procedure] +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// // 3rd filtering: low price 30m < BB30_30m lowerband +// // 4th filtering: RSI3_30m < 15, RSI10_30m < 35 +// // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 +// // 6th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m + +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut bb30_1d_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// let mut current_price: Option; +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && bb30_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.truncate(2); +// opclo_1d_vec.reverse(); +// bb30_1d_vec.reverse(); +// bb30_1d_vec.truncate(2); +// bb30_1d_vec.reverse(); + +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.first().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// current_price = get_current_price(&symbol, &alldata.price_vec).await; + +// if current_price.is_some() { +// if current_price.unwrap().is_normal() { +// if (bb30_1d_vec[T].upperband +// > opclo_1d_vec.first().unwrap().opclo_price) +// && (opclo_1d_vec.first().unwrap().opclo_price +// > current_price.unwrap()) +// { +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1d_vec[T].upperband +// > opclo_1d_vec.last().unwrap().opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut ema3_30m_vec: Vec = Vec::new(); +// let mut sma30_30m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// let mut cnt = 0; +// for symbol in filtered_1st_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); +// let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && ema3_30m_option.is_some() && sma30_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); +// sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 5 && ema3_30m_vec.len() >= 1 && sma30_30m_vec.len() >= 1 { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(5); +// opclo_30m_vec.reverse(); + +// cnt = 0; +// for element in &opclo_30m_vec { +// if element.candle_type == "DOWN" { +// cnt += 1; +// } +// } + +// if cnt >= 4 { +// let result = ema3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema3_30m_vec[T].ema_value > opclo_30m_vec.last().unwrap().opclo_price +// { +// let result = sma30_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma30_30m_vec[T].sma_value +// > opclo_30m_vec.last().unwrap().opclo_price +// { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } + +// // 3rd filtering: low price 30m < BB30_30m lowerband +// let mut low_30m_vec: Vec = Vec::new(); +// let mut bb30_30m_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec = Vec::new(); +// for symbol in filtered_2nd_symbols { +// let low_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if low_30m_option.is_some() && bb30_30m_option.is_some() { +// low_30m_vec = alldata.rt_price_30m_vec[low_30m_option.unwrap()].1.clone(); +// bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); + +// if low_30m_vec.len() >= 1 && bb30_30m_vec.len() >= 1 { +// let result = bb30_30m_vec.binary_search_by_key( +// &low_30m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_30m_vec[T].lowerband > low_30m_vec.last().unwrap().low_price { +// filtered_3rd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 4th filtering: 30m RSI 3 < 15, 30m RSI 10 < 35 +// let mut rsi3_30m_vec: Vec = Vec::new(); +// let mut rsi10_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec = Vec::new(); +// for symbol in filtered_3rd_symbols { +// let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); +// rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// let result = rsi3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_30m_vec[T].rsi_value < 15.0 { +// let result = rsi10_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_30m_vec[T].rsi_value < 35.0 { +// filtered_4th_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 +// let mut rsi3_1m_vec: Vec = Vec::new(); +// let mut rsi10_1m_vec: Vec = Vec::new(); +// let mut filtered_5th_symbols: Vec = Vec::new(); // (symbol, closetime) +// for symbol in filtered_4th_symbols { +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); + +// if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { +// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); + +// if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { +// if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 +// && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 +// { +// filtered_5th_symbols.push(symbol); +// } +// } +// } +// } + +// // 6th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m, clo_1m < BB30_1m lowerband +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut ema3_1m_vec: Vec = Vec::new(); +// let mut ema10_1m_vec: Vec = Vec::new(); +// let mut bb30_1m_vec: Vec = Vec::new(); +// let mut filtered_6th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_5th_symbols { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); +// let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); +// let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1m_option.is_some() +// && opclo_30m_option.is_some() +// && ema3_1m_option.is_some() +// && ema10_1m_option.is_some() +// && bb30_1m_option.is_some() +// { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); +// ema10_1m_vec = alldata.ema10_1m_data[ema10_1m_option.unwrap()].1.clone(); +// bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); + +// if opclo_1m_vec.len() >= 1 +// && opclo_30m_vec.len() >= 1 +// && ema3_1m_vec.len() >= 1 +// && ema10_1m_vec.len() >= 1 +// && bb30_1m_vec.len() >= 1 +// { +// let result = ema3_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema3_1m_vec[T].ema_value > opclo_1m_vec.last().unwrap().opclo_price { +// let result = ema10_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema10_1m_vec[T].ema_value +// > opclo_1m_vec.last().unwrap().opclo_price +// { +// let result = bb30_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| { +// close_time +// }, +// ); +// match result { +// Ok(T) => { +// if bb30_1m_vec[T].lowerband +// > opclo_1d_vec.last().unwrap().close_price +// { +// filtered_6th_symbols.push(( +// symbol, +// opclo_30m_vec.last().unwrap().close_time, +// )); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// insert_pre_suggested_coins(13, &filtered_6th_symbols, alldata).await; + +// Ok(()) +// } + +// pub async fn strategist_014( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_014 procedure] +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d, +// // 2nd filtering: the latest 2 opclo_1d < SMA3_1d (apply this filtering if 5days angle of marketcap is negative and marketcap opinion is DOWN or KEEP) +// // 3rd filtering: RSI3_1d < 20, RSI10_1d < 35, RSI30_1d < 45 (if 5days angle of marketcap is negative and marketcap opinion is UP, this filtering will be passed) +// // 4th filtering: +// // 1) check the latest candle is DOWN (common) +// // 2) DOWN candles having 0.3% below change is not counted +// // 3) check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// // 4) OR, check 5 samples of candle 30m has DOWN candles at least 3, the latest clo_30m < BB30_30m lowerband +// // 5th filtering: RSI3_30m < 20, RSI10_30m < 35 +// // 6th filtering: RSI3_1m < 10, RSI10_1m < 25 +// // 7th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m, clo_1m < BB30_1m lowerband +// // 8th filtering: check the latest candle is DOWN and check 5 samples of candle 1m has DOWN candles at least 3 + +// let signal_opinions = select_signal_association_opinion().await; +// let market_cap_index = select_marketcap().await; + +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band and SMA3_1d, current price < previous opclo_1d, +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut bb30_1d_vec: Vec = Vec::new(); +// let mut sma3_1d_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// let mut current_price: Option; +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); +// let sma3_1d_option = alldata.sma3_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && bb30_1d_option.is_some() && sma3_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); +// sma3_1d_vec = alldata.sma3_1d_data[sma3_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 && sma3_1d_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.truncate(2); +// opclo_1d_vec.reverse(); +// bb30_1d_vec.reverse(); +// bb30_1d_vec.truncate(2); +// bb30_1d_vec.reverse(); +// sma3_1d_vec.reverse(); +// sma3_1d_vec.truncate(2); +// sma3_1d_vec.reverse(); + +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.first().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// current_price = get_current_price(&symbol, &alldata.price_vec).await; + +// if current_price.is_some() { +// if current_price.unwrap().is_normal() { +// if (bb30_1d_vec[T].upperband +// > opclo_1d_vec.first().unwrap().opclo_price) +// && (opclo_1d_vec.first().unwrap().opclo_price +// > current_price.unwrap()) +// { +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1d_vec[T].upperband +// > opclo_1d_vec.last().unwrap().opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 2nd filtering: the latest 2 opclo_1d < SMA3_1d (apply this filtering if 5days angle of marketcap is negative and marketcap opinion is DOWN or KEEP) +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut sma3_1d_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// if (signal_opinions[0].opinion.contains("DOWN") || signal_opinions[0].opinion.contains("KEEP")) +// && market_cap_index[1].market_cap_index.is_sign_negative() +// { +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let sma3_1d_option = alldata.sma3_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && sma3_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// sma3_1d_vec = alldata.sma3_1d_data[sma3_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && sma3_1d_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.truncate(2); +// opclo_1d_vec.reverse(); +// sma3_1d_vec.reverse(); +// sma3_1d_vec.truncate(2); +// sma3_1d_vec.reverse(); + +// let result = sma3_1d_vec.binary_search_by_key( +// &opclo_1d_vec.first().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma3_1d_vec[T].sma_value > opclo_1d_vec.first().unwrap().opclo_price +// { +// let result = sma3_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma3_1d_vec[T].sma_value +// > opclo_1d_vec.last().unwrap().opclo_price +// { +// filtered_2nd_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } else { +// filtered_2nd_symbols = filtered_1st_symbols; +// } + +// // 3rd filtering: RSI3_1d < 20, RSI10_1d < 35, RSI30_1d < 45 (if 5days angle of marketcap is negative and marketcap opinion is UP, this filtering will be passed) +// let mut rsi3_1d_vec: Vec = Vec::new(); +// let mut rsi10_1d_vec: Vec = Vec::new(); +// let mut rsi30_1d_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec = Vec::new(); +// if signal_opinions[0].opinion.contains("UP") +// && market_cap_index[1].market_cap_index.is_sign_negative() +// { +// filtered_3rd_symbols = filtered_2nd_symbols; +// } else { +// for symbol in filtered_2nd_symbols { +// let rsi3_1d_option = alldata.rsi3_1d_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1d_option = alldata.rsi10_1d_data.iter().position(|x| *x.0 == *symbol); +// let rsi30_1d_option = alldata.rsi30_1d_data.iter().position(|x| *x.0 == *symbol); + +// if rsi3_1d_option.is_some() && rsi10_1d_option.is_some() && rsi30_1d_option.is_some() { +// rsi3_1d_vec = alldata.rsi3_1d_data[rsi3_1d_option.unwrap()].1.clone(); +// rsi10_1d_vec = alldata.rsi10_1d_data[rsi10_1d_option.unwrap()].1.clone(); +// rsi30_1d_vec = alldata.rsi30_1d_data[rsi30_1d_option.unwrap()].1.clone(); + +// if rsi3_1d_vec.len() >= 1 && rsi10_1d_vec.len() >= 1 && rsi30_1d_vec.len() >= 1 { +// if rsi3_1d_vec.last().unwrap().rsi_value < 20.0 +// && rsi10_1d_vec.last().unwrap().rsi_value < 35.0 +// && rsi30_1d_vec.last().unwrap().rsi_value < 45.0 +// { +// filtered_3rd_symbols.push(symbol); +// } +// } +// } +// } +// } + +// // 4th filtering: +// // 1) check the latest candle is DOWN (common) +// // 2) DOWN candles having 0.3% below change is not counted +// // 3) check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// // 4) OR, check 5 samples of candle 30m has DOWN candles at least 3, the latest clo_30m < BB30_30m lowerband + +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut ema3_30m_vec: Vec = Vec::new(); +// let mut sma30_30m_vec: Vec = Vec::new(); +// let mut bb30_30m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec = Vec::new(); +// let mut cnt = 0; +// for symbol in filtered_3rd_symbols { +// let mut is_filtering_passed: bool = false; +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); +// let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); +// let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() +// && ema3_30m_option.is_some() +// && sma30_30m_option.is_some() +// && bb30_30m_option.is_some() +// { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); +// sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); +// bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 5 +// && ema3_30m_vec.len() >= 1 +// && sma30_30m_vec.len() >= 1 +// && bb30_30m_vec.len() >= 1 +// { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(5); +// opclo_30m_vec.reverse(); + +// if opclo_30m_vec.last().unwrap().candle_type == "DOWN" { +// cnt = 0; +// for element in &opclo_30m_vec { +// if element.candle_type == "DOWN" { +// if (element.open_price / element.close_price) - 1.0 > 0.003 { +// cnt += 1; +// } +// } +// } + +// if cnt >= 4 { +// let result = ema3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema3_30m_vec[T].ema_value +// > opclo_30m_vec.last().unwrap().opclo_price +// { +// let result = sma30_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma30_30m_vec[T].sma_value +// > opclo_30m_vec.last().unwrap().opclo_price +// { +// is_filtering_passed = true; +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } else if cnt == 3 { +// let result = bb30_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_30m_vec[T].lowerband +// > opclo_30m_vec.last().unwrap().close_price +// { +// is_filtering_passed = true; +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } +// if is_filtering_passed == true { +// filtered_4th_symbols.push(symbol); +// } +// } + +// // 5th filtering: RSI3_30m < 20, RSI10_30m < 35 +// let mut rsi3_30m_vec: Vec = Vec::new(); +// let mut rsi10_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_5th_symbols: Vec = Vec::new(); +// for symbol in filtered_4th_symbols { +// let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); +// rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// let result = rsi3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_30m_vec[T].rsi_value < 20.0 { +// let result = rsi10_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_30m_vec[T].rsi_value < 35.0 { +// filtered_5th_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 6th filtering: RSI3_1m < 10, RSI10_1m < 25 +// let mut rsi3_1m_vec: Vec = Vec::new(); +// let mut rsi10_1m_vec: Vec = Vec::new(); +// let mut filtered_6th_symbols: Vec = Vec::new(); +// for symbol in filtered_5th_symbols { +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); + +// if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() { +// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); + +// if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 { +// if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 +// && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 +// { +// filtered_6th_symbols.push(symbol); +// } +// } +// } +// } + +// // // 6. 5th filtering symbols: 30m current vol > 30m previous vol * 2 +// // let mut opclo_30m_vec: Vec = Vec::new(); +// // let mut filtered_4th_symbols: Vec<(String, u64)> = Vec::new(); // (symbol, closetime) +// // for element in filtered_3rd_symbols { +// // let opclo_30m_result = read_price_into_vector("30m", &element).await; + +// // if opclo_30m_result.is_ok() { +// // let opclo_30m_option = opclo_30m_result?; +// // if opclo_30m_option.is_some() { +// // opclo_30m_vec = opclo_30m_option.unwrap(); + +// // if opclo_30m_vec.len() >= 2 { +// // opclo_30m_vec.reverse(); +// // opclo_30m_vec.truncate(2); +// // opclo_30m_vec.reverse(); + +// // if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume < opclo_30m_vec.last().unwrap().quote_asset_volume && opclo_30m_vec.last().unwrap().candle_type == "DOWN" { +// // filtered_4th_symbols.push((element, opclo_30m_vec.last().unwrap().close_time)); +// // } +// // } +// // } +// // } +// // } + +// // 7th filtering: opclo_1m < EMA3_1m, opclo_1m < EMA10_1m, clo_1m < BB30_1m lowerband +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut ema3_1m_vec: Vec = Vec::new(); +// let mut ema10_1m_vec: Vec = Vec::new(); +// let mut bb30_1m_vec: Vec = Vec::new(); +// let mut filtered_7th_symbols: Vec = Vec::new(); +// for symbol in filtered_6th_symbols { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let ema3_1m_option = alldata.ema3_1m_data.iter().position(|x| *x.0 == *symbol); +// let ema10_1m_option = alldata.ema10_1m_data.iter().position(|x| *x.0 == *symbol); +// let bb30_1m_option = alldata.bb30_1m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1m_option.is_some() +// && ema3_1m_option.is_some() +// && ema10_1m_option.is_some() +// && bb30_1m_option.is_some() +// { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// ema3_1m_vec = alldata.ema3_1m_data[ema3_1m_option.unwrap()].1.clone(); +// ema10_1m_vec = alldata.ema10_1m_data[ema10_1m_option.unwrap()].1.clone(); +// bb30_1m_vec = alldata.bb30_1m_data[bb30_1m_option.unwrap()].1.clone(); + +// if opclo_1m_vec.len() >= 1 +// && ema3_1m_vec.len() >= 1 +// && ema10_1m_vec.len() >= 1 +// && bb30_1m_vec.len() >= 1 +// { +// let result = ema3_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema3_1m_vec[T].ema_value > opclo_1m_vec.last().unwrap().opclo_price { +// let result = ema10_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema10_1m_vec[T].ema_value +// > opclo_1m_vec.last().unwrap().opclo_price +// { +// let result = bb30_1m_vec.binary_search_by_key( +// &opclo_1m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| { +// close_time +// }, +// ); +// match result { +// Ok(T) => { +// if bb30_1m_vec[T].lowerband +// > opclo_1d_vec.last().unwrap().close_price +// { +// filtered_7th_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 8th filtering: +// // check the latest candle is DOWN and check 5 samples of candle 30m has DOWN candles at least 3 +// let mut opclo_1m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_8th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) + +// let mut cnt = 0; +// for symbol in filtered_7th_symbols { +// let opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && opclo_1m_option.is_some() { +// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if opclo_1m_vec.len() >= 5 && opclo_30m_vec.len() >= 5 { +// opclo_1m_vec.reverse(); +// opclo_1m_vec.truncate(5); +// opclo_1m_vec.reverse(); + +// if opclo_1m_vec.last().unwrap().candle_type == "DOWN" { +// cnt = 0; +// for element in &opclo_1m_vec { +// if element.candle_type == "DOWN" { +// cnt += 1; +// } +// } + +// if cnt >= 3 { +// filtered_8th_symbols +// .push((symbol, opclo_30m_vec.last().unwrap().close_time)); +// } +// } +// } +// } +// } + +// insert_pre_suggested_coins(14, &filtered_8th_symbols, alldata).await; + +// Ok(()) +// } + +// pub async fn strategist_015( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_015 procedure] +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// // 3rd filtering: low price 30m < BB30_30m lowerband +// // 4th filtering: RSI3_30m < 15, RSI10_30m < 35 +// // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 + +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut bb30_1d_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// let mut current_price: Option; +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && bb30_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.truncate(2); +// opclo_1d_vec.reverse(); +// bb30_1d_vec.reverse(); +// bb30_1d_vec.truncate(2); +// bb30_1d_vec.reverse(); + +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.first().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// current_price = get_current_price(&symbol, &alldata.price_vec).await; + +// if current_price.is_some() { +// if current_price.unwrap().is_normal() { +// if (bb30_1d_vec[T].upperband +// > opclo_1d_vec.first().unwrap().opclo_price) +// && (opclo_1d_vec.first().unwrap().opclo_price +// > current_price.unwrap()) +// { +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1d_vec[T].upperband +// > opclo_1d_vec.last().unwrap().opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut ema3_30m_vec: Vec = Vec::new(); +// let mut sma30_30m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// let mut cnt = 0; +// for symbol in filtered_1st_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); +// let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && ema3_30m_option.is_some() && sma30_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); +// sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 5 && ema3_30m_vec.len() >= 1 && sma30_30m_vec.len() >= 1 { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(5); +// opclo_30m_vec.reverse(); + +// cnt = 0; +// for element in &opclo_30m_vec { +// if element.candle_type == "DOWN" { +// cnt += 1; +// } +// } + +// if cnt >= 4 { +// let result = ema3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema3_30m_vec[T].ema_value > opclo_30m_vec.last().unwrap().opclo_price +// { +// let result = sma30_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma30_30m_vec[T].sma_value +// > opclo_30m_vec.last().unwrap().opclo_price +// { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } + +// // 3rd filtering: low price 30m < BB30_30m lowerband +// let mut low_30m_vec: Vec = Vec::new(); +// let mut bb30_30m_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec = Vec::new(); +// for symbol in filtered_2nd_symbols { +// let low_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let bb30_30m_option = alldata.bb30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if low_30m_option.is_some() && bb30_30m_option.is_some() { +// low_30m_vec = alldata.rt_price_30m_vec[low_30m_option.unwrap()].1.clone(); +// bb30_30m_vec = alldata.bb30_30m_data[bb30_30m_option.unwrap()].1.clone(); + +// if low_30m_vec.len() >= 1 && bb30_30m_vec.len() >= 1 { +// let result = bb30_30m_vec.binary_search_by_key( +// &low_30m_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_30m_vec[T].lowerband > low_30m_vec.last().unwrap().low_price { +// filtered_3rd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 4th filtering: 30m RSI 3 < 15, 30m RSI 10 < 35 +// let mut rsi3_30m_vec: Vec = Vec::new(); +// let mut rsi10_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec = Vec::new(); +// for symbol in filtered_3rd_symbols { +// let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); +// rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// let result = rsi3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_30m_vec[T].rsi_value < 15.0 { +// let result = rsi10_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_30m_vec[T].rsi_value < 35.0 { +// filtered_4th_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 5th filtering: RSI3_1m < 10, RSI10_1m < 25 +// let mut rsi3_1m_vec: Vec = Vec::new(); +// let mut rsi10_1m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_5th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_4th_symbols { +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 +// && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 +// { +// filtered_5th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); +// } +// } + +// // if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// // let result = rsi3_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi3_1m_vec[T].rsi_value < 10.0 { +// // let result = rsi10_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi10_1m_vec[T].rsi_value < 25.0 { +// // filtered_5th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// } +// } +// // // 6. 5th filtering symbols: 30m current vol > 30m previous vol * 2 +// // let mut opclo_30m_vec: Vec = Vec::new(); +// // let mut filtered_5th_symbols: Vec<(String, u64)> = Vec::new(); // (symbol, closetime) +// // for element in filtered_4th_symbols { +// // let opclo_30m_result = read_price_into_vector("30m", &element).await; + +// // if opclo_30m_result.is_ok() { +// // let opclo_30m_option = opclo_30m_result?; +// // if opclo_30m_option.is_some() { +// // opclo_30m_vec = opclo_30m_option.unwrap(); + +// // if opclo_30m_vec.len() >= 2 { +// // opclo_30m_vec.reverse(); +// // opclo_30m_vec.truncate(2); +// // opclo_30m_vec.reverse(); + +// // if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume < opclo_30m_vec.last().unwrap().quote_asset_volume && opclo_30m_vec.last().unwrap().candle_type == "DOWN" { +// // filtered_5th_symbols.push((element, opclo_30m_vec.last().unwrap().close_time)); +// // } +// // } +// // } +// // } +// // } +// // println!("5: {:?}", filtered_5th_symbols); +// // 7. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(15, &filtered_5th_symbols, alldata).await; + +// Ok(()) +// } + +// pub async fn strategist_016( +// alldata: &AllData, +// ) -> Result<(), Box> { +// // [strategist_016 procedure] +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 +// // 4th filtering: RSI3_1m < 10, RSI10_1m < 25 + +// // 1st filtering: the latest 2 opclo_1d < BB30_1d upper band, current price < previous opclo_1d +// let mut opclo_1d_vec: Vec = Vec::new(); +// let mut bb30_1d_vec: Vec = Vec::new(); +// let mut filtered_1st_symbols: Vec = Vec::new(); +// let mut current_price: Option; +// for symbol in &alldata.valid_symbol_vec { +// let opclo_1d_option = alldata.rt_price_1d_vec.iter().position(|x| *x.0 == *symbol); +// let bb30_1d_option = alldata.bb30_1d_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_1d_option.is_some() && bb30_1d_option.is_some() { +// opclo_1d_vec = alldata.rt_price_1d_vec[opclo_1d_option.unwrap()].1.clone(); +// bb30_1d_vec = alldata.bb30_1d_data[bb30_1d_option.unwrap()].1.clone(); + +// if opclo_1d_vec.len() >= 2 && bb30_1d_vec.len() >= 2 { +// opclo_1d_vec.reverse(); +// opclo_1d_vec.truncate(2); +// opclo_1d_vec.reverse(); +// bb30_1d_vec.reverse(); +// bb30_1d_vec.truncate(2); +// bb30_1d_vec.reverse(); + +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.first().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// current_price = get_current_price(&symbol, &alldata.price_vec).await; + +// if current_price.is_some() { +// if current_price.unwrap().is_normal() { +// if (bb30_1d_vec[T].upperband +// > opclo_1d_vec.first().unwrap().opclo_price) +// && (opclo_1d_vec.first().unwrap().opclo_price +// > current_price.unwrap()) +// { +// let result = bb30_1d_vec.binary_search_by_key( +// &opclo_1d_vec.last().unwrap().close_time, +// |&BollingerBandData { +// sma, +// upperband, +// lowerband, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if bb30_1d_vec[T].upperband +// > opclo_1d_vec.last().unwrap().opclo_price +// { +// filtered_1st_symbols.push(symbol.clone()); +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 2nd filtering: check 5 samples of candle 30m has DOWN candles at least 4, the latest opclo_30m < EMA3_30m, the latest opclo_30m < SMA30_30m +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut ema3_30m_vec: Vec = Vec::new(); +// let mut sma30_30m_vec: Vec = Vec::new(); +// let mut filtered_2nd_symbols: Vec = Vec::new(); +// let mut cnt = 0; +// for symbol in filtered_1st_symbols { +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); +// let ema3_30m_option = alldata.ema3_30m_data.iter().position(|x| *x.0 == *symbol); +// let sma30_30m_option = alldata.sma30_30m_data.iter().position(|x| *x.0 == *symbol); + +// if opclo_30m_option.is_some() && ema3_30m_option.is_some() && sma30_30m_option.is_some() { +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); +// ema3_30m_vec = alldata.ema3_30m_data[ema3_30m_option.unwrap()].1.clone(); +// sma30_30m_vec = alldata.sma30_30m_data[sma30_30m_option.unwrap()].1.clone(); + +// if opclo_30m_vec.len() >= 5 && ema3_30m_vec.len() >= 1 && sma30_30m_vec.len() >= 1 { +// opclo_30m_vec.reverse(); +// opclo_30m_vec.truncate(5); +// opclo_30m_vec.reverse(); + +// cnt = 0; +// for element in &opclo_30m_vec { +// if element.candle_type == "DOWN" { +// cnt += 1; +// } +// } + +// if cnt >= 4 { +// let result = ema3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&EmaData { +// ema_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if ema3_30m_vec[T].ema_value > opclo_30m_vec.last().unwrap().opclo_price +// { +// let result = sma30_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&SmaData { +// sma_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if sma30_30m_vec[T].sma_value +// > opclo_30m_vec.last().unwrap().opclo_price +// { +// filtered_2nd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } +// } + +// // 3rd filtering: RSI3_30m < 15, RSI10_30m < 35 +// let mut rsi3_30m_vec: Vec = Vec::new(); +// let mut rsi10_30m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_3rd_symbols: Vec = Vec::new(); +// for symbol in filtered_2nd_symbols { +// let rsi3_30m_option = alldata.rsi3_30m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_30m_option = alldata.rsi10_30m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_30m_option.is_some() && rsi10_30m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_30m_vec = alldata.rsi3_30m_data[rsi3_30m_option.unwrap()].1.clone(); +// rsi10_30m_vec = alldata.rsi10_30m_data[rsi10_30m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_30m_vec.len() >= 1 && rsi10_30m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// let result = rsi3_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi3_30m_vec[T].rsi_value < 15.0 { +// let result = rsi10_30m_vec.binary_search_by_key( +// &opclo_30m_vec.last().unwrap().close_time, +// |&RsiData { +// rsi_value, +// close_time, +// }| close_time, +// ); +// match result { +// Ok(T) => { +// if rsi10_30m_vec[T].rsi_value < 35.0 { +// filtered_3rd_symbols.push(symbol); +// } +// } +// Err(E) => {} +// } +// } +// } +// Err(E) => {} +// } +// } +// } +// } + +// // 4th filtering: RSI3_1m < 10, RSI10_1m < 25 +// let mut rsi3_1m_vec: Vec = Vec::new(); +// let mut rsi10_1m_vec: Vec = Vec::new(); +// let mut opclo_30m_vec: Vec = Vec::new(); +// let mut filtered_4th_symbols: Vec<(String, i64)> = Vec::new(); // (symbol, closetime) +// for symbol in filtered_3rd_symbols { +// let rsi3_1m_option = alldata.rsi3_1m_data.iter().position(|x| *x.0 == *symbol); +// let rsi10_1m_option = alldata.rsi10_1m_data.iter().position(|x| *x.0 == *symbol); +// let opclo_30m_option = alldata +// .rt_price_30m_vec +// .iter() +// .position(|x| *x.0 == *symbol); + +// if rsi3_1m_option.is_some() && rsi10_1m_option.is_some() && opclo_30m_option.is_some() { +// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); +// rsi10_1m_vec = alldata.rsi10_1m_data[rsi10_1m_option.unwrap()].1.clone(); +// opclo_30m_vec = alldata.rt_price_30m_vec[opclo_30m_option.unwrap()] +// .1 +// .clone(); + +// if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// if rsi3_1m_vec.last().unwrap().rsi_value < 10.0 +// && rsi10_1m_vec.last().unwrap().rsi_value < 25.0 +// { +// filtered_4th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); +// } +// } + +// // if rsi3_1m_vec.len() >= 1 && rsi10_1m_vec.len() >= 1 && opclo_30m_vec.len() >= 1 { +// // let result = rsi3_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi3_1m_vec[T].rsi_value < 10.0 { +// // let result = rsi10_1m_vec.binary_search_by_key(&opclo_30m_vec.last().unwrap().close_time, |&RsiData{rsi_value, close_time}|close_time); +// // match result { +// // Ok(T) => { +// // if rsi10_1m_vec[T].rsi_value < 25.0 { +// // filtered_5th_symbols.push((symbol, opclo_30m_vec.last().unwrap().close_time)); +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// // }, +// // Err(E) => {} +// // } +// // } +// } +// } + +// // // 6. 5th filtering symbols: 30m current vol > 30m previous vol * 2 +// // let mut opclo_30m_vec: Vec = Vec::new(); +// // let mut filtered_4th_symbols: Vec<(String, u64)> = Vec::new(); // (symbol, closetime) +// // for element in filtered_3rd_symbols { +// // let opclo_30m_result = read_price_into_vector("30m", &element).await; + +// // if opclo_30m_result.is_ok() { +// // let opclo_30m_option = opclo_30m_result?; +// // if opclo_30m_option.is_some() { +// // opclo_30m_vec = opclo_30m_option.unwrap(); + +// // if opclo_30m_vec.len() >= 2 { +// // opclo_30m_vec.reverse(); +// // opclo_30m_vec.truncate(2); +// // opclo_30m_vec.reverse(); + +// // if 2.0 * opclo_30m_vec.first().unwrap().quote_asset_volume < opclo_30m_vec.last().unwrap().quote_asset_volume && opclo_30m_vec.last().unwrap().candle_type == "DOWN" { +// // filtered_4th_symbols.push((element, opclo_30m_vec.last().unwrap().close_time)); +// // } +// // } +// // } +// // } +// // } +// // println!("4: {:?}", filtered_4th_symbols); +// // 7. insert record into [pre_suggested_coin_list] +// insert_pre_suggested_coins(16, &filtered_4th_symbols, alldata).await; + +// Ok(()) +// } // useful functions for strategists pub async fn get_current_price(symbol: &String, price_vec: &Vec) -> Option { diff --git a/src/main.rs b/src/main.rs index 0b5d6d0..de67911 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1082,483 +1082,483 @@ async fn main() -> Result<(), Box> { // Task#11 // SMA, EMA, RSI, Stoch RSI, BollingerBand (3, 10, 30) for candle 1m, 30m, 1d, 1w, and 1mon - tokio::task::spawn(async move { - let moving_number_vec = vec![3, 10, 30]; - sleep(Duration::from_secs(10)).await; - let mut elapsed_time = 0; - loop { - let instant = Instant::now(); - let valid_usdt_trade_vec = rx2_valid_usdt_trade_vec.borrow().clone(); - let rt_price_1m_vec = rx2_rt_price_1m_vec.borrow().clone(); - let rt_price_30m_vec = rx2_rt_price_30m_vec.borrow().clone(); - let rt_price_1d_vec = rx2_rt_price_1d_vec.borrow().clone(); - let rt_price_1w_vec = rx2_rt_price_1w_vec.borrow().clone(); - let rt_price_1mon_vec = rx2_rt_price_1mon_vec.borrow().clone(); + // tokio::task::spawn(async move { + // let moving_number_vec = vec![3, 10, 30]; + // sleep(Duration::from_secs(10)).await; + // let mut elapsed_time = 0; + // loop { + // let instant = Instant::now(); + // let valid_usdt_trade_vec = rx2_valid_usdt_trade_vec.borrow().clone(); + // let rt_price_1m_vec = rx2_rt_price_1m_vec.borrow().clone(); + // let rt_price_30m_vec = rx2_rt_price_30m_vec.borrow().clone(); + // let rt_price_1d_vec = rx2_rt_price_1d_vec.borrow().clone(); + // let rt_price_1w_vec = rx2_rt_price_1w_vec.borrow().clone(); + // let rt_price_1mon_vec = rx2_rt_price_1mon_vec.borrow().clone(); - for moving_number_element in &moving_number_vec { - // calculate SMA - let mut sma_1m_data: Vec<(String, Vec)> = Vec::new(); - let mut sma_30m_data: Vec<(String, Vec)> = Vec::new(); - let mut sma_1d_data: Vec<(String, Vec)> = Vec::new(); - // let mut sma_1w_data: Vec<(String, Vec)> = Vec::new(); - // let mut sma_1mon_data: Vec<(String, Vec)> = Vec::new(); - let sma_1m_result = value_estimation_team::indicators::sma::sma( - *moving_number_element, - &rt_price_1m_vec, - &mut sma_1m_data, - &valid_usdt_trade_vec, - ) - .await; - let sma_30m_result = value_estimation_team::indicators::sma::sma( - *moving_number_element, - &rt_price_30m_vec, - &mut sma_30m_data, - &valid_usdt_trade_vec, - ) - .await; - let sma_1d_result = value_estimation_team::indicators::sma::sma( - *moving_number_element, - &rt_price_1d_vec, - &mut sma_1d_data, - &valid_usdt_trade_vec, - ) - .await; - // let sma_1w_result = value_estimation_team::indicators::sma::sma(*moving_number_element, &rt_price_1w_vec, &mut sma_1w_data, &valid_usdt_trade_vec).await; - // let sma_1mon_result = value_estimation_team::indicators::sma::sma(*moving_number_element, &rt_price_1mon_vec, &mut sma_1mon_data, &valid_usdt_trade_vec).await; + // for moving_number_element in &moving_number_vec { + // // calculate SMA + // let mut sma_1m_data: Vec<(String, Vec)> = Vec::new(); + // let mut sma_30m_data: Vec<(String, Vec)> = Vec::new(); + // let mut sma_1d_data: Vec<(String, Vec)> = Vec::new(); + // // let mut sma_1w_data: Vec<(String, Vec)> = Vec::new(); + // // let mut sma_1mon_data: Vec<(String, Vec)> = Vec::new(); + // let sma_1m_result = value_estimation_team::indicators::sma::sma( + // *moving_number_element, + // &rt_price_1m_vec, + // &mut sma_1m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // let sma_30m_result = value_estimation_team::indicators::sma::sma( + // *moving_number_element, + // &rt_price_30m_vec, + // &mut sma_30m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // let sma_1d_result = value_estimation_team::indicators::sma::sma( + // *moving_number_element, + // &rt_price_1d_vec, + // &mut sma_1d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // // let sma_1w_result = value_estimation_team::indicators::sma::sma(*moving_number_element, &rt_price_1w_vec, &mut sma_1w_data, &valid_usdt_trade_vec).await; + // // let sma_1mon_result = value_estimation_team::indicators::sma::sma(*moving_number_element, &rt_price_1mon_vec, &mut sma_1mon_data, &valid_usdt_trade_vec).await; - // calculate EMA - let mut ema_1m_data: Vec<(String, Vec)> = Vec::new(); - let mut ema_30m_data: Vec<(String, Vec)> = Vec::new(); - let mut ema_1d_data: Vec<(String, Vec)> = Vec::new(); - // let mut ema_1w_data: Vec<(String, Vec)> = Vec::new(); - // let mut ema_1mon_data: Vec<(String, Vec)> = Vec::new(); - let ema_1m_result = value_estimation_team::indicators::ema::ema( - *moving_number_element, - &rt_price_1m_vec, - &mut ema_1m_data, - &valid_usdt_trade_vec, - ) - .await; - let ema_30m_result = value_estimation_team::indicators::ema::ema( - *moving_number_element, - &rt_price_30m_vec, - &mut ema_30m_data, - &valid_usdt_trade_vec, - ) - .await; - let ema_1d_result = value_estimation_team::indicators::ema::ema( - *moving_number_element, - &rt_price_1d_vec, - &mut ema_1d_data, - &valid_usdt_trade_vec, - ) - .await; - // let ema_1w_result = value_estimation_team::indicators::ema::ema(*moving_number_element, &rt_price_1w_vec, &mut ema_1w_data, &valid_usdt_trade_vec).await; - // let ema_1mon_result = value_estimation_team::indicators::ema::ema(*moving_number_element, &rt_price_1mon_vec, &mut ema_1mon_data, &valid_usdt_trade_vec).await; + // // calculate EMA + // let mut ema_1m_data: Vec<(String, Vec)> = Vec::new(); + // let mut ema_30m_data: Vec<(String, Vec)> = Vec::new(); + // let mut ema_1d_data: Vec<(String, Vec)> = Vec::new(); + // // let mut ema_1w_data: Vec<(String, Vec)> = Vec::new(); + // // let mut ema_1mon_data: Vec<(String, Vec)> = Vec::new(); + // let ema_1m_result = value_estimation_team::indicators::ema::ema( + // *moving_number_element, + // &rt_price_1m_vec, + // &mut ema_1m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // let ema_30m_result = value_estimation_team::indicators::ema::ema( + // *moving_number_element, + // &rt_price_30m_vec, + // &mut ema_30m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // let ema_1d_result = value_estimation_team::indicators::ema::ema( + // *moving_number_element, + // &rt_price_1d_vec, + // &mut ema_1d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // // let ema_1w_result = value_estimation_team::indicators::ema::ema(*moving_number_element, &rt_price_1w_vec, &mut ema_1w_data, &valid_usdt_trade_vec).await; + // // let ema_1mon_result = value_estimation_team::indicators::ema::ema(*moving_number_element, &rt_price_1mon_vec, &mut ema_1mon_data, &valid_usdt_trade_vec).await; - // // calculate TEMA - // let mut tema_1m_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); - // let mut tema_30m_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); - // let mut tema_1d_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); - // let mut tema_1w_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); - // let mut tema_1mon_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); - // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1m_data, &mut tema_1m_data, &valid_usdt_trade_vec).await; - // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_30m_data, &mut tema_30m_data, &valid_usdt_trade_vec).await; - // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1d_data, &mut tema_1d_data, &valid_usdt_trade_vec).await; - // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1w_data, &mut tema_1w_data, &valid_usdt_trade_vec).await; - // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1mon_data, &mut tema_1mon_data, &valid_usdt_trade_vec).await; + // // // calculate TEMA + // // let mut tema_1m_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); + // // let mut tema_30m_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); + // // let mut tema_1d_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); + // // let mut tema_1w_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); + // // let mut tema_1mon_data: Vec<(String, Vec<(f64, i64)>)> = Vec::new(); + // // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1m_data, &mut tema_1m_data, &valid_usdt_trade_vec).await; + // // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_30m_data, &mut tema_30m_data, &valid_usdt_trade_vec).await; + // // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1d_data, &mut tema_1d_data, &valid_usdt_trade_vec).await; + // // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1w_data, &mut tema_1w_data, &valid_usdt_trade_vec).await; + // // value_estimation_team::indicators::tema::tema(*moving_number_element, &ema_1mon_data, &mut tema_1mon_data, &valid_usdt_trade_vec).await; - // calculate RSI - let mut rsi_1m_data: Vec<(String, Vec)> = Vec::new(); - let mut rsi_30m_data: Vec<(String, Vec)> = Vec::new(); - let mut rsi_1d_data: Vec<(String, Vec)> = Vec::new(); - // let mut rsi_1w_data: Vec<(String, Vec)> = Vec::new(); - // let mut rsi_1mon_data: Vec<(String, Vec)> = Vec::new(); - let rsi_1m_result = value_estimation_team::indicators::rsi::rsi( - *moving_number_element, - &rt_price_1m_vec, - &mut rsi_1m_data, - &valid_usdt_trade_vec, - ) - .await; - let rsi_30m_result = value_estimation_team::indicators::rsi::rsi( - *moving_number_element, - &rt_price_30m_vec, - &mut rsi_30m_data, - &valid_usdt_trade_vec, - ) - .await; - let rsi_1d_result = value_estimation_team::indicators::rsi::rsi( - *moving_number_element, - &rt_price_1d_vec, - &mut rsi_1d_data, - &valid_usdt_trade_vec, - ) - .await; - // let rsi_1w_result = value_estimation_team::indicators::rsi::rsi(*moving_number_element, &rt_price_1w_vec, &mut rsi_1w_data, &valid_usdt_trade_vec).await; - // let rsi_1mon_result = value_estimation_team::indicators::rsi::rsi(*moving_number_element, &rt_price_1mon_vec, &mut rsi_1mon_data, &valid_usdt_trade_vec).await; + // // calculate RSI + // let mut rsi_1m_data: Vec<(String, Vec)> = Vec::new(); + // let mut rsi_30m_data: Vec<(String, Vec)> = Vec::new(); + // let mut rsi_1d_data: Vec<(String, Vec)> = Vec::new(); + // // let mut rsi_1w_data: Vec<(String, Vec)> = Vec::new(); + // // let mut rsi_1mon_data: Vec<(String, Vec)> = Vec::new(); + // let rsi_1m_result = value_estimation_team::indicators::rsi::rsi( + // *moving_number_element, + // &rt_price_1m_vec, + // &mut rsi_1m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // let rsi_30m_result = value_estimation_team::indicators::rsi::rsi( + // *moving_number_element, + // &rt_price_30m_vec, + // &mut rsi_30m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // let rsi_1d_result = value_estimation_team::indicators::rsi::rsi( + // *moving_number_element, + // &rt_price_1d_vec, + // &mut rsi_1d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // // let rsi_1w_result = value_estimation_team::indicators::rsi::rsi(*moving_number_element, &rt_price_1w_vec, &mut rsi_1w_data, &valid_usdt_trade_vec).await; + // // let rsi_1mon_result = value_estimation_team::indicators::rsi::rsi(*moving_number_element, &rt_price_1mon_vec, &mut rsi_1mon_data, &valid_usdt_trade_vec).await; - // calculate Stoch RSI - let mut stoch_rsi_1m_k_data: Vec<(String, Vec)> = Vec::new(); - let mut stoch_rsi_1m_d_data: Vec<(String, Vec)> = Vec::new(); - let mut stoch_rsi_1m_result; - if rsi_1m_result.is_ok() { - if *moving_number_element == 10 { - stoch_rsi_1m_result = - value_estimation_team::indicators::stoch_rsi::stoch_rsi( - &rsi_1m_data, - 3, - &mut stoch_rsi_1m_k_data, - &mut stoch_rsi_1m_d_data, - &valid_usdt_trade_vec, - ) - .await; - if stoch_rsi_1m_result.is_ok() { - tx_stoch_rsi3_1m_3_k_data.send_modify(|vec| *vec = stoch_rsi_1m_k_data); - tx_stoch_rsi3_1m_3_d_data.send_modify(|vec| *vec = stoch_rsi_1m_d_data); - } - } else if *moving_number_element == 30 { - stoch_rsi_1m_result = - value_estimation_team::indicators::stoch_rsi::stoch_rsi( - &rsi_1m_data, - 30, - &mut stoch_rsi_1m_k_data, - &mut stoch_rsi_1m_d_data, - &valid_usdt_trade_vec, - ) - .await; - if stoch_rsi_1m_result.is_ok() { - tx_stoch_rsi30_1m_30_k_data - .send_modify(|vec| *vec = stoch_rsi_1m_k_data); - tx_stoch_rsi30_1m_30_d_data - .send_modify(|vec| *vec = stoch_rsi_1m_d_data); - } - } - } + // // calculate Stoch RSI + // let mut stoch_rsi_1m_k_data: Vec<(String, Vec)> = Vec::new(); + // let mut stoch_rsi_1m_d_data: Vec<(String, Vec)> = Vec::new(); + // let mut stoch_rsi_1m_result; + // if rsi_1m_result.is_ok() { + // if *moving_number_element == 10 { + // stoch_rsi_1m_result = + // value_estimation_team::indicators::stoch_rsi::stoch_rsi( + // &rsi_1m_data, + // 3, + // &mut stoch_rsi_1m_k_data, + // &mut stoch_rsi_1m_d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // if stoch_rsi_1m_result.is_ok() { + // tx_stoch_rsi3_1m_3_k_data.send_modify(|vec| *vec = stoch_rsi_1m_k_data); + // tx_stoch_rsi3_1m_3_d_data.send_modify(|vec| *vec = stoch_rsi_1m_d_data); + // } + // } else if *moving_number_element == 30 { + // stoch_rsi_1m_result = + // value_estimation_team::indicators::stoch_rsi::stoch_rsi( + // &rsi_1m_data, + // 30, + // &mut stoch_rsi_1m_k_data, + // &mut stoch_rsi_1m_d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // if stoch_rsi_1m_result.is_ok() { + // tx_stoch_rsi30_1m_30_k_data + // .send_modify(|vec| *vec = stoch_rsi_1m_k_data); + // tx_stoch_rsi30_1m_30_d_data + // .send_modify(|vec| *vec = stoch_rsi_1m_d_data); + // } + // } + // } - // calculate BollingerBand - let mut bb3_1m_data: Vec<(String, Vec)> = Vec::new(); - let mut bb3_30m_data: Vec<(String, Vec)> = Vec::new(); - let mut bb3_1d_data: Vec<(String, Vec)> = Vec::new(); - // let mut bb3_1w_data: Vec<(String, Vec)> = Vec::new(); - // let mut bb3_1mon_data: Vec<(String, Vec)> = Vec::new(); - let mut bb10_1m_data: Vec<(String, Vec)> = Vec::new(); - let mut bb10_30m_data: Vec<(String, Vec)> = Vec::new(); - let mut bb10_1d_data: Vec<(String, Vec)> = Vec::new(); - // let mut bb10_1w_data: Vec<(String, Vec)> = Vec::new(); - // let mut bb10_1mon_data: Vec<(String, Vec)> = Vec::new(); - let mut bb30_1m_data: Vec<(String, Vec)> = Vec::new(); - let mut bb30_30m_data: Vec<(String, Vec)> = Vec::new(); - let mut bb30_1d_data: Vec<(String, Vec)> = Vec::new(); - // let mut bb30_1w_data: Vec<(String, Vec)> = Vec::new(); - // let mut bb30_1mon_data: Vec<(String, Vec)> = Vec::new(); - let mut bb_1m_result; - let mut bb_30m_result; - let mut bb_1d_result; - // let mut bb_1w_result; - // let mut bb_1mon_result; + // // calculate BollingerBand + // let mut bb3_1m_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb3_30m_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb3_1d_data: Vec<(String, Vec)> = Vec::new(); + // // let mut bb3_1w_data: Vec<(String, Vec)> = Vec::new(); + // // let mut bb3_1mon_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb10_1m_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb10_30m_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb10_1d_data: Vec<(String, Vec)> = Vec::new(); + // // let mut bb10_1w_data: Vec<(String, Vec)> = Vec::new(); + // // let mut bb10_1mon_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb30_1m_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb30_30m_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb30_1d_data: Vec<(String, Vec)> = Vec::new(); + // // let mut bb30_1w_data: Vec<(String, Vec)> = Vec::new(); + // // let mut bb30_1mon_data: Vec<(String, Vec)> = Vec::new(); + // let mut bb_1m_result; + // let mut bb_30m_result; + // let mut bb_1d_result; + // // let mut bb_1w_result; + // // let mut bb_1mon_result; - match moving_number_element { - 3 => { - bb_1m_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_1m_data, - &rt_price_1m_vec, - &mut bb3_1m_data, - &valid_usdt_trade_vec, - ) - .await; - bb_30m_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_30m_data, - &rt_price_30m_vec, - &mut bb3_30m_data, - &valid_usdt_trade_vec, - ) - .await; - bb_1d_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_1d_data, - &rt_price_1d_vec, - &mut bb3_1d_data, - &valid_usdt_trade_vec, - ) - .await; - // bb_1w_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1w_data, &rt_price_1w_vec, &mut bb3_1w_data, &valid_usdt_trade_vec).await; - // bb_1mon_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1mon_data, &rt_price_1mon_vec, &mut bb3_1mon_data, &valid_usdt_trade_vec).await; - } - 10 => { - bb_1m_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_1m_data, - &rt_price_1m_vec, - &mut bb10_1m_data, - &valid_usdt_trade_vec, - ) - .await; - bb_30m_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_30m_data, - &rt_price_30m_vec, - &mut bb10_30m_data, - &valid_usdt_trade_vec, - ) - .await; - bb_1d_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_1d_data, - &rt_price_1d_vec, - &mut bb10_1d_data, - &valid_usdt_trade_vec, - ) - .await; - // bb_1w_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1w_data, &rt_price_1w_vec, &mut bb10_1w_data, &valid_usdt_trade_vec).await; - // bb_1mon_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1mon_data, &rt_price_1mon_vec, &mut bb10_1mon_data, &valid_usdt_trade_vec).await; - } - 30 => { - bb_1m_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_1m_data, - &rt_price_1m_vec, - &mut bb30_1m_data, - &valid_usdt_trade_vec, - ) - .await; - bb_30m_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_30m_data, - &rt_price_30m_vec, - &mut bb30_30m_data, - &valid_usdt_trade_vec, - ) - .await; - bb_1d_result = - value_estimation_team::indicators::bollingerband::bollingerband( - *moving_number_element, - 3.0, - &sma_1d_data, - &rt_price_1d_vec, - &mut bb30_1d_data, - &valid_usdt_trade_vec, - ) - .await; - // bb_1w_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1w_data, &rt_price_1w_vec, &mut bb30_1w_data, &valid_usdt_trade_vec).await; - // bb_1mon_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1mon_data, &rt_price_1mon_vec, &mut bb30_1mon_data, &valid_usdt_trade_vec).await; - } - _ => { - bb_1m_result = Ok(()); - bb_30m_result = Ok(()); - bb_1d_result = Ok(()); - // bb_1w_result = Ok(()); - // bb_1mon_result = Ok(()); - } - } + // match moving_number_element { + // 3 => { + // bb_1m_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_1m_data, + // &rt_price_1m_vec, + // &mut bb3_1m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // bb_30m_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_30m_data, + // &rt_price_30m_vec, + // &mut bb3_30m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // bb_1d_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_1d_data, + // &rt_price_1d_vec, + // &mut bb3_1d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // // bb_1w_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1w_data, &rt_price_1w_vec, &mut bb3_1w_data, &valid_usdt_trade_vec).await; + // // bb_1mon_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1mon_data, &rt_price_1mon_vec, &mut bb3_1mon_data, &valid_usdt_trade_vec).await; + // } + // 10 => { + // bb_1m_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_1m_data, + // &rt_price_1m_vec, + // &mut bb10_1m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // bb_30m_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_30m_data, + // &rt_price_30m_vec, + // &mut bb10_30m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // bb_1d_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_1d_data, + // &rt_price_1d_vec, + // &mut bb10_1d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // // bb_1w_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1w_data, &rt_price_1w_vec, &mut bb10_1w_data, &valid_usdt_trade_vec).await; + // // bb_1mon_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1mon_data, &rt_price_1mon_vec, &mut bb10_1mon_data, &valid_usdt_trade_vec).await; + // } + // 30 => { + // bb_1m_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_1m_data, + // &rt_price_1m_vec, + // &mut bb30_1m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // bb_30m_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_30m_data, + // &rt_price_30m_vec, + // &mut bb30_30m_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // bb_1d_result = + // value_estimation_team::indicators::bollingerband::bollingerband( + // *moving_number_element, + // 3.0, + // &sma_1d_data, + // &rt_price_1d_vec, + // &mut bb30_1d_data, + // &valid_usdt_trade_vec, + // ) + // .await; + // // bb_1w_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1w_data, &rt_price_1w_vec, &mut bb30_1w_data, &valid_usdt_trade_vec).await; + // // bb_1mon_result = value_estimation_team::indicators::bollingerband::bollingerband(*moving_number_element, 2.0, &sma_1mon_data, &rt_price_1mon_vec, &mut bb30_1mon_data, &valid_usdt_trade_vec).await; + // } + // _ => { + // bb_1m_result = Ok(()); + // bb_30m_result = Ok(()); + // bb_1d_result = Ok(()); + // // bb_1w_result = Ok(()); + // // bb_1mon_result = Ok(()); + // } + // } - match moving_number_element { - 3 => { - if sma_1m_result.is_ok() { - tx_sma3_1m_data.send_modify(|vec| *vec = sma_1m_data); - } - if sma_30m_result.is_ok() { - tx_sma3_30m_data.send_modify(|vec| *vec = sma_30m_data); - } - if sma_1d_result.is_ok() { - tx_sma3_1d_data.send_modify(|vec| *vec = sma_1d_data); - } - // if sma_1w_result.is_ok() { tx_sma3_1w_data.send_modify(|vec| *vec = sma_1w_data); } - // if sma_1mon_result.is_ok() { tx_sma3_1mon_data.send_modify(|vec| *vec = sma_1mon_data); } + // match moving_number_element { + // 3 => { + // if sma_1m_result.is_ok() { + // tx_sma3_1m_data.send_modify(|vec| *vec = sma_1m_data); + // } + // if sma_30m_result.is_ok() { + // tx_sma3_30m_data.send_modify(|vec| *vec = sma_30m_data); + // } + // if sma_1d_result.is_ok() { + // tx_sma3_1d_data.send_modify(|vec| *vec = sma_1d_data); + // } + // // if sma_1w_result.is_ok() { tx_sma3_1w_data.send_modify(|vec| *vec = sma_1w_data); } + // // if sma_1mon_result.is_ok() { tx_sma3_1mon_data.send_modify(|vec| *vec = sma_1mon_data); } - if ema_1m_result.is_ok() { - tx_ema3_1m_data.send_modify(|vec| *vec = ema_1m_data); - } - if ema_30m_result.is_ok() { - tx_ema3_30m_data.send_modify(|vec| *vec = ema_30m_data); - } - if ema_1d_result.is_ok() { - tx_ema3_1d_data.send_modify(|vec| *vec = ema_1d_data); - } - // if ema_1w_result.is_ok() { tx_ema3_1w_data.send_modify(|vec| *vec = ema_1w_data); } - // if ema_1mon_result.is_ok() { tx_ema3_1mon_data.send_modify(|vec| *vec = ema_1mon_data); } + // if ema_1m_result.is_ok() { + // tx_ema3_1m_data.send_modify(|vec| *vec = ema_1m_data); + // } + // if ema_30m_result.is_ok() { + // tx_ema3_30m_data.send_modify(|vec| *vec = ema_30m_data); + // } + // if ema_1d_result.is_ok() { + // tx_ema3_1d_data.send_modify(|vec| *vec = ema_1d_data); + // } + // // if ema_1w_result.is_ok() { tx_ema3_1w_data.send_modify(|vec| *vec = ema_1w_data); } + // // if ema_1mon_result.is_ok() { tx_ema3_1mon_data.send_modify(|vec| *vec = ema_1mon_data); } - // tx_tema3_1m_data.send_modify(|vec| *vec = tema_1m_data); - // tx_tema3_30m_data.send_modify(|vec| *vec = tema_30m_data); - // tx_tema3_1d_data.send_modify(|vec| *vec = tema_1d_data); - // tx_tema3_1w_data.send_modify(|vec| *vec = tema_1w_data); - // tx_tema3_1mon_data.send_modify(|vec| *vec = tema_1mon_data); + // // tx_tema3_1m_data.send_modify(|vec| *vec = tema_1m_data); + // // tx_tema3_30m_data.send_modify(|vec| *vec = tema_30m_data); + // // tx_tema3_1d_data.send_modify(|vec| *vec = tema_1d_data); + // // tx_tema3_1w_data.send_modify(|vec| *vec = tema_1w_data); + // // tx_tema3_1mon_data.send_modify(|vec| *vec = tema_1mon_data); - if rsi_1m_result.is_ok() { - tx_rsi3_1m_data.send_modify(|vec| *vec = rsi_1m_data); - } - if rsi_30m_result.is_ok() { - tx_rsi3_30m_data.send_modify(|vec| *vec = rsi_30m_data); - } - if rsi_1d_result.is_ok() { - tx_rsi3_1d_data.send_modify(|vec| *vec = rsi_1d_data); - } - // if rsi_1w_result.is_ok() { tx_rsi3_1w_data.send_modify(|vec| *vec = rsi_1w_data); } - // if rsi_1mon_result.is_ok() { tx_rsi3_1mon_data.send_modify(|vec| *vec = rsi_1mon_data); } + // if rsi_1m_result.is_ok() { + // tx_rsi3_1m_data.send_modify(|vec| *vec = rsi_1m_data); + // } + // if rsi_30m_result.is_ok() { + // tx_rsi3_30m_data.send_modify(|vec| *vec = rsi_30m_data); + // } + // if rsi_1d_result.is_ok() { + // tx_rsi3_1d_data.send_modify(|vec| *vec = rsi_1d_data); + // } + // // if rsi_1w_result.is_ok() { tx_rsi3_1w_data.send_modify(|vec| *vec = rsi_1w_data); } + // // if rsi_1mon_result.is_ok() { tx_rsi3_1mon_data.send_modify(|vec| *vec = rsi_1mon_data); } - if bb_1m_result.is_ok() { - tx_bb3_1m_data.send_modify(|vec| *vec = bb3_1m_data); - } - if bb_30m_result.is_ok() { - tx_bb3_30m_data.send_modify(|vec| *vec = bb3_30m_data); - } - if bb_1d_result.is_ok() { - tx_bb3_1d_data.send_modify(|vec| *vec = bb3_1d_data); - } - // if bb_1w_result.is_ok() { tx_bb3_1w_data.send_modify(|vec| *vec = bb3_1w_data); } - // if bb_1mon_result.is_ok() { tx_bb3_1mon_data.send_modify(|vec| *vec = bb3_1mon_data); } + // if bb_1m_result.is_ok() { + // tx_bb3_1m_data.send_modify(|vec| *vec = bb3_1m_data); + // } + // if bb_30m_result.is_ok() { + // tx_bb3_30m_data.send_modify(|vec| *vec = bb3_30m_data); + // } + // if bb_1d_result.is_ok() { + // tx_bb3_1d_data.send_modify(|vec| *vec = bb3_1d_data); + // } + // // if bb_1w_result.is_ok() { tx_bb3_1w_data.send_modify(|vec| *vec = bb3_1w_data); } + // // if bb_1mon_result.is_ok() { tx_bb3_1mon_data.send_modify(|vec| *vec = bb3_1mon_data); } - tx_task11 - .send(11) - .expect("The mpsc channel has been closed."); - } - 10 => { - if sma_1m_result.is_ok() { - tx_sma10_1m_data.send_modify(|vec| *vec = sma_1m_data); - } - if sma_30m_result.is_ok() { - tx_sma10_30m_data.send_modify(|vec| *vec = sma_30m_data); - } - if sma_1d_result.is_ok() { - tx_sma10_1d_data.send_modify(|vec| *vec = sma_1d_data); - } - // if sma_1w_result.is_ok() { tx_sma10_1w_data.send_modify(|vec| *vec = sma_1w_data); } - // if sma_1mon_result.is_ok() { tx_sma10_1mon_data.send_modify(|vec| *vec = sma_1mon_data); } + // tx_task11 + // .send(11) + // .expect("The mpsc channel has been closed."); + // } + // 10 => { + // if sma_1m_result.is_ok() { + // tx_sma10_1m_data.send_modify(|vec| *vec = sma_1m_data); + // } + // if sma_30m_result.is_ok() { + // tx_sma10_30m_data.send_modify(|vec| *vec = sma_30m_data); + // } + // if sma_1d_result.is_ok() { + // tx_sma10_1d_data.send_modify(|vec| *vec = sma_1d_data); + // } + // // if sma_1w_result.is_ok() { tx_sma10_1w_data.send_modify(|vec| *vec = sma_1w_data); } + // // if sma_1mon_result.is_ok() { tx_sma10_1mon_data.send_modify(|vec| *vec = sma_1mon_data); } - if ema_1m_result.is_ok() { - tx_ema10_1m_data.send_modify(|vec| *vec = ema_1m_data); - } - if ema_30m_result.is_ok() { - tx_ema10_30m_data.send_modify(|vec| *vec = ema_30m_data); - } - if ema_1d_result.is_ok() { - tx_ema10_1d_data.send_modify(|vec| *vec = ema_1d_data); - } - // if ema_1w_result.is_ok() { tx_ema10_1w_data.send_modify(|vec| *vec = ema_1w_data); } - // if ema_1mon_result.is_ok() { tx_ema10_1mon_data.send_modify(|vec| *vec = ema_1mon_data); } + // if ema_1m_result.is_ok() { + // tx_ema10_1m_data.send_modify(|vec| *vec = ema_1m_data); + // } + // if ema_30m_result.is_ok() { + // tx_ema10_30m_data.send_modify(|vec| *vec = ema_30m_data); + // } + // if ema_1d_result.is_ok() { + // tx_ema10_1d_data.send_modify(|vec| *vec = ema_1d_data); + // } + // // if ema_1w_result.is_ok() { tx_ema10_1w_data.send_modify(|vec| *vec = ema_1w_data); } + // // if ema_1mon_result.is_ok() { tx_ema10_1mon_data.send_modify(|vec| *vec = ema_1mon_data); } - // tx_tema10_1m_data.send_modify(|vec| *vec = tema_1m_data); - // tx_tema10_30m_data.send_modify(|vec| *vec = tema_30m_data); - // tx_tema10_1d_data.send_modify(|vec| *vec = tema_1d_data); - // tx_tema10_1w_data.send_modify(|vec| *vec = tema_1w_data); - // tx_tema10_1mon_data.send_modify(|vec| *vec = tema_1mon_data); + // // tx_tema10_1m_data.send_modify(|vec| *vec = tema_1m_data); + // // tx_tema10_30m_data.send_modify(|vec| *vec = tema_30m_data); + // // tx_tema10_1d_data.send_modify(|vec| *vec = tema_1d_data); + // // tx_tema10_1w_data.send_modify(|vec| *vec = tema_1w_data); + // // tx_tema10_1mon_data.send_modify(|vec| *vec = tema_1mon_data); - if rsi_1m_result.is_ok() { - tx_rsi10_1m_data.send_modify(|vec| *vec = rsi_1m_data); - } - if rsi_30m_result.is_ok() { - tx_rsi10_30m_data.send_modify(|vec| *vec = rsi_30m_data); - } - if rsi_1d_result.is_ok() { - tx_rsi10_1d_data.send_modify(|vec| *vec = rsi_1d_data); - } - // if rsi_1w_result.is_ok() { tx_rsi10_1w_data.send_modify(|vec| *vec = rsi_1w_data); } - // if rsi_1mon_result.is_ok() { tx_rsi10_1mon_data.send_modify(|vec| *vec = rsi_1mon_data); } + // if rsi_1m_result.is_ok() { + // tx_rsi10_1m_data.send_modify(|vec| *vec = rsi_1m_data); + // } + // if rsi_30m_result.is_ok() { + // tx_rsi10_30m_data.send_modify(|vec| *vec = rsi_30m_data); + // } + // if rsi_1d_result.is_ok() { + // tx_rsi10_1d_data.send_modify(|vec| *vec = rsi_1d_data); + // } + // // if rsi_1w_result.is_ok() { tx_rsi10_1w_data.send_modify(|vec| *vec = rsi_1w_data); } + // // if rsi_1mon_result.is_ok() { tx_rsi10_1mon_data.send_modify(|vec| *vec = rsi_1mon_data); } - if bb_1m_result.is_ok() { - tx_bb10_1m_data.send_modify(|vec| *vec = bb10_1m_data); - } - if bb_30m_result.is_ok() { - tx_bb10_30m_data.send_modify(|vec| *vec = bb10_30m_data); - } - if bb_1d_result.is_ok() { - tx_bb10_1d_data.send_modify(|vec| *vec = bb10_1d_data); - } - // if bb_1w_result.is_ok() { tx_bb10_1w_data.send_modify(|vec| *vec = bb10_1w_data); } - // if bb_1mon_result.is_ok() { tx_bb10_1mon_data.send_modify(|vec| *vec = bb10_1mon_data); } + // if bb_1m_result.is_ok() { + // tx_bb10_1m_data.send_modify(|vec| *vec = bb10_1m_data); + // } + // if bb_30m_result.is_ok() { + // tx_bb10_30m_data.send_modify(|vec| *vec = bb10_30m_data); + // } + // if bb_1d_result.is_ok() { + // tx_bb10_1d_data.send_modify(|vec| *vec = bb10_1d_data); + // } + // // if bb_1w_result.is_ok() { tx_bb10_1w_data.send_modify(|vec| *vec = bb10_1w_data); } + // // if bb_1mon_result.is_ok() { tx_bb10_1mon_data.send_modify(|vec| *vec = bb10_1mon_data); } - tx_task11 - .send(11) - .expect("The mpsc channel has been closed."); - } - 30 => { - if sma_1m_result.is_ok() { - tx_sma30_1m_data.send_modify(|vec| *vec = sma_1m_data); - } - if sma_30m_result.is_ok() { - tx_sma30_30m_data.send_modify(|vec| *vec = sma_30m_data); - } - if sma_1d_result.is_ok() { - tx_sma30_1d_data.send_modify(|vec| *vec = sma_1d_data); - } - // if sma_1w_result.is_ok() { tx_sma30_1w_data.send_modify(|vec| *vec = sma_1w_data); } - // if sma_1mon_result.is_ok() { tx_sma30_1mon_data.send_modify(|vec| *vec = sma_1mon_data); } + // tx_task11 + // .send(11) + // .expect("The mpsc channel has been closed."); + // } + // 30 => { + // if sma_1m_result.is_ok() { + // tx_sma30_1m_data.send_modify(|vec| *vec = sma_1m_data); + // } + // if sma_30m_result.is_ok() { + // tx_sma30_30m_data.send_modify(|vec| *vec = sma_30m_data); + // } + // if sma_1d_result.is_ok() { + // tx_sma30_1d_data.send_modify(|vec| *vec = sma_1d_data); + // } + // // if sma_1w_result.is_ok() { tx_sma30_1w_data.send_modify(|vec| *vec = sma_1w_data); } + // // if sma_1mon_result.is_ok() { tx_sma30_1mon_data.send_modify(|vec| *vec = sma_1mon_data); } - if ema_1m_result.is_ok() { - tx_ema30_1m_data.send_modify(|vec| *vec = ema_1m_data); - } - if ema_30m_result.is_ok() { - tx_ema30_30m_data.send_modify(|vec| *vec = ema_30m_data); - } - if ema_1d_result.is_ok() { - tx_ema30_1d_data.send_modify(|vec| *vec = ema_1d_data); - } - // if ema_1w_result.is_ok() { tx_ema30_1w_data.send_modify(|vec| *vec = ema_1w_data); } - // if ema_1mon_result.is_ok() { tx_ema30_1mon_data.send_modify(|vec| *vec = ema_1mon_data); } + // if ema_1m_result.is_ok() { + // tx_ema30_1m_data.send_modify(|vec| *vec = ema_1m_data); + // } + // if ema_30m_result.is_ok() { + // tx_ema30_30m_data.send_modify(|vec| *vec = ema_30m_data); + // } + // if ema_1d_result.is_ok() { + // tx_ema30_1d_data.send_modify(|vec| *vec = ema_1d_data); + // } + // // if ema_1w_result.is_ok() { tx_ema30_1w_data.send_modify(|vec| *vec = ema_1w_data); } + // // if ema_1mon_result.is_ok() { tx_ema30_1mon_data.send_modify(|vec| *vec = ema_1mon_data); } - // tx_tema30_1m_data.send_modify(|vec| *vec = tema_1m_data); - // tx_tema30_30m_data.send_modify(|vec| *vec = tema_30m_data); - // tx_tema30_1d_data.send_modify(|vec| *vec = tema_1d_data); - // tx_tema30_1w_data.send_modify(|vec| *vec = tema_1w_data); - // tx_tema30_1mon_data.send_modify(|vec| *vec = tema_1mon_data); + // // tx_tema30_1m_data.send_modify(|vec| *vec = tema_1m_data); + // // tx_tema30_30m_data.send_modify(|vec| *vec = tema_30m_data); + // // tx_tema30_1d_data.send_modify(|vec| *vec = tema_1d_data); + // // tx_tema30_1w_data.send_modify(|vec| *vec = tema_1w_data); + // // tx_tema30_1mon_data.send_modify(|vec| *vec = tema_1mon_data); - if rsi_1m_result.is_ok() { - tx_rsi30_1m_data.send_modify(|vec| *vec = rsi_1m_data); - } - if rsi_30m_result.is_ok() { - tx_rsi30_30m_data.send_modify(|vec| *vec = rsi_30m_data); - } - if rsi_1d_result.is_ok() { - tx_rsi30_1d_data.send_modify(|vec| *vec = rsi_1d_data); - } - // if rsi_1w_result.is_ok() { tx_rsi30_1w_data.send_modify(|vec| *vec = rsi_1w_data); } - // if rsi_1mon_result.is_ok() { tx_rsi30_1mon_data.send_modify(|vec| *vec = rsi_1mon_data); } + // if rsi_1m_result.is_ok() { + // tx_rsi30_1m_data.send_modify(|vec| *vec = rsi_1m_data); + // } + // if rsi_30m_result.is_ok() { + // tx_rsi30_30m_data.send_modify(|vec| *vec = rsi_30m_data); + // } + // if rsi_1d_result.is_ok() { + // tx_rsi30_1d_data.send_modify(|vec| *vec = rsi_1d_data); + // } + // // if rsi_1w_result.is_ok() { tx_rsi30_1w_data.send_modify(|vec| *vec = rsi_1w_data); } + // // if rsi_1mon_result.is_ok() { tx_rsi30_1mon_data.send_modify(|vec| *vec = rsi_1mon_data); } - if bb_1m_result.is_ok() { - tx_bb30_1m_data.send_modify(|vec| *vec = bb30_1m_data); - } - if bb_30m_result.is_ok() { - tx_bb30_30m_data.send_modify(|vec| *vec = bb30_30m_data); - } - if bb_1d_result.is_ok() { - tx_bb30_1d_data.send_modify(|vec| *vec = bb30_1d_data); - } - // if bb_1w_result.is_ok() { tx_bb30_1w_data.send_modify(|vec| *vec = bb30_1w_data); } - // if bb_1mon_result.is_ok() { tx_bb30_1mon_data.send_modify(|vec| *vec = bb30_1mon_data); } + // if bb_1m_result.is_ok() { + // tx_bb30_1m_data.send_modify(|vec| *vec = bb30_1m_data); + // } + // if bb_30m_result.is_ok() { + // tx_bb30_30m_data.send_modify(|vec| *vec = bb30_30m_data); + // } + // if bb_1d_result.is_ok() { + // tx_bb30_1d_data.send_modify(|vec| *vec = bb30_1d_data); + // } + // // if bb_1w_result.is_ok() { tx_bb30_1w_data.send_modify(|vec| *vec = bb30_1w_data); } + // // if bb_1mon_result.is_ok() { tx_bb30_1mon_data.send_modify(|vec| *vec = bb30_1mon_data); } - tx_task11 - .send(11) - .expect("The mpsc channel has been closed."); - } - _ => {} - } - } + // tx_task11 + // .send(11) + // .expect("The mpsc channel has been closed."); + // } + // _ => {} + // } + // } - // sleep as much as the loop recurs per 1 second if all operation finished within 1 second. - elapsed_time = instant.elapsed().as_millis(); - if 1_000 > elapsed_time { - sleep(Duration::from_millis((1_000 - elapsed_time) as u64)).await; - } - } - }); + // // sleep as much as the loop recurs per 1 second if all operation finished within 1 second. + // elapsed_time = instant.elapsed().as_millis(); + // if 1_000 > elapsed_time { + // sleep(Duration::from_millis((1_000 - elapsed_time) as u64)).await; + // } + // } + // }); // Task#12: monitoring total market cap if RUNNING_MODE == REAL || RUNNING_MODE == SIMUL || RUNNING_MODE == TEST { @@ -1695,76 +1695,76 @@ async fn main() -> Result<(), Box> { // all_data.rt_price_1mon_vec = rx3_rt_price_1mon_vec.borrow().clone(); // SMA data - all_data.sma3_1m_data = rx2_sma3_1m_data.borrow().clone(); - all_data.sma3_30m_data = rx2_sma3_30m_data.borrow().clone(); - all_data.sma3_1d_data = rx2_sma3_1d_data.borrow().clone(); + // all_data.sma3_1m_data = rx2_sma3_1m_data.borrow().clone(); + // all_data.sma3_30m_data = rx2_sma3_30m_data.borrow().clone(); + // all_data.sma3_1d_data = rx2_sma3_1d_data.borrow().clone(); // all_data.sma3_1w_data = rx2_sma3_1w_data.borrow().clone(); // all_data.sma3_1mon_data = rx2_sma3_1mon_data.borrow().clone(); - all_data.sma10_1m_data = rx2_sma10_1m_data.borrow().clone(); - all_data.sma10_30m_data = rx2_sma10_30m_data.borrow().clone(); - all_data.sma10_1d_data = rx2_sma10_1d_data.borrow().clone(); + // all_data.sma10_1m_data = rx2_sma10_1m_data.borrow().clone(); + // all_data.sma10_30m_data = rx2_sma10_30m_data.borrow().clone(); + // all_data.sma10_1d_data = rx2_sma10_1d_data.borrow().clone(); // all_data.sma10_1w_data = rx2_sma10_1w_data.borrow().clone(); // all_data.sma10_1mon_data = rx2_sma10_1mon_data.borrow().clone(); - all_data.sma30_1m_data = rx2_sma30_1m_data.borrow().clone(); - all_data.sma30_30m_data = rx2_sma30_30m_data.borrow().clone(); - all_data.sma30_1d_data = rx2_sma30_1d_data.borrow().clone(); + // all_data.sma30_1m_data = rx2_sma30_1m_data.borrow().clone(); + // all_data.sma30_30m_data = rx2_sma30_30m_data.borrow().clone(); + // all_data.sma30_1d_data = rx2_sma30_1d_data.borrow().clone(); // all_data.sma30_1w_data = rx2_sma30_1w_data.borrow().clone(); // all_data.sma30_1mon_data = rx2_sma30_1mon_data.borrow().clone(); // EMA data - all_data.ema3_1m_data = rx2_ema3_1m_data.borrow().clone(); - all_data.ema3_30m_data = rx2_ema3_30m_data.borrow().clone(); - all_data.ema3_1d_data = rx2_ema3_1d_data.borrow().clone(); + // all_data.ema3_1m_data = rx2_ema3_1m_data.borrow().clone(); + // all_data.ema3_30m_data = rx2_ema3_30m_data.borrow().clone(); + // all_data.ema3_1d_data = rx2_ema3_1d_data.borrow().clone(); // all_data.ema3_1w_data = rx2_ema3_1w_data.borrow().clone(); // all_data.ema3_1mon_data = rx2_ema3_1mon_data.borrow().clone(); - all_data.ema10_1m_data = rx2_ema10_1m_data.borrow().clone(); - all_data.ema10_30m_data = rx2_ema10_30m_data.borrow().clone(); - all_data.ema10_1d_data = rx2_ema10_1d_data.borrow().clone(); + // all_data.ema10_1m_data = rx2_ema10_1m_data.borrow().clone(); + // all_data.ema10_30m_data = rx2_ema10_30m_data.borrow().clone(); + // all_data.ema10_1d_data = rx2_ema10_1d_data.borrow().clone(); // all_data.ema10_1w_data = rx2_ema10_1w_data.borrow().clone(); // all_data.ema10_1mon_data = rx2_ema10_1mon_data.borrow().clone(); - all_data.ema30_1m_data = rx2_ema30_1m_data.borrow().clone(); - all_data.ema30_30m_data = rx2_ema30_30m_data.borrow().clone(); - all_data.ema30_1d_data = rx2_ema30_1d_data.borrow().clone(); + // all_data.ema30_1m_data = rx2_ema30_1m_data.borrow().clone(); + // all_data.ema30_30m_data = rx2_ema30_30m_data.borrow().clone(); + // all_data.ema30_1d_data = rx2_ema30_1d_data.borrow().clone(); // all_data.ema30_1w_data = rx2_ema30_1w_data.borrow().clone(); // all_data.ema30_1mon_data = rx2_ema30_1mon_data.borrow().clone(); // RSI data - all_data.rsi3_1m_data = rx_rsi3_1m_data.borrow().clone(); - all_data.rsi3_30m_data = rx_rsi3_30m_data.borrow().clone(); - all_data.rsi3_1d_data = rx_rsi3_1d_data.borrow().clone(); + // all_data.rsi3_1m_data = rx_rsi3_1m_data.borrow().clone(); + // all_data.rsi3_30m_data = rx_rsi3_30m_data.borrow().clone(); + // all_data.rsi3_1d_data = rx_rsi3_1d_data.borrow().clone(); // all_data.rsi3_1w_data = rx_rsi3_1w_data.borrow().clone(); // all_data.rsi3_1mon_data = rx_rsi3_1mon_data.borrow().clone(); - all_data.rsi10_1m_data = rx_rsi10_1m_data.borrow().clone(); - all_data.rsi10_30m_data = rx_rsi10_30m_data.borrow().clone(); - all_data.rsi10_1d_data = rx_rsi10_1d_data.borrow().clone(); + // all_data.rsi10_1m_data = rx_rsi10_1m_data.borrow().clone(); + // all_data.rsi10_30m_data = rx_rsi10_30m_data.borrow().clone(); + // all_data.rsi10_1d_data = rx_rsi10_1d_data.borrow().clone(); // all_data.rsi10_1w_data = rx_rsi10_1w_data.borrow().clone(); // all_data.rsi10_1mon_data = rx_rsi10_1mon_data.borrow().clone(); - all_data.rsi30_1m_data = rx_rsi30_1m_data.borrow().clone(); - all_data.rsi30_30m_data = rx_rsi30_30m_data.borrow().clone(); - all_data.rsi30_1d_data = rx_rsi30_1d_data.borrow().clone(); + // all_data.rsi30_1m_data = rx_rsi30_1m_data.borrow().clone(); + // all_data.rsi30_30m_data = rx_rsi30_30m_data.borrow().clone(); + // all_data.rsi30_1d_data = rx_rsi30_1d_data.borrow().clone(); // all_data.rsi30_1w_data = rx_rsi30_1w_data.borrow().clone(); // all_data.rsi30_1mon_data = rx_rsi30_1mon_data.borrow().clone(); // Stoch RSI data - all_data.stoch_rsi3_1m_3_k_data = rx_stoch_rsi3_1m_3_k_data.borrow().clone(); - all_data.stoch_rsi3_1m_3_d_data = rx_stoch_rsi3_1m_3_d_data.borrow().clone(); - all_data.stoch_rsi30_1m_30_k_data = rx_stoch_rsi30_1m_30_k_data.borrow().clone(); - all_data.stoch_rsi30_1m_30_d_data = rx_stoch_rsi30_1m_30_d_data.borrow().clone(); + // all_data.stoch_rsi3_1m_3_k_data = rx_stoch_rsi3_1m_3_k_data.borrow().clone(); + // all_data.stoch_rsi3_1m_3_d_data = rx_stoch_rsi3_1m_3_d_data.borrow().clone(); + // all_data.stoch_rsi30_1m_30_k_data = rx_stoch_rsi30_1m_30_k_data.borrow().clone(); + // all_data.stoch_rsi30_1m_30_d_data = rx_stoch_rsi30_1m_30_d_data.borrow().clone(); // BollingerBand data - all_data.bb3_1m_data = rx_bb3_1m_data.borrow().clone(); - all_data.bb3_30m_data = rx_bb3_30m_data.borrow().clone(); - all_data.bb3_1d_data = rx_bb3_1d_data.borrow().clone(); + // all_data.bb3_1m_data = rx_bb3_1m_data.borrow().clone(); + // all_data.bb3_30m_data = rx_bb3_30m_data.borrow().clone(); + // all_data.bb3_1d_data = rx_bb3_1d_data.borrow().clone(); // all_data.bb3_1w_data = rx_bb3_1w_data.borrow().clone(); // all_data.bb3_1mon_data = rx_bb3_1mon_data.borrow().clone(); - all_data.bb10_1m_data = rx_bb10_1m_data.borrow().clone(); - all_data.bb10_30m_data = rx_bb10_30m_data.borrow().clone(); - all_data.bb10_1d_data = rx_bb10_1d_data.borrow().clone(); + // all_data.bb10_1m_data = rx_bb10_1m_data.borrow().clone(); + // all_data.bb10_30m_data = rx_bb10_30m_data.borrow().clone(); to be deleted + // all_data.bb10_1d_data = rx_bb10_1d_data.borrow().clone(); // all_data.bb10_1w_data = rx_bb10_1w_data.borrow().clone(); // all_data.bb10_1mon_data = rx_bb10_1mon_data.borrow().clone(); - all_data.bb30_1m_data = rx_bb30_1m_data.borrow().clone(); - all_data.bb30_30m_data = rx_bb30_30m_data.borrow().clone(); - all_data.bb30_1d_data = rx_bb30_1d_data.borrow().clone(); + // all_data.bb30_1m_data = rx_bb30_1m_data.borrow().clone(); + // all_data.bb30_30m_data = rx_bb30_30m_data.borrow().clone(); + // all_data.bb30_1d_data = rx_bb30_1d_data.borrow().clone(); // all_data.bb30_1w_data = rx_bb30_1w_data.borrow().clone(); // all_data.bb30_1mon_data = rx_bb30_1mon_data.borrow().clone(); @@ -1803,85 +1803,85 @@ async fn main() -> Result<(), Box> { all_data.rt_price_1w_vec = rx3_rt_price_1w_vec.borrow().clone(); all_data.rt_price_1mon_vec = rx3_rt_price_1mon_vec.borrow().clone(); // SMA data - all_data.sma3_1m_data = rx2_sma3_1m_data.borrow().clone(); - all_data.sma3_30m_data = rx2_sma3_30m_data.borrow().clone(); - all_data.sma3_1d_data = rx2_sma3_1d_data.borrow().clone(); - all_data.sma3_1w_data = rx2_sma3_1w_data.borrow().clone(); - all_data.sma3_1mon_data = rx2_sma3_1mon_data.borrow().clone(); - all_data.sma10_1m_data = rx2_sma10_1m_data.borrow().clone(); - all_data.sma10_30m_data = rx2_sma10_30m_data.borrow().clone(); - all_data.sma10_1d_data = rx2_sma10_1d_data.borrow().clone(); - all_data.sma10_1w_data = rx2_sma10_1w_data.borrow().clone(); - all_data.sma10_1mon_data = rx2_sma10_1mon_data.borrow().clone(); - all_data.sma30_1m_data = rx2_sma30_1m_data.borrow().clone(); - all_data.sma30_30m_data = rx2_sma30_30m_data.borrow().clone(); - all_data.sma30_1d_data = rx2_sma30_1d_data.borrow().clone(); - all_data.sma30_1w_data = rx2_sma30_1w_data.borrow().clone(); - all_data.sma30_1mon_data = rx2_sma30_1mon_data.borrow().clone(); + // all_data.sma3_1m_data = rx2_sma3_1m_data.borrow().clone(); + // all_data.sma3_30m_data = rx2_sma3_30m_data.borrow().clone(); + // all_data.sma3_1d_data = rx2_sma3_1d_data.borrow().clone(); + // all_data.sma3_1w_data = rx2_sma3_1w_data.borrow().clone(); + // all_data.sma3_1mon_data = rx2_sma3_1mon_data.borrow().clone(); + // all_data.sma10_1m_data = rx2_sma10_1m_data.borrow().clone(); + // all_data.sma10_30m_data = rx2_sma10_30m_data.borrow().clone(); + // all_data.sma10_1d_data = rx2_sma10_1d_data.borrow().clone(); + // all_data.sma10_1w_data = rx2_sma10_1w_data.borrow().clone(); + // all_data.sma10_1mon_data = rx2_sma10_1mon_data.borrow().clone(); + // all_data.sma30_1m_data = rx2_sma30_1m_data.borrow().clone(); + // all_data.sma30_30m_data = rx2_sma30_30m_data.borrow().clone(); + // all_data.sma30_1d_data = rx2_sma30_1d_data.borrow().clone(); + // all_data.sma30_1w_data = rx2_sma30_1w_data.borrow().clone(); + // all_data.sma30_1mon_data = rx2_sma30_1mon_data.borrow().clone(); // EMA data - all_data.ema3_1m_data = rx2_ema3_1m_data.borrow().clone(); - all_data.ema3_30m_data = rx2_ema3_30m_data.borrow().clone(); - all_data.ema3_1d_data = rx2_ema3_1d_data.borrow().clone(); - all_data.ema3_1w_data = rx2_ema3_1w_data.borrow().clone(); - all_data.ema3_1mon_data = rx2_ema3_1mon_data.borrow().clone(); - all_data.ema10_1m_data = rx2_ema10_1m_data.borrow().clone(); - all_data.ema10_30m_data = rx2_ema10_30m_data.borrow().clone(); - all_data.ema10_1d_data = rx2_ema10_1d_data.borrow().clone(); - all_data.ema10_1w_data = rx2_ema10_1w_data.borrow().clone(); - all_data.ema10_1mon_data = rx2_ema10_1mon_data.borrow().clone(); - all_data.ema30_1m_data = rx2_ema30_1m_data.borrow().clone(); - all_data.ema30_30m_data = rx2_ema30_30m_data.borrow().clone(); - all_data.ema30_1d_data = rx2_ema30_1d_data.borrow().clone(); - all_data.ema30_1w_data = rx2_ema30_1w_data.borrow().clone(); - all_data.ema30_1mon_data = rx2_ema30_1mon_data.borrow().clone(); + // all_data.ema3_1m_data = rx2_ema3_1m_data.borrow().clone(); + // all_data.ema3_30m_data = rx2_ema3_30m_data.borrow().clone(); + // all_data.ema3_1d_data = rx2_ema3_1d_data.borrow().clone(); + // all_data.ema3_1w_data = rx2_ema3_1w_data.borrow().clone(); + // all_data.ema3_1mon_data = rx2_ema3_1mon_data.borrow().clone(); + // all_data.ema10_1m_data = rx2_ema10_1m_data.borrow().clone(); + // all_data.ema10_30m_data = rx2_ema10_30m_data.borrow().clone(); + // all_data.ema10_1d_data = rx2_ema10_1d_data.borrow().clone(); + // all_data.ema10_1w_data = rx2_ema10_1w_data.borrow().clone(); + // all_data.ema10_1mon_data = rx2_ema10_1mon_data.borrow().clone(); + // all_data.ema30_1m_data = rx2_ema30_1m_data.borrow().clone(); + // all_data.ema30_30m_data = rx2_ema30_30m_data.borrow().clone(); + // all_data.ema30_1d_data = rx2_ema30_1d_data.borrow().clone(); + // all_data.ema30_1w_data = rx2_ema30_1w_data.borrow().clone(); + // all_data.ema30_1mon_data = rx2_ema30_1mon_data.borrow().clone(); // RSI data - all_data.rsi3_1m_data = rx_rsi3_1m_data.borrow().clone(); - all_data.rsi3_30m_data = rx_rsi3_30m_data.borrow().clone(); - all_data.rsi3_1d_data = rx_rsi3_1d_data.borrow().clone(); - all_data.rsi3_1w_data = rx_rsi3_1w_data.borrow().clone(); - all_data.rsi3_1mon_data = rx_rsi3_1mon_data.borrow().clone(); - all_data.rsi10_1m_data = rx_rsi10_1m_data.borrow().clone(); - all_data.rsi10_30m_data = rx_rsi10_30m_data.borrow().clone(); - all_data.rsi10_1d_data = rx_rsi10_1d_data.borrow().clone(); - all_data.rsi10_1w_data = rx_rsi10_1w_data.borrow().clone(); - all_data.rsi10_1mon_data = rx_rsi10_1mon_data.borrow().clone(); - all_data.rsi30_1m_data = rx_rsi30_1m_data.borrow().clone(); - all_data.rsi30_30m_data = rx_rsi30_30m_data.borrow().clone(); - all_data.rsi30_1d_data = rx_rsi30_1d_data.borrow().clone(); - all_data.rsi30_1w_data = rx_rsi30_1w_data.borrow().clone(); - all_data.rsi30_1mon_data = rx_rsi30_1mon_data.borrow().clone(); + // all_data.rsi3_1m_data = rx_rsi3_1m_data.borrow().clone(); + // all_data.rsi3_30m_data = rx_rsi3_30m_data.borrow().clone(); + // all_data.rsi3_1d_data = rx_rsi3_1d_data.borrow().clone(); + // all_data.rsi3_1w_data = rx_rsi3_1w_data.borrow().clone(); + // all_data.rsi3_1mon_data = rx_rsi3_1mon_data.borrow().clone(); + // all_data.rsi10_1m_data = rx_rsi10_1m_data.borrow().clone(); + // all_data.rsi10_30m_data = rx_rsi10_30m_data.borrow().clone(); + // all_data.rsi10_1d_data = rx_rsi10_1d_data.borrow().clone(); + // all_data.rsi10_1w_data = rx_rsi10_1w_data.borrow().clone(); + // all_data.rsi10_1mon_data = rx_rsi10_1mon_data.borrow().clone(); + // all_data.rsi30_1m_data = rx_rsi30_1m_data.borrow().clone(); + // all_data.rsi30_30m_data = rx_rsi30_30m_data.borrow().clone(); + // all_data.rsi30_1d_data = rx_rsi30_1d_data.borrow().clone(); + // all_data.rsi30_1w_data = rx_rsi30_1w_data.borrow().clone(); + // all_data.rsi30_1mon_data = rx_rsi30_1mon_data.borrow().clone(); // Stoch RSI data - all_data.stoch_rsi3_1m_3_k_data = rx_stoch_rsi3_1m_3_k_data.borrow().clone(); - all_data.stoch_rsi3_1m_3_d_data = rx_stoch_rsi3_1m_3_d_data.borrow().clone(); - all_data.stoch_rsi30_1m_30_k_data = rx_stoch_rsi30_1m_30_k_data.borrow().clone(); - all_data.stoch_rsi30_1m_30_d_data = rx_stoch_rsi30_1m_30_d_data.borrow().clone(); + // all_data.stoch_rsi3_1m_3_k_data = rx_stoch_rsi3_1m_3_k_data.borrow().clone(); + // all_data.stoch_rsi3_1m_3_d_data = rx_stoch_rsi3_1m_3_d_data.borrow().clone(); + // all_data.stoch_rsi30_1m_30_k_data = rx_stoch_rsi30_1m_30_k_data.borrow().clone(); + // all_data.stoch_rsi30_1m_30_d_data = rx_stoch_rsi30_1m_30_d_data.borrow().clone(); // BollingerBand data - all_data.bb3_1m_data = rx_bb3_1m_data.borrow().clone(); - all_data.bb3_30m_data = rx_bb3_30m_data.borrow().clone(); - all_data.bb3_1d_data = rx_bb3_1d_data.borrow().clone(); - all_data.bb3_1w_data = rx_bb3_1w_data.borrow().clone(); - all_data.bb3_1mon_data = rx_bb3_1mon_data.borrow().clone(); - all_data.bb10_1m_data = rx_bb10_1m_data.borrow().clone(); - all_data.bb10_30m_data = rx_bb10_30m_data.borrow().clone(); - all_data.bb10_1d_data = rx_bb10_1d_data.borrow().clone(); - all_data.bb10_1w_data = rx_bb10_1w_data.borrow().clone(); - all_data.bb10_1mon_data = rx_bb10_1mon_data.borrow().clone(); - all_data.bb30_1m_data = rx_bb30_1m_data.borrow().clone(); - all_data.bb30_30m_data = rx_bb30_30m_data.borrow().clone(); - all_data.bb30_1d_data = rx_bb30_1d_data.borrow().clone(); - all_data.bb30_1w_data = rx_bb30_1w_data.borrow().clone(); - all_data.bb30_1mon_data = rx_bb30_1mon_data.borrow().clone(); + // all_data.bb3_1m_data = rx_bb3_1m_data.borrow().clone(); + // all_data.bb3_30m_data = rx_bb3_30m_data.borrow().clone(); + // all_data.bb3_1d_data = rx_bb3_1d_data.borrow().clone(); + // all_data.bb3_1w_data = rx_bb3_1w_data.borrow().clone(); + // all_data.bb3_1mon_data = rx_bb3_1mon_data.borrow().clone(); + // all_data.bb10_1m_data = rx_bb10_1m_data.borrow().clone(); + // all_data.bb10_30m_data = rx_bb10_30m_data.borrow().clone(); to be deleted + // all_data.bb10_1d_data = rx_bb10_1d_data.borrow().clone(); + // all_data.bb10_1w_data = rx_bb10_1w_data.borrow().clone(); + // all_data.bb10_1mon_data = rx_bb10_1mon_data.borrow().clone(); + // all_data.bb30_1m_data = rx_bb30_1m_data.borrow().clone(); + // all_data.bb30_30m_data = rx_bb30_30m_data.borrow().clone(); + // all_data.bb30_1d_data = rx_bb30_1d_data.borrow().clone(); + // all_data.bb30_1w_data = rx_bb30_1w_data.borrow().clone(); + // all_data.bb30_1mon_data = rx_bb30_1mon_data.borrow().clone(); - let result = coex::strategy_team::execute_strategist_for_test(&all_data).await; + // let result = coex::strategy_team::execute_strategist_for_test(&all_data).await; - match result { - Ok(T) => { - tx_task18 - .send(18) - .expect("The mpsc channel has been closed."); - } - Err(E) => {} - } + // match result { + // Ok(T) => { + // tx_task18 + // .send(18) + // .expect("The mpsc channel has been closed."); + // } + // Err(E) => {} + // } // sleep as much as the loop recurs per 1 second if all operation finished within 1 second. elapsed_time = instant.elapsed().as_millis(); @@ -2059,20 +2059,6 @@ async fn main() -> Result<(), Box> { // realtime price data all_data.rt_price_30m_vec = rx4_rt_price_30m_vec.borrow().clone(); - // SMA data - all_data.sma3_1m_data = rx3_sma3_1m_data.borrow().clone(); - all_data.sma10_1m_data = rx3_sma10_1m_data.borrow().clone(); - - // EMA data - all_data.ema3_1m_data = rx3_ema3_1m_data.borrow().clone(); - all_data.ema10_1m_data = rx3_ema10_1m_data.borrow().clone(); - - // Stoch RSI data - all_data.stoch_rsi3_1m_3_k_data = rx2_stoch_rsi3_1m_3_k_data.borrow().clone(); - all_data.stoch_rsi3_1m_3_d_data = rx2_stoch_rsi3_1m_3_d_data.borrow().clone(); - all_data.stoch_rsi30_1m_30_k_data = rx2_stoch_rsi30_1m_30_k_data.borrow().clone(); - all_data.stoch_rsi30_1m_30_d_data = rx2_stoch_rsi30_1m_30_d_data.borrow().clone(); - let result = coex::order_team::monitoring_filled_buy_order( &all_data, &coin_price_vec,