Fetch, store, and manage OHLCV candle data from cryptocurrency exchanges (Binance, Upbit) with MySQL storage
Project description
Candle Data Manager
Candle data management tool for cryptocurrency and stock markets.
Installation
pip install candle-data-manager
Requirements
- Python >= 3.10
- MySQL Server
.envfile with API keys:
# Binance
BINANCE_API_KEY=your_binance_api_key
BINANCE_API_SECRET=your_binance_api_secret
# Upbit
UPBIT_API_KEY=your_upbit_api_key
UPBIT_API_SECRET=your_upbit_api_secret
Overview
Initialize
from candle_data_manager import CandleDataAPI
# Default: mysql+pymysql://root@localhost/candle_data_manager
api = CandleDataAPI()
# Or with custom database URL
api = CandleDataAPI(database_url="mysql+pymysql://user:password@host/dbname")
Active Update
Fetch and store all historical data for symbols.
# Update all Binance Futures PERPETUAL markets
result = api.active_update(
archetype="CRYPTO",
exchange="BINANCE",
tradetype="FUTURES"
)
# Update specific symbol with filters
result = api.active_update(
archetype="CRYPTO",
exchange="BINANCE",
tradetype="SPOT",
base="BTC",
quote="USDT",
timeframe="1d"
)
print(f"Success: {result.success_count}, Failed: {result.fail_count}, Rows: {result.total_rows}")
Passive Update
Incremental update for registered symbols.
result = api.passive_update(
archetype="CRYPTO",
exchange="BINANCE"
)
Load Data
Load candle data as Market objects.
markets = api.load(
archetype="CRYPTO",
exchange="BINANCE",
tradetype="SPOT",
base="BTC",
quote="USDT",
timeframe="1h",
start_at=1609459200,
end_at=1609545600
)
for market in markets:
print(market.symbol)
print(market.candles) # pandas DataFrame
API Reference
CandleDataAPI
| Method | Description |
|---|---|
__init__(database_url=None) |
Initialize API with MySQL connection. Creates database schema and tables if not exists. Default: mysql+pymysql://root@localhost/candle_data_manager |
active_update(archetype, exchange, tradetype, base, quote, timeframe) |
Register new symbols from exchange market list and fetch all historical candle data from the earliest available timestamp. Filters can be string or list (e.g., base=["BTC", "ETH"]). Returns UpdateResult with success/fail counts and total rows. |
passive_update(archetype, exchange, tradetype, base, quote, timeframe, buffer_size) |
Incremental update for registered symbols. Fetches candles from the last stored timestamp to current time, updating the last candle and appending new candles. Returns UpdateResult. |
load(archetype, exchange, tradetype, base, quote, timeframe, start_at, end_at) |
Load candle data from database as Market objects. Each Market contains symbol and candles (pandas DataFrame with OHLCV columns). Auto-fetches missing data if not in database. |
get_symbol(symbol_str) |
Get Symbol object by string identifier. Format: "ARCHETYPE-EXCHANGE-TRADETYPE-BASE-QUOTE-TIMEFRAME" (e.g., "CRYPTO-BINANCE-SPOT-BTC-USDT-1h"). Returns None if not found. |
close() |
Close all database connections and release resources. |
Supported Providers
| Provider | Archetype | Exchange | TradeType |
|---|---|---|---|
| Binance Spot | CRYPTO | BINANCE | SPOT |
| Binance Futures | CRYPTO | BINANCE | FUTURES |
| Upbit | CRYPTO | UPBIT | SPOT |
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file candle_data_manager-0.1.1.tar.gz.
File metadata
- Download URL: candle_data_manager-0.1.1.tar.gz
- Upload date:
- Size: 55.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce4c51e72e79fa9526e1569982ae767570fa8adb19ba3dc685db918ca3e65bba
|
|
| MD5 |
f6702f41143f74539c2832fba968e9ad
|
|
| BLAKE2b-256 |
fc99e6c9fdeaac4bc274875c8b1e7dbd2235b21159f0a73ef6c649b4f6324f9c
|
File details
Details for the file candle_data_manager-0.1.1-py3-none-any.whl.
File metadata
- Download URL: candle_data_manager-0.1.1-py3-none-any.whl
- Upload date:
- Size: 113.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bc82ddcb1bc1978eeec4cda63b9ffb4f1315ba33976b1ce3cd6fefe32372554
|
|
| MD5 |
33badea3a075d1c2b05cad2597b49e69
|
|
| BLAKE2b-256 |
83731744b9b24e6321febb356248e84430ceb1251ea5d6a444f7417f089a06f6
|