From d585153a0b2bfc16a100ecb14a3bf80874d319db Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Sat, 31 Aug 2024 23:06:19 -0500 Subject: [PATCH] mock and alphavantage data provider --- .env.example | 2 + app/Interfaces/MarketData/FakeMarketData.php | 63 ++++++++ app/Interfaces/MarketData/YahooMarketData.php | 6 +- composer.json | 3 +- composer.lock | 141 +++++++++++++++++- config/alphavantage.php | 5 + 6 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 app/Interfaces/MarketData/FakeMarketData.php create mode 100644 config/alphavantage.php diff --git a/.env.example b/.env.example index cfb4930..85f0a2d 100644 --- a/.env.example +++ b/.env.example @@ -56,6 +56,8 @@ MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}" +ALPHAVANTAGE_API_KEY= + AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 diff --git a/app/Interfaces/MarketData/FakeMarketData.php b/app/Interfaces/MarketData/FakeMarketData.php new file mode 100644 index 0000000..a90f687 --- /dev/null +++ b/app/Interfaces/MarketData/FakeMarketData.php @@ -0,0 +1,63 @@ + 'ACME Company Ltd', + 'symbol' => $symbol, + 'market_value' => 230.19, + 'fifty_two_week_high' => 512.90, + 'fifty_two_week_low' => 341.20, + 'forward_pe' => 20.1, + 'trailing_pe' => 30.34, + 'market_cap' => 9800700600 + ]); + } + + public function dividends($symbol, $startDate, $endDate): Collection + { + + return collect([ + [ + 'symbol' => $symbol, + 'date' => now()->subMonths(3)->format('Y-m-d H:i:s'), + 'dividend_amount' => 2.11, + ], + [ + 'symbol' => $symbol, + 'date' => now()->subMonths(6)->format('Y-m-d H:i:s'), + 'dividend_amount' => 1.89, + ], + [ + 'symbol' => $symbol, + 'date' => now()->subMonths(9)->format('Y-m-d H:i:s'), + 'dividend_amount' => 0.95, + ], + ]); + } + + public function splits($symbol, $startDate, $endDate): Collection + { + + return collect([ + [ + 'symbol' => $symbol, + 'date' => now()->subMonths(36)->format('Y-m-d H:i:s'), + 'split_amount' => 10, + ], + ]); + } +} \ No newline at end of file diff --git a/app/Interfaces/MarketData/YahooMarketData.php b/app/Interfaces/MarketData/YahooMarketData.php index ee71812..340a3c9 100644 --- a/app/Interfaces/MarketData/YahooMarketData.php +++ b/app/Interfaces/MarketData/YahooMarketData.php @@ -7,9 +7,9 @@ use Scheb\YahooFinanceApi\ApiClientFactory as YahooFinance; class YahooMarketData implements MarketDataInterface { - public $client; - - public function __construct() { + public function __construct( + public $client + ) { // create yahoo finance client factory $this->client = YahooFinance::createApiClient(); diff --git a/composer.json b/composer.json index 98bb26a..83634a8 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "predis/predis": "^2.2", "robsontenorio/mary": "^1.35", "scheb/yahoo-finance-api": "^4.10", - "staudenmeir/eloquent-has-many-deep": "^1.20" + "staudenmeir/eloquent-has-many-deep": "^1.20", + "tschucki/alphavantage-laravel": "^0.0.1" }, "require-dev": { "fakerphp/faker": "^1.23", diff --git a/composer.lock b/composer.lock index daf2143..be35f88 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3d6ea585015c0a9442f1faf0d5c9b141", + "content-hash": "47988869f65dbf94a6228627c7806e1f", "packages": [ { "name": "bacon/bacon-qr-code", @@ -4846,6 +4846,66 @@ }, "time": "2024-06-09T11:50:56+00:00" }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.5", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "c7413972cf22ffdff97b68499c22baa04eddb6a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/c7413972cf22ffdff97b68499c22baa04eddb6a2", + "reference": "c7413972cf22ffdff97b68499c22baa04eddb6a2", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0|^11.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.5" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2024-08-27T18:56:10+00:00" + }, { "name": "staudenmeir/eloquent-has-many-deep", "version": "v1.20.2", @@ -7307,6 +7367,85 @@ }, "time": "2023-12-08T13:03:43+00:00" }, + { + "name": "tschucki/alphavantage-laravel", + "version": "0.0.1", + "source": { + "type": "git", + "url": "https://github.com/Tschucki/alphavantage-laravel.git", + "reference": "409c78c123ed40a150d8ea6ac095ab36dc077f82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Tschucki/alphavantage-laravel/zipball/409c78c123ed40a150d8ea6ac095ab36dc077f82", + "reference": "409c78c123ed40a150d8ea6ac095ab36dc077f82", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^10.0||^11.0", + "php": "^8.2", + "spatie/laravel-package-tools": "^1.16" + }, + "require-dev": { + "larastan/larastan": "^2.9", + "laravel/pint": "^1.14", + "nunomaduro/collision": "^8.1.1||^7.10.0", + "orchestra/testbench": "^9.0.0||^8.22.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-arch": "^2.7", + "pestphp/pest-plugin-laravel": "^2.3", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpstan/phpstan-phpunit": "^1.3", + "roave/security-advisories": "dev-latest" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Tschucki\\Alphavantage\\AlphavantageServiceProvider" + ], + "aliases": { + "Alphavantage": "Tschucki\\Alphavantage\\Facades\\Alphavantage" + } + } + }, + "autoload": { + "psr-4": { + "Tschucki\\Alphavantage\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marcel Wagner", + "email": "info@marcelwagner.dev", + "role": "Developer" + } + ], + "description": "Laravel Wrapper for Alphavantage API", + "homepage": "https://github.com/tschucki/alphavantage-laravel", + "keywords": [ + "Marcel Wagner", + "Tschucki", + "alphavantage-laravel", + "laravel" + ], + "support": { + "issues": "https://github.com/Tschucki/alphavantage-laravel/issues", + "source": "https://github.com/Tschucki/alphavantage-laravel/tree/0.0.1" + }, + "funding": [ + { + "url": "https://github.com/Tschucki", + "type": "github" + } + ], + "time": "2024-07-14T17:31:03+00:00" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.1", diff --git a/config/alphavantage.php b/config/alphavantage.php new file mode 100644 index 0000000..62d20b9 --- /dev/null +++ b/config/alphavantage.php @@ -0,0 +1,5 @@ + env('ALPHAVANTAGE_API_KEY'), +];