API

The readings of the site for your bot or script. Pro includes every endpoint.

Without an account or Pro, data is still available as pay per call in USDC via x402.

Endpoints

GET/v1/readings Pro: includedx402: $0.01 one kind, $0.02 both

Every 🎯 tilt in play, with its rate, baseline, average move and how long it held. The same readings as the Live page.

symbolscomma-separated, for example BTCUSDT,ETHUSDT. Default: all
timeframes5m, 15m, 1h, 4h, 1d, comma-separated. Default: all
kindpattern, shapes or both (default)
curl -H "Authorization: Bearer YOUR_KEY" "https://candlestickanatomy.com/v1/readings?timeframes=15m,1h&kind=pattern"
Sample payload
{
  "as_of": "2026-11-29T10:00Z",
  "readings": [
    {
      "symbol": "ZECUSDT",
      "timeframe": "1h",
      "kind": "pattern",
      "key": "3outside:red",
      "name": "Three Outside Up/Down (red)",
      "description": "Traditionally read as a bearish reversal.",
      "tilt": {
        "side": "up",
        "rate": 0.546,
        "baseline": 0.502,
        "times_observed": 1068,
        "scope": "this_asset",
        "average_move": {
          "pct": 0.073,
          "baseline_pct": 0.004,
          "size": "small",
          "significant": false
        },
        "duration": {
          "holds_after": 1,
          "label": "Next candle only"
        }
      },
      "close": 716.15,
      "closed_at": "2026-11-28T22:00Z",
      "next_close": "2026-11-28T23:00Z"
    },
    {
      "symbol": "BTCUSDT",
      "timeframe": "1h",
      "kind": "shapes",
      "key": "large_red>small_red",
      "name": "large red › small red",
      "description": null,
      "tilt": {
        "side": "up",
        "rate": 0.597,
        "baseline": 0.506,
        "times_observed": 345,
        "scope": "this_asset",
        "average_move": {
          "pct": 0.029,
          "baseline_pct": 0.003,
          "size": "small",
          "significant": false
        },
        "duration": {
          "holds_after": 3,
          "label": "Holds after 3 candles"
        }
      },
      "close": 58614.4,
      "closed_at": "2026-11-29T10:00Z",
      "next_close": "2026-11-29T11:00Z"
    }
  ],
  "stats_version": "14.20261129",
  "disclaimer": "Historic rates from past data, not signals or advice."
}
What the fields mean
readingstilts whose next candle is still open
key
name
description
the pattern type or the shapes, as on the site. description is how a pattern is traditionally read. Our measurement is tilt, and it can point the other way
tilt.sideup or down: where the next candle's close tilts
tilt.rate
tilt.baseline
how often the next candle closed that way after this setup, and after any candle
tilt.times_observed
tilt.scope
past cases, and whether they are from this_asset or all_assets
tilt.average_moveaverage move after the setup next to the baseline, in percent, with its size (small, medium, large)
tilt.duration.holds_after1: next candle only. 3, 5: ⏱️ ⏳ still held after 3 or 5 candles
close
closed_at
next_close
close of the candle of the reading, when it closed, and when the next candle closes (UTC)
GET/v1/candles/latest Pro: includedx402: $0.01

One asset's newest closed candle: anatomy, the pattern and the shapes, and what happened 1, 3 and 5 candles after them, with or without a tilt.

