Event-Driven APIs in Financial Markets

Dakshitha Ratnayake
4 min readDec 23, 2020

--

Image source : http://bizweek.mu/fr/info/stock-market-will-there-be-santa-rally-2018

In December 2020, stock markets have risen to record levels. Investors are optimistic about a COVID-19 vaccine rolling out in a big way with the FDA approving Pfizer’s COVID-19 vaccine for emergency use. But the surge in COVID-19 cases raises the potential for further lockdowns. Holiday sales usually make up a significant portion of annual retail sales but with lockdowns and increasing unemployment rates, stock markets will have to watch just how cheerful consumers are feeling this holiday season.

Consequently, stocks will be affected, and investors will be updated about the negatively or positively affected stocks that matter to them. They usually subscribe to a market information provider or are notified via their trading platform to receive (near) real-time updates. Let’s take a look at the role of event-driven APIs in online trading and related application platforms so that their end-users, i.e., investors, are well-informed (near) real-time.

Event-driven APIs (also known as streaming APIs or asynchronous APIs) are APIs that give you the flexibility to subscribe to a backend event that you’re interested in and be notified when that event occurs, or start a job that may take some time to complete and be notified when the long-running job has been completed. Analysts predict that in the next 2–5 years, 50% of APIs will be event-based. Why? Overall, event-driven systems are efficient. In event-driven systems, everything is loosely-coupled. Consumers don’t have to know about the event producers they are consuming data from — they just care about what data they are consuming. This also allows the consumers to scale independently of the producers. Also, being event-driven is about moving towards real-time and being reactive to change instead of polling backend systems for changes, which is inefficient and leads to resource wastage.

Use Cases

The ubiquitous scrolling stock ticker on financial websites is a case in point. The ticker provides current information for stocks: quantity traded, price, a green ‘up’ arrow if the price is higher than the previous day’s closing value, a red ‘down’ arrow if the price is lower, and the net price change. Watching the ticker can help investors gauge overall market sentiment at any moment. It’s fed with data through asynchronous APIs.

High-frequency trading applications rely on ultra real-time information and algorithms to the order of milliseconds and therefore require specialized hardware; they don’t rely on web APIs. However, API-based front-end trading applications can usually talk to a combination of RESTful and streaming APIs that provide market data, order management, and risk information sourced by the backend or external providers. This information allows the apps to perform tasks like determine whether a buy or sell order should be created for a specific stock whenever it has reached a predetermined price or notify subscribers, i.e., investors. Similarly, performance dashboards and other applications can make use of incoming data from the streaming APIs to visualize graphs, analyze trends, make informed decisions, update UI components, and fire related events reactively.

Figure 1 — Event-driven APIs pushing market data to front-end applications via WebSockets or Server-Sent Events (SSE)

Consuming and Building Event-Driven APIs

So, if you are building such front-end applications, your application should subscribe to relevant asynchronous APIs that allow your end-users to receive near real-time financial market data. For example, an SSE-based, financial streaming API can be found here. Here’s another one based on WebSockets.

And if you want to provide financial market data APIs to web, mobile or desktop apps, you must expose streaming APIs, which should be sourced by integrating information from various exchanges (NYSE, AMEX, NASDAQ, etc.), market data aggregators or/and ECN brokers. With the rise of Internet-based online trading, stock exchanges started to provide quotes to the public which vary in speed and the amount of information available. Real-time quotes and additional information will come at an additional cost. Reuters, for example, provides quite a bit of financial information, but its stock quotes lag the market by at least 15 minutes. Financial news services, on the other hand, often offer real-time quotes as a premium subscription service. Such API providers usually expose Server-Sent Events or WebSocket APIs to easily push data to front-end applications with real-time quotes and trading updates. These APIs are generally managed by an API management solution that can secure, monitor, govern and monetize them.

For more detailed information about creating event-enabled API architectures with asynchronous API technologies (such as WebSockets and Server-Sent Events) and API management platforms, read this whitepaper written by me. PRs are welcome and if you like what you see, please don’t forget to star us :) !

--

--

Dakshitha Ratnayake
Dakshitha Ratnayake

Written by Dakshitha Ratnayake

Tech Evangelist | Developer Advocate | Sri Lanka

No responses yet