{"record":{"id":"6803ba01e55dbf38","repo":"nautechsystems/nautilus_trader","slug":"colors-dict-missing-required-keys-missing-keys","errorCode":null,"errorMessage":"Colors dict missing required keys: {missing_keys}. Required keys: {required_keys}","messagePattern":"Colors dict missing required keys: (.+?)\\. Required keys: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/nautilus_trader/analysis/themes.py","lineNumber":178,"sourceCode":"    ...         \"negative\": \"#ff0000\",\n    ...         \"neutral\": \"#808080\",\n    ...         \"background\": \"#ffffff\",\n    ...         \"grid\": \"#dddddd\",\n    ...     },\n    ... )\n\n    \"\"\"\n    _require_not_none(name, \"name\")\n    _require_not_none(template, \"template\")\n    _require_not_none(colors, \"colors\")\n\n    if not name.strip():\n        raise ValueError(\"Theme name cannot be empty\")\n\n    required_keys = {\"primary\", \"positive\", \"negative\", \"neutral\", \"background\", \"grid\"}\n    missing_keys = required_keys - set(colors.keys())\n    if missing_keys:\n        raise ValueError(\n            f\"Colors dict missing required keys: {missing_keys}. Required keys: {required_keys}\",\n        )\n\n    _THEMES[name] = {\n        \"template\": template,\n        \"colors\": colors.copy(),\n    }\n\n\ndef list_themes() -> list[str]:\n    \"\"\"\n    List all registered theme names.\n\n    Returns\n    -------\n    list[str]\n        List of available theme names.\n","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/python/nautilus_trader/analysis/themes.py#L160-L196","documentation":"register_theme requires the colors dict to contain all six mandatory color keys: primary, positive, negative, neutral, background, grid. Missing keys are reported as a set in the ValueError, since downstream plotly templates index these colors directly.","triggerScenarios":"register_theme(name, template, colors={\"primary\": \"#...\", \"positive\": \"#...\"}) with one or more of the required keys absent.","commonSituations":"Hand-writing a partial custom theme; migrating themes from another library with a different color schema; typos in key names (e.g. 'bg' instead of 'background').","solutions":["Add every required key: primary, positive, negative, neutral, background, grid","Merge a complete default palette with your overrides: colors = {**defaults, **overrides}","Check key spellings against the error's missing_keys list"],"exampleFix":"// before\nregister_theme(\"custom\", template, colors={\"primary\": \"blue\", \"positive\": \"green\"})  # missing keys\n// after\nregister_theme(\"custom\", template, colors={\"primary\": \"blue\", \"positive\": \"green\", \"negative\": \"red\", \"neutral\": \"gray\", \"background\": \"white\", \"grid\": \"#ddd\"})","handlingStrategy":"validation","validationCode":"REQUIRED_COLOR_KEYS = {\"primary\", \"positive\", \"negative\", \"neutral\", \"background\", \"grid\"}\nassert REQUIRED_COLOR_KEYS <= set(colors.keys()), REQUIRED_COLOR_KEYS - set(colors)","typeGuard":"def has_required_colors(colors: dict) -> bool:\n    return {\"primary\", \"positive\", \"negative\", \"neutral\", \"background\", \"grid\"} <= set(colors.keys())","tryCatchPattern":"try:\n    register_theme(name, template, colors)\nexcept ValueError as e:\n    if \"missing required keys\" in str(e):\n        colors = {**default_palette, **colors}\n        register_theme(name, template, colors)\n    else:\n        raise","preventionTips":["Start from a copy of a builtin palette and override only what you need","Validate custom color dicts against the required key set in tests","Avoid ad-hoc key spellings; use the documented key names exactly"],"tags":["python","validation","valueerror","schema","theme"],"backgroundTag":"schema-validation-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}