Skip to content

Chart Settings

Chart settings management for the dashboard.

Reads and writes per-run chart display settings from ~/.onesecondtrader/chart_settings.json.

SETTINGS_PATH = Path.home() / '.onesecondtrader' / 'chart_settings.json' module-attribute

VALID_STYLES = {'line', 'histogram', 'dots', 'dash1', 'dash2', 'dash3', 'background1', 'background2'} module-attribute

VALID_COLORS = {'black', 'red', 'blue', 'green', 'orange', 'purple', 'cyan', 'magenta', 'yellow', 'teal'} module-attribute

VALID_WIDTHS = {'thin', 'normal', 'thick', 'extra_thick'} module-attribute

DEFAULT_COLOR_CYCLE = ['blue', 'red', 'green', 'orange', 'purple', 'cyan', 'magenta', 'teal', 'black', 'yellow'] module-attribute

_read_all()

Read the entire settings file, returning empty dict on failure.

Source code in src/onesecondtrader/dashboard/chart_settings.py
def _read_all() -> dict:
    """Read the entire settings file, returning empty dict on failure."""
    if not SETTINGS_PATH.exists():
        return {}
    try:
        return json.loads(SETTINGS_PATH.read_text(encoding="utf-8"))
    except (json.JSONDecodeError, OSError):
        return {}

_write_all(data)

Write the entire settings file, creating parent dirs as needed.

Source code in src/onesecondtrader/dashboard/chart_settings.py
def _write_all(data: dict) -> None:
    """Write the entire settings file, creating parent dirs as needed."""
    SETTINGS_PATH.parent.mkdir(parents=True, exist_ok=True)
    SETTINGS_PATH.write_text(json.dumps(data, indent=2), encoding="utf-8")

load_chart_settings(run_id)

Load chart settings for a run.

Returns:

Type Description
dict

Settings dict for the run, or empty dict if none exist.

Source code in src/onesecondtrader/dashboard/chart_settings.py
def load_chart_settings(run_id: str) -> dict:
    """
    Load chart settings for a run.

    Returns:
        Settings dict for the run, or empty dict if none exist.
    """
    all_settings = _read_all()
    return all_settings.get(run_id, {})

save_chart_settings(run_id, settings)

Save chart settings for a run.

Parameters:

Name Type Description Default
run_id str

Unique identifier of the backtest run.

required
settings dict

Chart settings dict to persist.

required
Source code in src/onesecondtrader/dashboard/chart_settings.py
def save_chart_settings(run_id: str, settings: dict) -> None:
    """
    Save chart settings for a run.

    Parameters:
        run_id:
            Unique identifier of the backtest run.
        settings:
            Chart settings dict to persist.
    """
    all_settings = _read_all()
    all_settings[run_id] = settings
    _write_all(all_settings)