PHP code example of konfig / snaptrade-php-sdk

1. Go to this page and download the library: Download konfig/snaptrade-php-sdk 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/ */

    

konfig / snaptrade-php-sdk example snippets





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

$result = $snaptrade->accountInformation->getAllUserHoldings(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    brokerage_authorizations: "917c8734-8470-4a3e-a18f-57c3f2ee6631"
);

$result = $snaptrade->accountInformation->getAllUserHoldings(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    brokerage_authorizations: "917c8734-8470-4a3e-a18f-57c3f2ee6631"
);

$result = $snaptrade->accountInformation->getUserAccountBalance(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631"
);

$result = $snaptrade->accountInformation->getUserAccountDetails(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631"
);

$result = $snaptrade->accountInformation->getUserAccountOrders(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", 
    state: "all", 
    days: 30
);

$result = $snaptrade->accountInformation->getUserAccountPositions(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631"
);

$result = $snaptrade->accountInformation->getUserHoldings(
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123"
);

$result = $snaptrade->accountInformation->listUserAccounts(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123"
);

$result = $snaptrade->accountInformation->updateUserAccount(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "accountId_example"
);

$result = $snaptrade->apiStatus->check();

$result = $snaptrade->authentication->deleteSnapTradeUser(
    user_id: "[email protected]"
);

$result = $snaptrade->authentication->getUserJWT(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123"
);

$result = $snaptrade->authentication->listSnapTradeUsers();

$result = $snaptrade->authentication->loginSnapTradeUser(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    broker: "ALPACA", 
    immediate_redirect: True, 
    custom_redirect: "https://snaptrade.com", 
    reconnect: "8b5f262d-4bb9-365d-888a-202bd3b15fa1", 
    connection_type: "read", 
    connection_portal_version: "v2"
);

$result = $snaptrade->authentication->registerSnapTradeUser(
    user_id: "snaptrade-user-123"
);

$result = $snaptrade->authentication->resetSnapTradeUserSecret(
    user_id: "snaptrade-user-123", 
    user_secret: "h81@cx1lkalablakwjaltkejraj11="
);

$result = $snaptrade->connections->detailBrokerageAuthorization(
    authorization_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123"
);

$result = $snaptrade->connections->listBrokerageAuthorizations(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123"
);

$snaptrade->connections->removeBrokerageAuthorization(
    authorization_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123"
);

$result = $snaptrade->connections->sessionEvents(
    partner_client_id: "SNAPTRADETEST", 
    user_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2", 
    session_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2"
);

$result = $snaptrade->options->getOptionStrategy(
    underlying_symbol_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    legs: [
        [
            "action" => "BUY_TO_OPEN",
            "option_symbol_id" => "SPY220819P00200000",
            "quantity" => 1,
        ]
    ], 
    strategy_type: "CUSTOM", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "accountId_example"
);

$result = $snaptrade->options->getOptionsChain(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "accountId_example", 
    symbol: "symbol_example"
);

$result = $snaptrade->options->getOptionsStrategyQuote(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "accountId_example", 
    option_strategy_id: "2bcd7cc3-e922-4976-bce1-9858296801c3"
);

$result = $snaptrade->options->listOptionHoldings(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "accountId_example"
);

$result = $snaptrade->options->placeOptionStrategy(
    order_type: "Limit", 
    time_in_force: "FOK", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    option_strategy_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    price: 31.33
);

$result = $snaptrade->referenceData->getCurrencyExchangeRatePair(
    currency_pair: "currencyPair_example"
);

$result = $snaptrade->referenceData->getPartnerInfo();

$result = $snaptrade->referenceData->getSecurityTypes();

$result = $snaptrade->referenceData->getStockExchanges();

$result = $snaptrade->referenceData->getSymbols(
    substring: "apple"
);

$result = $snaptrade->referenceData->getSymbolsByTicker(
    query: "query_example"
);

$result = $snaptrade->referenceData->listAllBrokerageAuthorizationType(
    brokerage: "QUESTRADE,ALPACA"
);

$result = $snaptrade->referenceData->listAllBrokerages();

$result = $snaptrade->referenceData->listAllCurrencies();

$result = $snaptrade->referenceData->listAllCurrenciesRates();

$result = $snaptrade->referenceData->symbolSearchUserAccount(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", 
    substring: "apple"
);

$result = $snaptrade->trading->cancelUserAccountOrder(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", 
    brokerage_order_id: "2bcd7cc3-e922-4976-bce1-9858296801c3"
);

$result = $snaptrade->trading->getOrderImpact(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    action: "BUY", 
    order_type: "Limit", 
    price: 31.33, 
    stop: 31.33, 
    time_in_force: "FOK", 
    units: 3.14, 
    universal_symbol_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    notional_value: 100
);

$result = $snaptrade->trading->getUserAccountQuotes(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    symbols: "symbols_example", 
    account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", 
    use_ticker: True
);

$result = $snaptrade->trading->placeForceOrder(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    account_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    action: "BUY", 
    order_type: "Limit", 
    price: 31.33, 
    stop: 31.33, 
    time_in_force: "FOK", 
    units: 3.14, 
    universal_symbol_id: "2bcd7cc3-e922-4976-bce1-9858296801c3", 
    notional_value: 100
);

$result = $snaptrade->trading->placeOrder(
    trade_id: "tradeId_example", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    wait_to_confirm: True
);

$result = $snaptrade->transactionsAndReporting->getActivities(
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    start_date: "2022-01-24", 
    end_date: "2022-01-24", 
    accounts: "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2", 
    brokerage_authorizations: "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2", 
    type: "DIVIDEND"
);

$result = $snaptrade->transactionsAndReporting->getReportingCustomRange(
    start_date: "2022-01-24", 
    end_date: "2022-01-24", 
    user_id: "[email protected]", 
    user_secret: "USERSECRET123", 
    accounts: "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2", 
    detailed: True, 
    frequency: "monthly"
);
json
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/passiv/snaptrade-php-sdk.git"
    }
  ],
  "