zarbox added 4
This commit is contained in:
@@ -50,15 +50,31 @@ class ZaarboxPriceService
|
||||
));
|
||||
}
|
||||
|
||||
/** UUID سری زمانی نمودار در API تاریخچه Zaarbox */
|
||||
/**
|
||||
* UUID سری نمودار: settings.chart_id؛ وگرنه پیشفرض گلد علی.
|
||||
* GET https://price.zaarbox.ir/api/history/{id}
|
||||
*/
|
||||
public function historyId(): string
|
||||
{
|
||||
$id = trim((string) $this->config->getString(
|
||||
'zaarbox_gold_history_id',
|
||||
(string) config('price_providers.zaarbox_gold_history_id', self::DEFAULT_HISTORY_ID)
|
||||
));
|
||||
$chartId = $this->config->getString('chart_id', '');
|
||||
if ($chartId !== '') {
|
||||
return $chartId;
|
||||
}
|
||||
|
||||
return $id !== '' ? $id : self::DEFAULT_HISTORY_ID;
|
||||
$legacy = $this->config->getString(
|
||||
'zaarbox_gold_history_id',
|
||||
(string) config('price_providers.zaarbox_gold_history_id', '')
|
||||
);
|
||||
if ($legacy !== '') {
|
||||
return $legacy;
|
||||
}
|
||||
|
||||
return self::DEFAULT_HISTORY_ID;
|
||||
}
|
||||
|
||||
private function cacheKey(): string
|
||||
{
|
||||
return self::CACHE_KEY . ':' . $this->historyId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +82,7 @@ class ZaarboxPriceService
|
||||
*/
|
||||
public function getAllPrices(): array
|
||||
{
|
||||
$cached = Cache::get(self::CACHE_KEY);
|
||||
$cached = Cache::get($this->cacheKey());
|
||||
|
||||
if (is_array($cached) && isset($cached['prices'])) {
|
||||
return $cached['prices'];
|
||||
@@ -82,7 +98,7 @@ class ZaarboxPriceService
|
||||
{
|
||||
$prices = $this->fetchChartPrices();
|
||||
|
||||
Cache::put(self::CACHE_KEY, [
|
||||
Cache::put($this->cacheKey(), [
|
||||
'prices' => $prices,
|
||||
'refreshed_at' => now()->toIso8601String(),
|
||||
], now()->addMinutes(self::CACHE_TTL_MINUTES));
|
||||
@@ -244,7 +260,7 @@ class ZaarboxPriceService
|
||||
|
||||
$result[] = [
|
||||
'value' => intdiv($lastPoint['price'], 1000),
|
||||
'timestamp' => $lastPoint['timestamp'],
|
||||
'timestamp' => $bucket,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user