pywry.tvchart.datafeed¶
Abstract base class for TradingView datafeed providers. Implement
DatafeedProvider to connect any data source to a PyWry TradingView chart.
pywry.tvchart.datafeed.DatafeedProvider
¶
Bases: ABC
Interface that every TradingView datafeed adapter must implement.
Subclasses must implement four required methods and may override optional methods for marks, timescale marks, server time, and real-time subscriptions.
Required Methods
get_config Return the datafeed configuration dict. search_symbols Search for symbols matching a query string. resolve_symbol Resolve a symbol name to full symbol metadata. get_bars Fetch historical OHLCV bars for a symbol and resolution.
Optional Methods
get_marks Return chart marks (default: empty list). get_timescale_marks Return timescale marks (default: empty list). get_server_time Return server time as Unix seconds (default: local clock). on_subscribe Called when the chart subscribes to real-time bar updates. on_unsubscribe Called when the chart unsubscribes from bar updates. close Release resources held by the provider.
Feature Flags
Set these properties to True to enable optional handler wiring:
supports_marks, supports_timescale_marks, supports_time,
supports_search.
Attributes¶
supports_timescale_marks
property
¶
Whether this provider supplies timescale marks.
Functions¶
get_config
abstractmethod
async
¶
Return the datafeed configuration (onReady response).
Returns:
| Type | Description |
|---|---|
dict
|
Keys such as |
search_symbols
abstractmethod
async
¶
search_symbols(query: str, symbol_type: str = '', exchange: str = '', limit: int = 30) -> list[dict[str, Any]]
Search for symbols matching query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User-entered search text. |
required |
symbol_type
|
str
|
Filter by symbol type (e.g. |
''
|
exchange
|
str
|
Filter by exchange name. |
''
|
limit
|
int
|
Maximum number of results to return. |
30
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
Each dict should have |
resolve_symbol
abstractmethod
async
¶
Resolve a symbol name to full symbol metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Symbol name or ticker to resolve. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A |
get_bars
abstractmethod
async
¶
get_bars(symbol: str, resolution: str, from_ts: int, to_ts: int, countback: int | None = None) -> dict[str, Any]
Fetch historical OHLCV bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Symbol name or ticker. |
required |
resolution
|
str
|
Bar resolution (e.g. |
required |
from_ts
|
int
|
Start of requested range (Unix epoch seconds). |
required |
to_ts
|
int
|
End of requested range (Unix epoch seconds). |
required |
countback
|
int or None
|
Number of bars to return (optional, used by some servers). |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Must include |
get_marks
async
¶
Return chart marks (default: empty).
get_timescale_marks
async
¶
Return timescale marks (default: empty).
get_server_time
async
¶
Return server time as unix seconds (default: local clock).
on_subscribe
¶
Called when the chart subscribes to real-time bar updates.
on_unsubscribe
¶
Called when the chart unsubscribes from bar updates.