This commit is contained in:
hackerESQ
2025-04-12 20:03:40 -05:00
parent 56064ad84e
commit 5eab00ee33
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -119,32 +119,45 @@ class CurrencyRate extends Model
$end = $end ?? now();
dump('Creating period');
$period = CarbonPeriod::create($start, $end);
// No need to send network request - just generate 1s
if ($currency === config('investbrain.base_currency')) {
dump('same curr');
$dateRange = [];
foreach ($period as $date) {
$dateRange[$date->toDateString()] = 1;
}
return $dateRange;
}
dump('diff curr');
[$currency, $adjustment] = self::getCurrencyAliasAdjustments($currency);
$currencies = Currency::all()->pluck('currency')->toArray();
dump('currencies'.$currencies);
// call api in chunks
$rates = [];
foreach (collect($period)->chunk(500) as $chunk) {
dump('calling frankf time series');
$chunkRates = Frankfurter::setSymbols($currencies)->timeSeries($chunk->min(), $chunk->max());
$rates = array_merge($rates, Arr::get($chunkRates, 'rates', []));
}
dump('done with frankf');
// loop through each date
$updates = [];
foreach ($period as $date) {
@@ -169,9 +182,13 @@ class CurrencyRate extends Model
}
}
dump('inserting');
// persist
self::chunkInsert($updates);
dump('done');
return collect($updates)
->whereBetween('date', [$start, $end ?? now()])
->where('currency', $currency)