Python Analytical & Indicator Service
Relevant source files
The following files were used as context for generating this wiki page:
The Python Analytical & Indicator Service is a backend component of the Technical Analysis platform designed to perform complex mathematical computations for financial indicators. It leverages high-performance libraries such as pandas and pandas_ta to process market candle data and return technical analysis results to the frontend visualization layer.
The service operates as a standalone Sanic web server, providing a specialized API endpoint for indicator calculation. It complements the Node.js backend by handling data-intensive analytical tasks that are more efficiently executed in a Python environment.
Sources: backend/indicators/main.py:1-13, readme.md:16-19
Service Architecture & Data Flow
The service follows a request-response pattern where the frontend sends a collection of OHLCV (Open, High, Low, Close, Volume) candles along with indicator specific parameters. The Python service transforms this raw data into a Pandas DataFrame, applies the requested technical indicator logic, and returns a JSON array of records containing both the original data and the calculated indicator values.
Interaction Flow
This diagram illustrates how the frontend communicates with the Python Analytical Service to retrieve indicator data.
API Endpoints
The service exposes a primary endpoint for technical analysis calculations.
POST /indicator-calculator
Calculates technical indicators based on provided candle data.
| Parameter | Type | Description |
|---|---|---|
candles | Array<Candle> | List of candle objects containing open, high, low, close, volume, and timestamp. |
indicator | Object | Contains name of the indicator and optional parameters. |
Input Candle Structure:
Sources: backend/indicators/main.py:21-34, frontend/src/graphql.ts:40-49
export type Candle = {
open: number;
high: number;
low: number;
close: number;
volume: number;
timestamp: number;
};
Sources: frontend/src/graphql.ts:40-49
Supported Indicators & Logic
The service supports a wide range of indicators via the pandas_ta library, with specific logic handling for custom or complex indicators.
Indicator Routing Logic
The service uses conditional logic to determine which calculation method to invoke. While most indicators use the generic df.ta(kind=name) interface, specific indicators like pmax and heatmap_volume have custom parameter mappings.
Sources: backend/indicators/main.py:35-46
Custom Indicator Configuration Examples
| Indicator | Frontend Template | Parameters Sent to Python |
|---|---|---|
| VWAP | vwap.ts | { name: "vwap" } |
| Heatmap Volume | volume.ts | ma_length, std_length, extra_high_threshold, etc. |
For the heatmap_volume indicator, the frontend provides specific thresholds through calcParams which are then mapped to the indicator['parameters'] object in the POST body.
Sources: frontend/src/pages/chart/indicatorsTemplates/vwap.ts:25-28, frontend/src/pages/chart/indicatorsTemplates/volume.ts:72-81
Implementation Details
Data Pre-processing
The service ensures that input data is correctly typed and indexed before analysis. Timestamps are converted from milliseconds to Python datetime objects, and the DataFrame index is set to a DatetimeIndex to facilitate time-series analysis within pandas_ta.
Sources: backend/indicators/main.py:27-34
Null Value Handling
Financial indicators often produce NaN (Not a Number) values for the first few rows of a dataset (e.g., a 20-period moving average has no value for the first 19 candles). Before returning data to the frontend, the service replaces these with None to ensure valid JSON serialization.
Sources: backend/indicators/main.py:46
Conclusion
The Python Analytical & Indicator Service acts as the computational engine for the platform's technical analysis features. By isolating these calculations into a dedicated Python service, the system benefits from the robust financial analysis ecosystem of Python while maintaining a responsive React-based user interface.
Sources: readme.md:16-19, backend/indicators/main.py:48-49