This blog was last updated on November 12, 2024.
Before You Begin…
- Sign Up for a Trading API account: In order to follow this guide, you will need to have an Alpaca Trading API account. If you don’t have an account, sign up now. Alpaca’s Trading API provides commission-free trading* as well as features like paper trading. No real money is necessary!
- Download Postman and sign up for an account. Postman is a popular API testing and development tool. It’s free to sign up and use.
- Take a look at Alpaca’s API Documentation and have it open for reference.
Getting your API Keys
Once you’ve signed up for a Trading API account, you can generate your API Keys. Be sure to take note of both your API Key and Secret Key and save them somewhere private.
Note: Once you navigate away from this page or refresh, your Secret Key will disappear. You can always regenerate your keys, however, this will cause your old keys to expire and will require you to reconfigure your connection, so be careful!
After you’ve received your keys, you can set up Alpaca’s Paper Trading, allowing you to test various trading strategies or integrations without using real money! Every account comes with unlimited paper trading, so you can get started without worrying about starting capital.
Note: Everything documented in the steps below is a guide on using Alpaca’s Paper Trading in connection with Postman’s interface. It should not be seen as trading advice or a recommendation.
Setting Up Postman
Now that you have your keys ready, open up the Postman application. If this is your first time opening the app, you should see a page similar to this.
To initiate your first API request, click the “Send an API request” or click the “+” tab under the “Search Postman” UI. You should see this page:
Add the following request URL to the “GET”:
https://paper-api.alpaca.markets/v2/account
This link is called the endpoint. But don’t click send right away!
Instead, click the “Headers” section and add two keys called APCA-API-KEY-ID and APCA-API-SECRET-KEY. Enter in your key values in the VALUE column like the image below.
Then hit the send button, and you should see the following response.
You should be able to see various account information from this API call. Now you’re ready to trade!
Getting Asset Information
Now that you’ve made your first API call, you’re ready to make your first paper trade. In the example below, you will be buying and selling 1 share of GOOGL.
First, you’ll change the endpoint to the GOOGL asset (see image below). It’s active and tradable, so you’re ready to initiate your trade.
This can be done using our Get Asset ID Documentation, or you can simply change the endpoint in the API url to:
https://paper-api.alpaca.markets/v2/assets/GOOGL
Place Your First (Paper) Trade!
Next, you’ll be placing a market order for 1 share of GOOGL with time in force = day. To do this, change the “GET” option to “POST”. You’ll also want to change the endpoint in the API link to create an order (/v2/orders), and enter the following JSON body:
{
"side": "buy",
"type": "market",
"time_in_force": "day",
"symbol": "GOOGL",
"qty": "5"
}
Make sure that you enter your order information through a JSON message body and change the tab from “none” to “raw”. (The API does not accept orders through query params). It should look like the image below.
And there we go! You made your first order through Alpaca’s Trading API. You can even confirm that the order went through on your dashboard in real time!
You can also check your positions through Postman by using the GET v2/positions endpoint.
https://paper-api.alpaca.markets/v2/positions
Or, you can visit your positions page on your Alpaca dashboard to check all of your positions.
Closing Your Position
Now that you’ve tested opening a position (buying 1 share of GOOGL), you’re ready to sell it to close your position.
To do this, you will change “GET” to “DELETE”, and use v2/positions/GOOGL as your endpoint.
https://paper-api.alpaca.markets/v2/positions/GOOGL
Because I’m holding a long position on GOOGL, calling this endpoint will place a market sell order.
After you hit send, the following information is displayed, showing that your order has been placed, but not yet filled.
Moments later, on the “Activities” page on your Trading API account, you can see that your market sell order has been filled.
This is what your dashboard should look like. In this example, you may have lost $0.04 in fake money, but that was a fun learning experience! You should continue testing a strategy yourself in paper trading to see if and how it works before trying it in a live trading account.
Now What?
Now that you’ve tested buying and selling through Trading API’s paper trading environment, you can explore different ways to use it. This includes options trading and more! Once you get comfortable, you can even open a live trading account, where you can start implementing your algorithms with real money.
*Commission-free trading means that there are no commission charges for Alpaca self-directed individual cash brokerage accounts that trade U.S.-listed securities and options through an API. Relevant regulatory fees may apply. Commission-free trading is available to Alpaca's retail customers. Alpaca reserves the right to charge additional fees if it is determined that order flow is non-retail in nature. This does not apply to cryptocurrencies.
Alpaca Securities LLC and Postman are not affiliated, and neither are responsible for the liabilities of the other.
Please note that this article is for general informational purposes only and is believed to be accurate as of the posting date but may be subject to change. The examples and images above are for illustrative purposes only. Alpaca Crypto LLC does not recommend any specific cryptocurrencies.
Options trading is not suitable for all investors due to its inherent high risk, which can potentially result in significant losses. Please read Characteristics and Risks of Standardized Options before investing in options.
The Paper Trading API is offered by AlpacaDB, Inc. and does not require real money or permit a user to transact in real securities in the market. Providing use of the Paper Trading API is not an offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, given or in any manner endorsed by AlpacaDB, Inc. or any AlpacaDB, Inc. affiliate and the information made available through the Paper Trading API is not an offer or solicitation of any kind in any jurisdiction where AlpacaDB, Inc. or any AlpacaDB, Inc. affiliate (collectively, “Alpaca”) is not authorized to do business.
Securities brokerage services are provided by Alpaca Securities LLC ("Alpaca Securities"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.
Cryptocurrency services are made available by Alpaca Crypto LLC ("Alpaca Crypto"), a FinCEN registered money services business (NMLS # 2160858), and a wholly-owned subsidiary of AlpacaDB, Inc. Alpaca Crypto is not a member of SIPC or FINRA. Cryptocurrencies are not stocks and your cryptocurrency investments are not protected by either FDIC or SIPC. Please see the Disclosure Library for more information.
This is not an offer, solicitation of an offer, or advice to buy or sell securities or cryptocurrencies or open a brokerage account or cryptocurrency account in any jurisdiction where Alpaca Securities or Alpaca Crypto, respectively, are not registered or licensed, as applicable.