Update filtering

This commit is contained in:
Sik Yoon 2024-04-23 09:26:52 +09:00
parent e36005f11e
commit 7ab84cbe05

View File

@ -24,58 +24,62 @@ pub async fn list_up_for_buy(
} }
// current Tema(3) > current Tema(10) // current Tema(3) > current Tema(10)
let mut keys_to_remove: HashSet<String> = HashSet::new(); // let mut keys_to_remove: HashSet<String> = HashSet::new();
let tema_3 = tema(3, &alldata.rt_price_1d_vec, &filtered_data).await?; // let tema_3 = tema(3, &alldata.rt_price_1d_vec, &filtered_data).await?;
let tema_10 = tema(10, &alldata.rt_price_1d_vec, &filtered_data).await?; // let tema_10 = tema(10, &alldata.rt_price_1d_vec, &filtered_data).await?;
let server_epoch = get_server_epoch().await; // let server_epoch = get_server_epoch().await;
for (symbol, values) in &mut filtered_data { // for (symbol, values) in &mut filtered_data {
if let (Some(tema5_vec), Some(tema10_vec)) = (tema_3.get(symbol), tema_10.get(symbol)) { // if let (Some(tema5_vec), Some(tema10_vec)) = (tema_3.get(symbol), tema_10.get(symbol)) {
if tema5_vec.len() > 2 // if tema5_vec.len() > 2
&& tema10_vec.len() > 2 // && tema10_vec.len() > 2
&& tema5_vec.last().unwrap().close_time == tema10_vec.last().unwrap().close_time // && tema5_vec.last().unwrap().close_time == tema10_vec.last().unwrap().close_time
&& tema5_vec.last().unwrap().close_time > server_epoch // && tema5_vec.last().unwrap().close_time > server_epoch
&& tema10_vec.last().unwrap().close_time > server_epoch // && tema10_vec.last().unwrap().close_time > server_epoch
{ // {
if tema5_vec.last().unwrap().tema_value > tema10_vec.last().unwrap().tema_value { // if tema5_vec.last().unwrap().tema_value > tema10_vec.last().unwrap().tema_value {
} else { // } else {
keys_to_remove.insert(symbol.clone()); // keys_to_remove.insert(symbol.clone());
} // }
} else { // } else {
keys_to_remove.insert(symbol.clone()); // keys_to_remove.insert(symbol.clone());
} // }
} else { // } else {
keys_to_remove.insert(symbol.clone()); // keys_to_remove.insert(symbol.clone());
} // }
} // }
remove_keys(&mut filtered_data, keys_to_remove).await; // remove_keys(&mut filtered_data, keys_to_remove).await;
// current Tema(200) < current Tema(5) // current Tema(300) < current Tema(200) < current Tema(100)
// previous Tema(200) > previous Tema(5) // previous Tema(300) < previous Tema(100)
// previous Tema(200) < previous Tema(100)
// previous Tema(300) > previous Tema(200)
let mut keys_to_remove: HashSet<String> = HashSet::new(); let mut keys_to_remove: HashSet<String> = HashSet::new();
let tema_5 = tema(5, &alldata.rt_price_30m_vec, &filtered_data).await?; let tema_100 = tema(100, &alldata.rt_price_30m_vec, &filtered_data).await?;
let tema_200 = tema(200, &alldata.rt_price_30m_vec, &filtered_data).await?; let tema_200 = tema(200, &alldata.rt_price_30m_vec, &filtered_data).await?;
let tema_300 = tema(300, &alldata.rt_price_30m_vec, &filtered_data).await?;
let server_epoch = get_server_epoch().await; let server_epoch = get_server_epoch().await;
for (symbol, values) in &mut filtered_data { for (symbol, values) in &mut filtered_data {
if let (Some(tema5_vec), Some(tema200_vec)) = ( if let (Some(tema100_vec), Some(tema200_vec), Some(tema300_vec)) = (
tema_5.get(symbol), tema_100.get(symbol),
tema_200.get(symbol) tema_200.get(symbol),
tema_300.get(symbol)
) { ) {
if (tema5_vec.len() > 10 if (tema100_vec.len() > 15
&& tema200_vec.len() > 10) && tema200_vec.len() > 15
&& tema200_vec.last().unwrap().close_time == tema5_vec.last().unwrap().close_time && tema300_vec.len() > 15)
&& tema5_vec.last().unwrap().close_time > server_epoch && tema100_vec.last().unwrap().close_time == tema200_vec.last().unwrap().close_time
&& tema200_vec.last().unwrap().close_time == tema300_vec.last().unwrap().close_time
&& tema100_vec.last().unwrap().close_time > server_epoch
{ {
if tema200_vec.last().unwrap().tema_value < tema5_vec.last().unwrap().tema_value if tema100_vec.last().unwrap().tema_value > tema300_vec.last().unwrap().tema_value
&& tema200_vec[tema200_vec.len() - 2].tema_value && tema200_vec.last().unwrap().tema_value > tema300_vec.last().unwrap().tema_value
> tema5_vec[tema5_vec.len() - 2].tema_value && tema200_vec.last().unwrap().tema_value < tema100_vec.last().unwrap().tema_value
&& tema200_vec[tema200_vec.len() - 3].tema_value && tema100_vec[tema100_vec.len() - 2].tema_value > tema300_vec[tema300_vec.len() - 2].tema_value
> tema5_vec[tema5_vec.len() - 3].tema_value && tema200_vec[tema200_vec.len() - 2].tema_value < tema300_vec[tema300_vec.len() - 2].tema_value
&& tema200_vec[tema200_vec.len() - 4].tema_value && tema200_vec[tema200_vec.len() - 2].tema_value < tema100_vec[tema100_vec.len() - 2].tema_value
> tema5_vec[tema5_vec.len() - 4].tema_value && tema100_vec[tema100_vec.len() - 3].tema_value > tema300_vec[tema300_vec.len() - 3].tema_value
&& tema200_vec[tema200_vec.len() - 5].tema_value && tema200_vec[tema200_vec.len() - 3].tema_value < tema300_vec[tema300_vec.len() - 3].tema_value
> tema5_vec[tema5_vec.len() - 5].tema_value && tema200_vec[tema200_vec.len() - 3].tema_value < tema100_vec[tema100_vec.len() - 3].tema_value
&& tema200_vec[tema200_vec.len() - 6].tema_value
> tema5_vec[tema5_vec.len() - 6].tema_value
{ {
} else { } else {
keys_to_remove.insert(symbol.clone()); keys_to_remove.insert(symbol.clone());
@ -123,7 +127,7 @@ pub async fn list_up_for_buy(
values.closetime = rt_price_vec.last().unwrap().close_time; values.closetime = rt_price_vec.last().unwrap().close_time;
values.stoploss = band_value; values.stoploss = band_value;
values.target_price = decimal_add( values.target_price = decimal_add(
decimal_mul(decimal_sub(current_price, values.stoploss), dec!(5.0)), decimal_mul(decimal_sub(current_price, values.stoploss), dec!(10.0)),
current_price, current_price,
); );
} else if supertrend_vec.last().unwrap().area == SuperTrendArea::DOWN } else if supertrend_vec.last().unwrap().area == SuperTrendArea::DOWN
@ -134,7 +138,7 @@ pub async fn list_up_for_buy(
values.closetime = rt_price_vec.last().unwrap().close_time; values.closetime = rt_price_vec.last().unwrap().close_time;
values.stoploss = decimal_sub(open_price, decimal_sub(band_value, open_price)); values.stoploss = decimal_sub(open_price, decimal_sub(band_value, open_price));
values.target_price = decimal_add( values.target_price = decimal_add(
decimal_mul(decimal_sub(open_price, values.stoploss), dec!(5.0)), decimal_mul(decimal_sub(open_price, values.stoploss), dec!(10.0)),
current_price, current_price,
); );
} else { } else {
@ -169,9 +173,9 @@ pub async fn list_up_for_buy(
// } // }
// remove_keys(&mut filtered_data, keys_to_remove).await; // remove_keys(&mut filtered_data, keys_to_remove).await;
// StochRSI (RSI_len: 10, StochRSI_len: 10, K: 3, D: 3) K_current < 70, K_current > d_current // StochRSI (RSI_len: 200, StochRSI_len: 200, K: 3, D: 3) K_current < 70, K_prev < 70, K_prev_1 < 70
let mut keys_to_remove: HashSet<String> = HashSet::new(); let mut keys_to_remove: HashSet<String> = HashSet::new();
let stoch_rsis = stoch_rsi(30, 30, 3, 3, &alldata.rt_price_30m_vec, &filtered_data).await?; let stoch_rsis = stoch_rsi(200, 200, 3, 3, &alldata.rt_price_30m_vec, &filtered_data).await?;
for (symbol, values) in &mut filtered_data { for (symbol, values) in &mut filtered_data {
if stoch_rsis.contains_key(symbol) { if stoch_rsis.contains_key(symbol) {
let stoch_rsi_vec = stoch_rsis.get(symbol).unwrap(); let stoch_rsi_vec = stoch_rsis.get(symbol).unwrap();
@ -180,10 +184,9 @@ pub async fn list_up_for_buy(
.position(|x| x.close_time == values.closetime); .position(|x| x.close_time == values.closetime);
if stoch_rsi_vec.len() > 10 if stoch_rsi_vec.len() > 10
&& search_result.is_some_and(|a| { && search_result.is_some_and(|a| {
stoch_rsi_vec[a].k > stoch_rsi_vec[a].d stoch_rsi_vec[a].k < 70.0
&& stoch_rsi_vec[a].k < 70.0 && stoch_rsi_vec[a - 1].k < 70.0
&& stoch_rsi_vec[a - 1].k < 60.0 && stoch_rsi_vec[a - 2].k < 70.0
&& stoch_rsi_vec[a - 2].k < 50.0
}) })
{ {
} else { } else {
@ -321,24 +324,24 @@ pub async fn list_up_for_sell(
let supertrend_30m = let supertrend_30m =
supertrend(10, 2.0, true, &all_data.rt_price_30m_vec, &filtered_symbols).await?; supertrend(10, 2.0, true, &all_data.rt_price_30m_vec, &filtered_symbols).await?;
let tema_200 = tema(200, &all_data.rt_price_30m_vec, &filtered_symbols).await?; let tema_200 = tema(200, &all_data.rt_price_30m_vec, &filtered_symbols).await?;
let tema_5 = tema(5, &all_data.rt_price_30m_vec, &filtered_symbols).await?; let tema_100 = tema(100, &all_data.rt_price_30m_vec, &filtered_symbols).await?;
for element in filled_buy_orders { for element in filled_buy_orders {
let mut is_sell = false; let mut is_sell = false;
let mut is_overturned = false; let mut is_overturned = false;
if element.used_usdt >= dec!(10.0) { if element.used_usdt >= dec!(10.0) {
if let (Some(tema200_vec), Some(tema5_vec)) = if let (Some(tema200_vec), Some(tema100_vec)) =
(tema_200.get(&element.symbol), tema_5.get(&element.symbol)) (tema_200.get(&element.symbol), tema_100.get(&element.symbol))
{ {
if tema200_vec.len() > 2 if tema200_vec.len() > 2
&& tema5_vec.len() > 2 && tema100_vec.len() > 2
&& tema200_vec.last().unwrap().close_time && tema200_vec.last().unwrap().close_time
== tema5_vec.last().unwrap().close_time == tema100_vec.last().unwrap().close_time
&& tema200_vec.last().unwrap().close_time > server_epoch && tema200_vec.last().unwrap().close_time > server_epoch
&& tema5_vec.last().unwrap().close_time > server_epoch && tema100_vec.last().unwrap().close_time > server_epoch
&& tema200_vec.last().unwrap().tema_value && tema200_vec.last().unwrap().tema_value
> tema5_vec.last().unwrap().tema_value > tema100_vec.last().unwrap().tema_value
&& tema200_vec[tema200_vec.len() - 2].tema_value && tema200_vec[tema200_vec.len() - 2].tema_value
< tema5_vec[tema5_vec.len() - 2].tema_value < tema100_vec[tema100_vec.len() - 2].tema_value
{ {
is_overturned = true; is_overturned = true;
} }
@ -391,14 +394,14 @@ pub async fn list_up_for_sell(
is_sell = true; is_sell = true;
} else if element.current_price >= element.target_price { } else if element.current_price >= element.target_price {
is_sell = true; is_sell = true;
} else if server_epoch - element.transact_time > (1_800_000) * 1 } else if server_epoch - element.transact_time >= (1_800_000) * 5
&& is_overturned == true && is_overturned == true
{ {
is_sell = true; is_sell = true;
} }
let minimum_candles = 5; let minimum_candles = 5;
let maximum_candles = 30; let maximum_candles = 240;
for count_candles in minimum_candles..=maximum_candles { for count_candles in minimum_candles..=maximum_candles {
if count_candles < maximum_candles if count_candles < maximum_candles
&& server_epoch - element.transact_time && server_epoch - element.transact_time