-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
This guide provides a quick introduction to using the Marketstack PHP SDK. Once you have installed and configured the package, you can start making API calls with just a few lines of code.
The SDK provides a fluent and expressive interface for interacting with the Marketstack API. In a Laravel application, you can use the Marketstack facade to access all available endpoints.
Here is a simple example of how to get the latest end-of-day stock price for Apple (AAPL):
use Tigusigalpa\Marketstack\Facades\Marketstack;
// Get the latest EOD data for Apple
$stock = Marketstack::eod()->latest('AAPL')->dto();
// Display the closing price
echo "AAPL closed at: $" . $stock->close;You can also retrieve data for multiple stock symbols in a single request. The following example fetches end-of-day data for Apple, Google, and Microsoft for a specific date range:
use Tigusigalpa\Marketstack\Facades\Marketstack;
// Get EOD data for multiple symbols
$data = Marketstack::eod()
->symbols('AAPL', 'GOOG', 'MSFT')
->dateFrom('2023-01-01')
->dateTo('2023-01-31')
->sort('ASC')
->limit(100)
->collect();
foreach ($data as $eod) {
echo "{$eod->symbol}: {$eod->close}\n";
}The SDK offers several response formats to suit different needs:
-
collect(): Returns a Laravel Collection of DTOs (Data Transfer Objects). -
dto(): Returns a single DTO ornullif no result is found. -
json(): Returns a raw JSON array. -
get(): Returns the rawIlluminate\Http\Client\Responseobject.
For more details on response formats, see the Response Formats page.
Now that you have a basic understanding of how to use the SDK, you can explore the specific endpoints in more detail: