PHP code example of jeffreyhyer / alpaca-trade-api-php

1. Go to this page and download the library: Download jeffreyhyer/alpaca-trade-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeffreyhyer / alpaca-trade-api-php example snippets




lpaca\Alpaca;

$alpaca = new Alpaca("--KEY--", "--SECRET--");

$positions = $alpaca->getPositions();

use Alpaca\Alpaca;

$alpaca = new Alpaca("KEY", "SECRET", true);

// This call will now work as expected if your KEY and SECRET are valid.
// If not, the response will contain an error explaining what went wrong.
$resp = $alpaca->getAccount();

print_r($alpaca->getAccount()->getResponse());

/*
Results in:

stdClass Object
(
    [id] => null
    [status] => ACTIVE
    [currency] => USD
    [buying_power] => 25000
    [cash] => 25000
    [cash_withdrawable] => 0
    [portfolio_value] => 25000
    [pattern_day_trader] => 
    [trading_blocked] => 
    [transfers_blocked] => 
    [account_blocked] => 
    [created_at] => 2018-11-01T18:41:35.990779Z
    [trade_suspended_by_user] => 
)
*/
shell
$ composer