Skip to main content

Ehdtd - cryptoCurrency Exchange history data to database

Project description

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:

  1. Try to retrieve data from a file. Check this link:
    Binance Public Data
  2. If the file is not available, try to retrieve data from the API.
  3. 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 data is not used,
    and column status can 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.

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.

View License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ehdtd-0.2.12.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

ehdtd-0.2.12-py3-none-any.whl (52.3 kB view details)

Uploaded Python 3

File details

Details for the file ehdtd-0.2.12.tar.gz.

File metadata

  • Download URL: ehdtd-0.2.12.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.2

File hashes

Hashes for ehdtd-0.2.12.tar.gz
Algorithm Hash digest
SHA256 191cfb3859af473e839d77abe23c5d9b4ebc84ec9e46968e77aef98fb3b427b5
MD5 1238428cd7eaab534909d6cf21654803
BLAKE2b-256 b110287f8e3efc32f5853fb31845319a172b3def96eff3258a7711ab7ca06688

See more details on using hashes here.

File details

Details for the file ehdtd-0.2.12-py3-none-any.whl.

File metadata

  • Download URL: ehdtd-0.2.12-py3-none-any.whl
  • Upload date:
  • Size: 52.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.2

File hashes

Hashes for ehdtd-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 6f115e5217aa1ec7d2764682ea576e553d849fe5d3cd862c3f77f4cfd3cbf028
MD5 60568147d08e61c5bb3c09668bc5d03d
BLAKE2b-256 f330c7ab0db450c10cec187c92298135595e681d6ef307f2704038eacdb2dc44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page