symbolrequired, for example BTCUSDT
timeframeone timeframe. Default: 1h
kindpattern, shapes or both (default)
curl -H "Authorization: Bearer YOUR_KEY" "https://candlestickanatomy.com/v1/candles/latest?symbol=BTCUSDT&timeframe=15m"
Sample payload
{
  "symbol": "ZECUSDT",
  "timeframe": "1h",
  "venue": "Binance USDⓈ-M perpetuals",
  "summary": "ZECUSDT 1h, candle closed 2026-11-28T22:00Z: long lower wick candle, red (body 11%, upper wick 26%, lower wick 62%, volume 0.69x average). Three Outside Up/Down (red): on ZECUSDT, the next candle closed higher 55% of the time vs 50% baseline (observed 1,068 times). Average move +0.073% vs +0.004% baseline. 🎯 Tilt. ⚡ Next candle only. Last two shapes small red › long lower wick: on ZECUSDT, the next candle closed higher 47% of the time vs 50% baseline (observed 842 times). Average move -0.046% vs +0.004% baseline. 🤷 Too few cases. Historic rates from past data, not signals or advice.",
  "candle": {
    "closed_at": "2026-11-28T22:00Z",
    "next_close": "2026-11-28T23:00Z",
    "open": 717.08,
    "high": 719.21,
    "low": 711.08,
    "close": 716.15,
    "volume": 39578.213,
    "shape": "long_lower_wick",
    "anatomy": {
      "direction": "red",
      "body_pct": 0.114,
      "upper_wick_pct": 0.262,
      "lower_wick_pct": 0.624,
      "close_pos": 0.624,
      "range_atr": 0.71,
      "volume_ratio": 0.69,
      "gap_pct": 0.0
    },
    "pattern": {
      "key": "3outside:red",
      "name": "Three Outside Up/Down (red)",
      "description": "Traditionally read as a bearish reversal.",
      "tilt": {
        "side": "up",
        "rate": 0.546,
        "baseline": 0.502,
        "times_observed": 1068,
        "scope": "this_asset",
        "average_move": {
          "pct": 0.073,
          "baseline_pct": 0.004,
          "size": "small",
          "significant": false
        },
        "duration": {
          "holds_after": 1,
          "label": "Next candle only"
        }
      },
      "stats": {
        "this_asset": [
          {
            "candles_ahead": 1,
            "label": "tilt",
            "higher_rate": 0.546,
            "higher_baseline": 0.502,
            "lower_rate": 0.454,
            "lower_baseline": 0.498,
            "times_observed": 1068,
            "range_95": [
              0.515,
              0.576
            ],
            "recent": {
              "times_observed": 207,
              "higher_rate": 0.546
            },
            "average_move": {
              "pct": 0.073,
              "baseline_pct": 0.004,
              "size": "small",
              "significant": false
            },
            "duration": {
              "holds_after": 1,
              "label": "Next candle only"
            }
          },
          {
            "candles_ahead": 3,
            "label": "too_few_cases",
            "higher_rate": 0.541,
            "higher_baseline": 0.503,
            "lower_rate": 0.459,
            "lower_baseline": 0.497,
            "times_observed": 1072,
            "range_95": [
              0.511,
              0.571
            ],
            "recent": {
              "times_observed": 206,
              "higher_rate": 0.573
            },
            "average_move": {
              "pct": 0.167,
              "baseline_pct": 0.011,
              "size": "small",
              "significant": false
            },
            "duration": null
          },
          {
            "candles_ahead": 5,
            "label": "no_claim",
            "higher_rate": 0.549,
            "higher_baseline": 0.502,
            "lower_rate": 0.451,
            "lower_baseline": 0.498,
            "times_observed": 1074,
            "range_95": [
              0.52,
              0.579
            ],
            "recent": {
              "times_observed": 207,
              "higher_rate": 0.541
            },
            "average_move": {
              "pct": 0.221,
              "baseline_pct": 0.019,
              "size": "small",
              "significant": false
            },
            "duration": null
          }
        ],
        "all_assets": [
          {
            "candles_ahead": 1,
            "label": "tilt",
            "higher_rate": 0.539,
            "higher_baseline": 0.5,
            "lower_rate": 0.461,
            "lower_baseline": 0.5,
            "times_observed": 21690,
            "range_95": [
              0.529,
              0.548
            ],
            "recent": {
              "times_observed": 6045,
              "higher_rate": 0.525
            },
            "average_move": {
              "pct": 0.021,
              "baseline_pct": 0.001,
              "size": "small",
              "significant": false
            },
            "duration": {
              "holds_after": 5,
              "label": "Holds after 5 candles"
            }
          },
          {
            "candles_ahead": 3,
            "label": "tilt",
            "higher_rate": 0.53,
            "higher_baseline": 0.499,
            "lower_rate": 0.47,
            "lower_baseline": 0.501,
            "times_observed": 21756,
            "range_95": [
              0.52,
              0.539
            ],
            "recent": {
              "times_observed": 6065,
              "higher_rate": 0.515
            },
            "average_move": {
              "pct": 0.055,
              "baseline_pct": 0.002,
              "size": "small",
              "significant": false
            },
            "duration": null
          },
          {
            "candles_ahead": 5,
            "label": "tilt",
            "higher_rate": 0.53,
            "higher_baseline": 0.497,
            "lower_rate": 0.47,
            "lower_baseline": 0.503,
            "times_observed": 21792,
            "range_95": [
              0.52,
              0.54
            ],
            "recent": {
              "times_observed": 6081,
              "higher_rate": 0.511
            },
            "average_move": {
              "pct": 0.089,
              "baseline_pct": 0.003,
              "size": "small",
              "significant": false
            },
            "duration": null
          }
        ]
      }
    },
    "shapes": {
      "key": "small_red>long_lower_wick",
      "name": "small red › long lower wick",
      "tilt": null,
      "stats": {
        "this_asset": [
          {
            "candles_ahead": 1,
            "label": "too_few_cases",
            "higher_rate": 0.469,
            "higher_baseline": 0.502,
            "lower_rate": 0.531,
            "lower_baseline": 0.498,
            "times_observed": 842,
            "range_95": [
              0.435,
              0.503
            ],
            "recent": {
              "times_observed": 189,
              "higher_rate": 0.466
            },
            "average_move": {
              "pct": -0.046,
              "baseline_pct": 0.004,
              "size": "small",
              "significant": false
            },
            "duration": null
          },
          {
            "candles_ahead": 3,
            "label": "too_few_cases",
            "higher_rate": 0.501,
            "higher_baseline": 0.503,
            "lower_rate": 0.499,
            "lower_baseline": 0.497,
            "times_observed": 848,
            "range_95": [
              0.468,
              0.534
            ],
            "recent": {
              "times_observed": 190,
              "higher_rate": 0.505
            },
            "average_move": {
              "pct": -0.1,
              "baseline_pct": 0.011,
              "size": "small",
              "significant": false
            },
            "duration": null
          },
          {
            "candles_ahead": 5,
            "label": "too_few_cases",
            "higher_rate": 0.489,
            "higher_baseline": 0.502,
            "lower_rate": 0.511,
            "lower_baseline": 0.498,
            "times_observed": 847,
            "range_95": [
              0.455,
              0.522
            ],
            "recent": {
              "times_observed": 190,
              "higher_rate": 0.495
            },
            "average_move": {
              "pct": -0.081,
              "baseline_pct": 0.019,
              "size": "small",
              "significant": false
            },
            "duration": null
          }
        ],
        "all_assets": [
          {
            "candles_ahead": 1,
            "label": "no_tilt",
            "higher_rate": 0.493,
            "higher_baseline": 0.5,
            "lower_rate": 0.507,
            "lower_baseline": 0.5,
            "times_observed": 18668,
            "range_95": [
              0.483,
              0.503
            ],
            "recent": {
              "times_observed": 5397,
              "higher_rate": 0.5
            },
            "average_move": {
              "pct": -0.014,
              "baseline_pct": 0.001,
              "size": "small",
              "significant": false
            },
            "duration": null
          },
          {
            "candles_ahead": 3,
            "label": "no_tilt",
            "higher_rate": 0.496,
            "higher_baseline": 0.5,
            "lower_rate": 0.504,
            "lower_baseline": 0.5,
            "times_observed": 18748,
            "range_95": [
              0.486,
              0.507
            ],
            "recent": {
              "times_observed": 5423,
              "higher_rate": 0.489
            },
            "average_move": {
              "pct": -0.014,
              "baseline_pct": 0.002,
              "size": "small",
              "significant": false
            },
            "duration": null
          },
          {
            "candles_ahead": 5,
            "label": "no_tilt",
            "higher_rate": 0.496,
            "higher_baseline": 0.498,
            "lower_rate": 0.504,
            "lower_baseline": 0.502,
            "times_observed": 18749,
            "range_95": [
              0.484,
              0.507
            ],
            "recent": {
              "times_observed": 5425,
              "higher_rate": 0.485
            },
            "average_move": {
              "pct": -0.029,
              "baseline_pct": 0.003,
              "size": "small",
              "significant": false
            },
            "duration": null
          }
        ]
      }
    }
  },
  "latest_pattern": {
    "closed_at": "2026-11-28T22:00Z",
    "key": "3outside:red",
    "name": "Three Outside Up/Down (red)",
    "description": "Traditionally read as a bearish reversal.",
    "tilt": {
      "side": "up",
      "rate": 0.546,
      "baseline": 0.502,
      "times_observed": 1068,
      "scope": "this_asset",
      "average_move": {
        "pct": 0.073,
        "baseline_pct": 0.004,
        "size": "small",
        "significant": false
      },
      "duration": {
        "holds_after": 1,
        "label": "Next candle only"
      }
    },
    "stats": {
      "this_asset": [
        {
          "candles_ahead": 1,
          "label": "tilt",
          "higher_rate": 0.546,
          "higher_baseline": 0.502,
          "lower_rate": 0.454,
          "lower_baseline": 0.498,
          "times_observed": 1068,
          "range_95": [
            0.515,
            0.576
          ],
          "recent": {
            "times_observed": 207,
            "higher_rate": 0.546
          },
          "average_move": {
            "pct": 0.073,
            "baseline_pct": 0.004,
            "size": "small",
            "significant": false
          },
          "duration": {
            "holds_after": 1,
            "label": "Next candle only"
          }
        },
        {
          "candles_ahead": 3,
          "label": "too_few_cases",
          "higher_rate": 0.541,
          "higher_baseline": 0.503,
          "lower_rate": 0.459,
          "lower_baseline": 0.497,
          "times_observed": 1072,
          "range_95": [
            0.511,
            0.571
          ],
          "recent": {
            "times_observed": 206,
            "higher_rate": 0.573
          },
          "average_move": {
            "pct": 0.167,
            "baseline_pct": 0.011,
            "size": "small",
            "significant": false
          },
          "duration": null
        },
        {
          "candles_ahead": 5,
          "label": "no_claim",
          "higher_rate": 0.549,
          "higher_baseline": 0.502,
          "lower_rate": 0.451,
          "lower_baseline": 0.498,
          "times_observed": 1074,
          "range_95": [
            0.52,
            0.579
          ],
          "recent": {
            "times_observed": 207,
            "higher_rate": 0.541
          },
          "average_move": {
            "pct": 0.221,
            "baseline_pct": 0.019,
            "size": "small",
            "significant": false
          },
          "duration": null
        }
      ],
      "all_assets": [
        {
          "candles_ahead": 1,
          "label": "tilt",
          "higher_rate": 0.539,
          "higher_baseline": 0.5,
          "lower_rate": 0.461,
          "lower_baseline": 0.5,
          "times_observed": 21690,
          "range_95": [
            0.529,
            0.548
          ],
          "recent": {
            "times_observed": 6045,
            "higher_rate": 0.525
          },
          "average_move": {
            "pct": 0.021,
            "baseline_pct": 0.001,
            "size": "small",
            "significant": false
          },
          "duration": {
            "holds_after": 5,
            "label": "Holds after 5 candles"
          }
        },
        {
          "candles_ahead": 3,
          "label": "tilt",
          "higher_rate": 0.53,
          "higher_baseline": 0.499,
          "lower_rate": 0.47,
          "lower_baseline": 0.501,
          "times_observed": 21756,
          "range_95": [
            0.52,
            0.539
          ],
          "recent": {
            "times_observed": 6065,
            "higher_rate": 0.515
          },
          "average_move": {
            "pct": 0.055,
            "baseline_pct": 0.002,
            "size": "small",
            "significant": false
          },
          "duration": null
        },
        {
          "candles_ahead": 5,
          "label": "tilt",
          "higher_rate": 0.53,
          "higher_baseline": 0.497,
          "lower_rate": 0.47,
          "lower_baseline": 0.503,
          "times_observed": 21792,
          "range_95": [
            0.52,
            0.54
          ],
          "recent": {
            "times_observed": 6081,
            "higher_rate": 0.511
          },
          "average_move": {
            "pct": 0.089,
            "baseline_pct": 0.003,
            "size": "small",
            "significant": false
          },
          "duration": null
        }
      ]
    }
  },
  "context": {
    "trend": {
      "close_vs_sma50_pct": -2.43,
      "sma50_slope_5bars_pct": 0.137
    },
    "volatility": {
      "atr": 11.482315106331,
      "atr_percentile": 0.0
    },
    "range20": {
      "close_pos": 0.118
    }
  },
  "caveats": [],
  "stats_version": "14.20261129",
  "disclaimer": "Historic rates from past data, not signals or advice."
}
What the fields mean
candle.closed_at
next_close
when the candle closed, and when the next one closes (UTC)
candle.anatomybody and wicks as a share of the candle's range, range next to the ATR, volume next to its average
candle.patternthe pattern that the chart shows on this candle, or null
latest_patternthe newest pattern on the chart, also when it is on an older candle (see its closed_at), or null
candle.shapesthe last 2 or 3 shapes, up to this candle
key
name
description
the pattern type or the shapes, as on the site. description is how a pattern is traditionally read. Our measurement is tilt, and it can point the other way
tiltnull when there is no 🎯 tilt
tilt.sideup or down: where the next candle's close tilts
tilt.rate
tilt.baseline
how often the next candle closed that way after this setup, and after any candle
tilt.times_observed
tilt.scope
past cases, and whether they are from this_asset or all_assets
tilt.average_moveaverage move after the setup next to the baseline, in percent, with its size (small, medium, large)
tilt.duration.holds_after1: next candle only. 3, 5: ⏱️ ⏳ still held after 3 or 5 candles
statsthe measured history, for this_asset and all_assets
stats.candles_aheadcandles of the same timeframe: on 15m, 1 is the next 15m candle and 3 is 45 minutes later
stats.labeltilt, no_tilt, too_few_cases, or no_claim for later candles
stats.higher_rate
lower_rate
how often the close was higher or lower that many candles later, with their baselines
stats.range_95
stats.recent
95% range of higher_rate, and the same measure on recent data only
GET/v1/catalog Free

