You've successfully subscribed to Alpaca Learn | Developer-First API for Crypto and Stocks
Great! Next, complete checkout for full access to Alpaca Learn | Developer-First API for Crypto and Stocks
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.
Search
Community Examples

How to Build a Trading Bot with Alpaca and Trellis

Oluebube Princess Egbuna
Oluebube Princess Egbuna

Trading experts spend time spotting market trends before placing new trade orders. With the right software, you can immediately execute a trade action once you see a pattern or trend.

In this guide, learn about Trellis, a trading bot builder, and walk through the steps of building a demo investment bot to trade stocks on your Alpaca account with our free Paper Trading API.

What is a Bot?

A bot is a software designed to perform automated and repetitive operations such as saving and monitoring data. Most bots are executed either manually by their developers or by a trigger. For financial bots, they are executed based on a trigger such as a change in an asset, or at a defined time interval.

Most trading bots are built as scripts that interact with trading APIs using programming languages such as Python, Ruby amongst others. After development, these bots can be run locally on the trader’s computer, or deployed to cloud services.

For traders without a programming background, Alpaca provides a third-party integration with Trellis for building investment bots.

Introducing Trellis, a no-code bot builder

Trellis is a bot building platform that leverages the Alpaca APIs and aims to simplify the process of building an investment bot. Instead of using programming languages, Trellis offers a visual editor within the web-based dashboard for your Trellis account.

Triggers tell your Trellis bot when to perform a buy or sell action. Each trading strategy consists of these triggers, made up of a conditional statement written in plain English, and is evaluated to determine if the trigger should be executed.

To eliminate development costs, Trellis offers a free plan to use the Alpaca Paper Trading API when building your first bot. You can upgrade your Trellis account to the premium plan to have your bot trade with Alpaca Broker API.

Building your first bot

Now that you have an understanding of Trellis, let’s put your knowledge to use by building an investment bot that will trade Amazon.com (AMZN) stocks.  

To get started, create an account or login to an existing Trellis account through your web browser.

Note: You will need to verify your Trellis email address after creating a new account.

  1. Click the Create new bot button from your Trellis dashboard to create your first bot.

2. Select a ticker for your Trellis bot to trade. A ticker contains the changes in price of a stock security. When creating a trellis bot, you have over forty tickers to select from.


3. Provide a name for your bot, specify a trading interval, and allocate an amount of fake money to be traded with.

To have your bot trade with real money, click the checkbox and connect your bot with Alpaca Broker API.


4. Select the Simple Moving Average Crossover (SMAC) template to use an already-made trading strategy.  The SMAC template uses the average price of a security across 50 days to determine if there is a bull or bear momentum with the security.

5. Confirm the condition for the buy trigger to be evaluated by your bot before buying AMZN stocks. The SMAC template provides a predefined buy trigger for your bot.  

Clicking the AND button will add an additional trigger to your investment bot. The OR button will add a buy trigger executed when the moving avg of AMZN across 50 days is below  the moving avg of AMZN across 200 days.


6. Confirm the condition for the sell trigger to be evaluated by your bot before selling your purchased AMZN stocks. The SMAC provides a predefined sell trigger for your bot.  

To trade safely, click the checkbox and specify your desired number of shares to be sold when the sell trigger is executed.


7. Click the Deploy Bot button to save your changes and make your first bot go live.

Insights From Your Trading Bot

Notification Channels

Trellis provides a feature to integrate either Slack, mobile SMS, or email to receive a notification for each trading activity of your bot.

Click on your desired notification channel to get started with the integration process.


Trading Performance

The performance page displays how much money is left and the margins from your bot’s trades. All trades conducted at an interval will be used to populate the performance graph.


And there you have it! With your first investment bot created, all you need to do is to add more buy or sell triggers as you deem fit.


Disclosures  

Alpaca Securities LLC (“Alpaca Securities”) and Trellis Technologies, LLC (“Trellis”) are not affiliated and neither is responsible for the liabilities of the other.

Please note that this article is for educational and informational purposes only. All screenshots are for illustrative purposes only. Alpaca does not recommend any specific securities or investment strategies.

All investments involve risk and the past performance of a security, or financial product does not guarantee future results or returns. Keep in mind that while diversification may help spread risk it does not assure a profit, or protect against loss, in a down market. There is always the potential of losing money when you invest in securities, or other financial products. Investors should consider their investment objectives and risks carefully before investing.

Alpaca does not prepare, edit, or endorse Third Party Content. Alpaca does not guarantee the accuracy, timeliness, completeness or usefulness of Third Party Content, and is not responsible or liable for any content, advertising, products, or other materials on or available from third party sites.

Brokerage services are provided by Alpaca Securities LLC ("Alpaca"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.

This is not an offer, solicitation of an offer, or advice to buy or sell securities, or open a brokerage account in any jurisdiction where Alpaca Securities is not registered (Alpaca is registered only in the United States).

Community Examples