Algorithm Testing Dashboard
Relevant source files
The following files were used as context for generating this wiki page:
The Algorithm Testing Dashboard is a specialized module designed to evaluate and monitor trading strategies in real-time or via historical data. Built on top of the Tinkoff Invest API, it allows developers and traders to implement custom logic, receive automated trade signals, and visualize performance metrics directly within the terminal interface.
Sources: readme.md:1-10, frontend/src/pages/chart/index.tsx:327-327
System Architecture
The dashboard operates through a real-time bridge between the backend trading engine and the frontend visualization layer. The backend subscribes to market data (candles), processes them through a user-defined algorithm, and streams the resulting trade events back to the dashboard via GraphQL subscriptions.
Backend Processing Flow
The AlgorithmTestingResolver manages the lifecycle of market data subscriptions and signal generation. It maintains an internal candlesStorage for each instrument in the watchlist and updates it as new data arrives from the Tinkoff API.
The diagram shows how market data flows from the API through the decision-making logic to the UI.
Sources: backend/src/modules/algorithmTesting/algorithmTesting.resolver.ts:48-84
Trade Management Logic
Trades are automatically managed based on signals returned by the algorithm function. If a signal (isShort or isLong) is detected, the system checks for existing active trades for that instrument.
- Closing Trades: If an active trade exists when a new signal is generated, the
algorithmTestingServicecloses the existing trade at the current candle's closing price. - Opening Trades: A new
AlgorithmTradeentity is instantiated, capturing the entry price, trade type (Long/Short), interval, and current timestamp. - Live Profit/Loss: The system continuously calculates the
pricePercentChange. If the trade is closed, it uses the fixed close price; if open, it calculates live profit/loss based on the most recent candle incandlesStorage.
Sources: backend/src/modules/algorithmTesting/algorithmTesting.resolver.ts:68-83, backend/src/modules/algorithmTesting/algorithmTesting.resolver.ts:98-115
Trade Data Model
| Field | Type | Description |
|---|---|---|
id | Number | Unique identifier for the trade record |
type | TradeType | Direction of the trade: Long or Short |
price | Number | Entry price of the instrument |
closePrice | Number | Exit price (if trade is closed) |
pricePercentChange | Number | Calculated percentage of P/L |
closed | Boolean | Status indicating if the trade is finalized |
instrument | Instrument | The financial asset associated with the trade |
Sources: backend/src/modules/algorithmTesting/algorithmTesting.resolver.ts:95-117
Frontend Dashboard Interface
The dashboard is integrated into the side navigation of the main chart page. It consists of the AlgorithmTesting container and individual AlgorithmTrade components.
UI Components and Interaction
- Filtering: The dashboard includes a "Only Active" switch that filters the list to show only currently open trades using React state management.
- Navigation: Clicking on a trade item triggers the
onTickerSelectcallback, which updates the main KLineChart to display the specific instrument and historical data related to that trade. - Real-time Updates: The
useTradesSubscriptionhook ensures the list updates immediately when the backend publishes new trade data.
The sequence shows the reactive update loop for the frontend dashboard.
Sources: frontend/src/pages/chart/components/AlgorithmTesing.tsx:14-36, frontend/src/pages/chart/index.tsx:327-327
Implementation and Configuration
Users can define their own trading logic by modifying the core algorithm file.
- Algorithm Entry Point:
backend/src/modules/algorithmTesting/algorithms/index.ts - Environment Setup: Requires
TINKOFF_SECRETin the backend.envfile. - Service Integration: The system uses the
AlgorithmTestingServicefor database persistence andTinkoffServicefor real-time market connectivity.
Sources: readme.md:7-13, backend/src/modules/algorithmTesting/algorithmTesting.resolver.ts:13-17
Conclusion
The Algorithm Testing Dashboard provides a robust framework for strategy validation. By combining real-time data streaming, automated trade execution, and a reactive frontend list, it simplifies the process of monitoring complex technical analysis algorithms. The tight integration between the backend resolver and the chart interface allows for seamless transitions between high-level performance monitoring and detailed technical analysis of individual trades.