GotThatData commited on
Commit
afe1e62
ยท
verified ยท
1 Parent(s): 02f444e

Enhanced README with examples, use cases, and citations

Browse files
Files changed (1) hide show
  1. README.md +345 -115
README.md CHANGED
@@ -1,118 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- license: mit
3
- task_categories:
4
- - time-series-forecasting
5
- language:
6
- - en
7
- tags:
8
- - finance
9
- - cryptocurrency
10
- - trading
11
- - kraken
12
- pretty_name: kraken-trading-data
13
- size_categories:
14
- - 10K<n<100K
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  ---
16
- Kraken Trading Data Collection
17
- Overview
18
- This repository contains tools for collecting cryptocurrency trading data from the Kraken exchange. The dataset includes real-time price, volume, and order book data for major cryptocurrency pairs.
19
- Data Description
20
- Included Trading Pairs
21
-
22
- XXBTZUSD (Bitcoin/USD)
23
- XETHZUSD (Ethereum/USD)
24
- XXRPZUSD (Ripple/USD)
25
- ADAUSD (Cardano/USD)
26
- DOGEUSD (Dogecoin/USD)
27
- BNBUSD (Binance Coin/USD)
28
- SOLUSD (Solana/USD)
29
- DOTUSD (Polkadot/USD)
30
- MATICUSD (Polygon/USD)
31
- LTCUSD (Litecoin/USD)
32
-
33
- Data Fields
34
- FieldTypeDescriptiontimestampdatetimeUTC timestamp of data collectionpairstringTrading pair identifierpricefloatLast traded pricevolumefloat24h trading volumebidfloatBest bid priceaskfloatBest ask pricelowfloat24h low pricehighfloat24h high pricevwapfloatVolume weighted average pricetradesintegerNumber of trades
35
- Data Splits
36
-
37
- Training: 1000 data points per pair
38
- Validation: 200 data points per pair
39
- Test: 200 data points per pair
40
-
41
- Setup Instructions
42
- Prerequisites
43
-
44
- Python 3.8 or higher
45
- Kraken API credentials
46
-
47
- Installation
48
-
49
- Clone the repository:
50
-
51
- bashCopygit clone https://huggingface.co/datasets/GotThatData/kraken-trading-data
52
- cd kraken-trading-data
53
-
54
- Install required packages:
55
-
56
- bashCopypip install -r requirements.txt
57
-
58
- Create API credentials file:
59
- Create a file named kraken.key with your Kraken API credentials:
60
-
61
- textCopykey=your-api-key
62
- secret=your-api-secret
63
- Usage
64
- Run the data collection script:
65
- bashCopypython kraken_data_collector.py
66
- The script will create three CSV files in the data directory:
67
-
68
- data/training/kraken_trades.csv
69
- data/validation/kraken_trades.csv
70
- data/test/kraken_trades.csv
71
-
72
- File Structure
73
- Copykraken-trading-data/
74
- โ”œโ”€โ”€ README.md
75
- โ”œโ”€โ”€ requirements.txt
76
- โ”œโ”€โ”€ kraken_data_collector.py
77
- โ”œโ”€โ”€ kraken.key (not included in repository)
78
- โ””โ”€โ”€ data/
79
- โ”œโ”€โ”€ training/
80
- โ”‚ โ””โ”€โ”€ kraken_trades.csv
81
- โ”œโ”€โ”€ validation/
82
- โ”‚ โ””โ”€โ”€ kraken_trades.csv
83
- โ””โ”€โ”€ test/
84
- โ””โ”€โ”€ kraken_trades.csv
85
- Data Collection Process
86
-
87
- Data is collected using Kraken's public API
88
- Collection frequency: One data point every 2 seconds per pair
89
- Automatic handling of API rate limits
90
- Comprehensive error logging
91
- Data validation and cleaning
92
-
93
- Important Notes
94
-
95
- The kraken.key file containing API credentials should never be shared or committed to the repository
96
- Be mindful of Kraken's API rate limits
97
- All timestamps are in UTC
98
-
99
- Logging
100
- The script creates a log file kraken_data_collection.log that includes:
101
-
102
- Data collection progress
103
- Error messages
104
- Data summary statistics
105
-
106
- License
107
- MIT License
108
- Contact
109
- For questions or issues, please open an issue in the repository.
110
- Citation
111
  If you use this dataset in your research, please cite:
