Chart data types
Try it in Python
Inspect the data used to draw a candle. The chart specification can also be saved as JSON.
from pricegenerator import Generate, GenerationConfig
from pricegenerator.rendering import PrepareChart
spec = PrepareChart(Generate(GenerationConfig(seed=42, horizon=24)))
print(spec.candles[0].close)pricegenerator.rendering.spec
Describe a chart with plain Python objects. The specification fixes candle order, time zone, price and volume fields, overlay alignment, and presentation options so different renderers can use the same inputs.
ChartCandle
One validated OHLCV bar for a chart. The timestamp is normalized to UTC with millisecond precision. The low and high must enclose both open and close. Volume must be finite and nonnegative. Fractional volume from imported markets is accepted.
ChartCandle(datetime: str, open: float, high: float, low: float, close: float, volume: float)
Fields (6)
datetime- ISO 8601 timestamp for this bar with an explicit UTC offset or Z. Precision must not be finer than one millisecond. Internally it is normalized to UTC.
open- Opening price of the candle, one end of the candle body. It must fall within the interval from low to high.
high- Highest price during this bar, at or above both open and close.
low- Lowest price during this bar, at or below both open and close.
close- Closing price of the candle, the other end of the candle body. It must fall within the interval from low to high.
volume- Nonnegative traded quantity during this bar, in the unit used by the source data. The chart accepts fractional quantities for markets quoted in such units.
ChartSeries
Describe a named line or point layer with one value per candle. Use None for gaps. The key identifies a layer across the chart, while its group lets related layers share one toggle in HTML. Static export draws layers marked visible.
ChartSeries(
key: str,
label: str,
values: tuple[float | None, ...],
color: str | None = None,
kind: str = 'line',
visible: bool = True,
group: str | None = None,
width: float = 1.8,
dashed: bool = False,
)
Fields (9)
key- Unique chart identifier, at most 80 characters. Start with an ASCII letter, then use ASCII letters, digits, underscores, dots or hyphens.
label- Human-readable name of an indicator or overlay, used in chart legends and controls.
values- A finite number or None for each candle in the same order. None leaves a gap in the layer.
color- Optional six-digit hexadecimal color in #RRGGBB form. None uses the renderer’s default color for the element.
kind- Drawing style, either line for a connected line or points for individual markers.
visible- Initial visibility in HTML and whether the series is drawn in a static export.
group- Name used to toggle related indicator or overlay series together in the HTML chart.
width- Stroke width for the series, greater than 0 and no more than 20. This controls the overlay, independently of chart width.
dashed- Whether to use a dashed stroke for the line overlay.
ChartMarker
Attach a plain-text annotation to a candle by its zero-based index. Choose a position above, below or near the middle of the candle, and optionally set a color.
ChartMarker(candle_index: int, text: str, position: str = 'above', color: str | None = None)
Fields (4)
candle_index- Zero-based position of the annotated candle. It must refer to an existing candle in the enclosing ChartSpec.
text- Plain text to display next to the selected candle.
position- Marker position relative to its candle, one of above, center or below.
color- Optional six-digit hexadecimal color in #RRGGBB form. None uses the renderer’s default color for the element.
ChartSpec
A validated snapshot shared by HTML, SVG and raster exports. Provide at least one candle with strictly increasing timestamps, unique series keys and one value per candle in every overlay. Every marker must reference a candle in this snapshot.
ChartSpec(
candles: tuple[ChartCandle, ...],
title: str = 'PriceGenerator',
series: tuple[ChartSeries, ...] = (),
markers: tuple[ChartMarker, ...] = (),
summary: tuple[str, ...] = (),
theme: str = 'dark',
width: int = 1280,
height: int = 760,
price_precision: int = 2,
show_controls: bool = True,
)
Fields (10)
candles- One or more ChartCandle records in strictly increasing time order. Duplicate candle timestamps are invalid.
title- Title displayed on the chart and used as the heading of a separately exported Markdown report.
series- ChartSeries overlays. Each series has a unique key and supplies exactly one value or None per candle.
markers- Text annotations referencing existing candles. A marker can sit above, in the center of or below its candle.
summary- Sequence of report text lines. HTML places the details behind an expandable section. Static exports place the text below the plot.
theme- Initial palette, dark or light. The default is dark. Readers can switch it on an interactive chart.
width- Chart width in pixels, an integer from 480 to 16384 inclusive.
height- Chart height in pixels, from 360 to 16384 inclusive. A static export can be taller when the legend or summary needs extra space.
price_precision- Number of decimal places for ordinary displayed prices, from 0 to 12. This is a label setting. The underlying candle values retain their precision.
show_controls- Whether to display the interactive chart’s control bar, including zoom, theme and image export actions.
ChartSpec.ToDict
Return a detached dictionary containing the chart’s data, display settings and schema_version. Use it with FromDict to store and restore the same chart.
ChartSpec.ToDict() -> dict[str, Any]
ChartSpec.ToJSON
Return a compact JSON string containing the entire chart and its schema version. Characters significant inside HTML script elements are escaped. A JSON decoder restores the original text.
ChartSpec.ToJSON() -> str
ChartSpec.FromDict
Restore a validated ChartSpec from the dictionary produced by ToDict or by decoding ToJSON. A missing or unsupported schema_version, unknown fields, or inconsistent chart data raises ValueError.
ChartSpec.FromDict(data: Mapping[str, Any]) -> 'ChartSpec'
Parameters (1)
data- Mapping with schema_version and chart fields. Use ChartSpec.ToDict() or decode the JSON returned by ChartSpec.ToJSON().
Module constants
SCHEMA_VERSION= 1- Version number of the serialized ChartSpec layout. ChartSpec.FromDict accepts version 1 in this release.