Add filtering

This commit is contained in:
Sik Yoon 2023-12-09 03:04:53 +09:00
parent 572a07e662
commit 7736c2e373

View File

@ -278,6 +278,49 @@ pub async fn list_up_for_buy(
} }
try_join_all(task_vec).await?; try_join_all(task_vec).await?;
// 6th filtering: 0.5% <= the average amplitude of the latest 10 30m candles <= 2%
let filtered_data_5th_c = filtered_data_5th_arc.lock().await.clone();
let mut filtered_data_6th: Vec<FilteredData> = Vec::new();
let mut filtered_data_6th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_6th));
let mut task_vec = Vec::new();
for element in filtered_data_5th_c {
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_30m_vec_c = alldata.rt_price_30m_vec.clone();
let filtered_data_6th_arc_c = Arc::clone(&filtered_data_5th_arc);
task_vec.push(tokio::spawn(async move {
let position_idx = rt_price_30m_vec_c.iter().position(|elem| elem.0 == element.symbol);
if position_idx.is_some() {
let vec_len = rt_price_30m_vec_c[position_idx.unwrap()].1.len();
if vec_len >= 11 {
let candles = rt_price_30m_vec_c[position_idx.unwrap()].1.get(vec_len-12..vec_len-1).unwrap();
let windows = candles.windows(2);
let mut average_amplitude = 0.0;
for window in windows {
average_amplitude += (window.last().unwrap().high_price - window.last().unwrap().low_price) / window.first().unwrap().close_price;
}
average_amplitude /= 10.0;
if 0.005 <= average_amplitude && average_amplitude <= 0.02 {
let mut filtered_data_6th_lock = filtered_data_6th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
filtered_data.current_price = element.current_price;
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
filtered_data_6th_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;
// // 4th filtering: StochRSI (RSI length: 3, Stoch length: 3, smooth k: 3, smooth d: 3) 80 > k > kn-1 // // 4th filtering: StochRSI (RSI length: 3, Stoch length: 3, smooth k: 3, smooth d: 3) 80 > k > kn-1
// let filtered_4th_symbol_c = filtered_data_4th_arc.lock().await.clone(); // let filtered_4th_symbol_c = filtered_data_4th_arc.lock().await.clone();
// let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> = // let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> =
@ -360,7 +403,7 @@ pub async fn list_up_for_buy(
// } // }
// try_join_all(task_vec).await?; // try_join_all(task_vec).await?;
let final_filtered_data = filtered_data_5th_arc.lock().await.clone(); let final_filtered_data = filtered_data_6th_arc.lock().await.clone();
insert_pre_suggested_coins(4, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(4, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())