Single Blog

Fetch Crypto Deposits & Withdrawals in Python with Crypto-Pandas + CCXT: A Step-by-Step Guide

If you’re serious about crypto, whether as a trader, quant, or data analyst, you know that knowing your money flow is just as important as knowing your PnL. Exchanges keep their own transaction records, but relying solely on manual downloads or UI exports is inefficient. You want something automated, scriptable, and ready for integration into your analytics stack. That’s where Crypto-Pandas, built on CCXT, comes in.

It gives you a Pandas-friendly layer to interact with exchange APIs without having to wrangle messy JSON responses or inconsistent field names.

Step 1: Import Your Libraries

Before anything else, let’s import everything we need:

import ccxt
import pandas as pd
from dotenv import load_dotenv
import os
from crypto_pandas import CCXTPandasExchange
from crypto_pandas.utils.pandas_utils import timestamp_to_int

What’s happening here?

  • CCXT: Industry-standard Python library for interacting with crypto exchange APIs.
  • pandas: The go-to Python library for working with tabular data.
  • Dotenv: Helps load API keys from a .env file securely.
  • os: Used to access environment variables.
  • Crypto-Pandas: The star of the show; wraps CCXT calls in a Pandas-friendly interface.
  • Timestamp_to_int: A helper from Crypto-Pandas to format timestamps for API calls.

Why this matters: This combination of imports lets us go from API to DataFrame with minimal data cleaning.

Step 2: Load Environment Variables

We keep API keys out of our code for security and maintainability:

load_dotenv()

What’s happening here?

  • Reads a .env file from your project directory.
  • Makes your API keys available to Python via os.getenv().

Why this matters: If your code ever gets shared or pushed to GitHub, your API keys won’t be hardcoded, avoiding a very expensive mistake.

Step 3: Connect to Bybit Exchange in Sandbox Mode

We’re going to connect to Bybit’s test environment so you can experiment without risking real funds.

exchange = ccxt.bybit({

“apiKey”: os.getenv(“BYBIT_SANDBOX_API_KEY”),
“secret”: os.getenv(“BYBIT_SANDBOX_API_SECRET”),
})

exchange.set_sandbox_mode(True)

Key points:

  • ccxt.bybit(): Creates an instance of the Bybit exchange API.
  • os.getenv(): Pulls API key and secret from the environment variables you loaded earlier.
  • set_sandbox_mode(True): Switches to the Bybit testnet. Perfect for testing without live trades.
Why this matters:

Testing in sandbox mode means you can write, debug, and run your code without fear of losing real funds.

Step 4: Wrap the Exchange in CCXTPandasExchange

Crypto-Pandas takes CCXT’s raw API calls and outputs data as Pandas DataFrames.

pandas_exchange = CCXTPandasExchange(exchange=exchange)

Why this matters:

Without this wrapper, you’d be working with raw JSON responses from the API. Instead, you get neatly formatted DataFrames that are ready for analysis, merging, or export.

Step 5: Set Your Date Range

Let’s define the time window we want to query. In this example, we’re looking at transactions between June 21, 2025 and 7 days later:

start_time = pd.Timestamp(“2025-06-21T00:00:00″, tz=”UTC”)
end_time = start_time + pd.Timedelta(days=7)

params = {
“startTime”: timestamp_to_int(start_time),
“endTime”: timestamp_to_int(end_time),
}

Key points:

  • pd.Timestamp , Creates a timezone-aware datetime object.
  • pd.Timedelta(days=7) , Adds exactly 7 days to your start time.
  • timestamp_to_int() , Formats the datetime for Bybit’s API, which requires timestamps in integer format.
Why this matters:

API queries almost always require timestamps in a specific format. This ensures you get exactly the transactions you want , nothing more, nothing less.

Step 6: Fetch Deposits and Withdrawals

Here’s where the magic happens.

deposits = pandas_exchange.fetch_deposits(params=params) withdrawals = pandas_exchange.fetch_withdrawals(params=params)

What’s happening here?
fetch_deposits() , Queries exchange for all deposits in the given time range.
fetch_withdrawals() , Queries for all withdrawals in the same range.

Both return clean DataFrames with columns like:

  • Transaction ID
  • Timestamp
  • Currency
  • Amount
  • Network used
Practical Uses

This setup isn’t just a tutorial; it’s the foundation for real-world applications:

  • Portfolio tracking: Keep live tabs on your cash flow.
  • Tax prep: Export your DataFrame to CSV and send to your accountant.
  • Security monitoring: Flag unexpected withdrawals automatically.
  • Strategy analysis: Check how deposit/withdrawal timing affects your trading.
Why Use Crypto-Pandas Instead of Raw CCXT?

While CCXT is powerful, its raw JSON responses can be a pain to clean. Crypto-Pandas:

  • Outputs Pandas DataFrames directly
  • Handles timestamp formatting
  • Plays nicely with other Python data tools
  • For anyone already working in Pandas, this is a huge quality-of-life improvement.

From Clean Data to Pro-Level Power: Your Next Move

Fetching deposits and withdrawals from an exchange API doesn’t have to be messy or time-consuming. With Crypto-Pandas + CCXT, you’re already getting cleaner code, ready-to-analyse Pandas DataFrames, less time wasted on JSON wrangling, and a setup that scales easily across multiple exchanges. But that’s just the beginning.

We’re excited to announce that Crypto-Pandas-Pro is all set for you, built for traders and analysts who need more speed, deeper insights, and advanced query handling without sacrificing simplicity. With Pro, you can process larger datasets faster, unlock extended analytics, and take advantage of features designed for high-frequency and professional-grade workflows.

Beta slots are strictly limited, and early adopters will enjoy exclusive benefits, priority feature requests, and discounted access once the full version goes live. If you’ve been looking for a way to streamline your crypto data pipeline and level up your trading intelligence, now is the time to jump in and secure your place in the Pro beta.

Resources and Further Exploration

Crypto-Pandas-Pro: Cleaner data. Faster trades