Strategy Generation

The @vibe Decorator

Every strategy must have exactly ONE function decorated with @vibe. This registers the function as a callback that the engine executes at each tick.

from vibetrading import vibe

@vibe(interval="1m")
def on_tick():
    pass

For live trading, always use interval="1m". Implement frame-skipping for longer intervals:

last_execution_time = None

@vibe(interval="1m")
def strategy():
    global last_execution_time
    current_time = get_current_time()

    manage_risk()

    if last_execution_time and (current_time - last_execution_time).total_seconds() < 300:
        return
    last_execution_time = current_time
    # ... main logic ...

Write Strategies Manually

You can write strategies by hand. A strategy is a Python function decorated with @vibe:

Note: Strategy code uses from vibetrading import vibe, get_price, ... — these symbols are injected at runtime by the backtest engine or live runner. They don't need to be real functions in the package.

AI-Powered Generation

StrategyGenerator

The StrategyGenerator class handles the full generation + validation pipeline:

Closed-Loop Generation

The validator produces structured feedback that can be fed back to the LLM:

Agent Integration Components

Component
Import
Purpose

STRATEGY_SYSTEM_PROMPT

vibetrading.strategy.STRATEGY_SYSTEM_PROMPT

Complete system prompt for LLM strategy generation

VIBETRADING_API_REFERENCE

vibetrading.strategy.VIBETRADING_API_REFERENCE

API documentation string

STRATEGY_CONSTRAINTS

vibetrading.strategy.STRATEGY_CONSTRAINTS

Code generation rules

build_generation_prompt()

vibetrading.strategy.build_generation_prompt

Build message list for chat completion

validate()

vibetrading.strategy.validate

Validate generated code

StrategyGenerator

vibetrading.strategy.StrategyGenerator

Full generation + validation pipeline

Last updated