Update filtering

This commit is contained in:
Sik Yoon 2024-06-01 02:56:21 +09:00
parent 4afe543dc4
commit 2fa4696e81
2 changed files with 33 additions and 25 deletions

View File

@ -125,11 +125,13 @@ pub async fn list_up_for_buy(
.min_by(|x, y| x.opclo_price.partial_cmp(&y.opclo_price).unwrap()) .min_by(|x, y| x.opclo_price.partial_cmp(&y.opclo_price).unwrap())
.unwrap().opclo_price; .unwrap().opclo_price;
if values.current_price.to_f64().is_some_and(|a| a > min_price) { if values.current_price.to_f64().is_some_and(|a| a > min_price) {
let stoploss_percent = ((min_price - values.current_price.to_f64().unwrap()) * 100.0) / (values.current_price.to_f64().unwrap() * 2.0); let mut stoploss_percent = ((min_price - values.current_price.to_f64().unwrap()) * 100.0) / values.current_price.to_f64().unwrap();
stoploss_percent = (stoploss_percent * 100.0).floor() / 100.0;
values.stoploss = rust_decimal::prelude::FromPrimitive::from_f64(stoploss_percent).unwrap(); values.stoploss = rust_decimal::prelude::FromPrimitive::from_f64(stoploss_percent).unwrap();
let target_percent = stoploss_percent.abs() * 1.25; let mut target_percent = stoploss_percent.abs() * 1.5;
target_percent = (target_percent * 100.0).floor() / 100.0;
values.target_price = rust_decimal::prelude::FromPrimitive::from_f64(target_percent).unwrap(); values.target_price = rust_decimal::prelude::FromPrimitive::from_f64(target_percent).unwrap();
if stoploss_percent < - 0.07 { if stoploss_percent < - 0.07 && stoploss_percent > -1.5 {
do_buy = true; do_buy = true;
} }
} }
@ -331,33 +333,27 @@ pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &Ha
.timeout(tokio::time::Duration::from_millis(5000)) .timeout(tokio::time::Duration::from_millis(5000))
.build() .build()
.unwrap(); .unwrap();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let server_epoch = get_server_epoch().await; let server_epoch = get_server_epoch().await;
let mut filtered_symbols: HashMap<String, FilteredDataValue> = HashMap::new();
for element in &filled_positions {
filtered_symbols.insert(element.symbol.clone(), FilteredDataValue::new());
}
let supertrend_1m_map =
supertrend(30, 3.0, true, &all_data.rt_price_1m_vec, &filtered_symbols).await?;
for element in filled_positions { for element in filled_positions {
let mut is_sell = false; let mut is_sell = false;
// TODO: BNB 코인이 있으면
// let base_qty_to_be_ordered =
// element.base_qty_ordered.round_dp_with_strategy(
// lot_step_size.normalize().scale(),
// RoundingStrategy::ToZero,
// );
// TODO: BNB 코인이 없으면
if !element.current_price.is_zero() { if !element.current_price.is_zero() {
// if element.pure_profit_percent >= target_profit_percent * 2.5 {
// is_sell = true;
// } else if element.pure_profit_percent <= target_profit_percent * -2.0 {
// is_sell = true;
// }
// if over_turned == true && server_epoch - element.close_time > 1_800_000 {
// is_sell = true;
// } else
if element.pure_profit_percent >= element.target_percent { if element.pure_profit_percent >= element.target_percent {
is_sell = true; is_sell = true;
} else if element.pure_profit_percent <= element.stoploss_percent { } else if element.pure_profit_percent <= element.stoploss_percent {
is_sell = true; is_sell = true;
} else if server_epoch - element.close_time > 1_800_000 { } else if server_epoch - element.close_time > 7_200_000 {
is_sell = true;
} else if supertrend_1m_map.get(&element.symbol).is_some_and(|a| a.last().is_some_and(|b| b.close_time > server_epoch && b.area == SuperTrendArea::DOWN)) {
is_sell = true; is_sell = true;
} }

View File

@ -125,11 +125,13 @@ pub async fn list_up_for_buy(
.max_by(|x, y| x.opclo_price.partial_cmp(&y.opclo_price).unwrap()) .max_by(|x, y| x.opclo_price.partial_cmp(&y.opclo_price).unwrap())
.unwrap().opclo_price; .unwrap().opclo_price;
if values.current_price.to_f64().is_some_and(|a| a < max_price) { if values.current_price.to_f64().is_some_and(|a| a < max_price) {
let stoploss_percent = ((values.current_price.to_f64().unwrap() - max_price) * 100.0) / (values.current_price.to_f64().unwrap() * 2.0); let mut stoploss_percent = ((values.current_price.to_f64().unwrap() - max_price) * 100.0) / values.current_price.to_f64().unwrap();
stoploss_percent = (stoploss_percent * 100.0).floor() / 100.0;
values.stoploss = rust_decimal::prelude::FromPrimitive::from_f64(stoploss_percent).unwrap(); values.stoploss = rust_decimal::prelude::FromPrimitive::from_f64(stoploss_percent).unwrap();
let target_percent = stoploss_percent.abs() * 1.25; let mut target_percent = stoploss_percent.abs() * 1.5;
target_percent = (target_percent * 100.0).floor() / 100.0;
values.target_price = rust_decimal::prelude::FromPrimitive::from_f64(target_percent).unwrap(); values.target_price = rust_decimal::prelude::FromPrimitive::from_f64(target_percent).unwrap();
if stoploss_percent < - 0.07 { if stoploss_percent < - 0.07 && stoploss_percent > -1.5 {
do_buy = true; do_buy = true;
} }
} }
@ -331,7 +333,15 @@ pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &Ha
.timeout(tokio::time::Duration::from_millis(5000)) .timeout(tokio::time::Duration::from_millis(5000))
.build() .build()
.unwrap(); .unwrap();
let mut supertrend_vec: Vec<SupertrendData> = Vec::new();
let server_epoch = get_server_epoch().await; let server_epoch = get_server_epoch().await;
let mut filtered_symbols: HashMap<String, FilteredDataValue> = HashMap::new();
for element in &filled_positions {
filtered_symbols.insert(element.symbol.clone(), FilteredDataValue::new());
}
let supertrend_1m_map =
supertrend(30, 3.0, true, &all_data.rt_price_1m_vec, &filtered_symbols).await?;
for element in filled_positions { for element in filled_positions {
let mut is_sell = false; let mut is_sell = false;
@ -350,6 +360,8 @@ pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &Ha
is_sell = true; is_sell = true;
} else if server_epoch - element.close_time > 1_800_000 { } else if server_epoch - element.close_time > 1_800_000 {
is_sell = true; is_sell = true;
} else if supertrend_1m_map.get(&element.symbol).is_some_and(|a| a.last().is_some_and(|b| b.close_time > server_epoch && b.area == SuperTrendArea::UP)) {
is_sell = true;
} }
if is_sell == true { if is_sell == true {