Change filtering

This commit is contained in:
Sik Yoon 2023-12-31 19:35:15 +09:00
parent d559e51c25
commit 5858b97667
4 changed files with 46 additions and 54 deletions

View File

@ -66,6 +66,7 @@ pub struct BuyOrderedCoinList {
pub pure_profit_percent: f64,
pub minimum_profit_percent: f64,
pub maximum_profit_percent: f64,
pub sell_count: u16,
pub registerer: u16,
pub is_long: u8,
}
@ -89,6 +90,7 @@ pub struct SellOrderedCoinList {
pub base_qty_ordered: Decimal,
pub pure_profit_percent: Decimal,
pub maximum_profit_percent: f64,
pub sell_count: u16,
pub registerer: u16,
pub is_long: u8,
}
@ -132,6 +134,7 @@ impl DBlist for SellOrderedCoinList {
base_qty_ordered: Decimal::new(0, 8),
pure_profit_percent: Decimal::new(0, 8),
maximum_profit_percent: 0.0,
sell_count: 0,
registerer: 0,
is_long: 0,
};
@ -160,6 +163,7 @@ impl DBlist for BuyOrderedCoinList {
pure_profit_percent: 0.0,
minimum_profit_percent: 0.0,
maximum_profit_percent: 0.0,
sell_count: 0,
registerer: 0,
is_long: 0,
};
@ -326,6 +330,7 @@ pub async fn limit_order_buy(
"pure_profit_percent",
"minimum_profit_percent",
"maximum_profit_percent",
"sell_count",
"registerer",
"is_long",
];
@ -350,6 +355,7 @@ pub async fn limit_order_buy(
insert_value_container.push(0.0.to_string()); // pure_profit_percent
insert_value_container.push(0.0.to_string()); // minimum_profit_percent
insert_value_container.push(0.0.to_string()); // maximum_profit_percent
insert_value_container.push(0.to_string()); // registerer
insert_value_container.push(element.registerer.to_string()); // registerer
insert_value_container.push(0.to_string()); // is_long
@ -480,6 +486,7 @@ pub async fn limit_order_buy(
insert_value_container.push(0.0.to_string()); // pure_profit_percent
insert_value_container.push(0.0.to_string()); // minimum_profit_percent
insert_value_container.push(0.0.to_string()); // maximum_profit_percent
insert_value_container.push(0.to_string()); // sell_count
insert_value_container.push(element.registerer.to_string()); // registerer
insert_value_container.push(0.to_string()); // is_long
@ -718,6 +725,7 @@ pub async fn limit_order_sell(
"base_qty_ordered",
"pure_profit_percent",
"maximum_profit_percent",
"sell_count",
"registerer",
"is_long",
];
@ -1337,6 +1345,7 @@ pub async fn cancel_sell_order(
"pure_profit_percent",
"minimum_profit_percent",
"maximum_profit_percent",
"sell_count",
"registerer",
"is_long",
];
@ -1381,6 +1390,7 @@ pub async fn cancel_sell_order(
insert_value_container.push(0.0.to_string()); // pure_profit_percent
insert_value_container.push(0.0.to_string()); // minimum_profit_percent
insert_value_container.push(order.maximum_profit_percent.to_string()); // maximum_profit_percent
insert_value_container.push(order.sell_count.to_string()); // sell_count
insert_value_container.push(order.registerer.to_string()); // registerer
insert_value_container.push(order.is_long.to_string()); // is_long
@ -1531,6 +1541,7 @@ pub async fn cancel_sell_order(
insert_value_container.push(0.0.to_string()); // pure_profit_percent
insert_value_container.push(0.0.to_string()); // minimum_profit_percent
insert_value_container.push(0.0.to_string()); // maximum_profit_percent
insert_value_container.push(order.sell_count.to_string()); // sell_count
insert_value_container.push(order.registerer.to_string()); // registerer
insert_value_container.push(order.is_long.to_string()); // is_long

View File

@ -2,7 +2,7 @@ use super::{
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,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd
};
// Triple SuperTrend strategy
@ -168,30 +168,22 @@ pub async fn list_up_for_buy(
}
try_join_all(task_vec).await?;
// 4th filtering: supertrend(ATR period 3, multiplier: 1.05, 1d close price), the area should be in UP area.
// 4th filtering: MACD 1d (fast:3, slow:7, smoothing:3) MACD > signal
let filtered_data_3rd = filtered_data_3rd_arc.lock().await.clone();
let mut filtered_data_4th: Vec<FilteredData> = Vec::new();
let mut filtered_data_4th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_4th));
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
let macd_vec = ema_macd(3, 7, 3, &alldata.rt_price_1d_vec, &filtered_data_3rd).await?;
for element in filtered_data_3rd {
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 macd_vec_c = macd_vec.clone();
let filtered_data_4th_arc_c = Arc::clone(&filtered_data_4th_arc);
task_vec.push(tokio::spawn(async move {
let supertrend_option_1d =
supertrend(&element.symbol, &rt_price_1d_vec_c, 3, 1.05, true).await;
let search_result = macd_vec_c.iter().position(|x| x.0 == element.symbol);
if supertrend_option_1d.is_some() {
supertrend_vec = supertrend_option_1d.unwrap();
if supertrend_vec.len() >= 3 {
if supertrend_vec.last().unwrap()
.area
.contains("UP")
{
if search_result.is_some_and(|a| macd_vec_c[a].1.last().unwrap().macd_value > macd_vec_c[a].1.last().unwrap().signal_value) {
let mut filtered_4th_symbols_lock =
filtered_data_4th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
@ -203,8 +195,6 @@ pub async fn list_up_for_buy(
filtered_4th_symbols_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;

View File

@ -2,7 +2,7 @@ use super::{
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,
Arc, Client, ClientBuilder, Decimal, EmaData, ExchangeInfo, FilteredData, Mutex,
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch
RealtimePriceData, RoundingStrategy, RsiData, StochRsiData, SupertrendData, TradeFee, update_record3, adx, AdxData, server_epoch, MacdData, ema_macd
};
// Triple SuperTrend strategy
@ -176,30 +176,22 @@ pub async fn list_up_for_buy(
}
try_join_all(task_vec).await?;
// 4th filtering: supertrend(ATR period 3, multiplier: 1.05, 1d close price), the area should be in UP area.
// 4th filtering: MACD 1d (fast:3, slow:7, smoothing:3) MACD > signal
let filtered_data_3rd = filtered_data_3rd_arc.lock().await.clone();
let mut filtered_data_4th: Vec<FilteredData> = Vec::new();
let mut filtered_data_4th_arc: Arc<Mutex<Vec<FilteredData>>> =
Arc::new(Mutex::new(filtered_data_4th));
let mut task_vec = Vec::new();
let valid_symbol_vec_c = alldata.valid_symbol_vec.clone();
let macd_vec = ema_macd(3, 7, 3, &alldata.rt_price_1d_vec, &filtered_data_3rd).await?;
for element in filtered_data_3rd {
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 macd_vec_c = macd_vec.clone();
let filtered_data_4th_arc_c = Arc::clone(&filtered_data_4th_arc);
task_vec.push(tokio::spawn(async move {
let supertrend_option_1d =
supertrend(&element.symbol, &rt_price_1d_vec_c, 3, 1.05, true).await;
let search_result = macd_vec_c.iter().position(|x| x.0 == element.symbol);
if supertrend_option_1d.is_some() {
supertrend_vec = supertrend_option_1d.unwrap();
if supertrend_vec.len() >= 3 {
if supertrend_vec.last().unwrap()
.area
.contains("UP")
{
if search_result.is_some_and(|a| macd_vec_c[a].1.last().unwrap().macd_value > macd_vec_c[a].1.last().unwrap().signal_value) {
let mut filtered_4th_symbols_lock =
filtered_data_4th_arc_c.lock().await;
let mut filtered_data = FilteredData::new();
@ -211,8 +203,6 @@ pub async fn list_up_for_buy(
filtered_4th_symbols_lock.push(filtered_data);
}
}
}
}));
}
try_join_all(task_vec).await?;

View File

@ -37,7 +37,7 @@ pub async fn execute_list_up_for_buy(
// let all_data_c4 = all_data.clone();
let all_data_c5 = all_data.clone();
let all_data_c6 = all_data.clone();
let all_data_ct = all_data.clone();
// strategist_001(all_data).await?;
// strategist_002(all_data).await?;
// task_vec.push(tokio::spawn(async move {
@ -52,9 +52,10 @@ pub async fn execute_list_up_for_buy(
task_vec.push(tokio::spawn(async move {
crate::strategy_team::strategy_006::list_up_for_buy(all_data_c6).await;
}));
task_vec.push(tokio::spawn(async move {
crate::strategy_team::strategy_test::strategist_test(all_data_ct).await;
}));
// let all_data_ct = all_data.clone();
// task_vec.push(tokio::spawn(async move {
// crate::strategy_team::strategy_test::strategist_test(all_data_ct).await;
// }));
try_join_all(task_vec).await?;
Ok(())