Update filtering

This commit is contained in:
Sik Yoon 2024-04-21 22:58:23 +09:00
parent d005c2a2cb
commit e36005f11e

View File

@ -49,37 +49,33 @@ pub async fn list_up_for_buy(
}
remove_keys(&mut filtered_data, keys_to_remove).await;
// current Tema(30) < current Tema(5)
// previous Tema(30) > previous Tema(5)
// current Tema(200) < current Tema(5)
// previous Tema(200) > previous Tema(5)
let mut keys_to_remove: HashSet<String> = HashSet::new();
let tema_30 = tema(30, &alldata.rt_price_30m_vec, &filtered_data).await?;
let tema_5 = tema(5, &alldata.rt_price_30m_vec, &filtered_data).await?;
let tema_200 = tema(200, &alldata.rt_price_30m_vec, &filtered_data).await?;
let server_epoch = get_server_epoch().await;
for (symbol, values) in &mut filtered_data {
if let (Some(tema30_vec), Some(tema5_vec), Some(tema_200_vec), Some(rt_price_vec)) = (
tema_30.get(symbol),
if let (Some(tema5_vec), Some(tema200_vec)) = (
tema_5.get(symbol),
tema_200.get(symbol),
alldata.rt_price_30m_vec.get(symbol),
tema_200.get(symbol)
) {
if (tema30_vec.len() > 10
&& tema5_vec.len() > 10
&& tema_200_vec.len() > 10
&& rt_price_vec.len() > 10)
&& tema30_vec.last().unwrap().close_time == tema5_vec.last().unwrap().close_time
&& tema_200_vec.last().unwrap().close_time == tema5_vec.last().unwrap().close_time
if (tema5_vec.len() > 10
&& tema200_vec.len() > 10)
&& tema200_vec.last().unwrap().close_time == tema5_vec.last().unwrap().close_time
&& tema5_vec.last().unwrap().close_time > server_epoch
{
if tema30_vec.last().unwrap().tema_value < tema5_vec.last().unwrap().tema_value
&& tema30_vec[tema30_vec.len() - 2].tema_value
if tema200_vec.last().unwrap().tema_value < tema5_vec.last().unwrap().tema_value
&& tema200_vec[tema200_vec.len() - 2].tema_value
> tema5_vec[tema5_vec.len() - 2].tema_value
&& tema30_vec[tema30_vec.len() - 3].tema_value
&& tema200_vec[tema200_vec.len() - 3].tema_value
> tema5_vec[tema5_vec.len() - 3].tema_value
&& tema_200_vec.last().unwrap().tema_value
< rt_price_vec.last().unwrap().opclo_price
&& tema_200_vec[tema_200_vec.len() - 2].tema_value
< rt_price_vec[rt_price_vec.len() - 2].opclo_price
&& tema200_vec[tema200_vec.len() - 4].tema_value
> tema5_vec[tema5_vec.len() - 4].tema_value
&& tema200_vec[tema200_vec.len() - 5].tema_value
> tema5_vec[tema5_vec.len() - 5].tema_value
&& tema200_vec[tema200_vec.len() - 6].tema_value
> tema5_vec[tema5_vec.len() - 6].tema_value
{
} else {
keys_to_remove.insert(symbol.clone());
@ -127,7 +123,7 @@ pub async fn list_up_for_buy(
values.closetime = rt_price_vec.last().unwrap().close_time;
values.stoploss = band_value;
values.target_price = decimal_add(
decimal_mul(decimal_sub(current_price, values.stoploss), dec!(3.0)),
decimal_mul(decimal_sub(current_price, values.stoploss), dec!(5.0)),
current_price,
);
} else if supertrend_vec.last().unwrap().area == SuperTrendArea::DOWN
@ -138,7 +134,7 @@ pub async fn list_up_for_buy(
values.closetime = rt_price_vec.last().unwrap().close_time;
values.stoploss = decimal_sub(open_price, decimal_sub(band_value, open_price));
values.target_price = decimal_add(
decimal_mul(decimal_sub(open_price, values.stoploss), dec!(3.0)),
decimal_mul(decimal_sub(open_price, values.stoploss), dec!(5.0)),
current_price,
);
} else {
@ -324,24 +320,24 @@ pub async fn list_up_for_sell(
}
let supertrend_30m =
supertrend(10, 2.0, true, &all_data.rt_price_30m_vec, &filtered_symbols).await?;
let tema_30 = tema(30, &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?;
for element in filled_buy_orders {
let mut is_sell = false;
let mut is_overturned = false;
if element.used_usdt >= dec!(10.0) {
if let (Some(tema30_vec), Some(tema5_vec)) =
(tema_30.get(&element.symbol), tema_5.get(&element.symbol))
if let (Some(tema200_vec), Some(tema5_vec)) =
(tema_200.get(&element.symbol), tema_5.get(&element.symbol))
{
if tema30_vec.len() > 2
if tema200_vec.len() > 2
&& tema5_vec.len() > 2
&& tema30_vec.last().unwrap().close_time
&& tema200_vec.last().unwrap().close_time
== tema5_vec.last().unwrap().close_time
&& tema30_vec.last().unwrap().close_time > server_epoch
&& tema200_vec.last().unwrap().close_time > server_epoch
&& tema5_vec.last().unwrap().close_time > server_epoch
&& tema30_vec.last().unwrap().tema_value
&& tema200_vec.last().unwrap().tema_value
> tema5_vec.last().unwrap().tema_value
&& tema30_vec[tema30_vec.len() - 2].tema_value
&& tema200_vec[tema200_vec.len() - 2].tema_value
< tema5_vec[tema5_vec.len() - 2].tema_value
{
is_overturned = true;