Download the PHP package jeffreyhyer/alpaca-trade-api-php without Composer

On this page you can find all versions of the php package jeffreyhyer/alpaca-trade-api-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package alpaca-trade-api-php

Alpaca PHP SDK

Packagist Version Packagist

This repository contains a PHP SDK for use with the Alpaca API.

DISCLAIMER: This is NOT an official SDK, it is not affiliated with nor endorsed by Alpaca in any way.

Release Notes

v3.0.0

With the release of v3.0.0 of this library we use the Alpaca Data API v2. The getLastTrade and getLastQuote methods are backwards compatible and require no changes to your codebase.

:warning: The getBars method is NOT backwards compatible so you will need to update your codebase to use the new method signature found in the Market Data section below.

v2.0.0

With the release of v2.0.0 of this library we use v2 of the Alpaca API. However, the methods are all backwards compatible with v1.0.0 of this library and v1 of the Alpaca API so upgrading should be as simple as updating the package version in your composer.json file and installing. Everything should work as it did before but now you'll have access to the new methods and new method parameters.

Installation

NOTE: This package currently requires PHP >= 7.2.5

Usage

From within your PHP application you can access the Alpaca API with just a couple of lines:

OAuth

From v2.1.0 this package supports authenticating users via OAuth to the Alpaca API. For a detailed explanation on the OAuth flow, see the Alpaca Docs.

The following methods can be used to request Authorization to access an external users Alpaca account and retrieve an access token to make API calls on their behalf.

getOauthAuthorizeUrl($client_id, $redirect_uri, $scope = "", $state = null)

Provide your applications $client_id and an authorized/whitelisted $redirect_uri as well as your desired $scope and a random $state value. This function will return the URL to which you should redirect your user to in order to Authorize your application to access their account.

getOauthAccessToken($code, $client_id, $client_secret, $redirect_uri)

Once the user has authorized your application to access their account, Alpaca will redirect the user back to your application ($redirect_uri). In the URL will be a code parameter, you will pass that as the $code parameter to this function along with your $client_id and $client_secret and your original $redirect_url. This function will return an access token that can then be used to call the Alpaca API on behalf of that user/account.

To start using the access token call setAccessToken($token) with the value of the token.

Once authenticated, you can call getOauthAccessTokenDetails() to get the details of the access token (status, validity, etc).

API

Constructor

To get started initialize the Alpaca class with your Alpaca Key and Secret. You can also set the third parameter to enable or disable paper trading. The default is true to enable calling against the paper trading endpoint.

You can change these values after initialization if necessary using the following methods:

setKey($key)

Set your Alpaca Key

setSecret($secret)

Set your Alpaca Secret

setPaper(true)

Enable or disable paper trading. true = Paper Trading, false = Live Trading.


Response

All methods return an instance of the \Alpaca\Response class which has a number of convenient methods for working with the API response.

getCode()

Returns the HTTP status code of the request (e.g. 200, 403, etc).

getReason()

Returns the HTTP status reason of the request (e.g. OK, Forbidden, etc).

getResponse()

Returns the JSON decoded response. For example:


Account

:ledger: Alpaca Docs

getAccount()

Returns the account associated with the API key.


Orders

:ledger: Alpaca Docs

getOrders($status = null, $limit = null, $after = null, $until = null, $direction = null, $nested = null)

Retrieves a list of orders for the account, optionally filtered by the supplied query parameters.

createOrder($symbol, $qty, $side, $type, $time_in_force, $limit_price = null, $stop_price = null, $client_order_id = null, $extended_hours = null, $order_class = null, $additional = [])

Places a new order for the given account. An order request may be rejected if the account is not authorized for trading, or if the tradable balance is insufficient to fill the order.

getOrder($order_id)

Retrieves a single order for the given $order_id.

getOrderByClientId($client_order_id)

Retrieves a single order for the given $client_order_id.

