PHP SDK
The Market Data PHP SDK provides an easy-to-use interface for accessing real-time and historical financial data. This guide will help you get started quickly with integrating the SDK into your PHP projects.
See the php documentation hub for complete PHP SDK documentation.
Installation
To install the Market Data PHP SDK, use Composer:
composer require MarketDataApp/sdk-php
Basic Usage
Here's a quick overview of how to use the SDK:
Setup The Client
First, create a client instance with your API token:
$client = new MarketDataApp\Client('your_api_token');
Fetch Data
// Indices
$quote = $client->indices->quote('VIX');
$quotes = $client->indices->quotes(['VIX', 'DJI']);
$candles = $client->indices->candles(
symbol: "VIX",
from: '2022-09-01',
to: '2022-09-05',
resolution: 'D'
);
// Stocks
$candles = $client->stocks->candles('AAPL');
$bulk_candles = $client->stocks->bulkCandles(['AAPL, MSFT']);
$quote = $client->stocks->quote('AAPL');
$quotes = $client->stocks->quotes(['AAPL', 'MSFT']);
$bulk_quotes = $client->stocks->bulk_quotes(['AAPL', 'MSFT']);
$earnings = $client->stocks->earnings(symbol: 'AAPL', from: '2023-01-01');
$news = $client->stocks->news(symbol: 'AAPL', from: '2023-01-01');
// Markets
$status = $client->markets->status(date: '2023-01-01');
// Mutual Funds
$candles = $client->mutual_funds->candles(
symbol: 'VFINX',
from: '2022-09-01',
to: '2022-09-05',
resolution: 'D'
);
// Options
$expirations = $client->options->expirations('AAPL');
$lookup = $client->options->lookup('AAPL 7/28/23 $200 Call');
$strikes = $client->options->strikes(
symbol: 'AAPL',
expiration: '2023-01-20',
date: '2023-01-03',
);
$option_chain = $client->options->option_chain(
symbol: 'AAPL',
expiration: '2025-01-17',
side: Side::CALL,
);
$quotes = $client->options->quotes('AAPL250117C00150000');
// Utilities
$status = $client->utilities->api_status();
$headers = $client->utilities->headers();
Advanced Usage
All endpoints (except utilities) support universal parameters. For example, you can change the output format to CSV:
$option_chain = $client->options->option_chain(
symbol: 'AAPL',
expiration: '2025-01-17',
side: Side::CALL,
parameters: new Parameters(format: Format::CSV),
);
Testing
To run the test suite, use the following command:
./vendor/bin/phpunit
Keeping Up To Date
For more information and updates, visit the Market Data PHP SDK GitHub repository.
Contributing
We welcome contributions to the Market Data PHP SDK! If you find a bug, please open an issue on GitHub. If you'd like to contribute code, please fork the repository and submit a pull request.
Credits & Thanks
This SDK was generously contributed by Kerry Jones. We sincerely thank him for his time and effort to make this PHP SDK available to the Market Data community.
License
The Market Data PHP SDK is open-source software licensed under the MIT license.