Add checking value boundary

This commit is contained in:
Sik Yoon 2024-05-15 22:22:04 +09:00
parent fd6edef5a6
commit 7ee0abc465

View File

@ -80,28 +80,30 @@ pub async fn update_realtime_price_data(
// reflect realtime data to the last element in rt_price_vec
if interval.contains("1m") {
if let Some(current_price) = read_price.get(element) {
// update close_price
rt_price_vec.last_mut().unwrap().close_price = *current_price;
// update opclo_price
rt_price_vec.last_mut().unwrap().opclo_price =
(rt_price_vec.last_mut().unwrap().open_price
+ rt_price_vec.last_mut().unwrap().close_price)
/ 2.0;
// update candle_type
if rt_price_vec.last_mut().unwrap().close_price
>= rt_price_vec.last_mut().unwrap().open_price
{
rt_price_vec.last_mut().unwrap().candle_type = CandleType::UP;
} else {
rt_price_vec.last_mut().unwrap().candle_type = CandleType::DOWN;
}
// update high_price
if rt_price_vec.last_mut().unwrap().high_price < *current_price {
rt_price_vec.last_mut().unwrap().high_price = *current_price;
}
// update low_price
if rt_price_vec.last_mut().unwrap().low_price > *current_price {
rt_price_vec.last_mut().unwrap().low_price = *current_price;
if current_price.is_normal() {
// update close_price
rt_price_vec.last_mut().unwrap().close_price = *current_price;
// update opclo_price
rt_price_vec.last_mut().unwrap().opclo_price =
(rt_price_vec.last_mut().unwrap().open_price
+ rt_price_vec.last_mut().unwrap().close_price)
/ 2.0;
// update candle_type
if rt_price_vec.last_mut().unwrap().close_price
>= rt_price_vec.last_mut().unwrap().open_price
{
rt_price_vec.last_mut().unwrap().candle_type = CandleType::UP;
} else {
rt_price_vec.last_mut().unwrap().candle_type = CandleType::DOWN;
}
// update high_price
if rt_price_vec.last_mut().unwrap().high_price < *current_price {
rt_price_vec.last_mut().unwrap().high_price = *current_price;
}
// update low_price
if rt_price_vec.last_mut().unwrap().low_price > *current_price {
rt_price_vec.last_mut().unwrap().low_price = *current_price;
}
}
}
} else {
@ -181,9 +183,7 @@ pub async fn update_realtime_price_data(
rt_price_vec.last_mut().unwrap().quote_asset_volume =
update_quote_asset_volume;
}
if update_closeprice != 0.0
&& !update_closeprice.is_nan()
&& update_closeprice.is_finite()
if update_closeprice.is_normal()
{
rt_price_vec.last_mut().unwrap().close_price = update_closeprice;
rt_price_vec.last_mut().unwrap().opclo_price = (update_closeprice