Skip to main content

Client for SnapTrade

Project description

snaptrade-python-sdk@10.23.0

Connect brokerage accounts to your app for live positions and trading

Requirements

Python >=3.7

Installing

pip install snaptrade-python-sdk==10.23.0

Getting Started

import os
import uuid
from pprint import pprint
from snaptrade_client import SnapTrade

# 1) Initialize a client with your clientID and consumerKey.
snaptrade = SnapTrade(
    consumer_key=os.environ["SNAPTRADE_CONSUMER_KEY"],
    client_id=os.environ["SNAPTRADE_CLIENT_ID"],
)

# 2) Check that the client is able to make a request to the API server.
api_response = snaptrade.api_status.check()
pprint(api_response.body)

# 3) Create a new user on SnapTrade
user_id = str(uuid.uuid4())
register_response = snaptrade.authentication.register_snap_trade_user(
    body={"userId": user_id}
)
pprint(register_response.body)

# Note: A user secret is only generated once. It's required to access
# resources for certain endpoints.
user_secret = register_response.body["userSecret"]

# 4) Get a redirect URI. Users will need this to connect
# their brokerage to the SnapTrade server.
redirect_uri = snaptrade.authentication.login_snap_trade_user(
    query_params={"userId": user_id, "userSecret": user_secret}
)
print(redirect_uri.body)


snaptrade.portfolio_management.create(
    query_params={"userId": user_id, "userSecret": user_secret},
    body={"id": str(uuid.uuid4()), "name": "MyPortfolio"},
)
res = snaptrade.portfolio_management.list(
    query_params={"userId": user_id, "userSecret": user_secret}
)
pprint(res.body)

# 5) Obtaining account holdings data
holdings = snaptrade.account_information.get_all_user_holdings(
    query_params={"userId": user_id, "userSecret": user_secret}
)
pprint(holdings.body)

# 6) Deleting a user
deleted_response = snaptrade.authentication.delete_snap_trade_user(
    query_params={"userId": user_id}
)
pprint(deleted_response.body)

Async

async support is available by prepending a to any method.

import asyncio
from pprint import pprint
from snaptrade_client import SnapTrade, ApiException

snaptrade = SnapTrade(
    # Defining the host is optional and defaults to https://api.snaptrade.com/api/v1
    # See configuration.py for a list of all supported configuration parameters.
    host="https://api.snaptrade.com/api/v1",
    consumer_key="YOUR_CONSUMER_KEY",
    client_id="YOUR_CLIENT_ID",
)


async def main():
    try:
        # List all accounts for the user, plus balances and positions for each account.
        get_all_user_holdings_response = await snaptrade.account_information.aget_all_user_holdings(
            user_id="John.doe@snaptrade.com",  # required
            user_secret="USERSECRET123",  # required
            brokerage_authorizations="917c8734-8470-4a3e-a18f-57c3f2ee6631",  # optional
        )
        pprint(get_all_user_holdings_response.body)
        pprint(get_all_user_holdings_response.body["account"])
        pprint(get_all_user_holdings_response.body["balances"])
        pprint(get_all_user_holdings_response.body["positions"])
        pprint(get_all_user_holdings_response.body["total_value"])
        pprint(get_all_user_holdings_response.headers)
        pprint(get_all_user_holdings_response.status)
        pprint(get_all_user_holdings_response.round_trip_time)
    except ApiException as e:
        print(
            "Exception when calling AccountInformationApi.get_all_user_holdings: %s\n"
            % e
        )
        pprint(e.body)
        pprint(e.headers)
        pprint(e.status)
        pprint(e.reason)
        pprint(e.round_trip_time)


asyncio.run(main())

Documentation for API Endpoints

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

