Upbit Candle Collector
Project description
pyubcc
Upbit Candle Collector for Python
Description
Upbit Candle Collector is a Python script that collects historical candle data from the Upbit API and saves it to a SQLite3 DB or CSV file. It allows you to specify the market, time interval, and date range for the data collection.
Quick Start
$ pip install pyubcc
$ ubcc BTC --timeframe day --days 30
Starting data collection for BTC...
Period: 30 days, Timeframe: day
KRW-BTC: 30 candles [00:00, 116.88 candles/s]
No missing candles found.
=== BTC Data Collection Results ===
Collection Period: 2025-01-18 09:00 ~ 2025-02-17 00:00
Timeframe: day (1440 minutes)
Collected Candles: 30
Data Gaps: 0
Timestamp Order Mismatches: 0
$ sqlite3 db/KRW-BTC_day.db "SELECT COUNT(*) FROM ohlcv;"
30
Usage
CLI
usage: ubcc [-h]
[--timeframe {minute1,minute3,minute5,minute10,minute15,minute30,minute60,minute240,day,week,month}]
[--days DAYS] [--db-path DB_PATH] [--export-csv] [--verbose]
coin
Upbit Candle Collector
positional arguments:
coin Coin symbol (e.g., BTC, ETH, DOGE) or full ticker (e.g., KRW-
BTC, USDT-BTC)
options:
-h, --help show this help message and exit
--timeframe {minute1,minute3,minute5,minute10,minute15,minute30,minute60,minute240,day,week,month}
Time interval (default: day)
--days DAYS Collection period in days (default: 30)
--db-path DB_PATH DB file path (default: db/{coin}_{timeframe}.db)
--export-csv Export data to CSV file
--verbose Enable detailed logging
Module
from pyubcc import UpbitCandleCollector
# Initialize collector for BTC/KRW daily candles
collector = UpbitCandleCollector(
coin='BTC', # Coin symbol (e.g., BTC, ETH, DOGE)
timeframe='day', # Time interval (minute1 to month)
fiat='KRW', # Base currency (default: KRW)
verbose=True # Enable detailed logging
)
# Check database status
collector.check_db_status()
# Collect last 30 days of data
from datetime import datetime, timedelta
end_date = datetime.now()
start_date = end_date - timedelta(days=30)
results = collector.collect(start_date=start_date, end_date=end_date)
# Export collected data to CSV
collector.export_to_csv()
# Get data as pandas DataFrame
df = collector.get_ohlcv_data(start_date=start_date, end_date=end_date, filter_gaps=True)
print(df.head())
Return Values
The collect() method returns a tuple containing:
total_count: Number of collected candlesexpected_candles: Expected number of candles for the periodtimestamp_order_mismatches: Number of timestamp order mismatchesgaps: List of gaps in the data
Data Structure
The collected data includes:
timestamp: Candle timestampopen: Opening pricehigh: Highest pricelow: Lowest priceclose: Closing pricevolume: Trading volume
Public API
Constructor
UpbitCandleCollector(coin, timeframe, fiat="KRW", db_path=None, verbose=False, show_progress=False)
coin(str): Coin symbol (e.g., 'BTC', 'ETH', 'DOGE')timeframe(str): Time interval (minute1, minute3, minute5, minute10, minute15, minute30, minute60, minute240, day, week, month)fiat(str): Base currency (KRW, BTC, USDT, default: KRW)db_path(str, optional): DB file path (default: db/{coin}{timeframe}{fiat}.db)verbose(bool): Enable detailed loggingshow_progress(bool): Show progress bar (default: False)
Methods
check_db_status()
Checks the database status and returns information about the first and last timestamps.
- Returns: bool - True if database contains data, False if empty
collect(start_date=None, end_date=None)
Collects historical data for the specified period.
- Parameters:
start_date(datetime, optional): Start date for data collectionend_date(datetime, optional): End date for data collection (default: current time)
- Returns: tuple (total_count, expected_candles, timestamp_order_mismatches, gaps)
get_ohlcv_data(start_date=None, end_date=None, filter_gaps=True)
Retrieves stored OHLCV data as a pandas DataFrame.
- Parameters:
start_date(datetime, optional): Start date for data retrievalend_date(datetime, optional): End date for data retrievalfilter_gaps(bool): Whether to filter data gaps (default: True)
- Returns: pandas.DataFrame with OHLCV data
export_to_csv(start_date=None, end_date=None)
Exports OHLCV data to a CSV file.
- Parameters:
start_date(datetime, optional): Start date for data exportend_date(datetime, optional): End date for data export
- Returns: str - Path to the exported CSV file, or None if no data to export
analyze_gaps(start_date=None, end_date=None)
Analyzes gaps in candle data from database.
- Parameters:
start_date(datetime, optional): Start date for gap analysisend_date(datetime, optional): End date for gap analysis
- Returns: list of dictionaries containing gap information
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 pyubcc-0.1.1.tar.gz.
File metadata
- Download URL: pyubcc-0.1.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
950852718f1caf19cdf0f5009d3b8d09c948ef7b0c50501138781b23bcd35bbc
|
|
| MD5 |
297897cb41697a1d728f8ce8588b6bd4
|
|
| BLAKE2b-256 |
201f525de83cb7b96902bb70a263d6d88e374448c8fa0c77264ef195bb9d4623
|
Provenance
The following attestation bundles were made for pyubcc-0.1.1.tar.gz:
Publisher:
publish.yml on kyungw00k/pyubcc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyubcc-0.1.1.tar.gz -
Subject digest:
950852718f1caf19cdf0f5009d3b8d09c948ef7b0c50501138781b23bcd35bbc - Sigstore transparency entry: 171823944
- Sigstore integration time:
-
Permalink:
kyungw00k/pyubcc@dfecd2d833d2b7a54db007828cdc61b35d4011ee -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/kyungw00k
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dfecd2d833d2b7a54db007828cdc61b35d4011ee -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyubcc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyubcc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4faf7022910cf009d8c47166affc036dab6b715a9d2ca9c3a8b932f0c8d5d0b
|
|
| MD5 |
24db413981f9a17e2db672fcafac4d03
|
|
| BLAKE2b-256 |
f43981a579cf8c2082f68c1323b299170e95d9fc331e5abc9e0f805026a9eca8
|
Provenance
The following attestation bundles were made for pyubcc-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on kyungw00k/pyubcc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyubcc-0.1.1-py3-none-any.whl -
Subject digest:
b4faf7022910cf009d8c47166affc036dab6b715a9d2ca9c3a8b932f0c8d5d0b - Sigstore transparency entry: 171823945
- Sigstore integration time:
-
Permalink:
kyungw00k/pyubcc@dfecd2d833d2b7a54db007828cdc61b35d4011ee -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/kyungw00k
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dfecd2d833d2b7a54db007828cdc61b35d4011ee -
Trigger Event:
push
-
Statement type: