Move filtering

This commit is contained in:
Sik Yoon 2024-01-13 17:09:38 +09:00
parent 1a35cf73d4
commit 8b86a49fc4
7 changed files with 92 additions and 307 deletions

View File

@ -88,3 +88,56 @@ impl FilteredData {
a a
} }
} }
pub async fn duplicate_filter(registerer: i32, original_filtered_data: &Vec<FilteredData>)
-> Result<Vec<FilteredData>, Box<dyn std::error::Error + Send + Sync>>
{
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_data: Vec<FilteredData> = Vec::new();
let mut filtered_data_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data));
let mut task_vec = Vec::new();
for element in original_filtered_data {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(element.symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(registerer.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let element_c = element.clone();
let filtered_data_arc_c = Arc::clone(&filtered_data_arc);
task_vec.push(tokio::spawn(async move {
let inspect_result_1 =
exists_record(&inspect_table_name_1_c, &exists_condition_c).await;
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_lock = filtered_data_arc_c.lock().await;
filtered_data_lock.push(element_c);
}
}));
}
try_join_all(task_vec).await?;
let filtered_data_c = filtered_data_arc.lock().await.clone();
Ok(filtered_data_c)
}

View File

@ -5,7 +5,7 @@ use super::{
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd, RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd,
BollingerBandData, ToPrimitive BollingerBandData, ToPrimitive, duplicate_filter
}; };
// BB lowerband + SuperTrend + StochRSI // BB lowerband + SuperTrend + StochRSI
@ -18,60 +18,15 @@ pub async fn list_up_for_buy(
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); // 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()); // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: lookup tables if the tradepair is already there // 1st filtering: filtering valid trade pair
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_data_1st: Vec<FilteredData> = Vec::new(); let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
for symbol in &alldata.valid_symbol_vec { for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(1.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new(); let mut filtered_data = FilteredData::new();
let inspect_result_1 = filtered_data.symbol = symbol.clone();
exists_record(&inspect_table_name_1_c, &exists_condition_c).await; filtered_data_1st.push(filtered_data);
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
filtered_data.symbol = symbol_c;
filtered_data_1st_lock.push(filtered_data);
} }
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: supertrend(ATR period 20, multiplier: 2, 30m close price) // 2nd filtering: supertrend(ATR period 20, multiplier: 2, 30m close price)
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new(); let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> = let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd)); Arc::new(Mutex::new(filtered_data_2nd));
@ -254,7 +209,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 = duplicate_filter(1, &filtered_data_5th_arc.lock().await.clone()).await?;
insert_pre_suggested_coins(1, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(1, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())

View File

@ -5,7 +5,7 @@ use super::{
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd, RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd,
BollingerBandData, ToPrimitive BollingerBandData, ToPrimitive, duplicate_filter
}; };
// BB 30m lowerband + BB 1m lowerband // BB 30m lowerband + BB 1m lowerband
@ -17,60 +17,15 @@ pub async fn list_up_for_buy(
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); // 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()); // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: lookup tables if the tradepair is already there // 1st filtering: filtering valid trade pair
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_data_1st: Vec<FilteredData> = Vec::new(); let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
for symbol in &alldata.valid_symbol_vec { for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(2.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new(); let mut filtered_data = FilteredData::new();
let inspect_result_1 = filtered_data.symbol = symbol.clone();
exists_record(&inspect_table_name_1_c, &exists_condition_c).await; filtered_data_1st.push(filtered_data);
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
filtered_data.symbol = symbol_c;
filtered_data_1st_lock.push(filtered_data);
} }
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: BollingerBand (len:10, multiplier 2.5) previous_30m_price (close or low price) < lower_band // 2nd filtering: BollingerBand (len:10, multiplier 2.5) previous_30m_price (close or low price) < lower_band
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new(); let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> = let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd)); Arc::new(Mutex::new(filtered_data_2nd));
@ -265,7 +220,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 = duplicate_filter(2, &filtered_data_5th_arc.lock().await.clone()).await?;
insert_pre_suggested_coins(2, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(2, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())

View File

@ -5,7 +5,7 @@ use super::{
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, SmaData, Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, SmaData,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd, RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd,
BollingerBandData, ToPrimitive BollingerBandData, ToPrimitive, duplicate_filter
}; };
// BUY: 30m SMA5 (opclo_price) < 30m EMA3 (opclo_price) // BUY: 30m SMA5 (opclo_price) < 30m EMA3 (opclo_price)
@ -17,60 +17,15 @@ pub async fn list_up_for_buy(
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); // 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()); // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: lookup tables if the tradepair is already there // 1st filtering: filtering valid trade pair
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_data_1st: Vec<FilteredData> = Vec::new(); let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
for symbol in &alldata.valid_symbol_vec { for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(3.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new(); let mut filtered_data = FilteredData::new();
let inspect_result_1 = filtered_data.symbol = symbol.clone();
exists_record(&inspect_table_name_1_c, &exists_condition_c).await; filtered_data_1st.push(filtered_data);
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
filtered_data.symbol = symbol_c;
filtered_data_1st_lock.push(filtered_data);
} }
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: SMA5 (opclo_price) < EMA3 (opclo_price) && 5 previous MA > current MA // 2nd filtering: SMA5 (opclo_price) < EMA3 (opclo_price) && 5 previous MA > current MA
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new(); let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> = let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd)); Arc::new(Mutex::new(filtered_data_2nd));
@ -229,7 +184,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_4th_arc.lock().await.clone(); let final_filtered_data = duplicate_filter(3, &filtered_data_4th_arc.lock().await.clone()).await?;
insert_pre_suggested_coins(3, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(3, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())

View File

@ -5,7 +5,7 @@ use super::{
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd, RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd,
BollingerBandData, ToPrimitive BollingerBandData, ToPrimitive, duplicate_filter
}; };
// BB lowerband + SuperTrend + StochRSI // BB lowerband + SuperTrend + StochRSI
@ -18,60 +18,15 @@ pub async fn list_up_for_buy(
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); // 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()); // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: lookup tables if the tradepair is already there // 1st filtering: filtering valid trade pair
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_data_1st: Vec<FilteredData> = Vec::new(); let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
for symbol in &alldata.valid_symbol_vec { for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(4.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new(); let mut filtered_data = FilteredData::new();
let inspect_result_1 = filtered_data.symbol = symbol.clone();
exists_record(&inspect_table_name_1_c, &exists_condition_c).await; filtered_data_1st.push(filtered_data);
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
filtered_data.symbol = symbol_c;
filtered_data_1st_lock.push(filtered_data);
} }
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: BollingerBand (len:30, multiplier 3) previous_30m_price (close or low price) < lower_band // 2nd filtering: BollingerBand (len:30, multiplier 3) previous_30m_price (close or low price) < lower_band
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new(); let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> = let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd)); Arc::new(Mutex::new(filtered_data_2nd));
@ -298,7 +253,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_6th_arc.lock().await.clone(); let final_filtered_data = duplicate_filter(4, &filtered_data_6th_arc.lock().await.clone()).await?;
insert_pre_suggested_coins(4, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(4, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())

View File

@ -2,7 +2,8 @@ use super::{
dec, decimal_add, decimal_sub, ema, exists_record, insert_pre_suggested_coins, dec, decimal_add, decimal_sub, ema, exists_record, insert_pre_suggested_coins,
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd,
duplicate_filter
}; };
// Triple SuperTrend strategy // Triple SuperTrend strategy
@ -16,60 +17,15 @@ pub async fn list_up_for_buy(
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); // 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()); // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: lookup tables if the tradepair is already there // 1st filtering: filtering valid trade pair
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_data_1st: Vec<FilteredData> = Vec::new(); let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
for symbol in &alldata.valid_symbol_vec { for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(5.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new(); let mut filtered_data = FilteredData::new();
let inspect_result_1 = filtered_data.symbol = symbol.clone();
exists_record(&inspect_table_name_1_c, &exists_condition_c).await; filtered_data_1st.push(filtered_data);
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
filtered_data.symbol = symbol_c;
filtered_data_1st_lock.push(filtered_data);
} }
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: supertrend(ATR period 20, multiplier: 1.5, 30m close price), signal should be BUY // 2nd filtering: supertrend(ATR period 20, multiplier: 1.5, 30m close price), signal should be BUY
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new(); let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> = let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd)); Arc::new(Mutex::new(filtered_data_2nd));
@ -255,7 +211,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 = duplicate_filter(5, &filtered_data_5th_arc.lock().await.clone()).await?;
insert_pre_suggested_coins(5, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(5, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())

View File

@ -2,7 +2,8 @@ use super::{
dec, decimal_add, decimal_sub, ema, exists_record, insert_pre_suggested_coins, dec, decimal_add, decimal_sub, ema, exists_record, insert_pre_suggested_coins,
limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData, limit_order_sell, rsi, select_filled_buy_orders, stoch_rsi, supertrend, try_join_all, AllData,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex, Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd,
duplicate_filter
}; };
// Triple SuperTrend strategy // Triple SuperTrend strategy
@ -15,60 +16,15 @@ pub async fn list_up_for_buy(
// let a = alldata.rt_price_30m_vec.iter().position(|a| a.0 == "BTCUSDT"); // 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()); // println!("BTCUSDT: {:?}", alldata.rt_price_30m_vec[a.unwrap()].1.last().unwrap());
// 1st filtering: lookup tables if the tradepair is already there // 1st filtering: filtering valid trade pair
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_data_1st: Vec<FilteredData> = Vec::new(); let mut filtered_data_1st: Vec<FilteredData> = Vec::new();
let mut filtered_data_1st_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_1st));
let mut task_vec = Vec::new();
for symbol in &alldata.valid_symbol_vec { for symbol in &alldata.valid_symbol_vec {
let mut exists_condition_build = String::from("symbol=\'");
exists_condition_build.push_str(symbol.as_str());
exists_condition_build.push_str("\' AND registerer=");
exists_condition_build.push_str(6.to_string().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 exists_condition_c = exists_condition.clone();
let inspect_table_name_1_c = inspect_table_name_1.clone();
let inspect_table_name_2_c = inspect_table_name_2.clone();
let inspect_table_name_3_c = inspect_table_name_3.clone();
let inspect_table_name_4_c = inspect_table_name_4.clone();
let symbol_c = symbol.clone();
let filtered_data_1st_arc_c = Arc::clone(&filtered_data_1st_arc);
task_vec.push(tokio::spawn(async move {
let mut filtered_data = FilteredData::new(); let mut filtered_data = FilteredData::new();
let inspect_result_1 = filtered_data.symbol = symbol.clone();
exists_record(&inspect_table_name_1_c, &exists_condition_c).await; filtered_data_1st.push(filtered_data);
let inspect_result_2 =
exists_record(&inspect_table_name_2_c, &exists_condition_c).await;
let inspect_result_3 =
exists_record(&inspect_table_name_3_c, &exists_condition_c).await;
let inspect_result_4 =
exists_record(&inspect_table_name_4_c, &exists_condition_c).await;
if inspect_result_1 == false
&& inspect_result_2 == false
&& inspect_result_3 == false
&& inspect_result_4 == false
{
let mut filtered_data_1st_lock = filtered_data_1st_arc_c.lock().await;
filtered_data.symbol = symbol_c;
filtered_data_1st_lock.push(filtered_data);
} }
}));
}
try_join_all(task_vec).await?;
// 2nd filtering: supertrend(ATR period 20, multiplier: 1.5, 30m close price), signal should be BUY // 2nd filtering: supertrend(ATR period 20, multiplier: 1.5, 30m close price), signal should be BUY
let filtered_data_1st = filtered_data_1st_arc.lock().await.clone();
let mut filtered_data_2nd: Vec<FilteredData> = Vec::new(); let mut filtered_data_2nd: Vec<FilteredData> = Vec::new();
let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> = let mut filtered_data_2nd_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_2nd)); Arc::new(Mutex::new(filtered_data_2nd));
@ -262,7 +218,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 = duplicate_filter(6, &filtered_data_5th_arc.lock().await.clone()).await?;
insert_pre_suggested_coins(6, false, &final_filtered_data, &alldata).await; insert_pre_suggested_coins(6, false, &final_filtered_data, &alldata).await;
Ok(()) Ok(())