Class Method HTTP request Description
AccountInformationApi get_all_user_holdings get /holdings List all accounts for the user, plus balances and positions for each account.
AccountInformationApi get_user_account_balance get /accounts/{accountId}/balances Get all cash balances of an investment account
AccountInformationApi get_user_account_details get /accounts/{accountId} Return details of a specific investment account
AccountInformationApi get_user_account_orders get /accounts/{accountId}/orders Get all history of orders placed in account
AccountInformationApi get_user_account_positions get /accounts/{accountId}/positions Get all positions of an investment account
AccountInformationApi get_user_holdings get /accounts/{accountId}/holdings List balances, positions and orders for the specified account.
AccountInformationApi list_user_accounts get /accounts List all investment accounts for the user
AccountInformationApi update_user_account put /accounts/{accountId} Update details of an investment account
APIStatusApi check get / Get API Status
AuthenticationApi delete_snap_trade_user delete /snapTrade/deleteUser Delete user from SnapTrade, disabling all brokerage authorizations and permanently deleting all data associated with the user
AuthenticationApi get_user_jwt get /snapTrade/encryptedJWT Obtains an encrypted JWT tokens that should be decrypted on a user's local device
AuthenticationApi list_snap_trade_users get /snapTrade/listUsers Get a list of all SnapTrade users you've registered on our platform
AuthenticationApi login_snap_trade_user post /snapTrade/login Generate a redirect URI to securely login a user to the SnapTrade Connection Portal
AuthenticationApi register_snap_trade_user post /snapTrade/registerUser Register user with SnapTrade in order to create secure brokerage authorizations
ConnectionsApi detail_brokerage_authorization get /authorizations/{authorizationId} Get detail of a specific brokerage authorizations for the user
ConnectionsApi list_brokerage_authorizations get /authorizations List all brokerage authorizations for the user
ConnectionsApi remove_brokerage_authorization delete /authorizations/{authorizationId} Remove a brokerage authorization.
ConnectionsApi session_events get /sessionEvents List all session events for the partner
ErrorLogsApi list_user_errors get /snapTrade/listUserErrors Retrieve error logs on behalf of your SnapTrade users
OptionsApi get_option_strategy post /accounts/{accountId}/optionStrategy Creates an option strategy object that will be used to place an option strategy order
OptionsApi get_options_chain get /accounts/{accountId}/optionsChain Get the options chain
OptionsApi get_options_strategy_quote get /accounts/{accountId}/optionStrategy/{optionStrategyId} Get latest market data of option strategy
OptionsApi list_option_holdings get /accounts/{accountId}/options Get the options holdings in the account
OptionsApi place_option_strategy post /accounts/{accountId}/optionStrategy/{optionStrategyId}/execute Place an option strategy order on the brokerage
ReferenceDataApi get_currency_exchange_rate_pair get /currencies/rates/{currencyPair} Return the exchange rate of a currency pair
ReferenceDataApi get_partner_info get /snapTrade/partners Get metadata related to Snaptrade partner
ReferenceDataApi get_security_types get /securityTypes List of all security types.
ReferenceDataApi get_stock_exchanges get /exchanges Return list of stock exchanges on Passiv and their suffixes
ReferenceDataApi get_symbols post /symbols Search for symbols
ReferenceDataApi get_symbols_by_ticker get /symbols/{ticker} Get details of a symbol by the ticker
ReferenceDataApi list_all_brokerage_authorization_type get /brokerageAuthorizationTypes List of all brokerage authorization types
ReferenceDataApi list_all_brokerages get /brokerages List of all brokerages.
ReferenceDataApi list_all_currencies get /currencies List of all supported currencies
ReferenceDataApi list_all_currencies_rates get /currencies/rates Return the exchange rates of all supported currencies
ReferenceDataApi symbol_search_user_account post /accounts/{accountId}/symbols Search for symbols that are supported by a brokerage account using a substring
TradingApi cancel_user_account_order post /accounts/{accountId}/orders/cancel Cancel open order in account
TradingApi get_order_impact post /trade/impact Check impact of trades on account.
TradingApi get_user_account_quotes get /accounts/{accountId}/quotes Get symbol quotes
TradingApi place_force_order post /trade/place Place a trade with NO validation.
TradingApi place_oco_order post /trade/oco Place a OCO (One Cancels Other) order
TradingApi place_order post /trade/{tradeId} Place order
TransactionsAndReportingApi get_activities get /activities Get transaction history for a user
TransactionsAndReportingApi get_reporting_custom_range get /performance/custom Get performance information for a specific timeframe

Documentation For Models

Author

This Python package is automatically generated by Konfig

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snaptrade_python_sdk-10.23.0.tar.gz (185.4 kB view hashes)

Uploaded Source

Built Distribution

snaptrade_python_sdk-10.23.0-py3-none-any.whl (711.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page