Skip to main content

A robust framework for creating, backtesting, and deploying trading bots for Binance USDⓈ-M Futures

Project description

Open Binancian Futures

Python License

A Python framework for creating, backtesting, and deploying automated trading bots on Binance USDⓈ-M Futures.

Features

  • Live Trading – Monitor multiple symbols and execute trades automatically
  • Backtesting – Test strategies on historical data (experimental)
  • Webhooks – Real-time notifications via Slack/Discord

Prerequisites

  • Python 3.12+
  • Binance API keys with Enable Futures permission (Get keys)

Getting Started

1. Install the package

pip install open-binancian-futures

2. Create a .env file (see .env.example)

Variable Required Default Description
API_KEY Yes* - Binance API key (mainnet)
API_SECRET Yes* - Binance API secret (mainnet)
SYMBOLS No BTCUSDT comma-separated list of symbols to trade
INTERVALS No 1d Comma-separated candle intervals (1m, 5m, 1h, ...). First entry is the primary interval
LEVERAGE No 1 Leverage multiplier (1 ~ 125)
SIZE No 0.05 Trade size per order (e.g., 0.05 = 5% of balance)

* For testnet, use API_KEY_TEST and API_SECRET_TEST instead

View All Configuration Options
Variable Type Default Description
IS_TESTNET bool false Use testnet (true/false)
GTD_NLINES number - Candles to hold open orders (GTC if not set)
TIMEZONE string UTC Timezone (e.g., Asia/Seoul)
WEBHOOK_URL string - Slack/Discord webhook for notifications
Backtesting
IS_BACKTEST bool false Enable backtest mode
BALANCE number 100 Initial backtest balance
KLINES_LIMIT number 1000 Historical candles to fetch (max 1000)
INDICATOR_INIT_SIZE number 200 Candles for indicator warm-up

3. Create your strategy

Extend the Strategy class and implement load(), run(), and run_backtest() functions:

  • load(DataFrame): Loads technical indicators you want to use
  • run(str, str): Executes your trading logic
  • run_backtest(str, str, int): Backtesting logic (optional)
Example Strategy
import asyncio
import pandas_ta as ta

from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    NewOrderSideEnum,
    NewOrderTimeInForceEnum,
)
from open_binancian_futures.types import OrderType
from open_binancian_futures.strategy import Strategy
from open_binancian_futures.constants import settings
from open_binancian_futures.utils import fetch
from pandas import DataFrame
from typing import cast, override

class MyStrategy(Strategy):

    @override
    def load(self, df: DataFrame) -> DataFrame:
        """Add technical indicators to the dataframe"""
        # You can use `pandas_ta` to add technical indicators
        df["RSI_14"] = ta.rsi(df["Close"], length=14)
        return df

    @override
    async def run(self, symbol: str, interval: str) -> None:
        """Execute your trading logic"""
        latest = self.indicators[symbol][interval].iloc[-1] # Access to the latest candle
        entry_price = latest["Close"]

        if latest["RSI_14"] < 30:
            async with cast(asyncio.Lock, self.lock):
                if entry_quantity := self.exchange_info.to_entry_quantity(
                    symbol=symbol,
                    entry_price=entry_price,
                    balance=self.balance,
                ):
                    fetch(
                        self.client.rest_api.new_order,
                        symbol=symbol,
                        side=NewOrderSideEnum.BUY,
                        type=OrderType.LIMIT.value,
                        price=float(entry_price),
                        quantity=float(entry_quantity),
                        time_in_force=NewOrderTimeInForceEnum.GTC,
                    )

    @override
    async def run_backtest(self, symbol: str, interval: str, index: int) -> None:
        """Backtesting logic (optional)"""
        ...

4. Running

open-binancian-futures my_strategy.py

You can override environment variables from the command line:

open-binancian-futures --backtest --symbols BTCUSDT,ETHUSDT --intervals 1h,4h my_strategy.py

License

MIT License - see LICENSE for details.

Disclaimer

USE AT YOUR OWN RISK.

The author and contributors are not responsible for any financial losses or damages arising from the use of this software. Cryptocurrency trading involves significant risk. Always test thoroughly and trade responsibly.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open_binancian_futures-26.2.3.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

open_binancian_futures-26.2.3-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file open_binancian_futures-26.2.3.tar.gz.

File metadata

  • Download URL: open_binancian_futures-26.2.3.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for open_binancian_futures-26.2.3.tar.gz
Algorithm Hash digest
SHA256 31f0d1f7b0a55c2eded27d18fecb6eed899f7b1f4a401ebae2068dde445dde76
MD5 a7326e4b7aca60c42f15bd395d0f6a16
BLAKE2b-256 1549e4eb62ce6570a3efbb09b28dc298348c49e86e447ebd3ee08a3d834e8bb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_binancian_futures-26.2.3.tar.gz:

Publisher: pypi.yml on zionhann/open-binancian-futures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file open_binancian_futures-26.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for open_binancian_futures-26.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3a16fa7e0ca7bbf11a73a8048089ef1b743d0f22ebe60cf4b61790871c0754ca
MD5 a1e94d872207de19c740ee354d68d768
BLAKE2b-256 41a253d0a6278a6d7384e82d06cda4ff2ed19529de14b15ce25b34280e3d9ecf

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_binancian_futures-26.2.3-py3-none-any.whl:

Publisher: pypi.yml on zionhann/open-binancian-futures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page