Core Library: Providers¶
Base classes and provider implementations.
Provider base classes¶
core ¶
Provider base classes and helpers for historical and live data.
DataProvider ¶
DataProvider(
context: DerivedContext, preferences: dict | None = None
)
Bases: ABC
Base class for all data provider types.
Initialize provider with rate limiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
DerivedContext
|
Derived context containing provider secrets. |
required |
preferences
|
dict | None
|
Optional configuration preferences from database. |
None
|
Note
The HTTP session is created lazily in aenter to ensure it is initialized within an async context, avoiding aiohttp event loop issues.
Source code in quasar/lib/providers/core.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
__aenter__
async
¶
__aenter__()
Initialize session and return self for async context manager use.
Creates the aiohttp ClientSession within the async context to ensure proper event loop attachment.
Source code in quasar/lib/providers/core.py
240 241 242 243 244 245 246 247 248 249 250 | |
__aexit__
async
¶
__aexit__(*exc)
Close the HTTP session on context manager exit.
Source code in quasar/lib/providers/core.py
252 253 254 | |
aclose
async
¶
aclose()
Close the underlying HTTP session if it exists.
Source code in quasar/lib/providers/core.py
234 235 236 237 238 | |
fetch_available_symbols
abstractmethod
async
¶
fetch_available_symbols() -> list[SymbolInfo]
Return all symbols available for trading on this provider.
Source code in quasar/lib/providers/core.py
203 204 205 | |
get_available_symbols
async
¶
get_available_symbols() -> list[SymbolInfo]
Return all symbols available for trading on this provider.
Source code in quasar/lib/providers/core.py
207 208 209 210 | |
get_data
async
¶
get_data(reqs: Iterable[Req]) -> AsyncIterator[Bar]
get_data(
interval: Interval, symbols: list[str]
) -> list[Bar]
get_data(*args: Any, **kwargs: Any) -> AsyncIterator[Bar]
Route to historical or live data based on provider type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments for the concrete provider. |
()
|
**kwargs
|
Any
|
Keyword arguments for the concrete provider. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Bar |
AsyncIterator[Bar]
|
Bars produced by the provider implementation. |
Source code in quasar/lib/providers/core.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
HistoricalDataProvider ¶
HistoricalDataProvider(
context: DerivedContext, preferences: dict | None = None
)
Bases: DataProvider
Base class for all historical data provider types.
Source code in quasar/lib/providers/core.py
283 284 | |
get_history
abstractmethod
async
¶
get_history(
sym: str, start: date, end: date, interval: Interval
) -> AsyncIterator[Bar]
Return inclusive [start, end] bars ordered oldest→newest.
Source code in quasar/lib/providers/core.py
305 306 307 308 309 310 311 312 313 | |
get_history_many
async
¶
get_history_many(reqs: Iterable[Req]) -> AsyncIterator[Bar]
Yield bars for multiple requests using get_history by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reqs
|
Iterable[Req]
|
Requests to process. |
required |
Yields:
| Name | Type | Description |
|---|---|---|
Bar |
AsyncIterator[Bar]
|
Bars returned from |
Source code in quasar/lib/providers/core.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
IndexConstituent ¶
Bases: TypedDict
Constituent of an index with optional weight and asset metadata.
Required fields
symbol: Provider's symbol for this constituent
Optional fields
weight: Weight in the index (None = equal weight) name: Human-readable name (e.g., "Bitcoin") asset_class: Asset classification (e.g., "crypto", "equity") matcher_symbol: Symbol used for matching (defaults to symbol if not provided) base_currency: Base currency for pairs (e.g., "BTC") quote_currency: Quote currency for pairs (e.g., "USD") exchange: Exchange or market identifier
IndexProvider ¶
IndexProvider(
context: DerivedContext, preferences: dict | None = None
)
Bases: DataProvider
Base class for index providers that return constituent lists.
Initialize index provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
DerivedContext
|
Derived context containing provider secrets. |
required |
preferences
|
dict | None
|
Optional configuration preferences from database. |
None
|
Source code in quasar/lib/providers/core.py
465 466 467 468 469 470 471 472 | |
fetch_available_symbols
async
¶
fetch_available_symbols() -> list[SymbolInfo]
Not applicable for index providers.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
IndexProvider does not support this method. |
Source code in quasar/lib/providers/core.py
512 513 514 515 516 517 518 519 520 521 | |
fetch_constituents
abstractmethod
async
¶
fetch_constituents(
as_of_date: date | None = None,
) -> list[IndexConstituent]
Return index constituents for the given date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_of_date
|
date | None
|
Date for which to fetch constituents. None means current/latest. |
None
|
Returns:
| Type | Description |
|---|---|
list[IndexConstituent]
|
List of constituents with provider symbols and optional weights. |
Source code in quasar/lib/providers/core.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
get_constituents
async
¶
get_constituents(
as_of_date: date | None = None,
) -> list[IndexConstituent]
Public method to get constituents with usage tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_of_date
|
date | None
|
Date for which to fetch constituents. None means current/latest. |
None
|
Returns:
| Type | Description |
|---|---|
list[IndexConstituent]
|
List of constituents with provider symbols and optional weights. |
Source code in quasar/lib/providers/core.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
LiveDataProvider ¶
LiveDataProvider(
context: DerivedContext, preferences: dict | None = None
)
Bases: DataProvider
Base class for all live data provider types.
Source code in quasar/lib/providers/core.py
341 342 | |
close_buffer_seconds
abstractmethod
property
¶
close_buffer_seconds: int
Number of seconds to keep listening for messages after bar close.
get_live
async
¶
get_live(
interval: Interval,
symbols: list[str],
timeout: int = None,
) -> list[Bar]
Get live bars for the given symbols via websocket stream.
Source code in quasar/lib/providers/core.py
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 | |
subscribe
async
¶
subscribe(
connection: WebSocketClientConnection,
interval: Interval,
symbols: list[str],
)
Subscribe to the given symbols for the specified interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
WebSocketClientConnection
|
Active websocket connection. |
required |
interval
|
Interval
|
Interval requested. |
required |
symbols
|
list[str]
|
Symbols to subscribe. |
required |
Source code in quasar/lib/providers/core.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
unsubscribe
async
¶
unsubscribe(
conn: WebSocketClientConnection, symbols: list[str]
)
Unsubscribe from the given symbols.
Source code in quasar/lib/providers/core.py
390 391 392 393 394 395 396 397 398 399 400 | |
async_timeout ¶
async_timeout(
seconds: int = 60,
) -> Callable[
[Callable[..., Awaitable[T]]],
Callable[..., Awaitable[T]],
]
Return an async decorator that enforces a timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
int
|
Default timeout in seconds. |
60
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable[[Callable[..., Awaitable[T]]], Callable[..., Awaitable[T]]]
|
Decorator that wraps a coroutine with |
Raises:
| Type | Description |
|---|---|
Exception
|
Propagates any exception from the wrapped coroutine. |
Source code in quasar/lib/providers/core.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
get_next_interval_timestamp ¶
get_next_interval_timestamp(interval: Interval) -> datetime
Calculate the next even interval timestamp from current time
Source code in quasar/lib/providers/core.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
EODHD provider¶
eodhd ¶
Built-in historical data provider for EODHD.
EODHDProvider ¶
EODHDProvider(
context: DerivedContext, preferences: dict | None = None
)
Bases: HistoricalDataProvider
Source code in quasar/lib/providers/core.py
283 284 | |
fetch_available_symbols
async
¶
fetch_available_symbols() -> list[SymbolInfo]
Return available symbols from EODHD filtered to supported exchanges.
Source code in quasar/lib/providers/examples/eodhd.py
28 29 30 31 32 33 34 35 36 37 38 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 115 116 117 | |
get_history
async
¶
get_history(
sym: str, start: date, end: date, interval: Interval
)
Yield historical bars from EODHD for the given symbol and range.
Source code in quasar/lib/providers/examples/eodhd.py
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 | |
Kraken provider¶
kraken ¶
Built-in live data provider for Kraken WebSocket OHLC data.
KrakenProvider ¶
KrakenProvider(
context: DerivedContext, preferences: dict | None = None
)
Bases: LiveDataProvider
Source code in quasar/lib/providers/examples/kraken.py
23 24 25 | |
fetch_available_symbols
async
¶
fetch_available_symbols() -> list[SymbolInfo]
Return supported Kraken trading pairs denominated in USD or USDC.
Source code in quasar/lib/providers/examples/kraken.py
27 28 29 30 31 32 33 34 35 36 37 38 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 | |
Developer harness¶
Use quasar.lib.providers.devtools to exercise historical and live provider subclasses without bringing up the full stack.
- Python API:
run_historical(config)/run_live(config)/run_symbols(config)always validate outputs (strict by default). - CLI (bars):
python -m quasar.lib.providers.devtools bars --config ./config.json --limit 100 - CLI (symbols):
python -m quasar.lib.providers.devtools symbols --config ./config.json - Config must include
provider_type(historicalorlive) andprovider. - Strict mode is on by default; disable with
--no-strict(CLI) orstrict=False(API). - Example configs and stub providers live under
quasar/lib/providers/devtools/examples/andquasar.lib.providers.devtools.stubs.
Minimal examples:
python -m quasar.lib.providers.devtools bars \
--config quasar/lib/providers/devtools/examples/historical_stub.json
Fetch symbols:
python -m quasar.lib.providers.devtools symbols \
--config quasar/lib/providers/devtools/examples/historical_stub.json
from quasar.lib.providers.devtools import run_live
config = {
"provider_type": "live",
"provider": "quasar.lib.providers.devtools.stubs:LiveStub",
"interval": "1min",
"symbols": ["AAA", "BBB"],
"secrets": {},
}
bars = run_live(config)