Data¶
_fetch ¶
fetch_glassnode ¶
fetch_glassnode(endpoint: str, params: dict[str, str], api_key: str | None = None, cache_dir: Path | None = None) -> DataFrame
Fetch data from Glassnode and returns a DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
Example: '/v1/metrics/market/price_usd_close' |
required |
params
|
dict[str, str]
|
Example: {'a': 'BTC', 'i': '10m'} |
required |
api_key
|
str | None
|
Glassnode API key. If not provided, the function attempts to load it from the environment variable "GLASSNODE_API_KEY". |
None
|
cache_dir
|
Path | None
|
Directory path to store and retrieve cached parquet files. If None, caching is disabled and data is always fetched from the API. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Data fetched from Glassnode in DataFrame format. |
Source code in ctalearn/data/_fetch.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
fetch_glassnode_cs ¶
fetch_glassnode_cs(endpoint: str, params: dict[str, str], universe: list[str], api_key: str | None = None, cache_dir: Path | None = None, max_workers: int = 5) -> dict[str, DataFrame]
Fetch cross-sectional data from Glassnode for a universe of assets in parallel.
This function iterates through the universe list, fetching data for each asset
concurrently. It aggregates the results by metric, aligning data on the timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The Glassnode API endpoint (e.g., '/v1/metrics/market/price_usd_close'). |
required |
params
|
dict[str, str]
|
Dictionary of query parameters. The 'a' (asset) parameter will be overridden
by each symbol in the |
required |
universe
|
list[str]
|
A list of asset symbols to fetch (e.g., ['BTC', 'ETH', 'BNB']). |
required |
api_key
|
str | None
|
Glassnode API key. Defaults to None (will attempt to use env var). |
None
|
cache_dir
|
Path | None
|
Directory to use for caching requests. Defaults to None. |
None
|
max_workers
|
int
|
Maximum number of concurrent threads for fetching data. Defaults to 5. |
5
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
A dictionary mapping the original metric name to a combined DataFrame. Example Structure: { 'price': DataFrame(columns=[time_col, 'BTC', 'ETH', ...]), 'active_addr': DataFrame(columns=[time_col, 'BTC', 'ETH', ...]) } Note: The DataFrames are constructed using an 'inner' join logic across assets. This means the resulting DataFrame will only contain timestamps that exist in ALL assets. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If any asset in |
Source code in ctalearn/data/_fetch.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |