How to deploy a currency alerting pipeline with Quix and CoinAPI
How to build a powerful currency alerting pipeline in a few minutes with Quix and CoinAPI.
How to Deploy a Simple Currency Alerting Pipeline that uses CoinAPI
While it’s easy to write an app that does useful things with crypto market data, it can involve a bit of tedious busy work. For example, once you’ve programmed all required steps, you’ll need to find a way to securely deploy and host your app. Luckily, there are a few platforms out there that aim to simplify this part of the process.
Today, we’re going to look at a tool that specializes in helping developers and data engineers deploy real-time data apps and pipelines. (That's Quix, in case you were wondering 😉) It's a pretty handy tool if you’re working with any kind of volatile market data.
To help you understand how it works, let’s look at a very simple use case that leverages CoinAPI market data: an alerting app that sends an SMS when the price of Bitcoin crosses a specific threshold.
To build this simple alerting app, we’ll need to code the following major functions.
- Check The Bitcoin Price
Poll the CoinAPI market data endpoint for the current Bitcoin price (no less than every 15 mins if you’re on the free plan). - Compare The Bitcoin Price With The Threshold
See if the Bitcoin price has moved beyond the target price threshold in either direction. - Trigger an external notification
Send a message to let you know that the threshold has been met (for example, using an SMS API like Twilio).
We're going to break down the steps in a bit more detail and look at how you’d create and run them within the Quix platform. But first, it’s important to clarify that in Quix, you write functions in Python (or C#) that interact with Apache Kafka.
- Why Python? The Quix platform runs on the Quix SDK, which enables you to code in Python yet easily interact with Kafka topics. Up until recently, you’d need to know your way around Java before you could work with Apache Kafka, but Quix have build their on SDK so that you code in Python and C#. It’s designed to make Apache Kafka more accessible to data scientists and engineers who are typically more proficient in Python.
- And Why Kafka? To keep it simple, this example uses our REST API, but more advanced apps often use our Websocket endpoint—which is a constant stream of data. Apache Kafka is still the industry standard for working with data streams, which is why the Quix platform also uses Kafka as its foundation.
Ok, so how would you make these functions work together in the Quix platform? Let’s look at the end result first. What you see here are the 3 functions chained together to form a simple pipeline:
We’re going to explore a quick way to build each of these functions. Bear in mind that this is not a full tutorial, rather an overview of how programs are run and deployed in Quix (we’ll link to a more detailed tutorial after the overview).
1. Polling the Market Data endpoint
Quix has an extensive library of Python code templates to bring in data from many external sources — including CoinAPI. You just need to copy the library to your workspace and give it the environment variables that it expects. These are as follows:
- The API key that you use to access CoinAPI.
- The short code for the currency that you want to track (e.g. BTC),
- The short codes of the equivalent fiat currencies (USD, GBP).
- You’re free to adapt the code however you’d like, but it’s handy to have some boilerplate to get started.
- This boilerplate code writes the market data to a preconfigured Kafka topic called “coin-data”.
2. Do the comparison
Quix’s template library also contains a handy function for checking thresholds, so you can just enter your desired threshold and connect it to the incoming price data.
- This boilerplate code reads incoming prices from the “coin-data” topic and checks to see if the threshold has been crossed.
- When the threshold is crossed, the function will write a message to the “coin-alerts” topic.
- This boilerplate code reads incoming prices from the “coin-data” topic and checks to see if the threshold has been crossed.
- When the threshold is crossed, the function will write a message to the “coin-alerts” topic.
3. Send the notification with Twilio
Naturally, Quix also has boilerplate code for accessing Twilio. In this case, you enter a few variables related to your Twilio account. Sadly, there’s no easy way to automate the Twilio account creation process, but once you have a Twilio developer account, you can just plug your account details into the Quix UI. These are then saved as environment variables.
- The Twilio boilerplate code checks for incoming messages from the “coin-alerts” topic and uses the Twilio API to send an SMS to your phone.
4. Deploying the code as serverless functions
After you’ve finished setting up each step, you click the big blue “deploy” button. Each function then runs in the Quix platform as a serverless function.
The kind of architecture that we’ve outlined here is often called a “loosely coupled” architecture. It means that the different parts are not highly dependent on each other. For example, if the Twilio service goes down, the alerts will not fail, they will just be delayed. The “coin-alerts” topic will accumulate messages and the Twilio service will process the message backlog once it comes back online.
Learn more about deploying currency alerts in the Quix platform
We hope this walkthrough gave you a first taste about what the platform can do. Quix is a great match for market data APIs such as CoinAPI. It can handle more complex pipelines and back end architectures too. You can use Quix’s built-in connectors to bring your data in and send it back out again — to a mobile app, a data warehouse, or an external service. The choice is yours.
For a detailed tutorial on how to build what we just described in this walkthrough, check out this simple video tutorial.
Note that it doesn’t contain the threshold checking step, but you can easily add this step from the Quix library. Happy coding!
This post has been reposted on the CoinAPI blog here: https://www.coinapi.io/blog/2022/12/deploy-real-time-currency-alerting-pipeline/
What’s a Rich Text element?
The rich text element allows you to create and format headings, paragraphs, blockquotes, images, and video all in one place instead of having to add and format them individually. Just double-click and easily create content.
Static and dynamic content editing
A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel. Voila!
How to customize formatting for each rich text
Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.
Tomas Neubauer is Co-Founder and CTO at Quix, responsible for the direction of the company across the full technical stack, and working as a technical authority for the engineering team. He was previously Technical Lead at McLaren, where he led architecture uplift for Formula One racing real-time telemetry acquisition. He later led platform development outside motorsport, reusing the knowhow he gained from racing.