diff --git a/src/coex/strategy_team.rs b/src/coex/strategy_team.rs index 93bccfa..097d3a8 100644 --- a/src/coex/strategy_team.rs +++ b/src/coex/strategy_team.rs @@ -4,15 +4,15 @@ 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::bollingerband::{bollingerband, BollingerBandData}; use crate::value_estimation_team::indicators::ema::EmaData; use crate::value_estimation_team::indicators::heatmap_volume::{ heatmap_volume, HeatMapLevel, HeatmapVolumeData, }; use crate::value_estimation_team::indicators::macd::{ema_macd, EmaMacd}; -use crate::value_estimation_team::indicators::rsi::RsiData; -use crate::value_estimation_team::indicators::sma::SmaData; -use crate::value_estimation_team::indicators::stoch_rsi::{StochRsiDData, StochRsiKData}; +use crate::value_estimation_team::indicators::rsi::{rsi, RsiData}; +use crate::value_estimation_team::indicators::sma::{sma, SmaData}; +use crate::value_estimation_team::indicators::stoch_rsi::{stoch_rsi, StochRsiData}; use crate::value_estimation_team::indicators::supertrend::{supertrend, SupertrendData}; use csv::{DeserializeRecordsIter, StringRecord}; use futures::future::try_join_all; @@ -36,88 +36,11 @@ pub enum MA { #[derive(Debug)] pub struct AllData { pub valid_symbol_vec: Vec, - pub rt_price_1m_vec: Vec<(String, Vec)>, pub rt_price_30m_vec: Vec<(String, Vec)>, 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 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 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 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 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 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 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 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 { @@ -128,82 +51,6 @@ 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(), - - // 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(), - - // 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(), - - // 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(), - - // 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(), - - // 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(), - - // 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(), - - // 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 } @@ -258,673 +105,12 @@ struct Record { pub async fn execute_strategists( all_data: &AllData, ) -> Result<(), Box> { - - // strategist_002(all_data).await; - // strategist_003(all_data).await; - // strategist_004(all_data).await; - // strategist_005(all_data).await; - // strategist_006(all_data).await; - // strategist_007().await; - // strategist_008().await; - // strategist_009().await; - - // strategist_010().await; - // strategist_011().await; - // strategist_012().await; - // strategist_013(all_data).await; - // strategist_014(all_data).await; - // strategist_015(all_data).await; - // strategist_016(all_data).await; - strategist_001(all_data).await?; - // execute_strategist_for_test1(all_data).await; - // execute_strategist_for_test2(all_data).await; + strategist_002(all_data).await?; + Ok(()) } -// pub async fn execute_strategist_for_test(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 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 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 opclo_1m_vec: Vec = Vec::new(); -// let mut sma10_1m_vec: Vec = Vec::new(); -// let mut ema3_1m_vec: Vec = Vec::new(); -// let mut ema10_1m_vec: Vec = Vec::new(); -// let mut ema30_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 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 opclo_1m_option = alldata.rt_price_1m_vec.iter().position(|x| *x.0 == *symbol); -// let sma10_1m_option = alldata.sma10_1m_data.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 ema30_1m_option = alldata.ema30_1m_data.iter().position(|x| *x.0 == *symbol); - -// if rsi3_1m_option.is_some() && rsi30_1m_option.is_some() && opclo_1m_option.is_some() && sma10_1m_option.is_some() && ema3_1m_option.is_some() && ema10_1m_option.is_some() && ema30_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() { -// rsi3_1m_vec = alldata.rsi3_1m_data[rsi3_1m_option.unwrap()].1.clone(); -// rsi30_1m_vec = alldata.rsi30_1m_data[rsi30_1m_option.unwrap()].1.clone(); -// stoch_rsi3_1m_k_vec = alldata.stoch_rsi3_1m_3_k_data[stoch_rsi3_1m_k_option.unwrap()].1.clone(); -// stoch_rsi3_1m_d_vec = alldata.stoch_rsi3_1m_3_d_data[stoch_rsi3_1m_d_option.unwrap()].1.clone(); -// stoch_rsi30_1m_k_vec = alldata.stoch_rsi30_1m_30_k_data[stoch_rsi30_1m_k_option.unwrap()].1.clone(); -// stoch_rsi30_1m_d_vec = alldata.stoch_rsi30_1m_30_d_data[stoch_rsi30_1m_d_option.unwrap()].1.clone(); -// opclo_1m_vec = alldata.rt_price_1m_vec[opclo_1m_option.unwrap()].1.clone(); -// sma10_1m_vec = alldata.sma10_1m_data[sma10_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(); -// ema30_1m_vec = alldata.ema30_1m_data[ema30_1m_option.unwrap()].1.clone(); - -// if rsi3_1m_vec.len() >= 3 && opclo_1m_vec.len() >= 3 && sma10_1m_vec.len() >= 3 && ema3_1m_vec.len() >= 30 && ema10_1m_vec.len() >= 3 && ema30_1m_vec.len() >= 30 && 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 { -// opclo_1m_vec.reverse(); -// opclo_1m_vec.truncate(3); -// opclo_1m_vec.reverse(); -// stoch_rsi3_1m_k_vec.reverse(); -// stoch_rsi3_1m_k_vec.truncate(5); -// stoch_rsi3_1m_k_vec.reverse(); -// stoch_rsi3_1m_d_vec.reverse(); -// stoch_rsi3_1m_d_vec.truncate(5); -// stoch_rsi3_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_vec = supertrend(&symbol, &alldata.rt_price_1m_vec, 60, 1.0, true).await; -// let macd_vec = ema_macd(&ema10_1m_vec, &ema30_1m_vec, 30).await?; -// let macd_search_result = macd_vec.binary_search_by_key(&opclo_1m_vec[2].close_time, |&EmaMacd{macd_value, close_time}|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; - -// 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)); -// } -// } -// } -// } - -// // 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 { - -// // // 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 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); - -// // 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 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) => {} -// // } -// // } - -// // } - -// // } -// // } -// // } -// // } 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_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 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; - -// Ok(()) -// } - -// 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 strategist_001( alldata: &AllData, ) -> Result<(), Box> { @@ -1028,7 +214,7 @@ pub async fn strategist_001( // 3rd filtering: BollingerBand (length 10, stddev: 2.5, 30m close price) the current price should be under the lowerband of BB. let filtered_3rd_symbols_c = filtered_3rd_symbols_arc.lock().await.clone(); - let sma10_30m_data: Vec<(String, Vec)> = value_estimation_team::indicators::sma::sma( + let sma10_30m_data: Vec<(String, Vec)> = sma( 10, &alldata.rt_price_30m_vec, &filtered_3rd_symbols_c, @@ -1036,7 +222,7 @@ pub async fn strategist_001( .await?; let bb10_30m_data: Vec<(String, Vec)> = - value_estimation_team::indicators::bollingerband::bollingerband( + bollingerband( 10, 2.5, &sma10_30m_data, @@ -1090,7 +276,7 @@ pub async fn strategist_001( // 4th filtering: RSI (length: 10, 30m close price) the current index should be lower than 28. let filtered_4th_symbol_c = filtered_4th_symbols_arc.lock().await.clone(); let mut rsi10_30m_data: Vec<(String, Vec)> = Vec::new(); - value_estimation_team::indicators::rsi::rsi( + rsi( 10, &alldata.rt_price_30m_vec, &mut rsi10_30m_data, @@ -1229,6 +415,140 @@ pub async fn strategist_001( Ok(()) } +pub async fn strategist_002( + alldata: &AllData, +) -> Result<(), Box> { + // print rt_price for debugging + let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); + // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap()); + + + // 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(); + filtered_2nd_symbols.push((String::from("BTCUSDT"), alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap().close_time)); + + // 4th filtering: RSI (length: 10, 30m close price) the current index should be lower than 28. + + let mut rsi10_30m_data: Vec<(String, Vec)> = Vec::new(); + rsi( + 10, + &alldata.rt_price_30m_vec, + &mut rsi10_30m_data, + &filtered_2nd_symbols, + ) + .await?; + let stoch_rsi = stoch_rsi(&rsi10_30m_data, 10, 3, 3).await; + + let mut a = stoch_rsi.unwrap(); + a.reverse(); + a.truncate(30); + a.reverse(); + println!("BTCUSDT StochRsi: {:?}", a); + + // for element in filtered_2nd_symbols { + // let rsi10_30m_option = rsi10_30m_data.iter().position(|x| *x.0 == element.0); + + // if rsi10_30m_option.is_some() { + // 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( + // &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 <= 28.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 rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone(); + // let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0); + // if opclo_30m_option.is_some() { + // let opclo_30m_vec = rt_price_30m_vec_c[opclo_30m_option.unwrap()].1.clone(); + + // if opclo_30m_vec.len() >= 3 { + // let heatmap_volume_option = + // heatmap_volume(&element.0, &rt_price_30m_vec_c, 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); + // } + // } + // } + // } + // } + // } + + // // final job: adding price information to filtered results + // let mut filtered_symbols: Vec<(String, i64, f64)> = Vec::new(); // (symbol, closetime, current price) + // let mut filtered_symbols_arc = Arc::new(Mutex::new(filtered_symbols)); + // let mut task_vec = Vec::new(); + // for element in filtered_6th_symbols { + // let mut filtered_symbols_arc_c = Arc::clone(&filtered_symbols_arc); + // let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone(); + + // let elememt_c = element.clone(); + // task_vec.push(tokio::spawn(async move { + // let opclo_30m_option = rt_price_30m_vec_c.iter().position(|x| *x.0 == element.0); + // if opclo_30m_option.is_some() { + // if rt_price_30m_vec_c[opclo_30m_option.unwrap()] + // .1 + // .last() + // .is_some() + // { + // let mut filtered_symbols_lock: tokio::sync::MutexGuard< + // '_, + // Vec<(String, i64, f64)>, + // > = filtered_symbols_arc_c.lock().await; + // filtered_symbols_lock.push(( + // elememt_c.0, + // elememt_c.1, + // rt_price_30m_vec_c[opclo_30m_option.unwrap()] + // .1 + // .last() + // .unwrap() + // .close_price, + // )); + // } + // } + // })); + // } + + // try_join_all(task_vec).await?; + + // let a = filtered_symbols_arc.lock().await.clone(); + // insert_pre_suggested_coins(2, &a, alldata).await; + + Ok(()) +} + // pub async fn execute_strategist_for_test1( // alldata: &AllData, // ) -> Result<(), Box> {