This tutorial will be a step by step demonstration of connecting to OAuth using the Alpaca API. We will move forward assuming that you’ve registered on the Alpaca website. If you haven’t please visit Alpaca and sign up. Feel free to check out the other tutorials in this series at Alpaca Resources.
Alpaca implements OAuth 2.0 to allow third party applications to access Alpaca Trading API on behalf of the end-users. This document describes how you can integrate with Alpaca through OAuth.
Let’s Create a New OAuth app at the OAuth page in your account.
Enter the information for the app. Note all OAuth apps need to be approved by Alpaca before they can execute trades on behalf of users.
As soon as you create the app, you will be issued your Client ID and Client Secret ID. These can be found by clicking “View App Credentials”.
To integrate your application with Alpaca, use the following flow:
When redirecting a user to Alpaca to authorize access to your application, you’ll need to construct the authorization URL with the correct parameters and scopes. Here’s a list of parameters you should always specify:
You will see an authorization screen. Once you approve access Alpaca will redirect you back to your
redirect_uri with a temporary
code parameter. If you specified a state parameter in step 1, it will be returned as well. The parameter will always match the value specified in step 1.
Your application will receive the authorization code, which can be used to exchange for an access token by making a POST request. If your app is meant for funded accounts you would use the
api.alpaca.markets endpoint vs. the
paper-api.alpaca.markets endpoint for paper trading
Once you have integrated and have a valid access token you can start making calls to Alpaca Trading API v2 on behalf of the end-user.
Thank you for using Alpaca. Here are a couple more links that you might be interested in.
Sign up for the weekly newsletter to keep up with the API updates and upcoming competitions, job opportunities by clicking here.
Commission-Free trading means that there are no commission charges for Alpaca self-directed individual cash brokerage accounts that trade U.S. listed securities through an API. Relevant SEC and FINRA fees may apply.
Alpaca Learn | Developer-First API for Crypto and Stocks Newsletter
Join the newsletter to receive the latest updates in your inbox.