Building a Crypto Price Feed for the Web

How I built a user-facing crypto tracker using Python, REST APIs, and dynamic frontend rendering

Continue reading...

Featured Project
case study

What Happens If AI Handles Customer Support? ServiceNow Found Out

May 03, 2025

See how ServiceNow use smart AI agents to answer 80% of customer questions quickly, saving time and making customers happier.

Project
portfolio

Extract colors from an image

May 03, 2025

I built a fun tool that helps anyone grab colors from images easily, making it perfect for those who love vibrant design!

About

This is a cryptocurrency tracking tool that displays historical price data over the past 365 days, allowing users to easily view trends through both tabular data and visual charts.

Imagine you're really excited about cryptocurrency, but keeping track of all the price changes, market caps, and volumes can feel like trying to juggle while riding a unicycle. It's a bit tricky, right? That's where this code comes in, it helps automate the process of gathering and updating cryptocurrency data, making it easier for you to keep your finger on the pulse of the crypto market.

So, how does this code solve the problem of managing crypto data? It connects to a crypto data API (like CoinGecko) to fetch the latest information, stores it in a database, and updates it regularly. This way, you don’t need to manually check prices every day. Instead, the code does the heavy lifting for you!

Key Parts of the Code

Let’s break down a few interesting parts of this code that make it so effective:


# Helper function: Get crypto data if there's none
def get_crypto_data(coin_name, coin_id):
    # ... (code omitted for brevity)
    coin_in_db = db.session.query(CryptoMarketData).filter(CryptoMarketData.name == coin_name)

    # Clears previous data before adding new one
    if coin_in_db.all():
        coin_in_db.delete()
        db.session.commit()

This function, get_crypto_data, is like your best friend who cleans your room before bringing in new stuff. It checks if there’s any existing data for a cryptocurrency. If it finds any, it clears it out before bringing in the latest data. This ensures that you always have the most accurate and up-to-date information!


# Helper function: checks if timestamp is in a date list
def ts_in_date_list(ts, dates_: list):
    ts_date = dt.datetime.fromtimestamp(ts // 1000, dt.timezone.utc).date()
    return ts_date in dates_

Next up is the ts_in_date_list function. It’s like having a calendar that tells you if a specific date is on your schedule. It takes a timestamp and checks if that date is part of the dates you’re interested in. This is super helpful when the code needs to figure out if it has the right data for the days it wants to update.


# Helper function: Update crypto data rows
def update_crypto_data():
    # ... (code omitted for brevity)
    missing_dates = [date_ for date_ in date_range_required if date_ not in date_range_in_db]
    
    if missing_dates:
        # Get historical data in one API call instead of multiple
        params = {"vs_currency": "usd", "days": history_range, "interval": "daily"}
        # ... (code continues)

Finally, we have the update_crypto_data function. This is where the magic happens! It checks if there are any dates missing from the database. If it finds some, it fetches all the historical data in one go rather than in bits and pieces. It’s like going to the grocery store and buying everything you need for a week in one trip instead of going every day!

Wrapping It Up

In summary, this code is a handy tool that automates the process of tracking cryptocurrency data, making life a lot easier for anyone interested in the crypto market. By regularly fetching and updating data, it ensures that you’re always informed without the hassle of manual checking. Plus, it’s a great example of how coding can simplify complex tasks and help us stay on top of the latest trends. How cool is that?

You can try it out here:

Try it out


Explore my AI-powered crypto assistant project, designed to answer user questions about cryptocurrency using a structured, tool-driven approach. The system is built to interpret different types of queries, route them to the appropriate execution paths, and retrieve relevant data efficiently to generate clear and reliable responses.

The project integrates stored market data for fast price updates, along with specialized tools for technical analysis and news retrieval. It is also designed with stability and performance in mind, operating efficiently under resource constraints while delivering consistent outputs and client-side visualizations.

To learn more about the architecture, routing logic, and implementation details, explore the full project on this website.

Learn More

About

This is a cryptocurrency tracking tool that displays historical price data over the past 365 days, allowing users to easily view trends through both tabular data and visual charts.