diff --git a/app/Interfaces/MarketData/AlphaVantageMarketData.php b/app/Interfaces/MarketData/AlphaVantageMarketData.php index 355742c..e1347dd 100644 --- a/app/Interfaces/MarketData/AlphaVantageMarketData.php +++ b/app/Interfaces/MarketData/AlphaVantageMarketData.php @@ -98,13 +98,15 @@ class AlphaVantageMarketData implements MarketDataInterface return Carbon::parse($date)->between($startDate, $endDate); }) - ->map(function($history, $date) use ($symbol) { + ->mapWithKeys(function($history, $date) use ($symbol) { + + $date = Carbon::parse($date)->format('Y-m-d'); - return [ - 'symbol' => $symbol, - 'date' => Carbon::parse($date)->format('Y-m-d'), - 'close' => (float) Arr::get($history, '4. close') - ]; + return [ $date => [ + 'symbol' => $symbol, + 'date' => $date, + 'close' => (float) Arr::get($history, '4. close') + ]]; }); } } \ No newline at end of file diff --git a/app/Interfaces/MarketData/FakeMarketData.php b/app/Interfaces/MarketData/FakeMarketData.php index 9a3cfd4..e99bb62 100644 --- a/app/Interfaces/MarketData/FakeMarketData.php +++ b/app/Interfaces/MarketData/FakeMarketData.php @@ -2,6 +2,7 @@ namespace App\Interfaces\MarketData; +use Illuminate\Support\Carbon; use Illuminate\Support\Collection; class FakeMarketData implements MarketDataInterface @@ -66,13 +67,16 @@ class FakeMarketData implements MarketDataInterface public function history($symbol, $startDate, $endDate): Collection { + $numDays = Carbon::parse($startDate)->diffInDays($endDate, true); - for ($i = 0; $i < 14; $i++) { + for ($i = 0; $i < $numDays; $i++) { - $series[] = [ + $date = now()->subDays($i)->format('Y-m-d'); + + $series[$date] = [ 'symbol' => $symbol, - 'date' => now()->subDays($i)->format('Y-m-d'), - 'close' => (float) rand(1, 100), + 'date' => $date, + 'close' => (float) rand(150, 400), ]; } diff --git a/app/Interfaces/MarketData/YahooMarketData.php b/app/Interfaces/MarketData/YahooMarketData.php index ebbc217..77c8773 100644 --- a/app/Interfaces/MarketData/YahooMarketData.php +++ b/app/Interfaces/MarketData/YahooMarketData.php @@ -77,13 +77,15 @@ class YahooMarketData implements MarketDataInterface { return collect($this->client->getHistoricalQuoteData($symbol, ApiClient::INTERVAL_1_DAY, $startDate, $endDate)) - ->map(function($history) use ($symbol) { + ->mapWithKeys(function($history) use ($symbol) { - return [ - 'symbol' => $symbol, - 'date' => $history->getDate()->format('Y-m-d'), - 'close' => (float) $history->getClose(), - ]; + $date = $history->getDate()->format('Y-m-d'); + + return [ $date => [ + 'symbol' => $symbol, + 'date' => $date, + 'close' => (float) $history->getClose(), + ]]; }); } } \ No newline at end of file