- Installation & Usage
- Getting Started
- Reference
snaptrade.accountInformation.getAllUserHoldings
snaptrade.accountInformation.getUserAccountBalance
snaptrade.accountInformation.getUserAccountDetails
snaptrade.accountInformation.getUserAccountOrders
snaptrade.accountInformation.getUserAccountPositions
snaptrade.accountInformation.getUserHoldings
snaptrade.accountInformation.listUserAccounts
snaptrade.accountInformation.updateUserAccount
snaptrade.apiStatus.check
snaptrade.authentication.deleteSnapTradeUser
snaptrade.authentication.getUserJWT
snaptrade.authentication.listSnapTradeUsers
snaptrade.authentication.loginSnapTradeUser
snaptrade.authentication.registerSnapTradeUser
snaptrade.authentication.resetSnapTradeUserSecret
snaptrade.connections.detailBrokerageAuthorization
snaptrade.connections.listBrokerageAuthorizations
snaptrade.connections.removeBrokerageAuthorization
snaptrade.connections.sessionEvents
snaptrade.options.getOptionStrategy
snaptrade.options.getOptionsChain
snaptrade.options.getOptionsStrategyQuote
snaptrade.options.listOptionHoldings
snaptrade.options.placeOptionStrategy
snaptrade.referenceData.getCurrencyExchangeRatePair
snaptrade.referenceData.getPartnerInfo
snaptrade.referenceData.getSecurityTypes
snaptrade.referenceData.getStockExchanges
snaptrade.referenceData.getSymbols
snaptrade.referenceData.getSymbolsByTicker
snaptrade.referenceData.listAllBrokerageAuthorizationType
snaptrade.referenceData.listAllBrokerages
snaptrade.referenceData.listAllCurrencies
snaptrade.referenceData.listAllCurrenciesRates
snaptrade.referenceData.symbolSearchUserAccount
snaptrade.trading.cancelUserAccountOrder
snaptrade.trading.getOrderImpact
snaptrade.trading.getUserAccountQuotes
snaptrade.trading.placeForceOrder
snaptrade.trading.placeOrder
snaptrade.transactionsAndReporting.getActivities
snaptrade.transactionsAndReporting.getReportingCustomRange
This library requires PHP ^7.0
To install the bindings via Composer, add the following to composer.json
:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/passiv/snaptrade-php-7-sdk.git"
}
],
"require": {
"konfig/snaptrade-php-7-sdk": "2.0.14"
}
}
Then run composer install
Download the files and include autoload.php
:
<?php
require_once('/path/to/snaptrade-php-7-sdk/vendor/autoload.php');
Please follow the installation procedure and then run the following:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$snaptrade = new \SnapTrade\Client(
getenv("SNAPTRADE_CONSUMER_KEY"),
getenv("SNAPTRADE_CLIENT_ID")
);
$result = $snaptrade->accountInformation->getAllUserHoldings(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631"
);
Lists balances, positions and orders for the specified account. The data returned is similar to the data returned over the more fine-grained positions, orders and balances endpoints.
$result = $snaptrade->accountInformation->getAllUserHoldings(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631"
);
Optional. Comma seperated list of authorization IDs (only use if filtering is needed on one or more authorizations).
/holdings
GET
π Back to Table of Contents
A list of account balances for the specified account (one per currency that the account holds).
$result = $snaptrade->accountInformation->getUserAccountBalance(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631"
);
The ID of the account to get balances.
/accounts/{accountId}/balances
GET
π Back to Table of Contents
Returns an account object with details for the specified account, including the total account market value.
$result = $snaptrade->accountInformation->getUserAccountDetails(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631"
);
The ID of the account to get detail of.
/accounts/{accountId}
GET
π Back to Table of Contents
Fetch all recent orders from a user's account.
$result = $snaptrade->accountInformation->getUserAccountOrders(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631",
"all",
30
);
The ID of the account to get orders.
defaults value is set to "all"
Number of days in the past to fetch the most recent orders. Defaults to the last 30 days if no value is passed in.
/accounts/{accountId}/orders
GET
π Back to Table of Contents
Returns a list of positions in the the specified account.
$result = $snaptrade->accountInformation->getUserAccountPositions(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631"
);
The ID of the account to get positions.
/accounts/{accountId}/positions
GET
π Back to Table of Contents
Lists balances, positions and orders for the specified account as well as option_positions and account metadata. The data returned is similar to the data returned over the more fine-grained positions, orders and balances endpoints.
$result = $snaptrade->accountInformation->getUserHoldings(
"917c8734-8470-4a3e-a18f-57c3f2ee6631",
"John.doe@snaptrade.com",
"USERSECRET123"
);
The ID of the account to fetch holdings for.
/accounts/{accountId}/holdings
GET
π Back to Table of Contents
Get a list of all Account objects for the authenticated SnapTrade user.
$result = $snaptrade->accountInformation->listUserAccounts(
"John.doe@snaptrade.com",
"USERSECRET123"
);
/accounts
GET
π Back to Table of Contents
Updates various properties of a specified account.
$result = $snaptrade->accountInformation->updateUserAccount(
"John.doe@snaptrade.com",
"USERSECRET123",
"accountId_example"
);
The ID of the account to update.
/accounts/{accountId}
PUT
π Back to Table of Contents
Check whether the API is operational and verify timestamps.
$result = $snaptrade->apiStatus->check();
/
GET
π Back to Table of Contents
Deletes a user you've registered over the SnapTrade API, and any data associated with them or their investment accounts.
$result = $snaptrade->authentication->deleteSnapTradeUser(
"John.doe@snaptrade.com"
);
/snapTrade/deleteUser
DELETE
π Back to Table of Contents
This API is available to ClientIDs which have opted to use encrypted JWTs (JSON Web Tokens) instead of standard SnapTrade signature verification.
$result = $snaptrade->authentication->getUserJWT(
"John.doe@snaptrade.com",
"USERSECRET123"
);
/snapTrade/encryptedJWT
GET
π Back to Table of Contents
Returns a list of users you've registered over the SnapTrade API.
$result = $snaptrade->authentication->listSnapTradeUsers();
string[]
/snapTrade/listUsers
GET
π Back to Table of Contents
Logs in a SnapTrade user and returns an authenticated connection portal URL for them to use to connect a brokerage account.
$result = $snaptrade->authentication->loginSnapTradeUser(
"John.doe@snaptrade.com",
"USERSECRET123",
"ALPACA",
True,
"https://snaptrade.com",
"8b5f262d-4bb9-365d-888a-202bd3b15fa1",
"read",
"v2"
);
Slug of the brokerage to connect the user to
When set to True, user will be redirected back to the partner's site instead of the connection portal
URL to redirect the user to after the user connects their brokerage account
The UUID of the brokerage connection to be reconnected. This parameter should be left empty unless you are reconnecting a disabled connection. See βReconnecting Accountsβ for more information.
Sets whether the connection should be read or trade
Sets the version of the connection portal to render, with a default to 'v2'
AuthenticationLoginSnapTradeUser200Response
/snapTrade/login
POST
π Back to Table of Contents
Registers a new SnapTrade user under your ClientID. Most SnapTrade operations require a user to be passed as a parameter.
$result = $snaptrade->authentication->registerSnapTradeUser(
"snaptrade-user-123"
);
SnapTrade User ID. Provided by SnapTrade Partner. Can be any string, as long as it's unique to a user
/snapTrade/registerUser
POST
π Back to Table of Contents
This API is used to generate a new secret for a SnapTrade user. You might use this if a userSecret is comprimised or lost among other reasons.
$result = $snaptrade->authentication->resetSnapTradeUserSecret(
"snaptrade-user-123",
"h81@cx1lkalablakwjaltkejraj11="
);
SnapTrade User ID. Provided by SnapTrade Partner. Can be any string, as long as it's unique to a user
SnapTrade User Secret randomly generated by SnapTrade. This should be considered priviledged information and if compromised, you should delete and re-create this SnapTrade user.
/snapTrade/resetUserSecret
POST
π Back to Table of Contents
Get brokerage authorization details
$result = $snaptrade->connections->detailBrokerageAuthorization(
"2bcd7cc3-e922-4976-bce1-9858296801c3",
"John.doe@snaptrade.com",
"USERSECRET123"
);
The ID of a brokerage authorization object.
/authorizations/{authorizationId}
GET
π Back to Table of Contents
List all brokerage authorizations for the user
$result = $snaptrade->connections->listBrokerageAuthorizations(
"John.doe@snaptrade.com",
"USERSECRET123"
);
/authorizations
GET
π Back to Table of Contents
Delete brokerage authorization
$snaptrade->connections->removeBrokerageAuthorization(
"2bcd7cc3-e922-4976-bce1-9858296801c3",
"John.doe@snaptrade.com",
"USERSECRET123"
);
The ID of the Authorization to delete.
void (empty response body)
/authorizations/{authorizationId}
DELETE
π Back to Table of Contents
List all session events for the partner
$result = $snaptrade->connections->sessionEvents(
"SNAPTRADETEST",
"917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2",
"917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2"
);
Optional comma seperated list of user IDs used to filter the request on specific users
Optional comma seperated list of session IDs used to filter the request on specific users
ConnectionsSessionEvents200ResponseInner
/sessionEvents
GET
π Back to Table of Contents
Creates an option strategy object that will be used to place an option strategy order
$result = $snaptrade->options->getOptionStrategy(
"2bcd7cc3-e922-4976-bce1-9858296801c3",
[
[
"action" => "BUY_TO_OPEN",
"option_symbol_id" => "SPY220819P00200000",
"quantity" => 1,
]
],
"CUSTOM",
"John.doe@snaptrade.com",
"USERSECRET123",
"accountId_example"
);
legs: OptionLeg
[]
The ID of the account to create the option strategy object in.
/accounts/{accountId}/optionStrategy
POST
π Back to Table of Contents
Get the options chain
$result = $snaptrade->options->getOptionsChain(
"John.doe@snaptrade.com",
"USERSECRET123",
"accountId_example",
"symbol_example"
);
The ID of the account to get the options chain from.
Universal symbol ID if symbol
/accounts/{accountId}/optionsChain
GET
π Back to Table of Contents
Get latest market data of option strategy
$result = $snaptrade->options->getOptionsStrategyQuote(
"John.doe@snaptrade.com",
"USERSECRET123",
"accountId_example",
"2bcd7cc3-e922-4976-bce1-9858296801c3"
);
The ID of the account the strategy will be placed in.
Option strategy id obtained from response when creating option strategy object
/accounts/{accountId}/optionStrategy/{optionStrategyId}
GET
π Back to Table of Contents
Get the options holdings in the account
$result = $snaptrade->options->listOptionHoldings(
"John.doe@snaptrade.com",
"USERSECRET123",
"accountId_example"
);
The ID of the account to fetch options holdings for.
/accounts/{accountId}/options
GET
π Back to Table of Contents
Place an option strategy order on the brokerage
$result = $snaptrade->options->placeOptionStrategy(
"Limit",
"FOK",
"John.doe@snaptrade.com",
"USERSECRET123",
"2bcd7cc3-e922-4976-bce1-9858296801c3",
"2bcd7cc3-e922-4976-bce1-9858296801c3",
31.33
);
The ID of the account to execute the strategy in.
Option strategy id obtained from response when creating option strategy object
Trade Price if limit or stop limit order
/accounts/{accountId}/optionStrategy/{optionStrategyId}/execute
POST
π Back to Table of Contents
Return the exchange rate of a currency pair
$result = $snaptrade->referenceData->getCurrencyExchangeRatePair(
"currencyPair_example"
);
A currency pair based on currency code for example, {CAD-USD}
/currencies/rates/{currencyPair}
GET
π Back to Table of Contents
Returns useful data related to the specified ClientID, including allowed brokerages and data access.
$result = $snaptrade->referenceData->getPartnerInfo();
/snapTrade/partners
GET
π Back to Table of Contents
List security types available on SnapTrade.
$result = $snaptrade->referenceData->getSecurityTypes();
/securityTypes
GET
π Back to Table of Contents
List exchanges
$result = $snaptrade->referenceData->getStockExchanges();
/exchanges
GET
π Back to Table of Contents
Search for symbols
$result = $snaptrade->referenceData->getSymbols(
"apple"
);
/symbols
POST
π Back to Table of Contents
Get details of a symbol by the ticker or the universal_symbol_id
$result = $snaptrade->referenceData->getSymbolsByTicker(
"query_example"
);
The ticker or universal_symbol_id of the UniversalSymbol to get.
/symbols/{query}
GET
π Back to Table of Contents
List of all brokerage authorization types
$result = $snaptrade->referenceData->listAllBrokerageAuthorizationType(
"QUESTRADE,ALPACA"
);
Comma separated value of brokerage slugs
BrokerageAuthorizationTypeReadOnly
/brokerageAuthorizationTypes
GET
π Back to Table of Contents
List brokerages
$result = $snaptrade->referenceData->listAllBrokerages();
/brokerages
GET
π Back to Table of Contents
List currencies
$result = $snaptrade->referenceData->listAllCurrencies();
/currencies
GET
π Back to Table of Contents
List currency exchange rates
$result = $snaptrade->referenceData->listAllCurrenciesRates();
/currencies/rates
GET
π Back to Table of Contents
Returns a list of universal symbols that are supported by the specificied account. Returned symbols are based on the provided search string, matching on ticker and name.
$result = $snaptrade->referenceData->symbolSearchUserAccount(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631",
"apple"
);
The ID of the account to search for symbols within.
/accounts/{accountId}/symbols
POST
π Back to Table of Contents
Sends a signal to the brokerage to cancel the specified order. This will only work if the order has not yet been executed.
$result = $snaptrade->trading->cancelUserAccountOrder(
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631",
"2bcd7cc3-e922-4976-bce1-9858296801c3"
);
The ID of the account to cancel the order in.
/accounts/{accountId}/orders/cancel
POST
π Back to Table of Contents
Check impact of trades on account.
$result = $snaptrade->trading->getOrderImpact(
"John.doe@snaptrade.com",
"USERSECRET123",
"2bcd7cc3-e922-4976-bce1-9858296801c3",
"BUY",
"Limit",
31.33,
31.33,
"FOK",
3.14,
"2bcd7cc3-e922-4976-bce1-9858296801c3",
100
);
Trade Price if limit or stop limit order
Stop Price. If stop loss or stop limit order, the price to trigger the stop
units: float
notional_value: float
/trade/impact
POST
π Back to Table of Contents
Returns live quote(s) from the brokerage for the specified symbol(s).
$result = $snaptrade->trading->getUserAccountQuotes(
"John.doe@snaptrade.com",
"USERSECRET123",
"symbols_example",
"917c8734-8470-4a3e-a18f-57c3f2ee6631",
True
);
List of universal_symbol_id or tickers to get quotes for.
The ID of the account to get quotes.
Should be set to True if providing tickers.
/accounts/{accountId}/quotes
GET
π Back to Table of Contents
Place a trade with NO validation.
$result = $snaptrade->trading->placeForceOrder(
"John.doe@snaptrade.com",
"USERSECRET123",
"2bcd7cc3-e922-4976-bce1-9858296801c3",
"BUY",
"Limit",
31.33,
31.33,
"FOK",
3.14,
"2bcd7cc3-e922-4976-bce1-9858296801c3",
100
);
Trade Price if limit or stop limit order
Stop Price. If stop loss or stop limit order, the price to trigger the stop
units: float
notional_value: float
/trade/place
POST
π Back to Table of Contents
Place order
$result = $snaptrade->trading->placeOrder(
"tradeId_example",
"John.doe@snaptrade.com",
"USERSECRET123",
True
);
The ID of trade object obtained from trade/impact endpoint
Optional, defaults to true. Determines if a wait is performed to check on order status. If false, latency will be reduced but orders returned will be more likely to be of status PENDING as we will not wait to check on the status before responding to the request
/trade/{tradeId}
POST
π Back to Table of Contents
Returns activities (transactions) for a user. Specifying start and end date is highly recommended for better performance
$result = $snaptrade->transactionsAndReporting->getActivities(
"John.doe@snaptrade.com",
"USERSECRET123",
"2022-01-24",
"2022-01-24",
"917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2",
"917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2",
"DIVIDEND"
);
Optional comma seperated list of account IDs used to filter the request on specific accounts
Optional comma seperated list of brokerage authorization IDs used to filter the request on only accounts that belong to those authorizations
Optional comma seperated list of types to filter activities by. This is not an exhaustive list, if we fail to match to these types, we will return the raw description from the brokerage. Potential values include - DIVIDEND - BUY - SELL - CONTRIBUTION - WITHDRAWAL - EXTERNAL_ASSET_TRANSFER_IN - EXTERNAL_ASSET_TRANSFER_OUT - INTERNAL_CASH_TRANSFER_IN - INTERNAL_CASH_TRANSFER_OUT - INTERNAL_ASSET_TRANSFER_IN - INTERNAL_ASSET_TRANSFER_OUT - INTEREST - REBATE - GOV_GRANT - TAX - FEE - REI - FXT
/activities
GET
π Back to Table of Contents
Returns performance information (contributions, dividends, rate of return, etc) for a specific timeframe. Please note that Total Equity Timeframe and Rate of Returns are experimental features. Please contact support@snaptrade.com if you notice any inconsistencies.
$result = $snaptrade->transactionsAndReporting->getReportingCustomRange(
"2022-01-24",
"2022-01-24",
"John.doe@snaptrade.com",
"USERSECRET123",
"917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2",
True,
"monthly"
);
Optional comma seperated list of account IDs used to filter the request on specific accounts
Optional, increases frequency of data points for the total value and contribution charts if set to true
Optional frequency for the rate of return chart (defaults to monthly). Possible values are daily, weekly, monthly, quarterly, yearly.
/performance/custom
GET
π Back to Table of Contents
This PHP package is automatically generated by Konfig