Live release feed
Sub-second macro releases for FX backtests
Point-in-time history
USD 25/month
Start Free Trial

Trading Bot Integration

How-to Guides

How to Use Freqtrade with FXMacroData for Macro-Aware Trading Bots

Use Freqtrade with FXMacroData by caching macro calendar and session state, joining it into strategy dataframes, and testing macro-aware bot filters.

Share article X LinkedIn Email
Pip robot with FXMacroData logo mark sorting Freqtrade bot modules through macro, session, and risk filters
Freqtrade bot strategies should consume cached macro state as deterministic dataframe columns, not live model commentary.

Freqtrade is a popular open-source trading bot framework with strategy files, backtesting, hyperopt, dry-run, and live modes. FXMacroData fits beside it as an external macro-risk layer: calendar events, announcement history, FX sessions, USD macro context, and release windows that a bot can use as filters or annotations.

Quick answer: use FXMacroData with Freqtrade by caching macro state outside the candle loop, merging it into your strategy dataframe, and using it as a read-only entry filter or risk tag. Do not make every strategy candle perform a live macro API call.

Freqtrade is usually used for crypto pairs, but macro context still matters when USD liquidity, global risk appetite, rates, or release windows affect the quote currency or broader market. The goal is not to turn a bot into an economist. It is to stop the bot from behaving as if every candle has the same macro risk.

Fit

Use this for

Macro-aware entry filters, USD event windows, session context, and research around FreqAI feature sets.

Freqtrade works best when

Macro state is precomputed, cached, and joined to strategy dataframes instead of fetched ad hoc.

Avoid

Letting model-generated commentary place trades or override bot risk controls.

Why Freqtrade Fits Macro Filters

Freqtrade strategies already operate on dataframes and entry/exit signal columns. That is a clean place to add an external binary feature such as macro_block, usd_release_window, or session_state. The model or AI layer is optional; the strategy itself should use deterministic columns.

Useful first tests include blocking new entries before major USD events, tagging trades by FX session, or comparing bot behavior on days with high-impact US announcements against normal days.

Workflow Shape

1. Refresh

A sidecar job refreshes FXMacroData calendar and session state.

2. Cache

Store a small local JSON file with current macro flags and source paths.

3. Join

Merge macro flags into the dataframe used by the strategy.

4. Decide

The strategy blocks entries, tags trades, or adjusts research output.

REST, Cache, Strategy, or AI?

Layer Use it for Why
FXMacroData REST Fetching calendar, announcement, session, and macro context. It is the production data source.
Local cache Sharing macro state with the bot without slowing the candle loop. It avoids repeated network calls and backtest/live mismatches.
Strategy dataframe Deterministic entry and exit filters. Freqtrade expects strategies to express signals as dataframe columns.
AI or MCP Explaining results, generating strategy variants, or reviewing macro context. Keep it outside the order path unless a deterministic layer approves.

Step 1: Cache FXMacroData State

Run a small refresh job on a schedule that matches your trading timeframe. It can write a simple local file for the strategy to read.

import json
import os
import requests
from pathlib import Path

def fetch(path):
    r = requests.get(
        f"https://api.fxmacrodata.com/v1{path}",
        params={"api_key": os.environ["FXMD_API_KEY"]},
        timeout=20,
    )
    r.raise_for_status()
    return r.json()

state = {"calendar": fetch("/calendar/usd"), "sessions": fetch("/market_sessions")}
Path("user_data/fxmacrodata_state.json").write_text(json.dumps(state))

The public REST examples use query-parameter authentication:

curl "https://api.fxmacrodata.com/v1/calendar/usd?api_key=YOUR_API_KEY"
curl "https://api.fxmacrodata.com/v1/announcements/usd/inflation?api_key=YOUR_API_KEY"
curl "https://api.fxmacrodata.com/v1/market_sessions?api_key=YOUR_API_KEY"

Step 2: Use the State in a Strategy

Freqtrade strategy files define indicators and entry or exit rules. Load the cached state and turn it into deterministic columns.

from freqtrade.strategy import IStrategy
from pandas import DataFrame
import json

class MacroAwareStrategy(IStrategy):
    timeframe = "5m"

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        with open("user_data/fxmacrodata_state.json", "r", encoding="utf-8") as f:
            state = json.load(f)
        dataframe["macro_block"] = 0
        if has_usd_event_window(state, dataframe["date"].iloc[-1]):
            dataframe["macro_block"] = 1
        return dataframe

Then require the macro flag to be clear before new entries. Keep the rule readable while you prove the idea.

def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
    dataframe.loc[
        (dataframe["macro_block"] == 0) &
        (dataframe["volume"] > 0) &
        (dataframe["close"] > dataframe["close"].rolling(20).mean()),
        "enter_long"
    ] = 1
    return dataframe

Step 3: Backtest the Macro Filter

Freqtrade backtesting and hyperopt simulate only parts of live bot behavior, so test the macro feature in a way that matches its intended use. Compare runs with and without the filter, then inspect the trades blocked by macro windows.

freqtrade backtesting --strategy MacroAwareStrategy --timerange 20240101-20261231
freqtrade backtesting --strategy BaseStrategy --timerange 20240101-20261231

Do not call the live API from inside historical backtests. Use a fixed macro snapshot for the backtest range so the result can be reproduced later.

Optional AI Research Layer

If you use an AI coding assistant or research agent around Freqtrade, connect FXMacroData MCP at https://mcp.fxmacrodata.com. Use it to inspect macro context, explain backtest results, or generate a first draft of strategy code. Keep execution in Freqtrade's deterministic strategy and risk controls.

{
  "servers": {
    "FXMacroData": {
      "type": "http",
      "url": "https://mcp.fxmacrodata.com?api_key=YOUR_API_KEY"
    }
  }
}

Bot Guardrails

Minimum controls

  • Cache macro data outside Freqtrade's tight bot loop.
  • Use fixed snapshots for historical backtests.
  • Log source endpoints and refresh timestamps.
  • Keep model-generated text out of the order path.
  • Dry-run before any live strategy change.

Common Questions

Is Freqtrade an FX trading platform?

Freqtrade is primarily used as a crypto trading bot framework. FXMacroData is still relevant when USD macro events, global sessions, and rate-sensitive conditions affect crypto pairs or portfolio risk.

Should the strategy call FXMacroData every candle?

No. Refresh macro state in a sidecar or scheduled task, cache it locally, and let the strategy read deterministic columns.

Can MCP run the Freqtrade bot?

Do not use MCP as the bot control plane. Use MCP for research and assistant workflows, and keep Freqtrade strategy execution behind its normal controls.

Sources

Blogroll

AI Answer-Ready

Key Facts

Page
How To Use Freqtrade With FXmacrodata
Section
Articles
Canonical URL
https://fxmacrodata.com/articles/how-to-use-freqtrade-with-fxmacrodata
Source
FXMacroData editorial and official publisher references
Last Updated
2026-07-12 02:55 UTC

Provenance And Trust

Cite the canonical URL and source field above. Where available, this page maps to official publisher releases and timestamped updates.

Quick Q&A

Can Freqtrade use FXMacroData? Yes. Cache FXMacroData macro state outside the bot loop, then join it into the Freqtrade strategy dataframe as deterministic columns.

Should Freqtrade call FXMacroData every candle? No. Refresh macro data in a sidecar or scheduled task and let the strategy read cached state.

Should Freqtrade use FXMacroData MCP? Use MCP for research and assistant workflows, not as the Freqtrade order-control path.

Prompt Packs

Use these in ChatGPT, Claude, Gemini, Mistral, Perplexity, or Grok for consistent source-aware outputs.