From f62078793ebf16c2329ec4545c832e07e5016e73 Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Thu, 28 Mar 2024 00:57:10 +0900 Subject: [PATCH] Change criteria price with open price --- src/strategy_team/strategy_008.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/strategy_team/strategy_008.rs b/src/strategy_team/strategy_008.rs index a6c1ce7..ddd6752 100644 --- a/src/strategy_team/strategy_008.rs +++ b/src/strategy_team/strategy_008.rs @@ -80,20 +80,24 @@ pub async fn list_up_for_buy( rt_price_vec.last().unwrap().close_time > server_epoch { // input stoploss, target_price let band_value: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(supertrend_vec.last().unwrap().band_value).unwrap(); + let open_price: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(rt_price_vec.last().unwrap().open_price).unwrap(); + let current_price: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(rt_price_vec.last().unwrap().close_price).unwrap(); if supertrend_vec.last().unwrap().area == SuperTrendArea::UP && - supertrend_vec.last().unwrap().band_value < values.current_price.to_f64().unwrap() + band_value < current_price && + band_value < open_price { - values.current_price = rust_decimal::prelude::FromPrimitive::from_f64(rt_price_vec.last().unwrap().close_price).unwrap(); + values.current_price = current_price; values.closetime = rt_price_vec.last().unwrap().close_time; values.stoploss = band_value; - values.target_price = decimal_add(decimal_mul(decimal_sub(values.current_price, values.stoploss), dec!(2.0)), values.current_price); + values.target_price = decimal_add(decimal_mul(decimal_sub(open_price, values.stoploss), dec!(2.0)), open_price); } else if supertrend_vec.last().unwrap().area == SuperTrendArea::DOWN && - supertrend_vec.last().unwrap().band_value > values.current_price.to_f64().unwrap() + band_value > current_price && + band_value > open_price { - values.current_price = rust_decimal::prelude::FromPrimitive::from_f64(rt_price_vec.last().unwrap().close_price).unwrap(); + values.current_price = current_price; values.closetime = rt_price_vec.last().unwrap().close_time; - values.stoploss = decimal_sub(values.current_price, decimal_sub(band_value, values.current_price)); - values.target_price = decimal_add(decimal_mul(decimal_sub(values.current_price, values.stoploss), dec!(2.0)), values.current_price); + 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!(2.0)), open_price); } else { keys_to_remove.insert(symbol.clone()); @@ -126,7 +130,7 @@ pub async fn list_up_for_buy( } } remove_keys(&mut filtered_data, keys_to_remove).await; - + // limit buy price: 3 * abs(이전 3 개 중 최대값 제거 한 opclo 값 평균 - 현재 open 값) + 현재 open 값 > current_price let mut keys_to_remove: HashSet = HashSet::new(); let server_epoch = get_server_epoch().await;