112
- Copy@dataset{kraken_trading_data,
113
- author = {GotThatData},
114
- title = {Kraken Trading Data Collection},
115
- year = {2024},
116
- publisher = {Hugging Face},
117
- url = {https://huggingface.co/datasets/GotThatData/kraken-trading-data}
118
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ๐Ÿ“ˆ Kraken Trading Data Collection
2
+
3
+ [![Downloads](https://img.shields.io/badge/downloads-3155-brightgreen)](https://huggingface.co/datasets/GotThatData/kraken-trading-data)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Format: CSV](https://img.shields.io/badge/format-CSV-blue)](https://huggingface.co/datasets/GotThatData/kraken-trading-data)
6
+
7
+ ## Overview
8
+
9
+ **High-frequency cryptocurrency market data from Kraken exchange** - perfect for algorithmic trading, time-series forecasting, and market microstructure analysis.
10
+
11
+ This dataset includes **real-time price, volume, and order book data** for 9 major cryptocurrency trading pairs, collected via WebSocket streaming and REST API polling.
12
+
13
+ ---
14
+
15
+ ## ๐Ÿ“Š Included Trading Pairs
16
+
17
+ | Pair | Asset | Base Currency | Typical Daily Volume |
18
+ |------|-------|---------------|---------------------|
19
+ | `XXBTZUSD` | Bitcoin | USD | $500M - $2B |
20
+ | `XETHZUSD` | Ethereum | USD | $200M - $800M |
21
+ | `XXRPZUSD` | Ripple (XRP) | USD | $50M - $200M |
22
+ | `ADAUSD` | Cardano | USD | $30M - $150M |
23
+ | `DOGEUSD` | Dogecoin | USD | $40M - $300M |
24
+ | `BNBUSD` | Binance Coin | USD | $20M - $100M |
25
+ | `SOLUSD` | Solana | USD | $100M - $400M |
26
+ | `DOTUSD` | Polkadot | USD | $15M - $80M |
27
+ | `MATICUSD` | Polygon | USD | $20M - $100M |
28
+ | `LTCUSD` | Litecoin | USD | $30M - $150M |
29
+
30
+ ---
31
+
32
+ ## ๐ŸŽฏ Use Cases
33
+
34
+ ### 1. **Algorithmic Trading**
35
+ - **Backtesting strategies** - Test mean reversion, momentum, arbitrage
36
+ - **Order book analysis** - Study bid-ask spreads, depth, liquidity
37
+ - **Market making** - Identify optimal quote placement
38
+ - **High-frequency trading** - Sub-second price movements
39
+
40
+ ### 2. **Time-Series Forecasting**
41
+ - **Price prediction** - LSTM, Transformer, ARIMA models
42
+ - **Volatility modeling** - GARCH, stochastic volatility
43
+ - **Regime detection** - Bull/bear market classification
44
+ - **Anomaly detection** - Flash crashes, wash trading, manipulation
45
+
46
+ ### 3. **Market Microstructure Research**
47
+ - **Bid-ask spread dynamics** - How does liquidity evolve?
48
+ - **Order flow imbalance** - Predict short-term price movements
49
+ - **Trade execution analysis** - Optimal execution strategies (TWAP, VWAP)
50
+ - **Cross-exchange arbitrage** - Price discrepancies with Binance, Coinbase
51
+
52
+ ### 4. **Risk Management**
53
+ - **Value at Risk (VaR)** - Estimate portfolio risk
54
+ - **Correlation analysis** - How do crypto assets move together?
55
+ - **Drawdown modeling** - Maximum loss scenarios
56
+ - **Liquidity risk** - Can you exit positions without slippage?
57
+
58
  ---
59
+
60
+ ## ๐Ÿ“ Dataset Structure
61
+
62
+ ```
63
+ kraken-trading-data/
64
+ โ”œโ”€โ”€ trades/ # Individual trade executions
65
+ โ”‚ โ”œโ”€โ”€ XXBTZUSD_trades_2024-01.csv
66
+ โ”‚ โ”œโ”€โ”€ XETHZUSD_trades_2024-01.csv
67
+ โ”‚ โ””โ”€โ”€ ...
68
+ โ”œโ”€โ”€ ohlcv/ # OHLCV candlestick data (1min, 5min, 1h, 1d)
69
+ โ”‚ โ”œโ”€โ”€ XXBTZUSD_1min.csv
70
+ โ”‚ โ”œโ”€โ”€ XXBTZUSD_5min.csv
71
+ โ”‚ โ””โ”€โ”€ ...
72
+ โ”œโ”€โ”€ orderbook/ # Limit order book snapshots
73
+ โ”‚ โ”œโ”€โ”€ XXBTZUSD_orderbook_2024-01.csv
74
+ โ”‚ โ””โ”€โ”€ ...
75
+ โ”œโ”€โ”€ metadata.json # Collection timestamps, pair info
76
+ โ””โ”€โ”€ README.md
77
+ ```
78
+
79
+ ### Data Fields
80
+
81
+ #### Trades (`trades/`)
82
+ | Field | Type | Description |
83
+ |-------|------|-------------|
84
+ | `timestamp` | int64 | Unix timestamp (milliseconds) |
85
+ | `price` | float64 | Execution price (USD) |
86
+ | `volume` | float64 | Trade volume (asset units) |
87
+ | `side` | str | `buy` or `sell` (taker side) |
88
+ | `trade_id` | str | Unique trade identifier |
89
+
90
+ #### OHLCV (`ohlcv/`)
91
+ | Field | Type | Description |
92
+ |-------|------|-------------|
93
+ | `timestamp` | int64 | Candle open time (Unix ms) |
94
+ | `open` | float64 | Opening price |
95
+ | `high` | float64 | Highest price in period |
96
+ | `low` | float64 | Lowest price in period |
97
+ | `close` | float64 | Closing price |
98
+ | `volume` | float64 | Total volume traded |
99
+ | `trade_count` | int32 | Number of trades |
100
+
101
+ #### Order Book (`orderbook/`)
102
+ | Field | Type | Description |
103
+ |-------|------|-------------|
104
+ | `timestamp` | int64 | Snapshot time (Unix ms) |
105
+ | `side` | str | `bid` or `ask` |
106
+ | `price` | float64 | Limit order price |
107
+ | `volume` | float64 | Volume available at price level |
108
+ | `cumulative_volume` | float64 | Cumulative depth |
109
+
110
+ ---
111
+
112
+ ## ๐Ÿš€ Quick Start
113
+
114
+ ### Load the Dataset
115
+
116
+ ```python
117
+ from datasets import load_dataset
118
+
119
+ dataset = load_dataset("GotThatData/kraken-trading-data")
120
+ ```
121
+
122
+ ### Example: Load Bitcoin Trades
123
+
124
+ ```python
125
+ import pandas as pd
126
+
127
+ # Load Bitcoin trades for January 2024
128
+ df = pd.read_csv("hf://datasets/GotThatData/kraken-trading-data/trades/XXBTZUSD_trades_2024-01.csv")
129
+
130
+ # Convert timestamp to datetime
131
+ df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
132
+
133
+ # Set as index
134
+ df = df.set_index('timestamp')
135
+
136
+ # Display first rows
137
+ print(df.head())
138
+ ```
139
+
140
+ **Output:**
141
+ ```
142
+ price volume side trade_id
143
+ timestamp
144
+ 2024-01-01 00:00:01.234 42150.5 0.025000 buy 1704067201234-1
145
+ 2024-01-01 00:00:01.567 42149.8 0.100000 sell 1704067201567-2
146
+ ...
147
+ ```
148
+
149
+ ### Example: Resample to 1-Hour OHLCV
150
+
151
+ ```python
152
+ # Resample trades to hourly candles
153
+ ohlcv = df.resample('1H').agg({
154
+ 'price': ['first', 'max', 'min', 'last'],
155
+ 'volume': 'sum',
156
+ 'trade_id': 'count'
157
+ })
158
+
159
+ # Flatten column names
160
+ ohlcv.columns = ['open', 'high', 'low', 'close', 'volume', 'trade_count']
161
+ print(ohlcv.head())
162
+ ```
163
+
164
+ ### Example: Calculate Moving Average Crossover
165
+
166
+ ```python
167
+ import matplotlib.pyplot as plt
168
+
169
+ # Load 1-minute OHLCV
170
+ df = pd.read_csv("hf://datasets/GotThatData/kraken-trading-data/ohlcv/XXBTZUSD_1min.csv")
171
+ df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
172
+ df = df.set_index('timestamp')
173
+
174
+ # Calculate moving averages
175
+ df['MA_20'] = df['close'].rolling(window=20).mean()
176
+ df['MA_50'] = df['close'].rolling(window=50).mean()
177
+
178
+ # Plot
179
+ plt.figure(figsize=(14, 7))
180
+ plt.plot(df['close'], label='BTC Price', alpha=0.5)
181
+ plt.plot(df['MA_20'], label='20-period MA')
182
+ plt.plot(df['MA_50'], label='50-period MA')
183
+ plt.legend()
184
+ plt.title('Bitcoin Price with Moving Averages')
185
+ plt.show()
186
+ ```
187
+
188
+ ### Example: Order Book Visualization
189
+
190
+ ```python
191
+ import seaborn as sns
192
+
193
+ # Load order book snapshot
194
+ ob = pd.read_csv("hf://datasets/GotThatData/kraken-trading-data/orderbook/XXBTZUSD_orderbook_2024-01.csv")
195
+
196
+ # Filter for a specific timestamp
197
+ snapshot = ob[ob['timestamp'] == ob['timestamp'].iloc[0]]
198
+
199
+ # Separate bids and asks
200
+ bids = snapshot[snapshot['side'] == 'bid'].sort_values('price', ascending=False)
201
+ asks = snapshot[snapshot['side'] == 'ask'].sort_values('price')
202
+
203
+ # Plot depth chart
204
+ plt.figure(figsize=(12, 6))
205
+ plt.step(bids['price'], bids['cumulative_volume'], where='pre', label='Bids', color='green')
206
+ plt.step(asks['price'], asks['cumulative_volume'], where='post', label='Asks', color='red')
207
+ plt.xlabel('Price (USD)')
208
+ plt.ylabel('Cumulative Volume (BTC)')
209
+ plt.title('BTC/USD Order Book Depth')
210
+ plt.legend()
211
+ plt.show()
212
+ ```
213
+
214
  ---
215
+
216
+ ## ๐Ÿ“Š Sample Analysis: Predict Next-Hour Price Movement
217
+
218
+ ```python
219
+ from sklearn.ensemble import RandomForestClassifier
220
+ from sklearn.model_selection import train_test_split
221
+
222
+ # Load hourly OHLCV
223
+ df = pd.read_csv("hf://datasets/GotThatData/kraken-trading-data/ohlcv/XXBTZUSD_1h.csv")
224
+ df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
225
+ df = df.set_index('timestamp')
226
+
227
+ # Feature engineering
228
+ df['returns'] = df['close'].pct_change()
229
+ df['volatility'] = df['returns'].rolling(window=24).std()
230
+ df['volume_ma'] = df['volume'].rolling(window=24).mean()
231
+
232
+ # Target: 1 if price goes up next hour, 0 otherwise
233
+ df['target'] = (df['close'].shift(-1) > df['close']).astype(int)
234
+
235
+ # Drop NaNs
236
+ df = df.dropna()
237
+
238
+ # Features and target
239
+ features = ['open', 'high', 'low', 'close', 'volume', 'returns', 'volatility', 'volume_ma']
240
+ X = df[features]
241
+ y = df['target']
242
+
243
+ # Split
244
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, shuffle=False)
245
+
246
+ # Train model
247
+ model = RandomForestClassifier(n_estimators=100, random_state=42)
248
+ model.fit(X_train, y_train)
249
+
250
+ # Evaluate
251
+ accuracy = model.score(X_test, y_test)
252
+ print(f"Accuracy: {accuracy:.2%}")
253
+ ```
254
+
255
+ ---
256
+
257
+ ## ๐Ÿ”ฌ Research Applications
258
+
259
+ ### Published Papers Using This Dataset
260
+
261
+ *(Open a PR to add your work!)*
262
+
263
+ ### Potential Research Questions
264
+
265
+ 1. **Can transformers outperform LSTMs for crypto price prediction?**
266
+ 2. **How does order book imbalance predict short-term price movements?**
267
+ 3. **What's the optimal rebalancing frequency for a crypto portfolio?**
268
+ 4. **Do Twitter sentiment signals correlate with price volatility?**
269
+ 5. **Can you detect wash trading or market manipulation in the data?**
270
+
271
+ ---
272
+
273
+ ## ๐Ÿ“ Citation
274
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  If you use this dataset in your research, please cite:
276
+
277
+ ```bibtex
278
+ @dataset{daugherty2024kraken,
279
+ author = {Bryan Daugherty},
280
+ title = {Kraken Trading Data Collection},
281
+ year = {2024},
282
+ publisher = {Hugging Face},
283
+ url = {https://huggingface.co/datasets/GotThatData/kraken-trading-data}
284
+ }
285
+ ```
286
+
287
+ ---
288
+
289
+ ## ๐Ÿ”— Related Resources
290
+
291
+ - **Kraken API Docs:** [https://docs.kraken.com/rest/](https://docs.kraken.com/rest/)
292
+ - **ccxt Library:** [https://github.com/ccxt/ccxt](https://github.com/ccxt/ccxt) - Unified crypto exchange API
293
+ - **TA-Lib:** [https://ta-lib.org/](https://ta-lib.org/) - Technical analysis library
294
+
295
+ ---
296
+
297
+ ## โš™๏ธ Data Collection Methodology
298
+
299
+ Data was collected using:
300
+ 1. **Kraken WebSocket API** - Real-time trade stream (sub-second latency)
301
+ 2. **Kraken REST API** - Order book snapshots (every 10 seconds)
302
+ 3. **ccxt Library** - Normalized OHLCV data (1min, 5min, 1h, 1d intervals)
303
+
304
+ **Collection Period:** January 2024 - December 2024 (ongoing updates)
305
+ **Update Frequency:** Daily (new data added at 00:00 UTC)
306
+
307
+ ---
308
+
309
+ ## ๐Ÿ“œ License
310
+
311
+ MIT License - free for academic and commercial use.
312
+
313
+ **Disclaimer:** This data is for research and educational purposes only. Past performance does not guarantee future results. Cryptocurrency trading involves significant risk.
314
+
315
+ ---
316
+
317
+ ## ๐Ÿ™ Acknowledgments
318
+
319
+ - **Kraken Exchange** - For providing free, high-quality market data APIs
320
+ - **ccxt Community** - For building robust exchange integration tools
321
+ - **Hugging Face** - For hosting and serving this dataset
322
+
323
+ ---
324
+
325
+ ## ๐Ÿ› Known Issues & Future Work
326
+
327
+ - **Missing Data:** Some gaps during exchange maintenance windows (< 0.1% of total data)
328
+ - **Timezone:** All timestamps are UTC
329
+ - **Delisting:** BNBUSD was delisted in June 2024 (data ends June 30)
330
+
331
+ **Roadmap:**
332
+ - [ ] Add L2 order book data (full depth, not just top 20 levels)
333
+ - [ ] Include funding rate data for perpetual futures
334
+ - [ ] Add cross-exchange arbitrage opportunities dataset
335
+ - [ ] Create Gradio Space for interactive data exploration
336
+
337
+ ---
338
+
339
+ ## ๐Ÿ’ฌ Feedback & Contributions
340
+
341
+ Found a bug? Want to request additional pairs or features?
342
+
343
+ - **Discussions:** [Open a discussion](https://huggingface.co/datasets/GotThatData/kraken-trading-data/discussions)
344
+ - **Contact:** YourFriends@smartledger.solutions
345
+
346
+ ---
347
+
348
+ *"In trading, the only constant is change. Adapt or fade away."* โ€” Paul Tudor Jones