Symbols, timeframes, every pattern and shape with its rule, labels and prices.

curl "https://candlestickanatomy.com/v1/catalog"
Sample payload (shortened)
{
  "asset_class": "crypto",
  "symbols": [
    {
      "symbol": "BTCUSDT",
      "name": "Bitcoin"
    },
    {
      "symbol": "ETHUSDT",
      "name": "Ethereum"
    }
  ],
  "timeframes": [
    "5m",
    "15m",
    "1h",
    "4h",
    "1d"
  ],
  "candles_ahead": [
    1,
    3,
    5
  ],
  "venue": "Binance USDⓈ-M perpetuals",
  "labels": {
    "tilt": {
      "name": "Tilt",
      "explain": "The odds tilt vs the baseline; passes the false-discovery check and still held recently."
    },
    "no_tilt": {
      "name": "No tilt",
      "explain": "No clear tilt vs the baseline."
    },
    "too_few_cases": {
      "name": "Too few cases",
      "explain": "Too little data: an effect would not stand out from the noise yet."
    },
    "not_applicable": {
      "name": "Not applicable on 24/7 markets",
      "explain": "The pattern needs a price gap between candles. Markets that trade around the clock open each candle at about the previous close, so it almost never forms here."
    },
    "no_claim": {
      "name": "No claim",
      "explain": "We make a claim for later candles only when the next candle shows an edge and the later result points the same way."
    }
  },
  "durations": {
    "1": "Next candle only",
    "3": "Holds after 3 candles",
    "5": "Holds after 5 candles"
  },
  "patterns": [
    {
      "pattern": "engulfing",
      "name": "Engulfing Pattern",
      "candles": 2,
      "rule": "A candle, then an opposite candle whose body covers the whole first body.",
      "source": "TA-Lib",
      "types": [
        {
          "key": "engulfing:green",
          "name": "Engulfing Pattern (green)",
          "description": "Traditionally read as a bullish reversal.",
          "label": "no_tilt",
          "by_timeframe": {
            "1h": "no_tilt",
            "4h": "no_tilt",
            "1d": "too_few_cases"
          }
        },
        {
          "key": "engulfing:red",
          "name": "Engulfing Pattern (red)",
          "description": "Traditionally read as a bearish reversal.",
          "label": "no_tilt",
          "by_timeframe": {
            "1h": "no_tilt",
            "4h": "no_tilt",
            "1d": "too_few_cases"
          }
        }
      ]
    }
  ],
  "shapes": [
    {
      "shape": "doji",
      "rule": "no wick shape; body at most 15% of its own range"
    },
    {
      "shape": "long_lower_wick",
      "rule": "lower wick over 2x the body, at least 1.5x the upper wick, at least 10% of the median range of the previous 100"
    }
  ],
  "shapes_source": "Candlestick Anatomy shape rules v4",
  "shape_wicks": "a wick shape has a wick over 2x the body, at least 1.5x the other wick, and at least 10% of the median range of the previous 100 candles",
  "prices_usd": {
    "GET /v1/readings": {
      "both": "$0.02",
      "one_kind": "$0.01"
    },
    "GET /v1/candles/latest": "$0.01"
  },
  "stats_version": "14.20261129",
  "disclaimer": "Historic rates from past data, not signals or advice."
}

