pywry.tvchart.config¶
Configuration models for TradingView Lightweight Charts. These Pydantic models
define chart options, series options, drawing state, indicator presets,
templates, themes, and the top-level TVChartConfig.
Enums¶
pywry.tvchart.config.PriceScaleMode
¶
Bases: int, Enum
Price scale modes.
pywry.tvchart.config.CrosshairMode
¶
pywry.tvchart.config.LineStyle
¶
pywry.tvchart.config.LineWidth
¶
pywry.tvchart.config.DrawingToolType
¶
Chart Options¶
pywry.tvchart.config.PriceScaleConfig
¶
Bases: BaseModel
Price scale (Y-axis) configuration.
See: https://tradingview.github.io/lightweight-charts/docs/api/interfaces/PriceScaleOptions
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
PriceScaleMode
|
Scale mode (normal, logarithmic, percentage, indexed-to-100). |
auto_scale |
bool
|
Automatically fit visible data to the price scale. |
invert_scale |
bool
|
Invert the price axis (high at bottom). |
align_labels |
bool
|
Align price labels to the scale edge. |
border_visible |
bool
|
Show the price scale border line. |
border_color |
str or None
|
Border line color. |
text_color |
str or None
|
Label text color. |
entire_text_only |
bool
|
Show labels only when they fit without truncation. |
visible |
bool
|
Show the price scale. |
scale_margins |
dict or None
|
Top/bottom margins as fractions ( |
Attributes¶
pywry.tvchart.config.TimeScaleConfig
¶
Bases: BaseModel
Time scale (X-axis) configuration.
See: https://tradingview.github.io/lightweight-charts/docs/api/interfaces/TimeScaleOptions
Attributes:
| Name | Type | Description |
|---|---|---|
right_offset |
int
|
Whitespace bars to the right of the last data point. |
bar_spacing |
float
|
Minimum spacing between bars in pixels. |
min_bar_spacing |
float
|
Absolute minimum bar spacing (zoom limit). |
fix_left_edge |
bool
|
Prevent scrolling past the first bar. |
fix_right_edge |
bool
|
Prevent scrolling past the last bar. |
lock_visible_time_range_on_resize |
bool
|
Keep the same visible range when resizing. |
right_bar_stays_on_scroll |
bool
|
Pin the rightmost bar during scroll. |
border_visible |
bool
|
Show the time scale border line. |
border_color |
str or None
|
Border line color. |
visible |
bool
|
Show the time scale. |
time_visible |
bool
|
Show time-of-day on labels. |
seconds_visible |
bool
|
Show seconds on time labels. |
shift_visible_range_on_new_bar |
bool
|
Auto-scroll when a new bar arrives. |
tick_mark_max_character_length |
int or None
|
Max characters for tick mark labels. |
pywry.tvchart.config.CrosshairConfig
¶
Bases: BaseModel
Crosshair configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
CrosshairMode
|
Crosshair tracking mode (normal or magnet). |
vert_line |
dict or None
|
Vertical crosshair line style overrides. |
horz_line |
dict or None
|
Horizontal crosshair line style overrides. |
Attributes¶
pywry.tvchart.config.WatermarkConfig
¶
Bases: BaseModel
Watermark overlay text configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
visible |
bool
|
Show the watermark. |
text |
str
|
Watermark text content. |
font_size |
int
|
Font size in pixels. |
color |
str
|
Text color (CSS color string). |
horz_align |
str
|
Horizontal alignment ( |
vert_align |
str
|
Vertical alignment ( |
Attributes¶
pywry.tvchart.config.GridConfig
¶
Bases: BaseModel
Chart grid lines configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
vert_lines |
dict or None
|
Vertical grid line style ( |
horz_lines |
dict or None
|
Horizontal grid line style. |
pywry.tvchart.config.LayoutConfig
¶
Bases: BaseModel
Chart layout configuration.
See: https://tradingview.github.io/lightweight-charts/docs/api/interfaces/LayoutOptions
Attributes:
| Name | Type | Description |
|---|---|---|
background |
dict or None
|
Background style ( |
text_color |
str or None
|
Default text color for labels. |
font_size |
int or None
|
Default font size in pixels. |
font_family |
str or None
|
Default font family. |
Attributes¶
Series Options¶
pywry.tvchart.config.SeriesConfig
¶
Bases: BaseModel
Per-series configuration options.
Attributes:
| Name | Type | Description |
|---|---|---|
series_type |
SeriesType
|
Chart series type (candlestick, line, area, etc.). |
price_scale_id |
str
|
Target price scale ('right', 'left', or custom ID). |
up_color |
str or None
|
Candlestick up (bullish) body color. |
down_color |
str or None
|
Candlestick down (bearish) body color. |
color |
str or None
|
Line / area / histogram color. |
line_width |
int or None
|
Line thickness in pixels. |
Attributes¶
Drawing & Indicator Models¶
pywry.tvchart.config.DrawingToolConfig
¶
Bases: BaseModel
Configuration for an active drawing tool.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_type |
DrawingToolType
|
The drawing tool identifier. |
color |
str
|
Stroke color. |
line_width |
int
|
Stroke width in pixels. |
line_style |
LineStyle
|
Stroke dash pattern. |
fill_color |
str or None
|
Fill color (shapes only). |
fill_opacity |
float
|
Fill opacity 0-1. |
snap_to_candle |
bool
|
Whether coordinates snap to candle data points. |
Attributes¶
pywry.tvchart.config.DrawingCoordinate
¶
pywry.tvchart.config.DrawingState
¶
Bases: BaseModel
Serializable state of a single drawing on the chart.
Attributes:
| Name | Type | Description |
|---|---|---|
drawing_id |
str
|
Unique identifier for this drawing. |
tool_type |
DrawingToolType
|
The type of drawing tool used. |
coordinates |
list of DrawingCoordinate
|
Anchor points for the drawing. |
config |
DrawingToolConfig
|
Visual configuration (color, line width, etc.). |
z_order |
int
|
Stacking order (higher = on top). |
locked |
bool
|
Whether the drawing is locked from editing. |
visible |
bool
|
Whether the drawing is visible. |
Attributes¶
pywry.tvchart.config.IndicatorConfig
¶
Bases: BaseModel
Configuration for a computed indicator overlay.
Attributes:
| Name | Type | Description |
|---|---|---|
indicator_type |
str
|
Registry name (e.g. 'sma', 'rsi', 'macd'). |
params |
dict
|
Indicator-specific parameters (period, source, etc.). |
series_style |
SeriesConfig or None
|
Override series rendering options. |
pane_index |
int
|
0 = main pane, 1+ = sub-panes. |
Attributes¶
pywry.tvchart.config.IndicatorPreset
¶
Bases: BaseModel
Saveable indicator parameter preset.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Display name for the preset. |
indicator_type |
str
|
Registry name of the indicator (e.g. |
params |
dict
|
Indicator-specific parameter values. |
description |
str
|
Optional description. |
Attributes¶
Templates & Themes¶
pywry.tvchart.config.ChartTemplate
¶
Bases: BaseModel
Saveable chart style and indicator preset (no data).
Templates store indicator configurations and chart style but not symbol, timeframe, or bar data.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Template name. |
description |
str
|
Optional description. |
indicators |
list of IndicatorConfig
|
Indicator overlays and studies. |
series_config |
SeriesConfig or None
|
Main series rendering options. |
layout |
LayoutConfig or None
|
Chart layout overrides. |
grid |
GridConfig or None
|
Grid line overrides. |
crosshair |
CrosshairConfig or None
|
Crosshair overrides. |
price_scale |
PriceScaleConfig or None
|
Y-axis overrides. |
time_scale |
TimeScaleConfig or None
|
X-axis overrides. |
Attributes¶
indicators
class-attribute
instance-attribute
¶
indicators: list[IndicatorConfig] = Field(default_factory=list)
pywry.tvchart.config.ChartTheme
¶
Bases: BaseModel
Custom color theme for chart elements.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Theme name. |
description |
str
|
Optional description. |
background_color |
str
|
Chart background color. |
text_color |
str
|
Default text color. |
font_family |
str or None
|
Font family override. |
up_color |
str
|
Bullish (up) candle body color. |
down_color |
str
|
Bearish (down) candle body color. |
wick_up_color |
str
|
Bullish candle wick color. |
wick_down_color |
str
|
Bearish candle wick color. |
grid_color |
str
|
Grid line color. |
crosshair_color |
str
|
Crosshair line color. |
scale_border_color |
str
|
Price/time scale border color. |
scale_text_color |
str
|
Price/time scale text color. |
volume_up_color |
str
|
Up-volume bar color. |
volume_down_color |
str
|
Down-volume bar color. |
Saved Chart¶
pywry.tvchart.config.SavedChart
¶
Bases: BaseModel
Full chart state for persistence.
Stores everything needed to restore a chart view. Bar data itself is not stored -- only a reference (symbol + timeframe) -- since data should be re-fetched on load.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Layout name. |
symbol |
str
|
Symbol ticker (e.g. |
timeframe |
str
|
Resolution string (e.g. |
series_type |
SeriesType
|
Chart series type (candlestick, line, etc.). |
indicators |
list of IndicatorConfig
|
Active indicator overlays. |
drawings |
list of DrawingState
|
Saved drawing annotations. |
visible_range |
dict or None
|
Time range to restore ( |
template_ref |
str or None
|
Name of applied template. |
theme_ref |
str or None
|
Name of applied theme. |
compare_symbols |
list of str
|
Comparison overlay symbols. |
price_scale |
PriceScaleConfig or None
|
Y-axis configuration. |
time_scale |
TimeScaleConfig or None
|
X-axis configuration. |
layout |
LayoutConfig or None
|
Layout configuration. |
Attributes¶
indicators
class-attribute
instance-attribute
¶
indicators: list[IndicatorConfig] = Field(default_factory=list)
drawings
class-attribute
instance-attribute
¶
drawings: list[DrawingState] = Field(default_factory=list)
compare_symbols
class-attribute
instance-attribute
¶
Top-Level Configuration¶
pywry.tvchart.config.TVChartConfig
¶
Bases: BaseModel
Top-level TradingView Lightweight Charts configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
series |
SeriesConfig
|
Main data series rendering options. |
layout |
LayoutConfig or None
|
Chart layout (background, text color, font). |
grid |
GridConfig or None
|
Grid line configuration. |
crosshair |
CrosshairConfig or None
|
Crosshair behavior and style. |
watermark |
WatermarkConfig or None
|
Watermark overlay. |
price_scale |
PriceScaleConfig or None
|
Default price scale options. |
time_scale |
TimeScaleConfig or None
|
Time scale options. |
right_price_scale |
PriceScaleConfig or None
|
Right price scale overrides. |
left_price_scale |
PriceScaleConfig or None
|
Left price scale overrides. |
overlay_price_scales |
dict or None
|
Named price scales for overlay series. |
locale |
str or None
|
Locale for number/date formatting. |
price_formatter |
str or None
|
Custom price formatting function name. |
time_formatter |
str or None
|
Custom time formatting function name. |
auto_size |
bool
|
Automatically resize chart to fill its container. |
Attributes¶
series
class-attribute
instance-attribute
¶
series: SeriesConfig = Field(default_factory=SeriesConfig)
right_price_scale
class-attribute
instance-attribute
¶
right_price_scale: PriceScaleConfig | None = None
left_price_scale
class-attribute
instance-attribute
¶
left_price_scale: PriceScaleConfig | None = None
overlay_price_scales
class-attribute
instance-attribute
¶
overlay_price_scales: dict[str, PriceScaleConfig] | None = None
Functions¶
to_chart_options
¶
Serialize to the options dict expected by createChart().
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Chart options with camelCase keys. |
to_series_options
¶
Serialize the main series configuration.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Series options with camelCase keys. |