All projects

N9/04FintechComplexity: Light

Binance Futures Trading Bot

A clean Python command-line tool that places market and limit orders on the Binance Futures testnet.

Status
Complete
Year
2026
Built for
Technical assessment · Python developer role
Languages
Python
Team
Sujal Negi
01

Overview

A small, production-style trading tool: one command places a BUY or SELL order, at market price or at a limit price, on Binance’s USDT-M futures testnet.

It was built as a technical assessment, so the focus is on clean structure, careful input checks, structured logs and safe error handling, not on a trading strategy.

02

Problem and aim

Problem

Trading APIs are unforgiving: one wrong parameter or a leaked key can cost real money. Even a simple order tool needs validation, logging and safe defaults.

Aim

Show how a reliable, testable order-placement tool is structured, using the testnet so no real money is involved.

03

How it works

01 / 05

Command

You run python cli.py --symbol BTCUSDT --side BUY --type LIMIT --qty 0.01 --price 60000. Click parses and type-checks every option.

02 / 05

Validate

BUY or SELL and MARKET or LIMIT are fixed choices. A LIMIT order without a price is rejected before anything is sent.

03 / 05

Connect

The client is created for the futures testnet with the API key and secret read from environment variables, never from the code.

04 / 05

Place the order

The parameters are built (LIMIT orders get the price and “good till cancelled”) and sent with futures_create_order.

05 / 05

Log and report

Every request and response is logged to the console and to bot.log; the result (order ID, status, average price, quantity) is printed, or a clear error if it failed.

04

Architecture

From your terminal to the testnet

AYour computer

  • TerminalYou type one command.
  • cli.pyParses and validates options with Click.
  • .envAPI key and secret, never in code.

Bbot package

  • client.pyCreates a testnet futures client.
  • orders.pyBuilds parameters and places the order.
  • logger.pyLogs to console and bot.log.

CExchange

  • Binance Futures testnetUSDT-M futures REST API with test funds.

Request flow

  1. cli.py checks the symbol, side, type, quantity and price.
  2. client.py loads keys from the environment and connects to the testnet.
  3. orders.py adds price and “good till cancelled” for limit orders, then calls the API.
  4. The request and response are logged; the result or a clear error is printed.
05

Languages and code

  • Python100.0%

Repository

8 files508 linesTap any file to read its code

  • bot/The reusable core.
    • Reads keys from the environment and creates a client pointed at the futures testnet. 11 lines
    • Logging set-up: one format for the console and the bot.log file. 11 lines
    • place_futures_order(): builds the order parameters and sends them, logging both sides. 26 lines
  • Template for the API key and secret. 2 lines
  • 207 lines
  • Entry point. Defines the command and its options, validates them and prints the result. 30 lines
  • 218 lines
  • Python packages needed. 3 lines
  • bot.logExample log from real testnet runs. on GitHub
06

Methodology

  1. Separate the code by job: CLI entry, client setup, order logic and logging.
  2. Fail early: validate input before calling the exchange.
  3. Keep secrets in a .env file that is never committed.
  4. Run only against the testnet.
07

Technology

CorePython 3.8+Language for the tool.
python-binanceClient for the Binance Futures API.
ClickA tidy, validated command-line interface.
Operationspython-dotenvLoads API keys from the environment.
loggingStructured logs to console and file.
08

Demo

09

Concepts

01Market order vs limit order

A market order buys or sells immediately at the best available price. A limit order sets the price you will accept and waits in the order book until the market reaches it.

02What are USDT-M futures?

Futures contracts that are margined and settled in USDT (a dollar-pegged stablecoin). You trade a contract on the price of an asset rather than the asset itself.

03What does “good till cancelled” mean?

A time-in-force setting: the limit order stays open until it fills or you cancel it.

04Why use a testnet?

A testnet is a copy of the exchange with fake money. You can test real API calls end to end without any financial risk.

05Why keep keys in environment variables?

Keys written in code end up in Git history and can leak. Environment variables keep them on the machine that needs them.

10

Team