Overview
PriceSignal uses an NRules-based rule engine to evaluate price alerts and trading conditions in real-time. The rule engine processes incoming price data and triggers alerts when user-defined conditions are met.Architecture
The rule engine is implemented insrc/Application/Rules/Common/RuleEngine.cs and uses the following components:
- NRules Session: Manages the inference engine session for rule evaluation
- RuleCache: Stores and retrieves active rules
- PriceHistoryCache: Maintains historical price data for technical indicators
- IPrice: Price data interface for incoming market data
Core Functionality
Price Evaluation
TheEvaluateRules method is called for each incoming price update:
Technical Indicators
RSI Calculation
The rule engine includes built-in support for calculating the Relative Strength Index (RSI):Rule Lifecycle
- Price arrives from Binance WebSocket stream
- Cache updated with latest price data
- Price inserted into NRules session
- Rules loaded for the specific symbol
- Rules inserted into session
- Engine fires and evaluates all conditions
- Session cleaned by retracting price and rules
Performance Considerations
- Rules are filtered by symbol before insertion to minimize evaluation overhead
- Session objects are reused across evaluations
- Price history is cached to avoid database queries during rule evaluation
- Rules and prices are retracted after each evaluation to prevent memory leaks
Dependencies
Related Components
- Price Fetcher Service - Provides real-time price data
- NATS Messaging - Publishes triggered alerts