Samples are past readings, to show the format.

Stream: programmatic alerts

Programmatic alerts are available via the stream. The readings come to your script at every candle close, so it does not have to ask again and again. You need a Pro key and a small Python script that runs all the time.

GET/v1/stream Pro: included

Your script opens this once and keeps it open (Server-Sent Events). At every candle close we send the results of earlier readings and the new readings through the same connection.

symbolscomma-separated, for example BTCUSDT,ETHUSDT. Default: all
timeframes5m, 15m, 1h, 4h, 1d, comma-separated. Default: all
kindpattern, shapes or both (default)
Last-Event-IDheader: after a reconnect, events of the last 15 minutes come again, marked late
curl -N -H "Authorization: Bearer YOUR_KEY" "https://candlestickanatomy.com/v1/stream?symbols=BTCUSDT&timeframes=5m,15m"
Sample events
: connected

id: 1795903200000
event: readings
data: {"closed_at": "2026-11-28T22:00Z", "readings": [{"symbol": "ZECUSDT", "timeframe": "1h", "kind": "pattern", "key": "3outside:red", "name": "Three Outside Up/Down (red)", "description": "Traditionally read as a bearish reversal.", "tilt": {"side": "up", "rate": 0.546, "baseline": 0.502, "times_observed": 1068, "scope": "this_asset", "average_move": {"pct": 0.073, "baseline_pct": 0.004, "size": "small", "significant": false}, "duration": {"holds_after": 1, "label": "Next candle only"}}, "close": 716.15, "closed_at": "2026-11-28T22:00Z", "next_close": "2026-11-28T23:00Z"}]}

