Update filtering

This commit is contained in:
Sik Yoon 2024-05-26 07:53:45 +09:00
parent 31f211c3c2
commit 59a5e540ac
2 changed files with 85 additions and 0 deletions

View File

@ -278,6 +278,45 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::err
} }
} }
} }
let opclo_sample_length: usize = 60; // 15 candle samsples
let mut target_profit_percent = 0.0;
if let Some(price_30m_vec) = all_data.rt_price_30m_vec.get(&element.symbol) {
let vec_len = price_30m_vec.len();
if let Some(candles) =
price_30m_vec.get(vec_len - opclo_sample_length - 2..vec_len - 1)
{
let windows = candles.windows(2);
let mut sum_amplitude_candles = 0.0;
let mut sum_ratio_amp_body = 0.0;
let mut average_amplitude = 0.0;
for window in windows {
sum_amplitude_candles += ((window.last().unwrap().high_price
- window.last().unwrap().low_price)
* 100.0)
/ window.first().unwrap().close_price;
}
let average_amplitude = sum_amplitude_candles / opclo_sample_length as f64; // percent unit
let mut amplitude_variance = 0.0;
let windows = candles.windows(2);
for window in windows {
amplitude_variance += ((((window.last().unwrap().high_price
- window.last().unwrap().low_price)
* 100.0)
/ window.first().unwrap().close_price)
- average_amplitude)
.powi(2);
}
amplitude_variance = amplitude_variance / (opclo_sample_length - 1) as f64;
let standard_deviation_amplitude = amplitude_variance.sqrt();
target_profit_percent =
average_amplitude + (standard_deviation_amplitude * 2.0);
}
}
// TODO: BNB 코인이 있으면 // TODO: BNB 코인이 있으면
// let base_qty_to_be_ordered = // let base_qty_to_be_ordered =
// element.base_qty_ordered.round_dp_with_strategy( // element.base_qty_ordered.round_dp_with_strategy(
@ -294,6 +333,10 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::err
// } // }
if over_turned == true && server_epoch - element.registered_server_epoch > 1_800_000 { if over_turned == true && server_epoch - element.registered_server_epoch > 1_800_000 {
is_sell = true; is_sell = true;
} else if target_profit_percent.is_normal() && element.pure_profit_percent > target_profit_percent * 2.5 {
is_sell = true;
} else if target_profit_percent.is_normal() && element.pure_profit_percent < target_profit_percent * -1.5 {
is_sell = true;
} }
if is_sell == true { if is_sell == true {

View File

@ -277,6 +277,44 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::err
} }
} }
} }
let opclo_sample_length: usize = 60; // 15 candle samsples
let mut target_profit_percent = 0.0;
if let Some(price_30m_vec) = all_data.rt_price_30m_vec.get(&element.symbol) {
let vec_len = price_30m_vec.len();
if let Some(candles) =
price_30m_vec.get(vec_len - opclo_sample_length - 2..vec_len - 1)
{
let windows = candles.windows(2);
let mut sum_amplitude_candles = 0.0;
let mut sum_ratio_amp_body = 0.0;
let mut average_amplitude = 0.0;
for window in windows {
sum_amplitude_candles += ((window.last().unwrap().high_price
- window.last().unwrap().low_price)
* 100.0)
/ window.first().unwrap().close_price;
}
let average_amplitude = sum_amplitude_candles / opclo_sample_length as f64; // percent unit
let mut amplitude_variance = 0.0;
let windows = candles.windows(2);
for window in windows {
amplitude_variance += ((((window.last().unwrap().high_price
- window.last().unwrap().low_price)
* 100.0)
/ window.first().unwrap().close_price)
- average_amplitude)
.powi(2);
}
amplitude_variance = amplitude_variance / (opclo_sample_length - 1) as f64;
let standard_deviation_amplitude = amplitude_variance.sqrt();
target_profit_percent =
average_amplitude + (standard_deviation_amplitude * 2.0);
}
}
// TODO: BNB 코인이 있으면 // TODO: BNB 코인이 있으면
// let base_qty_to_be_ordered = // let base_qty_to_be_ordered =
// element.base_qty_ordered.round_dp_with_strategy( // element.base_qty_ordered.round_dp_with_strategy(
@ -293,6 +331,10 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::err
// } // }
if over_turned == true && server_epoch - element.registered_server_epoch > 1_800_000 { if over_turned == true && server_epoch - element.registered_server_epoch > 1_800_000 {
is_sell = true; is_sell = true;
} else if target_profit_percent.is_normal() && element.pure_profit_percent > target_profit_percent * 2.5 {
is_sell = true;
} else if target_profit_percent.is_normal() && element.pure_profit_percent < target_profit_percent * -1.5 {
is_sell = true;
} }
if is_sell == true { if is_sell == true {