I Connected Claude AI to Freqtrade in 5 Lines of Code published: true.

Published: (March 12, 2026 at 02:25 PM EDT)
5 min read
Source: Dev.to

Source: Dev.to

Source: Dev.to – I connected Claude AI to freqtrade in 5 lines of code

The problem with AI‑driven trading bots

You want to use Claude or GPT to analyze the market and trade automatically.
The usual approach looks like this:

  1. Call the AI API.
  2. Parse the response (and hope the format is consistent).
  3. Map the result to Binance/Bybit API calls.
  4. Handle authentication, signatures, and rate limits.
  5. Write all of this from scratch for every exchange.

You end up with hundreds of lines of glue code before writing a single line of actual trading logic.

There’s a better way.


PULSE Protocol

PULSE is an open‑source semantic‑messaging standard for AI‑to‑AI communication.
Think of it as a universal language – every agent (Claude, GPT, Freqtrade, Binance, etc.) can speak PULSE.


What a PULSE message looks like

from pulse.message import PulseMessage

msg = PulseMessage(
    action="ACT.RECOMMEND.ACTION",
    parameters={
        "pair": "BTC/USDT",
        "direction": "long",
        "confidence": 0.92,
        "reason": (
            "RSI 0.80: "
            "dataframe['enter_long'] = 1\n"
            "# Fallback: your normal RSI logic\n"
            "dataframe.loc[dataframe['rsi'] > 70, 'exit_long'] = 1"
        ),
        "agent_id": "my-trading-bot",
    },
)
  • action – a namespaced identifier that tells the receiver what to do.
  • parameters – a JSON‑serialisable dictionary that carries the payload.

Step 3 – Write the Claude agent

Run the snippet below on any machine (laptop, server, cloud instance, …).
It asks Claude to analyse a market snapshot, extracts the JSON answer, and forwards the recommendation to a local Freqtrade instance via PULSE.

import json
import requests
from pulse_anthropic import AnthropicAdapter
from pulse.message import PulseMessage

# ----------------------------------------------------------------------
# 1️⃣  Initialise the Anthropic (Claude) adapter
# ----------------------------------------------------------------------
adapter = AnthropicAdapter(api_key="sk-ant-...")   # <-- replace with your key

# ----------------------------------------------------------------------
# 2️⃣  Ask Claude to analyse the market
# ----------------------------------------------------------------------
analysis = adapter.send(
    PulseMessage(
        action="ACT.ANALYZE.SENTIMENT",
        parameters={
            "text": """
            BTC/USDT 1h chart:
            - RSI: 23 (oversold)
            - Price: $83,200, below 200‑SMA
            - Last 3 candles: bullish divergence
            - Volume: 40 % above average

            Should I open a long position?
            Answer with JSON:
            {"direction": "long/short/neutral", "confidence": 0‑1, "reason": "..."}
            """
        },
    )
)

# ----------------------------------------------------------------------
# 3️⃣  Parse Claude's JSON response
# ----------------------------------------------------------------------
# The exact path to the JSON payload may differ depending on the adapter
# version – adjust if necessary.
result = json.loads(
    analysis.content["parameters"]["result"]["content"]
)

# ----------------------------------------------------------------------
# 4️⃣  Forward the recommendation to Freqtrade via PULSE
# ----------------------------------------------------------------------
requests.post(
    "http://localhost:9999/",               # Freqtrade REST endpoint
    json={
        "action": "ACT.RECOMMEND.ACTION",
        "parameters": {
            "pair": "BTC/USDT",
            "direction": result["direction"],
            "confidence": result["confidence"],
            "reason": result["reason"],
            "agent_id": "claude-sonnet",
        },
    },
)

# ----------------------------------------------------------------------
# 5️⃣  Log what happened
# ----------------------------------------------------------------------
print(
    f"Signal sent: {result['direction']} "
    f"({result['confidence']:.0%} confidence)"
)
# → Signal sent: long (92% confidence)

