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
INTERVAL No 1d Candle interval (1m, 5m, 1h, ...)
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): Executes your trading logic
  • run_backtest(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.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) -> None:
        """Execute your trading logic"""
        latest = self.indicators[symbol].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, 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 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.0.tar.gz (25.7 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.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: open_binancian_futures-26.2.0.tar.gz
  • Upload date:
  • Size: 25.7 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.0.tar.gz
Algorithm Hash digest
SHA256 81471c8414a89f710931d7670d62798c41f281bbe4d7e8919700800c60e774ed
MD5 6202b5d79bbfb9759b7bed76ce695b9b
BLAKE2b-256 77d6675d798c87840ec35a1646f05a6d9c9f8709c9efc5bf8e5f7ac4204d8895

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_binancian_futures-26.2.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for open_binancian_futures-26.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 888e0215433cfa07b064f5081e2576aaa5eae267f5c76a5f634f9ee38f176a6c
MD5 25ca228ee6ef833484bba0aa0411ad51
BLAKE2b-256 256df68f7cc9a8d36df6fb87ec0cf195f6e57d8d585b3825e72e08ab278c6a09

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_binancian_futures-26.2.0-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