Download the PHP package ragingprodigy/alpaca-php without Composer
On this page you can find all versions of the php package ragingprodigy/alpaca-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ragingprodigy/alpaca-php
More information about ragingprodigy/alpaca-php
Files in ragingprodigy/alpaca-php
Package alpaca-php
Short Description Alpaca Trade API Client for PHP
License Apache-2.0
Informations about the package alpaca-php
Alpaca-PHP
Overview
This is a PHP Client for Alpaca (General Alpaca API Documentation). Alpaca API lets you build and trade with real-time market data for free.
Table of Contents
- Installation
- Basic Usage
- Full Scale Example
- Methods
Installation
The package can be installed via Composer.
composer require ragingprodigy/alpaca-php
Basic Usage
To use the Library, simply create an instance of the client as shown below:
Under the Hood, the library makes use of the Guzzle Http client library to send HTTP requests. You can also provide a custom ClientInterface as the second argument to the Client
constructor in order to further customize the GuzzleHttp Client.
You can then access the available APIs by calling:
Full Scale Example
Here's how you can use the library to print out account information, submit a limit order, and print out bars.
The output for the code above would be similar to:
Account Information:
Created At: 2019-06-26T15:19:01.819453Z
Buying Power: $ 398861.06
Portfolio Value: $ 100003.99
Clock:
Current Time: 2019-07-01T03:14:37.582893836-04:00
Market Next Open Time: 2019-07-01T09:30:00-04:00
Market Next Close Time: 2019-07-01T16:00:00-04:00
Market Order Response:
Symbol: AAPL
Client Order Id: 309626b7-5569-4ae5-bb16-d93930b8b82b
Quantity: 5
Type: market
Created At: 2019-07-01T07:14:39.022538874Z
Order Update Event: {"event":"new","order":{"asset_class":"us_equity","asset_id":"b0b6dd9d-8b9b-48a9-ba46-b9d54906e415","canceled_at":null,"client_order_id":"abea2d0b-2340-4034-a50c-b4f09cde1e0b","created_at":"2019-07-01T07:12:16.177026Z","expired_at":null,"failed_at":null,"filled_at":null,"filled_avg_price":null,"filled_qty":"0","id":"b3332b17-b7dc-4a55-9a3c-dfd0c50ecc62","limit_price":null,"order_type":"market","qty":"5","side":"buy","status":"new","stop_price":null,"submitted_at":"2019-07-01T07:12:16.165806Z","symbol":"AAPL","time_in_force":"day","type":"market","updated_at":"2019-07-01T07:12:20.373783079Z"}}
Market Order by ID Response:
Symbol: AAPL
Client Order Id: 309626b7-5569-4ae5-bb16-d93930b8b82b
Quantity: 5
Type: market
Created At: 2019-07-01T07:14:39.022539Z
Market Order by ID Response:
Symbol: AAPL
Client Order Id: 309626b7-5569-4ae5-bb16-d93930b8b82b
Quantity: 5
Type: market
Created At: 2019-07-01T07:14:39.022539Z
Order Update Event: {"event":"canceled","order":{"asset_class":"us_equity","asset_id":"b0b6dd9d-8b9b-48a9-ba46-b9d54906e415","canceled_at":"2019-07-01T07:12:20.369944583Z","client_order_id":"abea2d0b-2340-4034-a50c-b4f09cde1e0b","created_at":"2019-07-01T07:12:16.177026Z","expired_at":null,"failed_at":null,"filled_at":null,"filled_avg_price":null,"filled_qty":"0","id":"b3332b17-b7dc-4a55-9a3c-dfd0c50ecc62","limit_price":null,"order_type":"market","qty":"5","side":"buy","status":"canceled","stop_price":null,"submitted_at":"2019-07-01T07:12:16.165806Z","symbol":"AAPL","time_in_force":"day","type":"market","updated_at":"2019-07-01T07:12:20.384272245Z"},"timestamp":"2019-07-01T07:12:20.369944583Z"}
Bars Response:
========================
Symbol: AAPL
Open: 198.43
High: 199.26
Low: 195.29
Close: 195.57
Volume: 18361798
========================
Symbol: AAPL
Open: 197.83
High: 200.99
Low: 197.35
Close: 199.8
Volume: 22499633
========================
Symbol: AAPL
Open: 200.29
High: 201.57
Low: 199.57
Close: 199.73
Volume: 15460769
========================
Symbol: AAPL
Open: 199.24
High: 199.4
Low: 197.05
Close: 197.92
Volume: 18773228
Methods
All API methods are available on the Alpaca Client (RagingProdigy\Alpaca\Client
).
Account API
Calls GET /account
and returns the current account
Orders API
Request New Order
Calls POST /orders
and creates a new order.
Get Orders
Calls GET /orders
and returns an array of Order objects.
Get Order By ID
Calls GET /orders/{id}
and returns an Order.
Get Order By Client Order Id
Calls GET /orders:by_client_order_id
and returns an order by client_order_id
. You can set client_order_id
while creating your orders to easily keep track of your orders.
Cancel an Order
Calls DELETE /orders/{id}
and deletes an Order.
Raises an AlpacaApiException
when it fails.
Positions API
Get Position
Calls GET /positions/{symbol}
and returns a Position.
Get All Position
Calls GET /positions
and returns an array of Position objects.
Assets API
Get Assets
Calls GET /assets/
and returns an array of Assets matching your criteria.
Get Asset Information
Calls GET /assets/{symbol}
and returns an Asset entity.
Calendar API
Calls GET/calendar
and returns the market calendar for the selected dates
Data API
Get Bars
Tests
In order to run the tests, install the dev-dependencies (composer install --dev
) and then run:
All versions of alpaca-php with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^6.3
ratchet/pawl Version ^0.3.4