fix alphavantage filter dividends and splits
This commit is contained in:
@@ -52,10 +52,13 @@ class AlphaVantageMarketData implements MarketDataInterface
|
||||
public function dividends(String $symbol, $startDate, $endDate): Collection
|
||||
{
|
||||
$dividends = Alphavantage::fundamentals()->dividends($symbol);
|
||||
$dividends = Arr::get($dividends, 'data', []);
|
||||
|
||||
return collect($dividends)
|
||||
->where('ex_dividend_date', '>=', $startDate)
|
||||
->where('ex_dividend_date', '<', $endDate)
|
||||
->filter(function($dividend) use ($startDate, $endDate) {
|
||||
|
||||
return Carbon::parse(Arr::get($dividend, 'ex_dividend_date'))->between($startDate, $endDate);
|
||||
})
|
||||
->map(function($dividend) use ($symbol) {
|
||||
|
||||
return [
|
||||
@@ -69,12 +72,14 @@ class AlphaVantageMarketData implements MarketDataInterface
|
||||
|
||||
public function splits(String $symbol, $startDate, $endDate): Collection
|
||||
{
|
||||
|
||||
$splits = Alphavantage::fundamentals()->splits($symbol);
|
||||
$splits = Arr::get($splits, 'data', []);
|
||||
|
||||
return collect($splits)
|
||||
->where('effective_date', '>=', $startDate)
|
||||
->where('effective_date', '<', $endDate)
|
||||
->filter(function($split) use ($startDate, $endDate) {
|
||||
|
||||
return Carbon::parse(Arr::get($split, 'effective_date'))->between($startDate, $endDate);
|
||||
})
|
||||
->map(function($split) use ($symbol) {
|
||||
|
||||
return [
|
||||
|
||||
@@ -90,7 +90,7 @@ class Dividend extends Model
|
||||
self::syncHoldings($dividend_data);
|
||||
|
||||
// sync last dividend amount to market data table
|
||||
$market_data = MarketData::symbol($symbol)->first();
|
||||
$market_data = MarketData::firstOrNew(['symbol' => $symbol]);
|
||||
$market_data->last_dividend_amount = $dividend_data->sortByDesc('date')->first()['dividend_amount'];
|
||||
$market_data->save();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user