semvec/pypi-packages huggingface dataset:
ehdtd 0.2.37
Ehdtd - cryptoCurrency Exchange history data to database
License: MIT
Requires Python: <4.0,>=3.13

# 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](https://github.com/binance/binance-public-data/#trades-1)
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](LICENSE)
ccxw 0.2.34
Ccxw - CryptoCurrency eXchange Websocket Library
License: MIT
Requires Python: <4.0,>=3.13


# CCXW - CryptoCurrency eXchange Websocket Library

This library is designed to fetch data from exchange WebSocket APIs and store or update data in a temporary SQLite database in the background, making it readily accessible for retrieval.

Currently, it is available for several exchanges, including Binance, Bybit, and more. You can find a complete list of supported exchanges using `Ccxw.get_supported_exchanges()`.

Furthermore, the library supports a variety of endpoints, such as order_book, kline, and more. A comprehensive list of supported endpoints can be found via `Ccxw.get_supported_endpoints()`.

## Example

### Install

```bash
pip install ccxw
```

### Use

```python
import time
import pprint
from ccxw import Ccxw

symbol = 'BTC/USDT'

streams = [\
                {\
                    'endpoint': 'order_book',\
                    'symbol': symbol
                },\
                {\
                    'endpoint': 'kline',\
                    'symbol': symbol,\
                    'interval': interval\
                },\
                {\
                    'endpoint': 'trades',\
                    'symbol': symbol
                },\
                {\
                    'endpoint': 'ticker',\
                    'symbol': symbol
                }\
        ]

wsm = Ccxw('binance',\
            streams,\
            result_max_len=5,\
            data_max_len=10)

wsm.start()  # Start getting data

time.sleep(2)  # Wait for available data

for i in range(0, 10):
    for stream in streams:
        interval = 'none'
        if 'interval' in stream:
            interval = stream['interval']
        data = wsm.get_current_data(stream['endpoint'], stream['symbol'], interval)
        pprint.pprint(data, sort_dicts=False)
        print('----------------------------------')
        time.sleep(1)
    print('============================================================')

wsm.stop()  # Stop getting data
```

### Important Information

Please be aware that each instance opens a new connection to websockets. If you create multiple instances for the same exchange, you may exceed the websockets connection limits set by exchanges. Make sure to check the connection limits of exchanges before opening numerous instances.

[View License](LICENSE)