fix price
This commit is contained in:
@@ -9,7 +9,13 @@ class LivePriceCacheService
|
||||
{
|
||||
public const FULL_RESPONSE_KEY = 'live_price_full_response';
|
||||
|
||||
public const TTL_SECONDS = 15;
|
||||
public const LAST_TICK_KEY = 'live_price_last_tick_at';
|
||||
|
||||
/** همتراز با کران ۱۰ ثانیهای */
|
||||
public const TTL_SECONDS = 10;
|
||||
|
||||
/** اگر tick اخیر نباشد، buildFromDatabase قیمت را قفل میکند */
|
||||
public const TICK_MAX_AGE_SECONDS = 20;
|
||||
|
||||
public function get(): ?array
|
||||
{
|
||||
@@ -37,7 +43,22 @@ class LivePriceCacheService
|
||||
return $body;
|
||||
}
|
||||
|
||||
/** پاسخ سریع بدون API خارجی — از آخرین رکورد prices + تنظیمات (همان فرمول lastPrice) */
|
||||
public function markTick(): void
|
||||
{
|
||||
Cache::put(self::LAST_TICK_KEY, now(), now()->addMinutes(10));
|
||||
}
|
||||
|
||||
public function hasRecentTick(): bool
|
||||
{
|
||||
$lastTick = Cache::get(self::LAST_TICK_KEY);
|
||||
if ($lastTick === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return now()->diffInSeconds($lastTick) <= self::TICK_MAX_AGE_SECONDS;
|
||||
}
|
||||
|
||||
/** پاسخ سریع بدون API خارجی — فقط وقتی کران اخیراً tick زده (همان فرمول lastPrice) */
|
||||
public function buildFromDatabase(): array
|
||||
{
|
||||
$config = app(ConfigService::class);
|
||||
@@ -66,8 +87,10 @@ class LivePriceCacheService
|
||||
|
||||
if ($provider === 'montzar') {
|
||||
$liveMontzar = (float) $config->get('montzar_live_price', 0);
|
||||
if ($liveMontzar > 0) {
|
||||
$base = $liveMontzar;
|
||||
}
|
||||
$montzarSource = (int) ($liveMontzar > 0 ? $liveMontzar : $base);
|
||||
// DB از آخرین tick montzar پر شده — همان فرمول نمایش معامله
|
||||
$priceSource = 'montzar';
|
||||
} elseif ($provider === 'zaarbox') {
|
||||
$zaarboxSource = (int) $base;
|
||||
|
||||
Reference in New Issue
Block a user