PHPackages                             tmarois/alpaca-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tmarois/alpaca-php-sdk

AbandonedArchivedPackage[API Development](/categories/api)

tmarois/alpaca-php-sdk
======================

PHP SDK for the Alpaca Trading API

v1.3(6y ago)375PHPPHP &gt;=7

Since Nov 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/tmarois/alpaca-php-sdk)[ Packagist](https://packagist.org/packages/tmarois/alpaca-php-sdk)[ Docs](https://github.com/tmarois/alpaca-php-sdk)[ RSS](/packages/tmarois-alpaca-php-sdk/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Alpaca Trading PHP SDK
======================

[](#alpaca-trading-php-sdk)

This package acts as a PHP SDK for the [Alpaca Trading API](https://docs.alpaca.markets/).

Also, check out the [Polygon PHP SDK](https://github.com/tmarois/polygon-php-sdk) for real time data.

Installation
------------

[](#installation)

Use [Composer](http://getcomposer.org/) to install package.

Run `composer require tmarois/alpaca-php-sdk:^1.0`

Getting Started
---------------

[](#getting-started)

First you need to instantiate the `Alpaca` object.

```
use Alpaca\Alpaca;

$alpaca = new Alpaca("YOUR_API_KEY_ID", "YOUR_API_SECRET_KEY");
```

Example Usage
-------------

[](#example-usage)

**[Get Account](https://docs.alpaca.markets/api-documentation/api-v2/account/)**: Get the account details

```
// this will pull a request from alpaca to get account details
$account = $alpaca->account();

// here are some helper methods to quickly get the details
$number = $account->number();
$id = $account->id();
$status = $account->status();
$buyingPower = $account->buyingPower();
$cash = $account->cash();
$longValue = $account->longValue();
$shortValue = $account->shortValue();
$portfolioValue = $account->portfolioValue();

// gets the raw array from Alpaca
// view documentation for the correct keys
$raw = $account->raw();
```

**[Get Order](https://docs.alpaca.markets/api-documentation/api-v2/orders/#order-entity)**: Get a specific order

```
$order = $alpaca->orders()->get('ORDER_ID');
```

**[Get All Orders](https://docs.alpaca.markets/api-documentation/api-v2/orders/#order-entity)**: Get an array of all open orders

```
// get all open orders
$orders = $alpaca->orders()->getAll();

// get orders of specific types
// type: open, closed, or all
$orders = $alpaca->orders()->getAll($type,$limit,$dateFrom,$dateTo,$direction);
```

**[Cancel An Order](https://docs.alpaca.markets/api-documentation/api-v2/orders/#cancel-all-orders)**: Cancel a specific order

```
$orders = $alpaca->orders()->cancel('ORDER_ID);
```

**[Cancel All Orders](https://docs.alpaca.markets/api-documentation/api-v2/orders/#cancel-all-orders)**: Cancel all open orders

```
$orders = $alpaca->orders()->cancelAll();
```

**[Create An Order](https://docs.alpaca.markets/api-documentation/api-v2/orders/#request-a-new-order)**: Create a new order

```
$alpaca->orders()->create([
    // stock to purchase
    'symbol' => 'AAPL',

    // how many shares
    'qty' => 1,

    // buy or sell
    'side' => 'buy',

    // market, limit, stop, or stop_limit
    'type' => 'market',

    // day, gtc, opg, cls, ioc, fok.
    // @see https://docs.alpaca.markets/orders/#time-in-force
    'time_in_force' => 'day',

    // required if type is limit or stop_limit
    // 'limit_price' => 0,

    // required if type is stop or stop_limit
    // 'stop_price' => 0,

    'extended_hours' => false,

    // optional if adding custom id
    // 'client_order_id' => ''
]);
```

**[Replace An Order](https://docs.alpaca.markets/api-documentation/api-v2/orders/#replace-an-order)**: Replaces an existing order

```
$alpaca->orders()->replace('ORDER_ID',[
    'qty' => 1,

    // required if type is limit or stop_limit
    // 'limit_price' => 0,

    // required if type is stop or stop_limit
    // 'stop_price' => 0,

    // day, gtc, opg, cls, ioc, fok.
    // @see https://docs.alpaca.markets/orders/#time-in-force
    'time_in_force' => 'day',

    // optional if adding custom id
    // 'client_order_id' => ''
]);
```

**[Get Position](https://docs.alpaca.markets/api-documentation/api-v2/orders/#get-open-positions)**: Get an open position

```
$position = $alpaca->positions()->get('SYMBOL');
```

**[Get All Positions](https://docs.alpaca.markets/api-documentation/api-v2/orders/#get-an-open-position)**: Get all open positions

```
$positions = $alpaca->positions()->getAll();
```

**Position Entity Response:**

```
{
  "asset_id": "904837e3-3b76-47ec-b432-046db621571b",
  "symbol": "AAPL",
  "exchange": "NASDAQ",
  "asset_class": "us_equity",
  "avg_entry_price": "100.0",
  "qty": "5",
  "side": "long",
  "market_value": "600.0",
  "cost_basis": "500.0",
  "unrealized_pl": "100.0",
  "unrealized_plpc": "0.20",
  "unrealized_intraday_pl": "10.0",
  "unrealized_intraday_plpc": "0.0084",
  "current_price": "120.0",
  "lastday_price": "119.0",
  "change_today": "0.0084"
}
```

**[Close a Position](https://docs.alpaca.markets/api-documentation/api-v2/orders/#close-a-position)**: Close a position

```
$alpaca->positions()->close('SYMBOL');
```

**[Close All Positions](https://docs.alpaca.markets/api-documentation/api-v2/orders/#close-a-position)**: Close all open positions

```
$alpaca->positions()->closeAll();
```

**[Get Activity](https://docs.alpaca.markets/api-documentation/api-v2/account-activities/)**: Get the account activity, like order fills, dividends etc.

```
// type can be many, such as FILL, DIV, TRANS etc
// view on this page https://docs.alpaca.markets/api-documentation/api-v2/account-activities/
$activity = $alpaca->activity()->get('TYPE');
```

There are more in the [Alpaca Documentation](https://docs.alpaca.markets/) than what is presented above, if you want to extend this, please send in a pull request or request features you'd like to see added. Thanks!

Contributions
-------------

[](#contributions)

Anyone can contribute to **alpaca-php-sdk**. Please do so by posting issues when you've found something that is unexpected or sending a pull request for improvements.

License
-------

[](#license)

**alpaca-php-sdk** (This Repository) is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

This SDK has no affiliation with alpaca.markets, Alpaca Securities LLC and AlpacaDB and acts as an unofficial SDK designed to be a simple solution with using PHP applications. **Use at your own risk**. If you have any issues with the SDK please submit an issue or pull request.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Total

4

Last Release

2308d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fb2a1c2cd3f429541c1151da87ffedea46ff881b554626520b4e090b270bf5fc?d=identicon)[timothymarois](/maintainers/timothymarois)

---

Top Contributors

[![timothymarois](https://avatars.githubusercontent.com/u/2489333?v=4)](https://github.com/timothymarois "timothymarois (22 commits)")

---

Tags

alpacaalpaca-apialpaca-marketsalpaca-php-sdkalpaca-trading-apisdktrading-apiapialpacamarketstocksstock-markettrading apimarket api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tmarois-alpaca-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/tmarois-alpaca-php-sdk/health.svg)](https://phpackages.com/packages/tmarois-alpaca-php-sdk)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[get-stream/stream-chat

A PHP client for Stream Chat (https://getstream.io/chat/)

301.8M2](/packages/get-stream-stream-chat)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[jeffreyhyer/alpaca-trade-api-php

PHP SDK for the Alpaca trade API

285.0k](/packages/jeffreyhyer-alpaca-trade-api-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
