Flow: Visual Strategy Builder
Relevant source files
The following files were used as context for generating this wiki page:
Flow is a no-code strategy builder within the OpenAlgo platform that allows traders to design, host, and execute trading strategies through a visual, node-based interface. It eliminates the requirement for manual coding by providing drag-and-drop components for market data acquisition, technical indicators, logic conditions, and order execution.
The system is powered by the xyflow/React Flow library on the frontend and a dedicated backend service layer for workflow validation and execution. Strategies created in Flow support real-time market data, webhook triggers for external signals (such as TradingView), and complex branching logic using true/false or yes/no handles.
Sources: README.md:23-25, README.md:73-82
System Architecture
The Flow system operates across a React-based frontend and a Python-based backend. The frontend handles the visual orchestration of nodes and edges, while the backend manages the persistence, validation, and execution of the resulting JSON-represented graphs.
Visual Components
The Flow Editor consists of several functional areas:
- Node Palette: A sidebar containing pre-built nodes categorized by function (Market Data, Indicators, etc.).
- Canvas: The main workspace where nodes are positioned and connected via edges.
- Config Panel: A contextual sidebar that appears when a node is selected, allowing for parameter configuration.
- Execution Log Panel: Displays real-time logs and statuses when a workflow is executed.
Sources: frontend/src/pages/flow/FlowEditor.tsx:476-515, README.md:76-78
Workflow Lifecycle
The following diagram illustrates the lifecycle of a workflow from creation to execution.
The diagram shows the transition from a design-time entity to a runtime-active trading strategy.
Sources: frontend/src/pages/flow/FlowEditor.tsx:189-218, frontend/src/api/flow.ts:98-124
Data Models and Contracts
Workflows are represented as JSON objects containing arrays of nodes and edges. Each node carries specific data structures defined by its type.
Key Data Structures
| Entity | Type | Description |
|---|---|---|
Workflow | Object | The root object containing nodes, edges, and metadata like id, name, and is_active. |
Node | Object | Represents a functional block. Contains id, type, position, and data (parameters). |
Edge | Object | Represents the connection between nodes. Contains id, source, target, and sourceHandle. |
ExecutionLog | Object | Individual log entry containing time, message, and level (info, error, etc.). |
Sources: frontend/src/api/flow.ts:11-47, scripts/generate_indicator_reference.py:117-135
Implementation of Nodes
Node types are strictly validated to ensure they match the backend execution capabilities.
// Example of a Node representation in a Flow workflow
{
"id": "node_2",
"type": "indicator",
"position": { "x": 100, "y": 100 },
"data": {
"symbol": "RELIANCE",
"exchange": "NSE",
"interval": "5m",
"indicatorName": "rsi",
"params": "{\"period\": 14}",
"outputVariable": "r"
}
}
Sources: scripts/generate_indicator_reference.py:122-133
API and Communication
The Flow module interacts with the backend through a dedicated API base (/flow/api).
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
GET | /workflows | List all saved workflows. |
POST | /workflows | Create a new workflow strategy. |
PUT | /workflows/{id} | Update workflow nodes, edges, or metadata. |
POST | /workflows/{id}/activate | Register workflow for live execution. |
POST | /workflows/{id}/execute | Manually trigger a one-time execution. |
POST | /workflows/import | Create a new workflow from a JSON export. |
POST | /workflows/{id}/replace | Overwrite an existing workflow graph in place. |
Sources: frontend/src/api/flow.ts:60-153
Webhook Integration
Flow provides unique webhook URLs for each workflow, supporting external triggers like TradingView alerts.
The sequence shows how an external signal is processed through the Flow system to trigger real-world trading actions.
Sources: frontend/src/pages/flow/FlowIndex.tsx:162-282, README.md:79-80
Validation and Integrity
The system employs a strict validation layer (services/flow_workflow_validator.py) to prevent runtime failures of malformed strategies.
Structural Integrity Checks
- Cycle Detection: Prevents infinite loops in the node graph.
- Unreachable Nodes: Identifies nodes that are not connected to a trigger.
- Handle Validation: Ensures edges are connected to valid source handles (e.g., a
lognode cannot have atruehandle). - Trigger Count: Enforces that a workflow has exactly one trigger node (e.g.,
start,webhook,orderUpdateTrigger).
Sources: test/test_flow_workflow_validator.py:448-475, test/test_flow_workflow_validator.py:488-502
Indicator Resolution
Indicators in Flow are verified through introspection of the openalgo.ta library. The indicator node uses specific parameters and returns outputs mapped to latest, previous, or at_offset values.
| Field | Description |
|---|---|
Inputs | OHLCV columns automatically fed to the indicator. |
params | A JSON string of configuration (e.g., {"period": 14}). |
Outputs | Result keys like value or out0, out1 for multi-output indicators. |
Sources: scripts/generate_indicator_reference.py:90-106
User Interface and Interaction
The Flow Editor provides a professional workspace with keyboard shortcuts and visual feedback mechanisms.
Keyboard Shortcuts
| Command | Action |
|---|---|
Ctrl + S | Save workflow changes. |
Delete / Backspace | Remove selected node or edge. |
Escape | Deselect current node or edge. |
? | Open keyboard shortcuts reference. |
Sources: frontend/src/pages/flow/FlowKeyboardShortcuts.tsx:21-72
Workflow Controls
Users can toggle between Live Mode and Analyze Mode (sandbox environment with ₹1 Crore virtual capital) within the editor. The UI provides visual cues for workflow status, using green indicators for active strategies and grey for inactive ones.
Sources: frontend/src/pages/flow/FlowEditor.tsx:406-440, README.md:92-99
Flow serves as a central hub for strategy automation, bridging the gap between external signal providers and broker execution through a verifiable, visual, and highly configurable platform surface.