: ping

id: 1795906800000
event: results
data: {"closed_at": "2026-11-28T23:00Z", "results": [{"symbol": "ZECUSDT", "timeframe": "1h", "kind": "pattern", "key": "3outside:red", "name": "Three Outside Up/Down (red)", "side": "up", "rate": 0.546, "baseline": 0.502, "close": 716.15, "next": 717.57, "move_pct": 0.1983, "matched": true, "closed_at": "2026-11-28T22:00Z", "settled_at": "2026-11-28T23:00Z"}]}

event: ended
data: {"error": "pro_ended"}
What the fields mean
readingsevent: new readings of this close, with the same fields as in readings
resultsevent: earlier readings whose next candle closed now
side
rate
baseline
in results: the side of the reading, its historic rate, and the rate after any candle
close
next
move_pct
in results: the close of the reading, the next close, and the move between them in percent
matchedin results: the next close went to the side of the reading. An unchanged close counts as up
endedevent: the stream stops, because Pro ended or the key was replaced
Set it up
  1. Create your API key at the top of this page.
  2. Get the script (Python 3.9 or newer), on your bot server or your own computer:
    mkdir -p ~/candle && cd ~/candle
    python3 -m venv venv && venv/bin/pip install httpx
    curl -O https://candlestickanatomy.com/static/candle_stream.py
    Show the script
    """Candlestick Anatomy stream: receives readings and results, and reconnects by itself.
    
    Needs:  pip install httpx
    Run:    CANDLE_KEY=your_key python3 candle_stream.py
    """
    import json
    import os
    import sys
    import time
    
    import httpx
    
    URL = "https://candlestickanatomy.com/v1/stream"
    FILTER = {"symbols": "BTCUSDT,ETHUSDT", "timeframes": "5m,15m", "kind": "both"}   # what to receive
    
    
    def on_reading(r):      # a new reading: put your own code here
        t = r["tilt"]
        print(f"NEW     {r['symbol']} {r['timeframe']} {r['name']}: {t['side']} {t['rate']:.1%} (baseline {t['baseline']:.1%}), next close {r['next_close']}", flush=True)
    
    
    def on_result(r):       # an earlier reading closed
        print(f"RESULT  {r['symbol']} {r['timeframe']} {r['side']}: {r['move_pct']:+.2f}%, matched: {r['matched']}", flush=True)
    
    
    def stop(why):          # exit code 2: a restart would not help
        print(why, file=sys.stderr, flush=True)
        sys.exit(2)
    
    
    def main():
        key = os.environ.get("CANDLE_KEY") or stop("Set CANDLE_KEY to your API key.")
        last_id = None
        while True:
            headers = {"Authorization": f"Bearer {key}", **({"Last-Event-ID": last_id} if last_id else {})}
            try:
                with httpx.stream("GET", URL, params=FILTER, headers=headers, timeout=60) as resp:
                    if resp.status_code in (400, 401, 403):
                        stop(resp.read().decode())
                    resp.raise_for_status()
                    print("connected", flush=True)
                    event = None
                    for line in resp.iter_lines():
                        if line.startswith("event: "):
                            event = line[7:]
                        elif line.startswith("data: "):
                            data = json.loads(line[6:])
                            for r in data.get("readings", []):
                                on_reading(r)
                            for r in data.get("results", []):
                                on_result(r)
                            if event == "ended":
                                stop(f"The stream ended: {data['error']}")
                        elif line.startswith("id: "):
                            last_id = line[4:]
            except httpx.HTTPError as e:
                print("connection lost, trying again:", e, file=sys.stderr, flush=True)
            time.sleep(5)
    
    
    if __name__ == "__main__":
        main()
    
  3. Choose what to receive. Edit FILTER in the script, and put your own code into on_reading and on_result.
  4. Save your key and test. The script prints connected, and then the readings at the next closes that have one. Stop it with Ctrl+C.
    echo "CANDLE_KEY=YOUR_KEY" > candle.env && chmod 600 candle.env
    set -a; . ./candle.env; set +a
    venv/bin/python candle_stream.py
  5. Keep it running. The script must run as a long-running process. When it stops, the alerts stop.
    On a bot server (Linux, systemd): recommended

    It starts with the server and restarts after a crash. Save this as /etc/systemd/system/candle-stream.service and replace YOUR_USER:

    [Unit]
    Description=Candlestick Anatomy stream
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    User=YOUR_USER
    WorkingDirectory=/home/YOUR_USER/candle
    EnvironmentFile=/home/YOUR_USER/candle/candle.env
    ExecStart=/home/YOUR_USER/candle/venv/bin/python candle_stream.py
    Restart=always
    RestartSec=5
    RestartPreventExitStatus=2
    
    [Install]
    WantedBy=multi-user.target

    Start it, and see what it prints:

    sudo systemctl daemon-reload
    sudo systemctl enable --now candle-stream
    journalctl -u candle-stream -f
    On your own computer (macOS or Linux)

    It runs in the background after you close the terminal. The computer must stay on, awake and online, and you start the script again after a restart of the computer. On macOS, caffeinate -i stops idle sleep. A closed laptop lid still lets it sleep.

    cd ~/candle && set -a; . ./candle.env; set +a
    # macOS
    nohup caffeinate -i venv/bin/python candle_stream.py >> stream.log 2>&1 &
    # Linux
    nohup venv/bin/python candle_stream.py >> stream.log 2>&1 &
    
    tail -f stream.log                # see what it prints
    pkill -f candle_stream.py         # stop it

The script reconnects by itself and then gets the events of the last 15 minutes that it missed. It exits when the key is not valid or Pro has ended.

Pay per call (x402)

A request without a key gets HTTP 402 with the price. An x402 client pays in USDC and sends the request again. No account needed. The stream needs a Pro key.

Limits and errors

Per key: 60 requests a minute, 1,000 a day, 2 open streams. Keys are for your own use: reselling or publishing the data is not allowed.

401key_requiredSend a Pro key (Authorization: Bearer <key>).
401bad_keyThis key is not valid. Create a new one on the API page.
403pro_endedThe Pro plan of this key has ended.
429too_many_streamsToo many open streams for this key.
429rate_limitedToo many requests. See Retry-After.
402payment requiredNo key: pay with x402, then send the request again.