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
portfolio

A simple yet effective lead management tool with AI assistance

May 03, 2025

I built a smart tool for myself, business owners and marketers that automates lead management, making scheduling calls and tracking leads quick and easy.

Project
portfolio

Here's one thing you can do to master social media for your business in one minute

May 03, 2025

I created an AI tool that helps small businesses easily schedule and manage their social media posts, saving time while keeping their online presence strong.

From the Firehose

About

I built a smart tool that helps anyone interested in cryptocurrency track the latest prices and data without the hassle of checking daily.

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

Hungry for more? Dive into my latest project where I use AI to make answering questions super easy! This project uses something called Retrieval Augmented Generation (RAG) to help chatbots find the right answers from uploaded documents, making them more accurate and helpful. No more guessing games—my AI knows where it got its info from, so you can trust its answers!

In this project, I show how to upload a PDF and ask it questions. The AI gives you the answer, shows where it came from, and shares the text it used to find the answer. It's like having a smart friend who knows everything in your document! Ready to see how it works? Check it out!

Learn More

About

I built a smart tool that helps anyone interested in cryptocurrency track the latest prices and data without the hassle of checking daily.