cointoss.sources.coingecko¶
coingecko
¶
CoinGecko API client.
MARKET_CHART_MAX_DAYS = 365
module-attribute
¶
How far back /coins/{id}/market_chart reaches without a paid key.
Measured: days=max answers HTTP 401 Unauthorized on the free tier. The ceiling is enforced
before the request rather than discovered as a 401, and never quietly clipped to 365, because a
window silently shortened to a year looks like a coin that simply has no older history.
MARKETS_MAX_PER_PAGE = 250
module-attribute
¶
The most coins one /coins/markets page returns; a wider listing is paged.
MarketChartRangeUnavailable
¶
OhlcCandle
¶
Bases: BaseModel
OHLC candle. timestamp is milliseconds since epoch (CoinGecko convention).
Source code in src/cointoss/sources/coingecko.py
dt
property
¶
Timestamp as a UTC datetime.
MarketChartPoint
¶
Bases: BaseModel
One [ts, value] pair. timestamp is milliseconds since epoch (CoinGecko convention).
Source code in src/cointoss/sources/coingecko.py
dt
property
¶
Timestamp as a UTC datetime.
MarketChart
¶
Bases: BaseModel
Three parallel series over one time range: price, market cap and traded volume.
Measured against the live API, the three carry identical timestamps, but nothing in the
payload guarantees that, so they are kept as three series rather than zipped into one row
type here. cointoss.prices.bars_from_market_chart aligns them by UTC day.
Source code in src/cointoss/sources/coingecko.py
CoinGeckoClient
¶
Bases: NamespaceFragment
Async HTTP client for the CoinGecko public API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rpm
|
float | None
|
Max requests per minute. None means no local rate limiting. CoinGecko demo API allows ~30 rpm. |
None
|
Source code in src/cointoss/sources/coingecko.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | |
fetch_coin_list(*, include_platform=None)
async
¶
Fetch the full list of coins from /coins/list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_platform
|
bool | None
|
Include platform contract addresses. API default: false. |
None
|
Source code in src/cointoss/sources/coingecko.py
fetch_coins_markets(vs_currency='usd', *, ids=None, names=None, symbols=None, include_tokens=None, category=None, order=None, per_page=None, page=None, sparkline=None, price_change_percentage=None, locale=None, precision=None, include_rehypothecated=None)
async
¶
Fetch coin market data from /coins/markets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vs_currency
|
str
|
Target currency of market data. API default: usd. |
'usd'
|
ids
|
str | None
|
Coin IDs, comma-separated. |
None
|
names
|
str | None
|
Coin names, comma-separated. |
None
|
symbols
|
str | None
|
Coin symbols, comma-separated. |
None
|
include_tokens
|
str | None
|
For symbol lookups: "top" or "all". |
None
|
category
|
str | None
|
Filter by category slug. |
None
|
order
|
str | None
|
Sort order. API default: market_cap_desc. |
None
|
per_page
|
int | None
|
Results per page (1-250). API default: 100. |
None
|
page
|
int | None
|
Page number. API default: 1. |
None
|
sparkline
|
bool | None
|
Include 7-day sparkline. API default: false. |
None
|
price_change_percentage
|
str | None
|
Price change timeframes, comma-separated (1h, 24h, 7d, 14d, 30d, 200d, 1y). |
None
|
locale
|
str | None
|
Localization language. API default: en. |
None
|
precision
|
str | None
|
Decimal places for price ("full" or "0"-"18"). |
None
|
include_rehypothecated
|
bool | None
|
Include rehypothecated tokens. API default: false. |
None
|
Source code in src/cointoss/sources/coingecko.py
fetch_coin(coin_id, *, localization=None, tickers=None, market_data=None, community_data=None, developer_data=None, sparkline=None, include_categories_details=None, dex_pair_format=None)
async
¶
Fetch coin detail from /coins/{id}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coin_id
|
str
|
CoinGecko coin ID. |
required |
localization
|
bool | None
|
Include localized languages. API default: true. |
None
|
tickers
|
bool | None
|
Include tickers data. API default: true. |
None
|
market_data
|
bool | None
|
Include market data. API default: true. |
None
|
community_data
|
bool | None
|
Include community data. API default: true. |
None
|
developer_data
|
bool | None
|
Include developer data. API default: true. |
None
|
sparkline
|
bool | None
|
Include 7-day sparkline. API default: false. |
None
|
include_categories_details
|
bool | None
|
Include category details. API default: false. |
None
|
dex_pair_format
|
str | None
|
DEX pair format: "contract_address" or "symbol". API default: contract_address. |
None
|
Source code in src/cointoss/sources/coingecko.py
fetch_coin_ohlc(coin_id, vs_currency='usd', days='30', *, precision=None)
async
¶
Fetch OHLC candle data from /coins/{id}/ohlc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coin_id
|
str
|
CoinGecko coin ID. |
required |
vs_currency
|
str
|
Target currency. API default: usd. |
'usd'
|
days
|
str
|
Data up to N days ago (1, 7, 14, 30, 90, 180, 365). |
'30'
|
precision
|
str | None
|
Decimal places for price ("full" or "0"-"18"). |
None
|
Source code in src/cointoss/sources/coingecko.py
fetch_market_chart(coin_id, vs_currency='usd', days=MARKET_CHART_MAX_DAYS, *, interval=None, precision=None)
async
¶
Fetch price, market cap and volume series from /coins/{id}/market_chart.
The only CoinGecko endpoint that yields daily points with volume; /coins/{id}/ohlc is
4-hourly below 90 days and 4-daily above it and carries no volume at all. Measured,
days=365 returns 366 points spaced 24 hours apart on 00:00 UTC plus a trailing point
at the current time. Granularity is chosen by the API from days: hourly below 90 days,
daily at 90 and above.
Rate-limited hard enough to throttle on a second immediate call, so construct the client
with rpm when fetching more than one coin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coin_id
|
str
|
CoinGecko coin ID. |
required |
vs_currency
|
str
|
Target currency. API default: usd. |
'usd'
|
days
|
str | int
|
Data up to N days ago, 1 to 365. Larger windows and |
MARKET_CHART_MAX_DAYS
|
interval
|
str | None
|
Force a data interval ("5m", "hourly", "daily"). Paid tiers only; omit it to take the automatic granularity. |
None
|
precision
|
str | None
|
Decimal places for price ("full" or "0"-"18"). |
None
|