You've successfully subscribed to Alpaca Resources
Great! Next, complete checkout for full access to Alpaca Resources
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.
  • Home
  • We're hiring
  • Forum
  • Docs
  • Log in
  • Sign up
Use Cases

Agora: A Terminal-Based Market App Implementing the Alpaca API

Bob Walker
Bob Walker

Introduction

Agora is a NodeJS command-line application for market data and trading. It is designed to provide node developers with a visualization tool and analytical framework for financial information and algorithmic trading. Agora is currently in beta development and contributions are welcome.

HP4k1h5/agora
a command-line ui for market data and algo management. currently integrates with iexcloud for stock charts 💹 and market data 🗃, and alpaca 🦙 for trading. - HP4k1h5/agora

Agora uses Alpaca as a broker for the trading api. Alpaca provides a free, robust trading api that includes paper trading keys for testing code and algorithmic strategies against live market data. If you have a funded Alpaca account, you are also able to access polygon.io data for free.

Alpaca - Commission-Free API First Stock Brokerage
Alpaca is a modern platform for trading. Alpaca’s API is the interface for your trading algorithms, bots, or applications to communicate with Alpaca’s brokerage and other services.
Polygon.io - Stock Market Data APIs
Free stock data APIs. Real time and historical data, unlimited usage, tick level and aggregate granularity, in standardized JSON and CSV formats. Plus currencies data, including forex, crypto, and more.

This app currently uses iexcloud for most data requests. If you would like to use a different data broker you can clone the app and swap out the data calls and data shapers. Soon Agora will offer a variety of data solutions, including polygon.io data, out-of-the-box, but in the meantime you will likely need a free iexcloud API key to get the most out of Agora.

IEX Cloud | Financial Data Infrastructure
IEX Cloud is a financial data infrastructure platform that connects developers and financial data creators.

There is a tutorial available to help you get up and running.

screenshot of a terminal window displaying a stock chart, active gainers/losers, and stock related news

Here is a screenshot of a terminal window displaying a stock chart, active gainers/losers, and stock related news.


Motivations

API Choices:

The primary motivation for starting development on this app with this combination of market data and trading broker is that both can be used almost unlimitedly for free, and offer professional quality tools at a layman’s price (free). Additionally both scale well with ambition; a developer can use the same code for paper trading and for live accounts and have reasonable assurances that the algorithm will perform as expected.

It takes roughly 5 minutes and zero credit cards to sign-up for these two APIs and plug in two API keys (see README), and I wanted a maximum of simplicity in setup requirements for this app.

HP4k1h5/agora
a command-line ui for market data and algo management. currently integrates with iexcloud for stock charts 💹 and market data 🗃, and alpaca 🦙 for trading. - HP4k1h5/agora

Language Choice:

In comparison to python or other traditionally math-y languages, NodeJS has fewer tools available and a smaller community of enthusiasts and professionals who use it as their primary driver to manipulate, shape, and work with financial data.

Node.js
Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.

However, there are a growing number of math/algorithm libs for the node ecosystem and node’s network utilities are handy when basically all data is coming in off the wire.  Node’s async behavior is great for handling large/rapid data request volumes, and v8 delivers enough speed for most everything but extremely high frequency trading.

I wanted to offer node devs a convenient, terminal-based approach to financial algorithm development. I hope that the current set of features offers a stable enough environment for node developers to rapidly develop trading or signals bots, and enough of an idea of where the app is headed, to encourage some PRs and community contribution.


Uses:

Agora may be useful to anyone who is comfortable in the terminal and with node apps in general who wishes to have node-native access to financial market data. The app tries to make it relatively easy to hack your stock-terminal, starting with a robust config setup.

screenshot of a terminal window displaying a stock chart, active gainers/losers, and stock related news

Here is another screenshot of a terminal window displaying trading and bot-related information.

Ultimately, Agora may serve NodeJS fin-algo developers best. One advantage to running in the terminal is that other processes can be started and stopped natively, and you have full access to i/o functions that might otherwise be more cumbersome in a browser environment.

Eventually, the bot functions you write should be fully exportable to a remote server and Agora will offer the same integration capabilities, including monitoring, visualization, etc., that are available currently with a local provisioning setup.


Bots:

In a future article, I would like to get into what it takes to make an algo bot with Alpaca API and Agora in more detail. There is a short bots README, and a well-documented example bot.

For now I will conclude with some thoughts on why algo trading is such a powerful mode when compared with executing manual trades, even especially, for newer market participants, with less experience and knowledge in financial markets.

All traders and investors are limited to what they understand about the market. Their understanding is informed by all the data, information, news, signals they process. While many traders develop an overall sense of awareness of where the market is, and “what the market is doing”, this is often wrong, or just about to be wrong. When it is wrong, not all traders are able to assess why their understanding was wrong.

By comparison, a computer program can intake a billion times more data and analyze it a trillion times faster. It can work all night and all day and find opportunities that no team could discover. It can self-analyze and even improve. Whether you are a seasoned trader or a paper-trader, the advantages of algorithmic trading are vast.

Many professional traders recommend keeping a trade journal, where all the types of things mentioned above are logged, e.g.

  • Why did you trade that stock?
  • What were your entry/exit thresholds?
  • How are you scanning for opportunities?

This is the beginning of a scientific approach to the market. For many market participants, their strategy may be based on nothing more than pure intuition, though that intuition may be informed by an abundance of theory, practical advice, or even experiential “knowledge”. Their strategy may invoke a host of technical indicators and charts and even algorithmic processes, but the decisions they make as investors are still based entirely on intuition, unless they are able to scientifically document a process that should guarantee certain results, or provide indications as to why those guarantees were not met.

All the things that make great traders great can actually be built, piece-by-piece, into robust, secure, testable and profitable algorithms. Already there have been large shifts in trading behavior from Wall Street to Main Street, and soon, more and more people will be eager to develop these types of provable, highly-adaptable robots, that put ideas into code and code into practice.

Prior to beginning work on some simple algo-bots, I had never felt any confidence in my trading decisions, regardless of how much research I put into them. Algorithmic trading offers no greater guarantees about the effectiveness of my ideas, but I can measure them and have a much better idea, over time of what is working.


Roadmap:

There is a mostly up-to-date roadmap available on GitHub. In the short term, there are some upcoming bots-oriented minor versions to be pushed, which include loggers and some very early-development backtesting functionalities. There are also a large number of basic features that many users are probably hoping for, including better Alpaca watchlist management, stock screener capabilities, more in depth holding analysis and indices data. Most of these are in development or will be out soon. I encourage you to submit a PR on GitHub.

I hoped everyone enjoyed Part 1 of Agora: A Terminal-Based Market App Implementing the Alpaca API.  There is a Part 2 of this article series planned where I will focus on specifically using bots and algorithmic trading with both Agora and the Alpaca API.


Follow @AlpacaHQ on Twitter!

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.

Use CasesCode Examples

Bob Walker

interested in markets, linguistics, and computer science