Tip:
If you receive a parsing error, inspect analysis.content to locate the exact field that holds Claude’s JSON string.


Step 4 – Start Freqtrade normally

freqtrade trade \
  --config config.json \
  --strategy ClaudeStrategy \
  --enable-rest-api

Now the workflow is:

  1. Claude analyses the market and returns a JSON recommendation.
  2. The recommendation is wrapped in a PULSE message and posted to Freqtrade.
  3. Freqtrade receives the PULSE signal and executes the trade.

That’s all you need to connect Claude (or any other LLM) to your automated trading stack with PULSE. 🚀

Why not just call the Freqtrade REST API directly?

You could, but then you would have to:

  • Write custom HTTP code for every integration
  • Parse different response formats from different exchanges
  • Rewrite everything if you switch from Claude to GPT (or vice‑versa)
  • Handle authentication separately for each system

With PULSE, every component speaks the same language:

# Today: Claude drives Freqtrade on Binance
from pulse_anthropic import AnthropicAdapter
from pulse_freqtrade import FreqtradeAdapter, PulseMessage
from pulse_binance import BinanceAdapter

# … (same flow as above) …

Enjoy a unified, plug‑and‑play architecture for AI‑driven crypto trading!

# Imports for tomorrow: GPT drives Freqtrade on Bybit
from pulse_openai import OpenAIAdapter
from pulse_bybit import BybitAdapter

Your strategy code: unchanged


Bonus: Monitor Multiple Bots

Running a trend bot and a mean‑reversion bot simultaneously? Monitor both in one place:

from pulse_freqtrade import FreqtradeAdapter
from pulse.message import PulseMessage

bots = {
    "trend-bot":    FreqtradeAdapter(url="http://localhost:8080", ...),
    "reversal-bot": FreqtradeAdapter(url="http://localhost:8081", ...),
}

for name, adapter in bots.items():
    adapter.connect()
    response = adapter.send(
        PulseMessage(action="ACT.QUERY.STATUS", parameters={})
    )
    trades = response.content["parameters"]["result"]
    profit = adapter.get_profit()

    print(
        f"{name}: {len(trades)} open trades | "
        f"profit: {profit['profit_all_percent']:.2f}%"
    )
# trend-bot:    3 open trades | profit: +4.21%
# reversal-bot: 1 open trade  | profit: +1.87%

Supported PULSE actions

PULSE ActionWhat it does in Freqtrade
ACT.QUERY.STATUSGet open trades
ACT.QUERY.BALANCEGet portfolio balance
ACT.QUERY.LISTGet trade history
ACT.QUERY.DATAGet OHLCV candles for a pair
ACT.QUERY.PROFITGet profit/loss summary
ACT.TRANSACT.REQUESTForce open a trade
ACT.CANCELForce close a trade
ACT.STARTStart the bot
ACT.STOPStop the bot
ACT.RELOADReload config

Install

pip install pulse-freqtrade

GitHub: [https://github.com/your-repo/pulse-freqtrade]
PyPI: [https://pypi.org/project/pulse-freqtrade]
License: Apache 2.0


The Bigger Picture

pulse-freqtrade is part of the PULSE Protocol ecosystem – 11 packages that let any AI system talk to any other AI system using a common semantic language:

pulse-protocol     — core protocol
pulse-openai       — GPT adapter
pulse-anthropic    — Claude adapter
pulse-gemini       — Gemini adapter
pulse-ollama       — local models (Llama, Mistral)
pulse-binance      — Binance exchange
pulse-bybit        — Bybit exchange
pulse-kraken       — Kraken exchange
pulse-okx          — OKX exchange
pulse-gateway      — secure API gateway
pulse-freqtrade    — Freqtrade bot ← new

All packages share the same message format, so you can mix and match them freely.


Questions? Drop them in the comments—happy to help with setup or strategy ideas.

The code is open‑source, Apache 2.0, free forever.

0 views
Back to Blog

Related posts

Read more »