Writing a Binance Futures Trading Bot Without a Wrapper Library

Building a CLI trading bot on raw REST calls and HMAC-SHA256 signing, and the demo API key issue that ate an afternoon.

By Akshay More · 2026-06-02 · 6 min read · Projects

Writing a Binance Futures Trading Bot Without a Wrapper Library

For a Binance Futures Testnet assignment, the requirement was direct REST calls with manual HMAC SHA256 signing, no python binance or similar wrapper. That constraint turned out to be the interesting part.

What the bot supports

MARKET, LIMIT, and STOP order types. A mock demo mode for testing logic without hitting the API. Unit tests covering signature generation and order payload construction.

The signature

import hmac, hashlib

def sign(query string: str, secret: str) str: return hmac.new(secret.encode(), query string.encode(), hashlib.sha256).hexdigest() ```

The error that ate an afternoon

Every request returned a 2015 invalid API key error, even with keys copied correctly from the Binance Futures Testnet dashboard. The actual cause: the demo trading environment needs keys generated specifically from demo.binance.com, not the regular testnet key generator. Two systems that look identical, issuing incompatible keys.

Takeaway

When an error message says invalid credentials but the credentials look right, check whether you're even pointed at the right environment before touching the code.