Ehdtd - cryptoCurrency Exchange history data to database
This class retrieves historical data from exchanges and stores it in a database.
Example:
Install
```bash
pip install ehdtd
```
Use
```python
import time
from ehdtd import Ehdtd
exchange = 'binance'
symbol = 'BTC/USDT'
interval = '1m'
limit = 10
db_data = {
'db_type': 'postgresql', # postgresql, mysql
'db_name': 'ehdtd',
'db_user': 'ehdtd',
'db_pass': 'xxxxxxxxx',
'db_host': '127.0.0.1',
'db_port': '5432'
}
fetch_data = [
{
'symbol': symbol,
'interval': interval
}
]
ehd = Ehdtd(exchange, fetch_data, db_data) # Create an instance
ehd.start() # Start fetching data
time.sleep(900) # First time Wait for available data, for the data to be updated,
# you must wait between 90 minutes and 2.5 hours depending on the interval
for v in fetch_data:
symbol = v['symbol']
interval = v['interval']
start_from = 0
until_to = None
return_type = 'pandas'
data_db = ehd.get_data_from_db(symbol, interval, start_from, until_to, return_type)
print(data_db)
print('=========================================================================')
print('')
time.sleep(1)
ehd.stop() # Stop fetching data
```
How It Works:
For Binance:
- Try to retrieve data from a file. Check this link:
Binance Public Data - If the file is not available, try to retrieve data from the API.
- Then get data from the WebSocket API using the Ccxw class.
Database Columns:
-
open_time,open_date,open_price,close_time,close_date,close_price,low,high,volume,exchange,symbol,interval,status,data -
Column
datais not used,
and columnstatuscan have three values:'__NON_CHECK__','__OK__','__ERROR__'.- If
status == '__OK__', the file has consistent data. - If
status == '__ERROR__', the file has inconsistent data. - If
status == '__NON_CHECK__', the file is not analyzed.
- If
Retrieving Data from Database:
Use the function ehd.get_data_from_db(symbol, interval, start_from, until_to, return_type):
- If
return_type == 'pandas', it returns a Pandas DataFrame. - If
return_type == 'list', it returns a list of dictionaries.
Metadata
Release files for ehdtd 0.2.43
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ehdtd-0.2.43.tar.gz | 43.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ehdtd-0.2.43-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 96.3 kB
Release files / ehdtd-0.2.43.tar.gz
| Download URL | ehdtd-0.2.43.tar.gz |
|---|---|
| Size | 43.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
485ac118581ed047696deb1e9c69bae16e4110bc62ab20ebb00beccfb779c5ac
|
|
BLAKE2b-256 checksum How to use checksums |
a7e3743604736c2d87163e8c532324f0deb1df74f06de453dd046e2bbbc6effb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / ehdtd-0.2.43-py3-none-any.whl
| Download URL | ehdtd-0.2.43-py3-none-any.whl |
|---|---|
| Size | 53.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d885618d326ff463c18b69839f929c7a78b4ba826aad99419dfc4d8f2c388ce
|
|
BLAKE2b-256 checksum How to use checksums |
747c6b212141a639ac24f9b850a864c760476d221edf5e49a2c9178731a0f378
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|