> For the complete documentation index, see [llms.txt](https://docs.vibetrading.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vibetrading.dev/getting-started/quick-start.md).

# Quick Start

## Setup

Install and set your LLM API key:

```bash
pip install vibetrading
export OPENAI_API_KEY=sk-...   # or ANTHROPIC_API_KEY, GEMINI_API_KEY, etc.
```

## Generate a Strategy

```python
import vibetrading.strategy

code = vibetrading.strategy.generate(
    "BTC momentum strategy: RSI(14) oversold entry, SMA crossover confirmation, "
    "3x leverage, 10% position size, 8% take-profit, 4% stop-loss",
    model="gpt-4o",
)

print(code)
```

## Backtest

```python
import vibetrading.backtest
import vibetrading.tools

data = vibetrading.tools.download_data(["BTC"], exchange="binance", interval="1h")

results = vibetrading.backtest.run(code, interval="1h", data=data)

if results:
    metrics = results["metrics"]
    print(f"Return: {metrics['total_return']:.2%}")
    print(f"Sharpe: {metrics['sharpe_ratio']:.2f}")
    print(f"Max Drawdown: {metrics['max_drawdown']:.2%}")
    print(f"Win Rate: {metrics['win_rate']:.2%}")
```

## Analyze Results

Use an LLM to evaluate backtest performance:

```python
report = vibetrading.strategy.analyze(results, strategy_code=code, model="gpt-4o")

print(f"Score: {report.score}/10")
print(report.summary)

for s in report.suggestions:
    print(f"  → {s}")
```

See [Backtest Analysis](/library/backtest-analysis.md) for full details.

## Use the Prompt Template with Any LLM

Don't want to use the built-in generator? Use the prompt template directly with any LLM client:

### OpenAI

```python
import openai
import vibetrading.strategy

messages = vibetrading.strategy.build_generation_prompt(
    "BTC grid strategy with 0.25% spacing, 72 levels per side, 5x leverage",
    assets=["BTC"],
    market_type="perp",
    max_leverage=5,
)

response = openai.chat.completions.create(model="gpt-4o", messages=messages)
strategy_code = response.choices[0].message.content
```

### Anthropic

```python
import anthropic
import vibetrading.strategy

messages = vibetrading.strategy.build_generation_prompt("SOL scalping with VWAP and RSI")

client = anthropic.Anthropic()
response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=4096,
    system=messages[0]["content"],
    messages=[{"role": "user", "content": messages[1]["content"]}],
)
strategy_code = response.content[0].text
```

## Validate Generated Code

Check generated strategy code for common errors before running:

```python
import vibetrading.strategy

result = vibetrading.strategy.validate(strategy_code)

if result.is_valid:
    print("Strategy passed validation")
else:
    print(result)
    feedback = result.format_for_llm()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.vibetrading.dev/getting-started/quick-start.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
