pywry.tvchart.udf¶
UDF (Universal Datafeed) adapter that connects a PyWry TradingView chart to any UDF-compatible HTTP server. Handles config discovery, symbol search, bar fetching, marks, quotes, and optional real-time polling.
UDFAdapter¶
pywry.tvchart.udf.UDFAdapter
¶
UDFAdapter(base_url: str, headers: dict[str, str] | None = None, poll_interval: float | None = None, quote_interval: float | None = None, timeout: float = 30.0)
Bases: DatafeedProvider
Connect a PyWry TradingView chart to a UDF HTTP server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Root URL of the UDF server (e.g. |
required |
headers
|
dict or None
|
Additional HTTP headers (e.g. |
None
|
poll_interval
|
float or None
|
If set, poll |
None
|
quote_interval
|
float or None
|
If set, poll |
None
|
timeout
|
float
|
HTTP request timeout in seconds (default 30). |
30.0
|
Attributes¶
_client
instance-attribute
¶
supports_timescale_marks
property
¶
Whether the UDF server supports timescale marks.
config
property
¶
The cached UDF server configuration, or None if not yet fetched.
Functions¶
search_symbols
async
¶
search_symbols(query: str, symbol_type: str = '', exchange: str = '', limit: int = 30) -> list[dict[str, Any]]
Search UDF server for matching symbols.
resolve_symbol
async
¶
Resolve symbol metadata from the UDF server.
get_bars
async
¶
get_bars(symbol: str, resolution: str, from_ts: int, to_ts: int, countback: int | None = None) -> dict[str, Any]
Fetch bars from /history and convert to the PyWry response format.
get_marks
async
¶
Fetch chart marks from the UDF /marks endpoint.
get_timescale_marks
async
¶
Fetch timescale marks from the UDF /timescale_marks endpoint.
on_subscribe
¶
Track a bar subscription and start polling if configured.
on_unsubscribe
¶
Remove a bar subscription and stop its poll timer.
_get_quotes
async
¶
_get_quotes(symbols: list[str]) -> list[QuoteData]
Fetch real-time quotes for one or more symbols.
subscribe_quotes
¶
Register symbols for periodic quote polling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
list[str]
|
Symbols to track (e.g. |
required |
on_quote
|
callable
|
|
None
|
unsubscribe_quotes
¶
Remove symbols from quote polling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
list[str] or None
|
Symbols to remove. If None, removes all. |
None
|
connect
¶
connect(app: PyWry, symbol: str = 'AAPL', resolution: str = 'D', **show_kwargs: Any) -> Any
Wire up all UDF datafeed events and show the chart.
This is the main entry point. Call it once; it fetches
/config from the UDF server, auto-wires all datafeed
event handlers via the :class:DatafeedProvider protocol,
and calls app.show_tvchart(use_datafeed=True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
PyWry
|
The application instance. |
required |
symbol
|
str
|
Initial symbol to display (default |
'AAPL'
|
resolution
|
str
|
Initial resolution in UDF format (default |
'D'
|
**show_kwargs
|
Any
|
Extra keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
NativeWindowHandle or BaseWidget
|
The window or widget returned by |
QuoteData¶
pywry.tvchart.udf.QuoteData
¶
Snapshot of a single symbol's quote from the /quotes endpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol |
str
|
Full symbol name (e.g. |
status |
str
|
Per-symbol status ( |
error |
str
|
Error message if |
short_name |
str
|
Abbreviated symbol name. |
exchange |
str
|
Exchange name. |
description |
str
|
Human-readable description. |
last_price |
float | None
|
Last traded price. |
change |
float | None
|
Absolute price change. |
change_percent |
float | None
|
Percentage price change. |
open_price |
float | None
|
Opening price. |
high_price |
float | None
|
High price. |
low_price |
float | None
|
Low price. |
prev_close_price |
float | None
|
Previous close price. |
volume |
float | None
|
Trading volume. |
ask |
float | None
|
Ask price. |
bid |
float | None
|
Bid price. |
raw |
dict
|
The raw |
Attributes¶
__slots__
class-attribute
instance-attribute
¶
__slots__ = ('ask', 'bid', 'change', 'change_percent', 'description', 'error', 'exchange', 'high_price', 'last_price', 'low_price', 'open_price', 'prev_close_price', 'raw', 'short_name', 'status', 'symbol', 'volume')
Functions¶
format_ticker_html
¶
Build an HTML snippet suitable for a Marquee TickerItem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_change
|
bool
|
Include change / change-percent after the price. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Ready-to-use HTML string. |
Utility Functions¶
pywry.tvchart.udf.to_udf_resolution
¶
Convert a PyWry canonical resolution to UDF wire format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canonical
|
str
|
Resolution string like |
required |
Returns:
| Type | Description |
|---|---|
str
|
UDF format like |
pywry.tvchart.udf.from_udf_resolution
¶
Convert a UDF resolution string to PyWry canonical format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
udf_res
|
str
|
UDF resolution like |
required |
Returns:
| Type | Description |
|---|---|
str
|
Canonical format like |
pywry.tvchart.udf.parse_udf_columns
¶
Parse a UDF "response-as-a-table" columnar object into row dicts.
In UDF format, each key maps to either a scalar (same for all rows) or a list (one value per row). This function normalises both into a list of per-row dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Raw UDF columnar response. |
required |
count
|
int or None
|
Expected row count. If None, inferred from the first list-valued field. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
One dict per row. |