Skip to content

Repository files navigation

SnapTrade CLI

snaptrade is the quickest way to get started with the SnapTrade API. Link your own brokerage accounts, manage your portfolios, and execute live trades all from the command line!

🚀 Quick Start

Install the CLI globally using npm:

npm install -g @snaptrade/snaptrade-cli

Then run the CLI:

snaptrade

When you run snaptrade <command> for the first time, the CLI asks how you want to authenticate:

  • Personal SnapTrade account: sign in with SnapTrade OAuth in your browser, or enter your SnapTrade client ID and consumer key. OAuth sign-in requests openid profile email read trade and stores refreshable browser tokens locally. Personal client ID and consumer key profiles store only those credentials; the CLI does not register or save a SnapTrade user for them.
  • Commercial SnapTrade account: enter your SnapTrade client ID and consumer key. The CLI stores those credentials locally and creates a SnapTrade user when needed.

Image


Once authentication is set, call snaptrade connect to connect a new account. For Commercial client ID and consumer key profiles, this will register a new SnapTrade user if one does not exist yet. For Personal OAuth and Personal client ID and consumer key profiles, the CLI uses the authenticated Personal user implicitly. In all cases, the command opens the Connection Portal in your default browser. Pick a broker of your choice to finish the connection process. If you don't have/want to use a live account, you can register an Alpaca paper account with just an email and choose Alpaca Paper in the Connection Portal.

Note

New Personal OAuth sign-ins request trade alongside identity and read scopes. SnapTrade may grant fewer scopes than requested; snaptrade status shows those confirmed in the token response. Existing read-only OAuth profiles will open browser consent again before a trading command. Trading also requires a brokerage connection and account with trading access; the CLI checks the OAuth grant before sending an order.

Image

Image

Image


To see which brokers are supported along with whether trading is enabled, you can run snaptrade brokers.

Note

To see the latest broker support and capabilities, please refer to this Notion page.

Image

You can also specify the broker directly with snaptrade connect --broker <broker slug> to skip the broker selection step of the Connection Portal.

Image


Use snaptrade status to check the active profile. Personal OAuth profiles show the authenticated SnapTrade email, saved OAuth scopes, and whether those scopes include trade. Personal client ID and consumer key profiles show the client ID and credential status. Commercial profiles show the SnapTrade user, client ID, credential status, and trading access.

Run snaptrade logout to sign out of the active Personal OAuth profile. The CLI attempts to revoke its tokens, clears its locally stored OAuth credentials, and keeps the profile for a later sign-in. The next authenticated command will prompt you to sign in again.

Profiles are managed with snaptrade profiles:

  • snaptrade profiles list shows each local profile and its authentication mode.
  • snaptrade profiles use <name> switches to a profile, creating it locally if needed.
  • snaptrade profiles delete <name> deletes a local profile. For Personal OAuth profiles, the CLI attempts to revoke the stored OAuth tokens before removing the profile.

Once connected, call snaptrade connections to list all current connections.

Image

and snaptrade accounts to list all connected accounts.

Image


Use snaptrade positions to list all positions for an account. You'll be prompted to select an account first. Image Image

or snaptrade positions --all to list all positions across all accounts.

Image


To submit an equity order, use snaptrade trade equity. It'll prompt you for confirmation before continuing.

You can pass --useLastAccount to skip the account selector and use the previously selected account instead.

Note

A free key does not have access to trading at the moment. Please reach out to sales@snaptrade.com to discuss your trading usecase.

Image


To submit a multi-leg option order, use snaptrade trade option. It'll prompt you for confirmation before continuing.

Image


Once the order is submitted successfully, you have the option to cancel it if it hasn't been filled by the broker. You can find the broker order ID in the response:

Image

To submit a cancellation request, use snaptrade cancel-order. It'll prompt you for confirmation before continuing.

Image


To see a list of all your recent orders, including the one you just placed, use snaptrade orders.

Image


This concludes the quick start guide. Check out our documentation for more information.

📚 Commands

Usage: snaptrade [options] [command]

CLI tool to interact with SnapTrade API

Options:
  -V, --version              output the version number
  --useLastAccount           Use the last selected account for account specific commands (default: false)
  --verbose                  Enable verbose output (default: false)
  -h, --help                 display help for command

Commands:
  status                     Get current status of your SnapTrade authentication
  logout                     Sign out of the active Personal OAuth profile
  brokers                    List all brokers available to connect
  connect [options]          Establish a new broker connection
  reconnect [connectionId]   Re-establish an existing disabled connection
  disconnect [connectionId]  Remove an existing broker connection
  connections                List all broker connections
  accounts                   List all connected accounts
  positions [options]        List all positions for a given account
  recent-orders              List the most recent orders (within last 24 hours) for a given account
  orders                     List all orders for a given account
  instruments                Get a list of available instruments from a broker
  quote [symbols]            Get the latest market quote
  trade [options]            Execute different types of trades (equity, options, crypto)
  cancel-order [options]     Cancel an existing order
  profiles                   Manage SnapTrade CLI profiles
  help [command]             display help for command

☕️ Development

You need the following before getting started:

  • mise - manages the project specific node version

To run the cli locally:

npm install
npm link
snaptrade

To release a new version, run npm run release

About

SnapTrade's official command line tool

Resources

Stars

30 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages