add history interface
This commit is contained in:
@@ -85,4 +85,26 @@ class AlphaVantageMarketData implements MarketDataInterface
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function history($symbol, $startDate, $endDate): Collection
|
||||
{
|
||||
|
||||
$history = Alphavantage::timeSeries()->daily($symbol);
|
||||
|
||||
$history = Arr::get($history, 'Time Series (Daily)', []);
|
||||
|
||||
return collect($history)
|
||||
->filter(function ($history, $date) use ($startDate, $endDate) {
|
||||
|
||||
return Carbon::parse($date)->between($startDate, $endDate);
|
||||
})
|
||||
->map(function($history, $date) use ($symbol) {
|
||||
|
||||
return [
|
||||
'symbol' => $symbol,
|
||||
'date' => Carbon::parse($date)->format('Y-m-d'),
|
||||
'close' => (float) Arr::get($history, '4. close')
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -63,4 +63,19 @@ class FakeMarketData implements MarketDataInterface
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function history($symbol, $startDate, $endDate): Collection
|
||||
{
|
||||
|
||||
for ($i = 0; $i < 14; $i++) {
|
||||
|
||||
$series[] = [
|
||||
'symbol' => $symbol,
|
||||
'date' => now()->subDays($i)->format('Y-m-d'),
|
||||
'close' => (float) rand(1, 100),
|
||||
];
|
||||
}
|
||||
|
||||
return collect($series);
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,15 @@ interface MarketDataInterface
|
||||
* @return Collection
|
||||
*/
|
||||
public function splits(String $symbol, \DateTimeInterface $startDate, \DateTimeInterface $endDate): Collection;
|
||||
|
||||
/**
|
||||
* Get historical close data
|
||||
*
|
||||
* @param String $symbol
|
||||
* @param \DateTimeInterface $startDate
|
||||
* @param \DateTimeInterface $endDate
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function history(String $symbol, \DateTimeInterface $startDate, \DateTimeInterface $endDate): Collection;
|
||||
}
|
||||
|
||||
@@ -72,4 +72,18 @@ class YahooMarketData implements MarketDataInterface
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function history($symbol, $startDate, $endDate): Collection
|
||||
{
|
||||
|
||||
return collect($this->client->getHistoricalQuoteData($symbol, ApiClient::INTERVAL_1_DAY, $startDate, $endDate))
|
||||
->map(function($history) use ($symbol) {
|
||||
|
||||
return [
|
||||
'symbol' => $symbol,
|
||||
'date' => $history->getDate()->format('Y-m-d'),
|
||||
'close' => (float) $history->getClose(),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user