Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:51bitquant Ai hedge fund crypto Binance API Access

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Market_Data
Last Updated 2026-10-28 09:34 GMT

Overview

Network access to Binance REST API for fetching historical and live OHLCV kline (candlestick) data; public market data requires no credentials.

Description

This environment provides access to the Binance cryptocurrency exchange REST API. The repository bundles a vendored python-binance client under src/gateway/binance/ that handles request signing, rate limiting, and response parsing. Public market data endpoints (klines, ticker prices) require no API keys. Private endpoints (account balances, order placement) would require API key/secret credentials, but the current codebase only uses public data endpoints for backtesting and signal generation.

Usage

Use this environment whenever the system needs to fetch historical or live kline data from Binance. It is the mandatory prerequisite for the BinanceDataProvider implementations and the DataNode graph node. Network connectivity to api.binance.com or fapi.binance.com (futures) is required.

System Requirements

Category Requirement Notes
OS Any (cross-platform Python) No OS-specific constraints
Hardware CPU + network interface Internet access required
Network HTTPS access to Binance API api.binance.com, fapi.binance.com; may be blocked in some regions (use VPN/proxy if needed)
Disk Write access to ./cache/ CSV cache files are written here to avoid repeated API calls

Dependencies

System Packages

  • Internet connection with HTTPS access

Python Packages

  • requests >= 2.32.3 (sync REST client)
  • aiohttp >= 3.11.18 (async client)
  • websockets >= 15.0.1 (websocket streams)
  • pycryptodome >= 3.22.0 (HMAC request signing)
  • yarl >= 1.20.0 (URL parsing)
  • dateparser >= 1.2.1 (date string parsing)

Bundled Client

  • src/gateway/binance/client.py — Synchronous Binance REST client (vendored python-binance)
  • src/gateway/binance/async_client.py — Asynchronous Binance REST client

Credentials

The following environment variables are optional for public market data:

  • BINANCE_API_KEY: Binance API key — only needed for private endpoints (account, trading). Not required for kline/ticker data.
  • BINANCE_API_SECRET: Binance API secret — only needed for signed private requests.

Warning: Never include actual API keys in code or wiki pages. Store them in .env.

Quick Install

# Dependencies are installed as part of the main project
pip install requests>=2.32.3 aiohttp>=3.11.18 websockets>=15.0.1 \
    pycryptodome>=3.22.0 yarl>=1.20.0 dateparser>=1.2.1

# For private endpoints (optional), set in .env:
# BINANCE_API_KEY=your_key_here
# BINANCE_API_SECRET=your_secret_here

Code Evidence

BinanceDataProvider initialization with optional credentials from src/utils/binance_data_provider.py:21-33:

def __init__(self, api_key: Optional[str] = None, api_secret: Optional[str] = None):
    """
    Initialize the BinanceDataProvider with API credentials.
    Args:
        api_key: Binance API key (optional for public data)
        api_secret: Binance API secret (optional for public data)
    """
    self.client = Client(api_key=api_key, api_secret=api_secret)
    self.cache_dir = Path("./cache")
    self.cache_dir.mkdir(exist_ok=True)

Historical klines fetch via the REST client from src/utils/binance_data_provider.py:94-100:

klines = self.client.get_historical_klines(
    symbol=formatted_symbol,
    interval=self._format_timeframe(timeframe),
    start_str=start_ts,
    end_str=end_ts
)

Futures klines with end time from src/utils/binance_data_provider.py:203-208:

klines = self.client.futures_historical_klines_with_end_time(
    symbol=formatted_symbol,
    interval=self._format_timeframe(timeframe),
    end_str=end_time.strftime("%Y-%m-%d %H:%M:%S"),
    limit=limit
)

Common Errors

Error Message Cause Solution
requests.exceptions.ConnectionError Network blocked or no internet Ensure HTTPS access to api.binance.com; use VPN if in restricted region
Error fetching historical data for ... (empty DataFrame) API rate limit or symbol not found Check symbol format (e.g., BTCUSDT not BTC/USDT); wait and retry for rate limits
-1021 Timestamp for this request is outside of the recvWindow System clock drift Sync system time (NTP); the client uses timestamp-based signing
-1003 Request weight limit exceeded API rate limit hit Reduce request frequency; use CSV cache to avoid repeated calls

Compatibility Notes

  • Regional restrictions: Binance API may be blocked in some countries (e.g., US). Use a VPN or proxy if needed.
  • Futures vs Spot: The futures_historical_klines_with_end_time method hits the futures API endpoint; ensure the symbol exists on Binance Futures.
  • Rate limits: Binance enforces IP-based rate limits. The CSV cache strategy (see Heuristic:51bitquant_Ai_hedge_fund_crypto_CSV_Cache_Reuse) is critical to avoid -1003 errors during backtests.
  • No credentials for public data: BinanceDataProvider() called with no arguments works for all kline/ticker endpoints used by this repo.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment