Skip to content

Forex price/sentiment divergence

Flags majors where 7-day price and sentiment are pulling in opposite directions, a contrarian shortlist.

Analyze Forex 2 tools 35 tokens / run Python · Node.js

What this recipe solves

A currency grinding higher while its coverage sours, or selling off while the mood turns constructive, is worth a closer look. This script checks seven majors for that gap.

Copy, run, ship

Drop this script into your project and run it locally or on a cron. Set GUAVY_KEY in your environment, swap the symbols, and go.

Python
# forex_divergence.py
import os, requests

API    = "https://guavy.com/api/v2/forex"
H      = {"Authorization": f"Bearer {os.environ['GUAVY_KEY']}"}
MAJORS = ["EUR", "GBP", "JPY", "CHF", "CAD", "AUD", "NZD"]

for sym in MAJORS:
    r = requests.get(
        f"{API}/technical-analysis/get-price-history/{sym}",
        headers=H, params={"limit": 8}
    )
    if r.status_code != 200:
        continue
    prices = r.json()["price_history"]
    prices.sort(key=lambda p: p["timestamp"])
    if len(prices) < 8:
        continue
    change = (prices[-1]["price"] - prices[-8]["price"]) / prices[-8]["price"] * 100

    sent = requests.get(
        f"{API}/sentiment/get-sentiment-history/{sym}",
        headers=H, params={"limit": 7}
    ).json()["sentiment"]
    net = sum(r["positive"] - r["negative"] for r in sent)

    if change > 5 and net < 0:
        print(f"{sym}: price +{change:.1f}% but sentiment net-negative ({net})")
    elif change < -5 and net > 0:
        print(f"{sym}: price {change:.1f}% but sentiment net-positive (+{net})")

2 tools, one script

This script calls 2 endpoints from the Guavy REST API. Every data point maps back to the endpoint it came from.

Run this recipe on the free plan

Grab a free API key, set it as an env var, and run the script. Free sandbox forever.