Safer Prompting & Precise Time Context
🛡️ Crash-Proof Prompt Formatting
The most significant change in this release is the implementation of a Safe Prompt Formatting system in the AiTradingService. Previously, if a custom prompt template in prompts.toml referenced a variable that the backend did not provide (e.g., {volume} or {rsi}), the application would crash with a KeyError.
- Smart Fallbacks: The system now uses a
SafePromptDictcombined withformat_map. If a template requests a missing variable, the system intercepts the error, logs a warning for the developer, and silently replaces the missing key with an empty string. - Uninterrupted Service: This ensures that outdated or malformed prompt templates no longer cause runtime exceptions, keeping the trading loop active even during configuration mishaps.
⏱️ Precise Data Time Context
The strategy for providing time context to the AI has been refined to better support multi-symbol analysis.
- Embedded Timestamps: The global "Current Analysis Time" header has been removed from the start of the user prompt. instead, a
Current Timefield is now injected directly into the candle/market data block for each specific symbol (=== SYMBOL: BTC ===). - Data Synchronicity: The timestamp now prioritizes the actual ticker timestamp from the data feed. If that is unavailable, it gracefully falls back to the system's UTC time. This change ensures the AI understands exactly when the specific data point it is analyzing occurred, rather than just when the prompt was constructed.
🧹 Legacy Variable Support
To ensure backward compatibility with older custom prompts, several deprecated variables have been explicitly shimmed:
current_timevolumersimarket_summaryposition_summary
These variables now resolve to empty strings instead of errors, allowing users to transition their prompt templates at their own pace without breaking functionality.