How-To
Welcome to the how-to section of our documentation! Here, you’ll find some examples of how to do specific tasks using the Alpaca API in supported programming languages.
Before running these examples, it is recommended that you set the following environment variables to the corresponding values found on your dashboard. Please be aware of whether you’re using the values for your paper trading account or for your live trading account.
APCA_API_BASE_URL
APCA_API_KEY_ID
APCA_API_SECRET_KEY
On Linux, this can be done with export ENV_VAR_NAME=DASHBOARD_VALUE
. (You’ll probably want to add them to
your ~/.bash_profile
so they stay set when the machine restarts.) On Windows, you can instead
use setx ENV_VAR_NAME "DASHBOARD_VALUE"
. After running these commands, you’ll want to open a new command
prompt window so the variables are available.
View Account Information By sending a GET request to our /v2/account endpoint, you can see various information about your account, such as the amount of buying power available or whether or not it has a PDT flag. C# !function() { let currentTab = window.parent.document.getElementById(“accountInfo.csharp”); currentTab.onclick = function () { changeExamplesTab(“accountInfo”, “accountInfo.csharp”) }; }() Go !function() { let currentTab = window.parent.document.getElementById(“accountInfo.go”); currentTab.onclick = function () { changeExamplesTab(”
Get a List of Assets If you send a GET request to our /v2/assets endpoint, you’ll receive a list of US equities. C# !function() { let currentTab = window.parent.document.getElementById(“listAssets.csharp”); currentTab.onclick = function () { changeExamplesTab(“listAssets”, “listAssets.csharp”) }; }() Go !function() { let currentTab = window.parent.document.getElementById(“listAssets.go”); currentTab.onclick = function () { changeExamplesTab(“listAssets”, “listAssets.go”) }; }() Javascript !function() { let currentTab = window.parent.document.getElementById(“listAssets.js”); currentTab.onclick = function () { changeExamplesTab(”
See if the Market is Open With GET requests to our /v2/calendar and /v2/clock endpoints, you can check if the market is open now, or view what times the market will be open or closed on a particular date. C# !function() { let currentTab = window.parent.document.getElementById(“marketHours.csharp”); currentTab.onclick = function () { changeExamplesTab(“marketHours”, “marketHours.csharp”) }; }() Go !function() { let currentTab = window.parent.document.getElementById(“marketHours.go”); currentTab.onclick = function () { changeExamplesTab(”
Alpaca provides market data from various sources. To learn more about data options and which one is right for you, please see this page. Get Historical Price and Volume Data By making a GET request to our /v1/bars endpoint, you can see what a stock price was at a particular time. C# !function() { let currentTab = window.parent.document.getElementById(“getPrices.csharp”); currentTab.onclick = function () { changeExamplesTab(“getPrices”, “getPrices.csharp”) }; }() Go !
This page contains examples of some of the things you can do with order objects through our API. For additional help understanding different types of orders and how they behave once they’re placed, please see the order page Place New Orders Orders can be placed with a POST request to our /v2/orders endpoint. C# !function() { let currentTab = window.parent.document.getElementById(“placeOrder.csharp”); currentTab.onclick = function () { changeExamplesTab(“placeOrder”, “placeOrder.csharp”) }; }() Go !
View Open Positions in Your Portfolio You can view the positions in your portfolio by making a GET request to our /v2/positions endpoint. If you specify a symbol, you’ll see only your position for the associated stock. C# !function() { let currentTab = window.parent.document.getElementById(“getPositions.csharp”); currentTab.onclick = function () { changeExamplesTab(“getPositions”, “getPositions.csharp”) }; }() Go !function() { let currentTab = window.parent.document.getElementById(“getPositions.go”); currentTab.onclick = function () { changeExamplesTab(”