Change criteria price with open price

This commit is contained in:
Sik Yoon 2024-03-28 00:57:10 +09:00
parent 6835b9cfa6
commit f62078793e

View File

@ -80,20 +80,24 @@ pub async fn list_up_for_buy(
rt_price_vec.last().unwrap().close_time > server_epoch { rt_price_vec.last().unwrap().close_time > server_epoch {
// input stoploss, target_price // input stoploss, target_price
let band_value: Decimal = rust_decimal::prelude::FromPrimitive::from_f64(supertrend_vec.last().unwrap().band_value).unwrap(); 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 && 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.closetime = rt_price_vec.last().unwrap().close_time;
values.stoploss = band_value; 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 && } 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.closetime = rt_price_vec.last().unwrap().close_time;
values.stoploss = decimal_sub(values.current_price, decimal_sub(band_value, values.current_price)); values.stoploss = decimal_sub(open_price, decimal_sub(band_value, open_price));
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 { } else {
keys_to_remove.insert(symbol.clone()); 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; remove_keys(&mut filtered_data, keys_to_remove).await;
// limit buy price: 3 * abs(이전 3 개 중 최대값 제거 한 opclo 값 평균 - 현재 open 값) + 현재 open 값 > current_price // limit buy price: 3 * abs(이전 3 개 중 최대값 제거 한 opclo 값 평균 - 현재 open 값) + 현재 open 값 > current_price
let mut keys_to_remove: HashSet<String> = HashSet::new(); let mut keys_to_remove: HashSet<String> = HashSet::new();
let server_epoch = get_server_epoch().await; let server_epoch = get_server_epoch().await;