Binance spot bars
All plugins

Plugin libraryCrypto

Plugin

Binance spot bars

Downloads closed Binance spot bars from M1 to D1 for crypto pairs like BTCUSDT, and writes daily close feeds for pairs a strategy wants to watch.

Data sourceNetwork: data-api.binance.visionDesktop onlyv1.0.0

About

A download source for crypto pairs. In the Data view, choose Binance spot as the source, type a Binance spot symbol (BTCUSDT, ETHUSDT) and a timeframe from M1 to D1. The plugin pages through Binance's public market data host 1,000 bars at a time, half a second apart, and the engine stores the bars like any other download.

Only closed bars are kept: the bar still forming at the moment of the download is left out, so a backtest never sees a candle that was not finished. Times are UTC, each bar under its open time.

The plugin also writes the daily close of the pairs in Daily close feeds as binance_<pair>_close (BTCUSDT by default), for strategies that look at another market, for example a filter on Bitcoin while trading something else.

Configuration

FieldTypeDefaultDescription
cache_daysRefetch close feeds after (days)number1Days before the close feeds are downloaded again. Within that time a run reads the cached feeds and needs no network.
close_feedsDaily close feeds (pairs, comma separated)string"BTCUSDT"Pairs whose daily close is written as a feed before a run, separated by commas, for example BTCUSDT, ETHUSDT. Empty writes none. The bar download does not use this setting.

Use it in a strategy

pythonbars = ctx.bars(1)
if bars:
    btc = ctx.data("binance_btcusdt_close", bars[-1].ts)
    if btc is not None and btc < 20000:
        ctx.signal("EXIT")

For the bars themselves no code is needed: download them in the Data view with Binance spot as the source and run a backtest on the pair. The close feeds are refreshed before a run whose strategy reads ctx.data, or when "Fetch external data (news and plugin feeds)" is ticked. A run on the server never fetches.

What it provides

binance_spotBarsThe download source: closed OHLCV bars in UTC for M1, M5, M15, M30, H1, H4 and D1. Volume is in the base asset (BTC for BTCUSDT).
binance_<pair>_closeFeedThe daily close of each pair in Daily close feeds, a number, under the day after the UTC day it closes.

Data source and terms

PublisherBinance spot market data (data-api.binance.vision, /api/v3/klines)
TermsRead the terms
API keyNone needed
AttributionMarket data: Binance spot
Rate limitUp to 1,000 bars per request, half a second apart: a year of M1 bars is about 530 requests and takes some minutes. Binance answers 429 or 418 when a machine asks too much.

Hosts it may reach: data-api.binance.vision

When values are known

A bar is complete at its close, and only closed bars are stored, each under its open time as every bar in the engine. A daily close feed value is stored under the next UTC day, when the day's bar has closed.

Limits

  • Binance refuses some countries with HTTP 451 (unavailable for legal reasons). The download then stops with a message saying so; the plugin cannot work around it.
  • Only pairs trading today can be chosen; pairs Binance delisted are missing, so a test over "all coins" leans towards the survivors.
  • One exchange's prices and volume, not a market wide index. Spot only, no futures and no funding.
  • A pair the engine does not know, such as BTCUSDT, needs its asset class set to crypto or a custom symbol before a run. The data stays on your machine and is for your own use under Binance's terms.
OrionQuant