replaceOrder($order_id, $qty, $time_in_force, $limit_price = null, $stop_price = null, $client_order_id = null)

Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order. The other attributes remain the same as the existing order.

cancelOrder($order_id)

Attempts to cancel an open order. If the order is no longer cancelable (example: status=order_filled), the server will respond with status 422, and reject the request.

cancelAllOrders()

Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.


Positions

:ledger: Alpaca Docs

getPositions()

Retrieves a list of the account's open positions.

getPosition($symbol)

Retrieves the account's open position for the given $symbol.

closeAllPositions()

Closes (liquidates) all of the account’s open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will respond with status 500 and reject the request.

closePosition($symbol)

Closes (liquidates) the account’s open position for the given $symbol. Works for both long and short positions.


Assets

:ledger: Alpaca Docs

getAssets($status = null, $asset_class = null)

Get a list of assets

getAsset($symbol)

Get an asset for the given $symbol.

getAssetById($id)

Get an asset for the given $id.


Watchlists

:ledger: Alpaca Docs

getWatchlists()

Returns the list of watchlists registered under the account.

createWatchlist($name, $symbols = [])

Create a new watchlist with initial set of assets ($symbols). The $name is used to identify the watchlist in any of the *WatchlistByName() methods below.

getWatchlist($id)

Returns a watchlist identified by the $id.

getWatchlistByName($name)

Returns a watchlist identified by the $name.

updateWatchlist($id, $name, $symbols = [])

Update the name and/or content of the watchlist identified by $id.

updateWatchlistByName($name, $symbols = [])

Update the name and/or content of the watchlist identified by $name.

addAssetToWatchlist($id, $symbol)

Append an asset for the $symbol to the end of watchlist asset list.

addAssetToWatchlistByName($name, $symbol)

Append an asset for the $symbol to the end of watchlist asset list.

deleteWatchlist($id)

Delete a watchlist. This is a permanent deletion.

deleteWatchlistByName($name)

Delete a watchlist. This is a permanent deletion.


Calendar

:ledger: Alpaca Docs

getCalendar($start = null, $end = null)

Returns the market calendar.


Clock

:ledger: Alpaca Docs

getClock()

Returns the market clock.


Account Configurations

:ledger: Alpaca Docs

getAccountConfigurations()

Returns the current account configuration values.

updateAccountConfigurations($config = [])

Updates and returns the current account configuration values. $config is an array of key-value pairs (e.g. ["key" => "value"].


Account Activities

:ledger: Alpaca Docs

getAccountActivitiesOfType($type, $date = null, $until = null, $after = null, $direction = null, $page_size = null, $page_token = null)

Returns account activity entries for a specific type of activity.

getAccountActivities($types = [])

Returns account activity entries for many types of activities.


Portfolio History

:ledger: Alpaca Docs

getPortfolioHistory($period = null, $timeframe = null, $date_end = null, $extended_hours = null)

Returns timeseries data about equity and profit/loss (P/L) of the account in requested timespan.


Market Data (v2 API)

:ledger: Alpaca Docs

getTrades($symbol, $start, $end, $limit = null, $page_token = null)

Returns trade historical data for the requested security.

getLastTrade($symbol)

Retrieve the last trade for the requested symbol.

getQuotes($symbol, $start, $end, $limit = null, $page_token = null)

Returns quote (NBBO) historical data for the requested security.

getLastQuote($symbol)

Retrieves the last quote for the requested symbol.

getBars($timeframe, $symbol, $start, $end, $limit = null, $page_token = null)

Returns aggregate historical data for the requested security.

getMultiSnapshot($symbols)

Returns the snapshots for the requested securities.

getSnapshot($symbol)

Returns the snapshot for the requested security.


All versions of alpaca-trade-api-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.5
guzzlehttp/guzzle Version ~6.0|~7.0
nesbot/carbon Version ^2.49
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jeffreyhyer/alpaca-trade-api-php contains the following files

Loading the files please wait ....