From 5eab00ee336e1fbda791b2480aa00412d56be3d9 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Sat, 12 Apr 2025 20:03:40 -0500 Subject: [PATCH] wip --- app/Models/CurrencyRate.php | 17 +++++++++++++++++ app/Models/Dividend.php | 2 ++ 2 files changed, 19 insertions(+) diff --git a/app/Models/CurrencyRate.php b/app/Models/CurrencyRate.php index a777aae..3ea96eb 100644 --- a/app/Models/CurrencyRate.php +++ b/app/Models/CurrencyRate.php @@ -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) diff --git a/app/Models/Dividend.php b/app/Models/Dividend.php index 2f5861c..253502c 100644 --- a/app/Models/Dividend.php +++ b/app/Models/Dividend.php @@ -119,6 +119,8 @@ class Dividend extends Model dump('4. got market data for '.$symbol); + // todo: use this for start_date - $dividend_data->first()->get('date') + // get historic conversion rates $rate_to_base = CurrencyRate::timeSeriesRates($market_data->currency, $dividend_data->first()->get('date'), $end_date);