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): 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.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) -> None:
        """Execute your trading logic"""
        primary_interval = settings.intervals_list[0]
        latest = self.indicators[symbol][primary_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, 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.2.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.2-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: open_binancian_futures-26.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 e1a62d40295972b2c81b924dd9bfe1c326774cab9ad1754c42159f691a3f6d55
MD5 3e4652786e92e125beb257f08e294d32
BLAKE2b-256 de45ce141172b07c774a497ce2a222c1fb8b30751a9dbcffab7c800156650044

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for open_binancian_futures-26.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3c8eac08c63799756991bdf0b784072ab85df90f420d3fe54a07129de582e32
MD5 847cbea11b76974d256a0634b5567e52
BLAKE2b-256 5f389415cbe4191e76f498744ccc0a931167a79106fda27d99417e18e0ad427b

See more details on using hashes here.

Provenance

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