Spaces:
Runtime error
Runtime error
Download src/data_fetch.py from jonyling/eth-usd-predictor: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/jonyling/eth-usd-predictor/resolve/main/src/data_fetch.py
- Command line
-
hf download hf://spaces/jonyling/eth-usd-predictor/src/data_fetch.py
-
curl -L -o data_fetch.py https://huggingface.co/spaces/jonyling/eth-usd-predictor/resolve/main/src/data_fetch.py
1.2 kB
| """Fetch latest hourly ETH data via CCXT — ready for V5 feature pipeline""" | |
| import ccxt # type: ignore | |
| import pandas as pd | |
| from datetime import datetime | |
| from src.config import SYMBOL, TIMEFRAME | |
| def fetch_latest_data(limit: int = 2000) -> pd.DataFrame: | |
| """Returns hourly OHLCV + placeholder on-chain columns (exactly as notebook)""" | |
| exchange = ccxt.binance({'enableRateLimit': True}) | |
| print(f"📡 Fetching latest {TIMEFRAME} ETH data from Binance...") | |
| ohlcv = exchange.fetch_ohlcv(SYMBOL, timeframe=TIMEFRAME, limit=limit) | |
| df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume']) | |
| df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms') | |
| df = df.set_index('timestamp').sort_index() | |
| df['return'] = df['close'].pct_change().fillna(0.0) | |
| # Placeholder on-chain (same scaling as original dataset) | |
| df['tx_count'] = df['volume'] * 1.5 | |
| df['active_senders'] = df['volume'] * 0.8 | |
| df['active_receivers'] = df['volume'] * 0.7 | |
| df['total_eth_transferred'] = df['volume'] * 1.2 | |
| df['total_gas_used'] = df['volume'] * 0.9 | |
| print(f"✅ Fetched {len(df)} hourly bars (up to {df.index[-1]})") | |
| return df | |