Change filtering method

This commit is contained in:
Sik Yoon 2023-12-08 02:04:17 +09:00
parent f34c7e0c52
commit 9753aca93b

View File

@ -185,7 +185,7 @@ pub async fn list_up_for_buy(
}
try_join_all(task_vec).await?;
// 5th filtering: supertrend(ATR period 10, multiplier: 1.2, 30m close price), the area should be UP
// 4th filtering: supertrend(ATR period 10, multiplier: 1.2, 30m close price), the area should be UP
// set stoploss and target_price
let filtered_data_3rd_c = filtered_data_3rd_arc.lock().await.clone();
let mut filtered_data_4th: Vec<FilteredData> = Vec::new();
@ -236,36 +236,43 @@ pub async fn list_up_for_buy(
}
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
let filtered_4th_symbol_c = filtered_data_4th_arc.lock().await.clone();
let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> =
rsi(3, &alldata.rt_price_1d_vec, &filtered_4th_symbol_c).await?;
let stoch_rsi_data = stoch_rsi(&rsi10_1d_data, 3, 3, 3).await?;
let mut stoch_rsi3_1d_vec: Vec<StochRsiData> = Vec::new();
// 5th filtering: supertrend(ATR period 3, multiplier: 1.1, 1d close price), the area should be in UP area.
let filtered_data_4th = filtered_data_4th_arc.lock().await.clone();
let mut filtered_data_5th: Vec<FilteredData> = Vec::new();
let mut filtered_data_5th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_5th));
let mut task_vec = Vec::new();
for element in filtered_4th_symbol_c {
let stoch_rsi3_1d_option = stoch_rsi_data.iter().position(|x| *x.0 == element.symbol);
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
for element in filtered_data_4th {
let mut opclo_1d_vec: Vec<RealtimePriceData> = Vec::new();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let rt_price_1d_vec_c = alldata.rt_price_1d_vec.clone();
let filtered_data_5th_arc_c = Arc::clone(&filtered_data_5th_arc);
if stoch_rsi3_1d_option.is_some() {
stoch_rsi3_1d_vec = stoch_rsi_data[stoch_rsi3_1d_option.unwrap()].1.clone();
if stoch_rsi3_1d_vec.len() >= 3 {
task_vec.push(tokio::spawn(async move {
let stoch_rsi_search_result = stoch_rsi3_1d_vec
.binary_search_by_key(&element.closetime, |&StochRsiData { k, d, close_time }| {
close_time
});
if stoch_rsi_search_result.is_ok() {
if 95.0 >= stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].k
&& stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].k
> stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap() - 1].k
&& stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].k
> stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].d
let supertrend_option_1d =
supertrend(&element.symbol, &rt_price_1d_vec_c, 3, 1.1, true).await;
if supertrend_option_1d.is_some() {
supertrend_vec = supertrend_option_1d.unwrap();
if supertrend_vec.len() >= 3 {
let supertrend_search_result = supertrend_vec.binary_search_by_key(
&element.closetime,
|SupertrendData {
band_value,
signal,
area,
close_time,
}| *close_time,
);
if supertrend_search_result.is_ok() {
if supertrend_vec[supertrend_search_result.unwrap()]
.area
.contains("UP")
{
let mut filtered_data_5th_lock = filtered_data_5th_arc_c.lock().await;
let mut filtered_5th_symbols_lock =
filtered_data_5th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
filtered_data.symbol = element.symbol.clone();
filtered_data.closetime = element.closetime;
@ -273,13 +280,59 @@ pub async fn list_up_for_buy(
filtered_data.stoploss = element.stoploss;
filtered_data.target_price = element.target_price;
filtered_data_5th_lock.push(filtered_data);
filtered_5th_symbols_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
// let filtered_4th_symbol_c = filtered_data_4th_arc.lock().await.clone();
// let mut rsi10_1d_data: Vec<(String, Vec<RsiData>)> =
// rsi(3, &alldata.rt_price_1d_vec, &filtered_4th_symbol_c).await?;
// let stoch_rsi_data = stoch_rsi(&rsi10_1d_data, 3, 3, 3).await?;
// let mut stoch_rsi3_1d_vec: Vec<StochRsiData> = Vec::new();
// let mut filtered_data_5th: Vec<FilteredData> = Vec::new();
// let mut filtered_data_5th_arc: Arc<Mutex<Vec<FilteredData>>> =
// Arc::new(Mutex::new(filtered_data_5th));
// let mut task_vec = Vec::new();
// for element in filtered_4th_symbol_c {
// let stoch_rsi3_1d_option = stoch_rsi_data.iter().position(|x| *x.0 == element.symbol);
// let filtered_data_5th_arc_c = Arc::clone(&filtered_data_5th_arc);
// if stoch_rsi3_1d_option.is_some() {
// stoch_rsi3_1d_vec = stoch_rsi_data[stoch_rsi3_1d_option.unwrap()].1.clone();
// if stoch_rsi3_1d_vec.len() >= 3 {
// task_vec.push(tokio::spawn(async move {
// let stoch_rsi_search_result = stoch_rsi3_1d_vec
// .binary_search_by_key(&element.closetime, |&StochRsiData { k, d, close_time }| {
// close_time
// });
// if stoch_rsi_search_result.is_ok() {
// if 95.0 >= stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].k
// && stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].k
// > stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap() - 1].k
// && stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].k
// > stoch_rsi3_1d_vec[stoch_rsi_search_result.unwrap()].d
// {
// let mut filtered_data_5th_lock = filtered_data_5th_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_5th_lock.push(filtered_data);
// }
// }
// }));
// }
// }
// }
// 6th filtertering: coefficient-of-variation 0.5<= CV <= 1.0
// 20개 amplitude 기준 CV 계산