Skip to content

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_marks property

supports_marks: bool

Whether this provider supplies chart marks.

supports_timescale_marks property

supports_timescale_marks: bool

Whether this provider supplies timescale marks.

supports_time property

supports_time: bool

Whether this provider supplies a server-time endpoint.

supports_search: bool

Whether this provider supports symbol search.

Functions

get_config abstractmethod async

get_config() -> dict[str, Any]

Return the datafeed configuration (onReady response).

Returns:

Type Description
dict

Keys such as supported_resolutions, exchanges, symbols_types, supports_marks, etc.

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. "crypto").

''
exchange str

Filter by exchange name.

''
limit int

Maximum number of results to return.

30

Returns:

Type Description
list[dict]

Each dict should have symbol, full_name, description, exchange, type keys.

resolve_symbol abstractmethod async

resolve_symbol(symbol: str) -> dict[str, Any]

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 TVChartSymbolInfo-compatible dict.

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. "1", "60", "D", "W").

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 bars (list[dict]), status ("ok" | "no_data" | "error"). May include no_data (bool), next_time (int), error (str).

get_marks async

get_marks(symbol: str, from_ts: int, to_ts: int, resolution: str) -> list[dict[str, Any]]

Return chart marks (default: empty).

get_timescale_marks async

get_timescale_marks(symbol: str, from_ts: int, to_ts: int, resolution: str) -> list[dict[str, Any]]

Return timescale marks (default: empty).

get_server_time async

get_server_time() -> int

Return server time as unix seconds (default: local clock).

on_subscribe

on_subscribe(listener_guid: str, symbol: str, resolution: str, chart_id: str | None = None) -> None

Called when the chart subscribes to real-time bar updates.

on_unsubscribe

on_unsubscribe(listener_guid: str) -> None

Called when the chart unsubscribes from bar updates.

close

close() -> None

Release resources held by the provider.