Add filtering

This commit is contained in:
Sik Yoon 2024-01-13 16:10:38 +09:00
parent d7e8de337a
commit f3725d3cd7

View File

@ -8,9 +8,8 @@ use super::{
BollingerBandData, ToPrimitive
};
// BB lowerband + SuperTrend + StochRSI
// SuperTrend length: 20, multiplier: 1.5, BUY signal
// ADX(10, 10) < 25.0
// BB 30m lowerband + BB 1m lowerband
// SuperTrend length: 10, multiplier: 2.5
pub async fn list_up_for_buy(
alldata: AllData,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
@ -76,25 +75,29 @@ pub async fn list_up_for_buy(
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd));
let mut task_vec = Vec::new();
let bollingerbands = bollingerband(10, 2.5, &alldata.rt_price_30m_vec, &filtered_data_1st).await?;
let bollingerbands_30m = bollingerband(10, 2.5, &alldata.rt_price_30m_vec, &filtered_data_1st).await?;
let bollingerbands_1m = bollingerband(30, 3.0, &alldata.rt_price_1m_vec, &filtered_data_1st).await?;
for element in filtered_data_1st {
let mut rt_30m_vec: Vec<RealtimePriceData> = Vec::new();
let mut bb_vec: Vec<BollingerBandData> = Vec::new();
let mut bb_30m_vec: Vec<BollingerBandData> = Vec::new();
let mut bb_1m_vec: Vec<BollingerBandData> = Vec::new();
let rt_price_30m_vec_c: Vec<(String, Vec<RealtimePriceData>)> = alldata.rt_price_30m_vec.clone();
let bollingerbands_c = bollingerbands.clone();
let bollingerbands_30m_c = bollingerbands_30m.clone();
let bollingerbands_1m_c = bollingerbands_1m.clone();
let filtered_data_2nd_arc_c = Arc::clone(&filtered_data_2nd_arc);
task_vec.push(tokio::spawn(async move {
let rt_30m_option = rt_price_30m_vec_c
.iter()
.position(|x| *x.0 == element.symbol);
let bb_option_30m = bollingerbands_c.iter().position(|x| x.0 == element.symbol);
if rt_30m_option.is_some() && bb_option_30m.is_some() {
let bb_option_30m = bollingerbands_30m_c.iter().position(|x| x.0 == element.symbol);
let bb_option_1m = bollingerbands_1m_c.iter().position(|x| x.0 == element.symbol);
if rt_30m_option.is_some() && bb_option_30m.is_some() && bb_option_1m.is_some() {
rt_30m_vec = rt_price_30m_vec_c[rt_30m_option.unwrap()].1.clone();
bb_vec = bollingerbands_c[bb_option_30m.unwrap()].1.clone();
bb_30m_vec = bollingerbands_30m_c[bb_option_30m.unwrap()].1.clone();
bb_1m_vec = bollingerbands_1m_c[bb_option_1m.unwrap()].1.clone();
let server_epoch = server_epoch().await;
if rt_30m_vec.len() >= 3 && bb_vec.len() >= 3 && rt_30m_vec.last().unwrap().close_time > server_epoch {
let bb_search_result = bb_vec.binary_search_by_key(
if rt_30m_vec.len() >= 3 && bb_30m_vec.len() >= 3 && bb_1m_vec.len() >= 3 && rt_30m_vec.last().unwrap().close_time > server_epoch {
let bb_30m_search_result = bb_30m_vec.binary_search_by_key(
&rt_30m_vec.last().unwrap().close_time,
|BollingerBandData {
sma,
@ -103,8 +106,9 @@ pub async fn list_up_for_buy(
close_time,
}| *close_time,
);
if bb_search_result.is_ok() {
if bb_vec[bb_search_result.unwrap()].lowerband > rt_30m_vec[rt_30m_vec.len()-1].close_price
if bb_30m_search_result.is_ok() {
if bb_30m_vec[bb_30m_search_result.unwrap()].lowerband > rt_30m_vec[rt_30m_vec.len()-1].close_price &&
bb_1m_vec.last().unwrap().lowerband > rt_30m_vec[rt_30m_vec.len()-1].close_price
{
let mut filtered_data_2nd_lock = filtered_data_2nd_arc_c.lock().await;
let mut filtered_data = FilteredData::new();