diff --git a/app/Services/ConfigService.php b/app/Services/ConfigService.php index ef81150..5fe5abf 100644 --- a/app/Services/ConfigService.php +++ b/app/Services/ConfigService.php @@ -314,10 +314,6 @@ class ConfigService $currentUp = (float) ($upSetting->value ?: 0); $currentDown = (float) ($downSetting->value ?: 0); - if ($currentUp > 0 && $priceInt < (int) ($currentUp * 0.9)) { - return; - } - if ($currentUp <= 0 || $priceInt > $currentUp) { $this->UpdateConfig('up_price', $priceInt); } @@ -327,7 +323,7 @@ class ConfigService } /** - * بیشترین/کمترین قیمت پایه امروز — با اصلاح outlier در down_price. + * بیشترین/کمترین قیمت پایه امروز — settings + candle + جدول prices. * * @return array{up: int, down: int} */ @@ -340,10 +336,11 @@ class ConfigService $candleHigh = $candle ? (int) round((float) $candle->high) : 0; $candleLow = $candle ? (int) round((float) $candle->low) : 0; - if ($up > 0 && $down > 0 && $down < (int) ($up * 0.9)) { - $correctedDown = $candleLow >= (int) ($up * 0.9) ? $candleLow : $up; - $down = $correctedDown; - $this->UpdateConfig('down_price', $correctedDown); + if ($candleHigh > 0) { + $up = $up > 0 ? max($up, $candleHigh) : $candleHigh; + } + if ($candleLow > 0) { + $down = $down > 0 ? min($down, $candleLow) : $candleLow; } if ($up <= 0 || $down <= 0) { @@ -367,6 +364,11 @@ class ConfigService [$up, $down] = [$down, $up]; } + $storedDown = $this->getInt('down_price', 0); + if ($down > 0 && $down < $storedDown) { + $this->UpdateConfig('down_price', $down); + } + return ['up' => $up, 'down' => $down]; } @@ -386,17 +388,9 @@ class ConfigService return ['min' => 0, 'max' => 0]; } - $max = (int) $prices->max(); - $threshold = (int) ($max * 0.9); - $valid = $prices->filter(fn (int $price) => $price >= $threshold); - - if ($valid->isEmpty()) { - return ['min' => $max, 'max' => $max]; - } - return [ - 'min' => (int) $valid->min(), - 'max' => $max, + 'min' => (int) $prices->min(), + 'max' => (int) $prices->max(), ]; }