Skip to content

Quick Start

Igor Sazonov edited this page Feb 4, 2026 · 1 revision

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.

Basic Usage

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.

Getting the Latest Stock Price

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;

Fetching Data for Multiple Symbols

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";
}

Response Formats

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 or null if no result is found.
  • json(): Returns a raw JSON array.
  • get(): Returns the raw Illuminate\Http\Client\Response object.

For more details on response formats, see the Response Formats page.

Next Steps

Now that you have a basic understanding of how to use the SDK, you can explore the specific endpoints in more detail:

Clone this wiki locally