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(); $end = $end ?? now();
dump('Creating period');
$period = CarbonPeriod::create($start, $end); $period = CarbonPeriod::create($start, $end);
// No need to send network request - just generate 1s // No need to send network request - just generate 1s
if ($currency === config('investbrain.base_currency')) { if ($currency === config('investbrain.base_currency')) {
dump('same curr');
$dateRange = []; $dateRange = [];
foreach ($period as $date) { foreach ($period as $date) {
$dateRange[$date->toDateString()] = 1; $dateRange[$date->toDateString()] = 1;
} }
return $dateRange; return $dateRange;
} }
dump('diff curr');
[$currency, $adjustment] = self::getCurrencyAliasAdjustments($currency); [$currency, $adjustment] = self::getCurrencyAliasAdjustments($currency);
$currencies = Currency::all()->pluck('currency')->toArray(); $currencies = Currency::all()->pluck('currency')->toArray();
dump('currencies'.$currencies);
// call api in chunks // call api in chunks
$rates = []; $rates = [];
foreach (collect($period)->chunk(500) as $chunk) { foreach (collect($period)->chunk(500) as $chunk) {
dump('calling frankf time series');
$chunkRates = Frankfurter::setSymbols($currencies)->timeSeries($chunk->min(), $chunk->max()); $chunkRates = Frankfurter::setSymbols($currencies)->timeSeries($chunk->min(), $chunk->max());
$rates = array_merge($rates, Arr::get($chunkRates, 'rates', [])); $rates = array_merge($rates, Arr::get($chunkRates, 'rates', []));
} }
dump('done with frankf');
// loop through each date // loop through each date
$updates = []; $updates = [];
foreach ($period as $date) { foreach ($period as $date) {
@@ -169,9 +182,13 @@ class CurrencyRate extends Model
} }
} }
dump('inserting');
// persist // persist
self::chunkInsert($updates); self::chunkInsert($updates);
dump('done');
return collect($updates) return collect($updates)
->whereBetween('date', [$start, $end ?? now()]) ->whereBetween('date', [$start, $end ?? now()])
->where('currency', $currency) ->where('currency', $currency)
+2
View File
@@ -119,6 +119,8 @@ class Dividend extends Model
dump('4. got market data for '.$symbol); dump('4. got market data for '.$symbol);
// todo: use this for start_date - $dividend_data->first()->get('date')
// get historic conversion rates // get historic conversion rates
$rate_to_base = CurrencyRate::timeSeriesRates($market_data->currency, $dividend_data->first()->get('date'), $end_date); $rate_to_base = CurrencyRate::timeSeriesRates($market_data->currency, $dividend_data->first()->get('date'), $end_date);