The fascination with cryptocurrency is going strong, especially after Elon Musk fanned the flames by voicing his preference for Dogecoin over Bitcoin. Cryptocurrency dominated trending Google searches in 2021, with Dogecoin and Ethereum making the top 10 list of most popular searches. If you have more than a casual interest, Deephaven provides essential tools to get you started. We'll show you how to use crypto data to make informed choices on entering and leaving the crypto market.
Earlier this year, we wrote a program to pull live and historical crypto prices. We stream data from CoinGecko and use that data to know when the current price is high or lower than a value based on historical data.
In this iteration, we compute exponential moving averages (EMAs), standard deviations, and averages on the data to help you choose when to buy and sell your favorite crypto.
To get started, launch Deephaven (see our quick start) and run our original code, included below. You'll need the appropriate import statements for working with real-time data.
Python code for our Crypto program
To use CoinGecko, we need to install the PyCoinGecko library. See How to install Python packages for the different ways to do this. In this case, we install it for a one-time use.
Now the fun part. Let's do some analysis on the coins. First, let's see what assets we can pull. This code gets a list of all IDs currently in CoinGecko and save them as a list to filter.
That is A LOT of assets so it's to limit them to what we actually want; in this case, we'll filter the assets to only those that contain the string doge.
We end up with over 200 assets without trimming. For ease, I'm going to create a targeted list of IDs to work with - the first 25 values. The code below recreates live_crypto_table and historical_crypto_table. Remember there is a pull limit, so only run historical_crypto_table once - if you set get_history to True previously, set it to False in the code below.
We can even merge the data for a seamless table:
The steps above collect and organize our data. Now, we can perform EMAs.
Here we add a column that contains our EMA value and highlights if the current price is above that value. EMAs are familiar tools to stock investors and allow us to see how the asset has changed with time. EMAs keep track of the average with the newest values having more weight than older values. This rolling window of averages can give us insight into what the crypto asset might do next. In this EMA, we set the window to be just 10 minutes - like everything in this code example, you can fine-tune this value to fit your data needs.
You can easily create different calculations, such as standard deviations and averages, by modifying the code:
This code provides a basic starter. Change the crypto assets to monitor your personal favorites, or switch out the calculations to suit your needs. Deephaven enables you to make smart choices about entering and leaving the market. With the speed of data changes in the crypto world, it's important to use the fastest real-time data engine possible: Deephaven.
We hope this program inspires you. If you make something of your own or have an idea to share, we'd love to hear about it on Slack!
