Components
Components
Section titled “Components”Components are the building blocks of GrailHub flows. Each component performs a specific function, from fetching market data to executing trades.
What is a Component?
Section titled “What is a Component?”A component is a reusable piece of functionality that:
- Accepts inputs (data it receives)
- Produces outputs (data it generates)
- Has configuration (settings that control its behavior)
- Implements logic (the actual work it performs)
Component Structure
Section titled “Component Structure”Inputs
Section titled “Inputs”Inputs are the data a component receives. Each input has:
- Name: Identifier for the input
- Type: The data type (string, number, boolean, etc.)
- Required: Whether the input must be connected
Example:
Inputs:
- price: number (required)
- volume: number (optional)Outputs
Section titled “Outputs”Outputs are the data a component produces. Each output has:
- Name: Identifier for the output
- Type: The data type it produces
Example:
Outputs:
- signal: string
- confidence: numberConfiguration
Section titled “Configuration”Configuration settings control the component’s behavior:
Configuration:
- symbol: string (default: "BTCUSDT")
- interval: string (default: "1m")
- threshold: number (default: 50)Component Categories
Section titled “Component Categories”Market Data
Section titled “Market Data”Components that fetch market data from exchanges:
- Ticker: Real-time price updates
- Orderbook: Current buy/sell orders
- Trades: Recent trade history
- Candles: OHLCV candlestick data
Technical Indicators
Section titled “Technical Indicators”Components that calculate technical indicators:
- RSI: Relative Strength Index
- MACD: Moving Average Convergence Divergence
- Bollinger Bands: Volatility bands
- Moving Averages: SMA, EMA, WMA
Pattern Recognition
Section titled “Pattern Recognition”Components that identify chart patterns:
- Candlestick Patterns: Doji, Hammer, Engulfing, etc.
- Chart Patterns: Head and Shoulders, Triangles, etc.
Logic & Control
Section titled “Logic & Control”Components that control flow execution:
- Condition: If/then logic
- Switch: Multi-way branching
- Loop: Repeat operations
- Delay: Add time delays
Execution
Section titled “Execution”Components that execute trades:
- Market Order: Execute at market price
- Limit Order: Execute at specific price
- Stop Loss: Automatic loss prevention
- Take Profit: Automatic profit taking
Notifications
Section titled “Notifications”Components that send alerts:
- Telegram: Send Telegram messages
- Email: Send email notifications
- Webhook: Call external APIs
Utilities
Section titled “Utilities”Helper components:
- Logger: Log data for debugging
- Calculator: Perform calculations
- Data Transform: Convert data formats
- Storage: Save/load data
Using Components
Section titled “Using Components”Adding to a Flow
Section titled “Adding to a Flow”- Open the Components panel
- Search or browse for the component
- Drag it onto the canvas
- Configure its settings
Configuring Components
Section titled “Configuring Components”Click on a component node to open its configuration panel:
- Set required configuration values
- Optionally set default input values
- Review input/output types
- Save changes
Connecting Components
Section titled “Connecting Components”Connect components by dragging from an output handle to an input handle:
- Click and drag from the output (right side)
- Drop on a compatible input (left side)
- The edge will be created automatically
Data Types
Section titled “Data Types”Components use typed inputs and outputs:
- String: Text data
- Number: Numeric values
- Boolean: True/false values
- Object: Complex data structures
- Array: Lists of values
- Any: Accepts any type
Component Lifecycle
Section titled “Component Lifecycle”Initialization
Section titled “Initialization”When a flow starts, each component:
- Validates its configuration
- Initializes internal state
- Prepares to receive data
Processing
Section titled “Processing”During execution, components:
- Receive data on inputs
- Process the data
- Produce outputs
- Repeat
Cleanup
Section titled “Cleanup”When a flow stops, components:
- Clean up resources
- Close connections
- Save state if needed
Building Custom Components
Section titled “Building Custom Components”You can create your own components using Go:
type MyComponent struct {
flow.BaseComponent
}
func (c *MyComponent) Inputs() []flow.Input {
return []flow.Input{
{ID: "input", Type: cty.Number},
}
}
func (c *MyComponent) Outputs() []flow.Output {
return []flow.Output{
{ID: "output", Type: cty.Number},
}
}
func (c *MyComponent) Process(ctx context.Context, inputs map[string]flow.InputChan, outputs map[string]flow.OutputChan) error {
// Your logic here
return nil
}Best Practices
Section titled “Best Practices”Choose the Right Component
Section titled “Choose the Right Component”Select components that match your needs. Don’t overcomplicate with unnecessary components.
Configure Properly
Section titled “Configure Properly”Always review and set appropriate configuration values.
Handle Errors
Section titled “Handle Errors”Use error handling components to gracefully handle failures.
Test Individually
Section titled “Test Individually”Test each component’s behavior before connecting them in complex flows.
Document Usage
Section titled “Document Usage”Add comments to explain why you’re using specific components.