konfig/snaptrade-php-sdk

Connect brokerage accounts to your app for live positions and trading


README

Connect brokerage accounts to your app for live positions and trading

For more information, please visit https://snaptrade.com/.

Installation & Usage

Requirements

This library requires PHP ^8.0

Composer

To install the bindings via Composer, add the following to composer.json:

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/passiv/snaptrade-php-sdk.git"
    }
  ],
  "require": {
    "konfig/snaptrade-php-sdk": "2.0.7"
  }
}

Then run composer install

Manual Installation

Download the files and include autoload.php:

<?php
require_once('/path/to/snaptrade-php-sdk/vendor/autoload.php');

Getting Started

Please follow the installation procedure and then run the following:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

$snaptrade = new \SnapTrade\Client(
    clientId: getenv("SNAPTRADE_CLIENT_ID"),
    consumerKey: getenv("SNAPTRADE_CONSUMER_KEY")
);

$user_id = "John.doe@snaptrade.com";
$user_secret = "USERSECRET123";
$brokerage_authorizations = "917c8734-8470-4a3e-a18f-57c3f2ee6631"; // Optional. Comma seperated list of authorization IDs (only use if filtering is needed on one or more authorizations).

try {
    $result = $snaptrade->accountInformation->getAllUserHoldings(
        user_id: $user_id, 
        user_secret: $user_secret, 
        brokerage_authorizations: $brokerage_authorizations
    );
    print_r($result->$getAccount());
    print_r($result->$getBalances());
    print_r($result->$getPositions());
    print_r($result->$getTotalValue());
} catch (\Exception $e) {
    echo 'Exception when calling AccountInformationApi->getAllUserHoldings: ', $e->getMessage(), PHP_EOL;
}

API Endpoints

All URIs are relative to https://api.snaptrade.com/api/v1

Class Method HTTP request Description
AccountInformationApi getAllUserHoldings GET /holdings List all accounts for the user, plus balances, positions, and orders for each account.
AccountInformationApi getUserAccountBalance GET /accounts/{accountId}/balances List account balances
AccountInformationApi getUserAccountDetails GET /accounts/{accountId} Return details of a specific investment account
AccountInformationApi getUserAccountOrders GET /accounts/{accountId}/orders List account orders
AccountInformationApi getUserAccountPositions GET /accounts/{accountId}/positions List account positions
AccountInformationApi getUserHoldings GET /accounts/{accountId}/holdings List balances, positions and orders for the specified account
AccountInformationApi listUserAccounts GET /accounts List accounts
AccountInformationApi updateUserAccount PUT /accounts/{accountId} Update details of an investment account
ApiStatusApi check GET / Get API Status
AuthenticationApi deleteSnapTradeUser DELETE /snapTrade/deleteUser Delete SnapTrade user
AuthenticationApi getUserJWT GET /snapTrade/encryptedJWT Generate encrypted JWT token
AuthenticationApi listSnapTradeUsers GET /snapTrade/listUsers List SnapTrade users
AuthenticationApi loginSnapTradeUser POST /snapTrade/login Login user & generate connection link
AuthenticationApi registerSnapTradeUser POST /snapTrade/registerUser Create SnapTrade user
AuthenticationApi resetSnapTradeUserSecret POST /snapTrade/resetUserSecret Obtain a new user secret for a user
ConnectionsApi detailBrokerageAuthorization GET /authorizations/{authorizationId} Get brokerage authorization details
ConnectionsApi listBrokerageAuthorizations GET /authorizations List all brokerage authorizations for the user
ConnectionsApi removeBrokerageAuthorization DELETE /authorizations/{authorizationId} Delete brokerage authorization
ConnectionsApi sessionEvents GET /sessionEvents List all session events for the partner
ErrorLogsApi listUserErrors GET /snapTrade/listUserErrors Retrieve error logs on behalf of your SnapTrade users
OptionsApi getOptionStrategy POST /accounts/{accountId}/optionStrategy Creates an option strategy object that will be used to place an option strategy order
OptionsApi getOptionsChain GET /accounts/{accountId}/optionsChain Get the options chain
OptionsApi getOptionsStrategyQuote GET /accounts/{accountId}/optionStrategy/{optionStrategyId} Get latest market data of option strategy
OptionsApi listOptionHoldings GET /accounts/{accountId}/options Get the options holdings in the account
OptionsApi placeOptionStrategy POST /accounts/{accountId}/optionStrategy/{optionStrategyId}/execute Place an option strategy order on the brokerage
ReferenceDataApi getCurrencyExchangeRatePair GET /currencies/rates/{currencyPair} Return the exchange rate of a currency pair
ReferenceDataApi getPartnerInfo GET /snapTrade/partners Get metadata related to Snaptrade partner
ReferenceDataApi getSecurityTypes GET /securityTypes List of all security types
ReferenceDataApi getStockExchanges GET /exchanges List exchanges
ReferenceDataApi getSymbols POST /symbols Search for symbols
ReferenceDataApi getSymbolsByTicker GET /symbols/{query} Get details of a symbol by the ticker or the universal_symbol_id
ReferenceDataApi listAllBrokerageAuthorizationType GET /brokerageAuthorizationTypes List of all brokerage authorization types
ReferenceDataApi listAllBrokerages GET /brokerages List brokerages
ReferenceDataApi listAllCurrencies GET /currencies List currencies
ReferenceDataApi listAllCurrenciesRates GET /currencies/rates List currency exchange rates
ReferenceDataApi symbolSearchUserAccount POST /accounts/{accountId}/symbols Search for symbols available in an account
TradingApi cancelUserAccountOrder POST /accounts/{accountId}/orders/cancel Cancel open order in account
TradingApi getOrderImpact POST /trade/impact Check impact of trades on account.
TradingApi getUserAccountQuotes GET /accounts/{accountId}/quotes Get symbol quotes
TradingApi placeForceOrder POST /trade/place Place a trade with NO validation.
TradingApi placeOCOOrder POST /trade/oco Place a OCO (One Cancels Other) order
TradingApi placeOrder POST /trade/{tradeId} Place order
TransactionsAndReportingApi getActivities GET /activities Get transaction history for a user
TransactionsAndReportingApi getReportingCustomRange GET /performance/custom Get performance information for a specific timeframe

Models

Author

This PHP package is automatically generated by Konfig: