Skip to content

This package provide realtime and historical global equity data.

Notifications You must be signed in to change notification settings

alexxd35/Stock-Data

Repository files navigation

Stock-Data

This package provide realtime and historical global equity data in 4 different temporal resolutions:(1)daily,(2)weekly,(3)monthly,and(4)intraday.Daily,weekly,and monthly time series contain 20+ years of historical data.

Build Status StyleCI Latest Stable Version Total Downloads

Installing

$ composer require alexxd/stock-data -vvv

Configuration

Before using this extension, you need to go to the Alphavantage to register your account, then create an app to get the API Key for your app.

Usage

use Alexxd\StockData\Stock;

$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$stock = new Stock($key);

Get intraDay stock data

$response = $stock->getIntradayStock('AAPL');

Example:


{
    "Meta Data": {
        "1. Information": "Intraday (5min) open, high, low, close prices and volume",
        "2. Symbol": "AAPL",
        "3. Last Refreshed": "2019-11-20 16:00:00",
        "4. Interval": "5min",
        "5. Output Size": "Compact",
        "6. Time Zone": "US/Eastern"
    },
    "Time Series (5min)": {
        "2019-11-20 16:00:00": {
            "1. open": "262.9000",
            "2. high": "263.0700",
            "3. low": "262.7800",
            "4. close": "262.7900",
            "5. volume": "707185"
        },
        "2019-11-20 15:55:00": {
            "1. open": "262.7200",
            "2. high": "262.8900",
            "3. low": "262.6222",
            "4. close": "262.8900",
            "5. volume": "386239"
        },
        "2019-11-20 15:50:00": {
            "1. open": "262.7100",
            "2. high": "262.9600",
            "3. low": "262.6800",
            "4. close": "262.7250",
            "5. volume": "329007"
        },
        ...
    }
}

Get daily stock data

$response = $stock->getDailyStock('AAPL');

Get weekly stock data

$response = $stock->getWeeklyStock('AMZN');

Get monthly stock data

$response = $stock->getMonthlyStock('TSLA');

Parameters

getIntradayStock($symbol, $interval = '5', $format = 'json',$output_size='compact')
getDailyStock($symbol, $format = 'json',$output_size='compact')
getWeeklyStock($symbol, $format = 'json',$output_size='compact')
getMonthlyStock($symbol, $format = 'json',$output_size='compact')

symbol :The name of the equity of your choice. For example:AAPL

interval:(Only intraday required)Time interval between two consecutive data points in the time series. The following values are supported: 1, 5, 15, 30, 60

format:By default, format=json. Strings json and csv are accepted with the following specifications: json returns the intraday time series in JSON format; csv returns the time series as a CSV (comma separated value) file.

output_size:By default, output_size=compact. Strings compact and full are accepted with the following specifications: compact returns only the latest 100 data points in the intraday time series; full returns the full-length intraday time series. The "compact" option is recommended if you would like to reduce the data size of each API call.

Used in Laravel

The same installation is used in Laravel, and the configuration is written in config/services.php:

    .
    .
    .
     'stock' => [
        'key' => env('STOCK_API_KEY'),
    ],

Then configure STOCK_API_KEY in .env :

STOCK_API_KEY=xxxxxxxxxxxxxxxxxxxxx

There are two ways to get an Alexxd\StockData\Stock instance:

Method parameter injection

    .
    .
    .
    public function test(Stock $stock) 
    {
        $response = $stock->getIntraDayStock('AAPL');
    }
    .
    .
    .

Service name access

    .
    .
    .
    public function test() 
    {
        $response = app('stock')->getIntraDayStock('AAPL');
    }
    .
    .
    .

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

License

MIT

About

This package provide realtime and historical global equity data.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages