Flows
A flow is the fundamental building block of GrailHub. It represents a complete trading strategy or automation as a visual diagram.
What is a Flow?
Section titled “What is a Flow?”A flow is a directed graph consisting of:
- Nodes: Instances of components that perform specific tasks
- Edges: Connections between nodes that define data flow
- Configuration: Settings that control the flow’s behavior
Flow Lifecycle
Section titled “Flow Lifecycle”1. Design
Section titled “1. Design”Create your flow by dragging components onto the canvas and connecting them together.
2. Configuration
Section titled “2. Configuration”Configure each node with the appropriate settings for your strategy.
3. Validation
Section titled “3. Validation”GrailHub validates your flow to ensure:
- All required inputs are connected
- Data types match between connected nodes
- No circular dependencies exist
4. Execution
Section titled “4. Execution”When you run a flow:
- GrailHub initializes all nodes
- Data begins flowing through the edges
- Each node processes data and produces outputs
- The flow continues until stopped or an error occurs
Flow Types
Section titled “Flow Types”Continuous Flows
Section titled “Continuous Flows”Continuous flows run indefinitely, processing data as it arrives:
[Market Data] → [Indicator] → [Strategy] → [Execution]Example: A trading bot that monitors market conditions and executes trades.
Scheduled Flows
Section titled “Scheduled Flows”Scheduled flows run at specific times or intervals:
[Timer] → [Data Fetch] → [Analysis] → [Report]Example: A daily portfolio rebalancing strategy.
Event-Driven Flows
Section titled “Event-Driven Flows”Event-driven flows trigger based on specific conditions:
[Price Monitor] → [Condition] → [Alert]Example: A price alert system.
Flow State
Section titled “Flow State”Each flow has a state that indicates its current status:
- Draft: Flow is being designed
- Ready: Flow is validated and ready to run
- Running: Flow is actively executing
- Paused: Flow execution is temporarily stopped
- Stopped: Flow execution has ended
- Failed: Flow encountered an error
Flow Execution
Section titled “Flow Execution”Starting a Flow
Section titled “Starting a Flow”You can start a flow in several ways:
- Manual Start: Click the “Run” button
- Scheduled Start: Configure a schedule
- API Start: Trigger via the REST API
Stopping a Flow
Section titled “Stopping a Flow”Flows can be stopped:
- Manual Stop: Click the “Stop” button
- Automatic Stop: When a terminal node is reached
- Error Stop: When an unrecoverable error occurs
Pausing a Flow
Section titled “Pausing a Flow”Pause a flow to temporarily halt execution without losing state. Resume to continue from where it left off.
Flow Monitoring
Section titled “Flow Monitoring”Monitor your flows in real-time:
- Node States: See which nodes are active, idle, or failed
- Data Flow: Watch data move through edges
- Logs: View detailed execution logs
- Metrics: Track performance metrics like execution time and throughput
Best Practices
Section titled “Best Practices”Keep Flows Simple
Section titled “Keep Flows Simple”Break complex strategies into multiple smaller flows that can be composed together.
Use Descriptive Names
Section titled “Use Descriptive Names”Name your flows and nodes clearly to make them easy to understand.
Add Comments
Section titled “Add Comments”Use comment nodes to document your strategy and explain complex logic.
Test Incrementally
Section titled “Test Incrementally”Build and test your flow one component at a time.
Handle Errors
Section titled “Handle Errors”Always include error handling nodes to gracefully handle failures.
Monitor Performance
Section titled “Monitor Performance”Keep an eye on execution time and resource usage.
Advanced Features
Section titled “Advanced Features”Subflows
Section titled “Subflows”Create reusable subflows that can be used as components in other flows.
Variables
Section titled “Variables”Use flow variables to store and share data between nodes.
Parallel Execution
Section titled “Parallel Execution”Some flows support parallel execution for improved performance.
Conditional Branching
Section titled “Conditional Branching”Use condition nodes to create different execution paths based on data.