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.
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.
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.
Architecture
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
cli.pychecks the symbol, side, type, quantity and price.client.pyloads keys from the environment and connects to the testnet.orders.pyadds price and “good till cancelled” for limit orders, then calls the API.- The request and response are logged; the result or a clear error is printed.
Languages and code
- Python100.0%
Repository
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.logfile. 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
Methodology
- Separate the code by job: CLI entry, client setup, order logic and logging.
- Fail early: validate input before calling the exchange.
- Keep secrets in a
.envfile that is never committed. - Run only against the testnet.
Technology
Demo
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.
Team
- Sujal NegiCo-founder, Nexara9PortfolioLinkedIn