Minimal Python wrapper for the Bitget V2 USDT-M futures API —
request signing, account, positions, orders and TP/SL in ~180 lines.
A small, dependency-light client for Bitget USDT-M futures. It exists to make the
signing scheme obvious: every request is signed with
HMAC-SHA256(timestamp + method + path + query + body), base64-encoded, and sent with
the ACCESS-* headers Bitget expects. Everything else is a thin method over one
endpoint.
Demo trading by default. The client sends the
paptrading: 1header, so requests hit Bitget's paper-trading environment. Remove that header inclient.pyto trade real funds — deliberately, not by accident.
| Path | Purpose |
|---|---|
bitgetdemo/client.py |
signing, headers, request execution, error raising |
bitgetdemo/futures.py |
Futures — account, positions, market data, orders, TP/SL |
bitgetdemo/config.py |
API credentials |
bitgetdemo/examples/ |
runnable snippets: balance, positions, orders |
from bitgetdemo.futures import Futures
f = Futures(API_KEY, API_SECRET, API_PASSPHRASE)
f.balance() # account equity
f.positions() # all open positions
f.price("BTCUSDT") # ticker
f.market_order("BTCUSDT", "buy", "0.001") # market entry
f.limit_order("BTCUSDT", "buy", "0.001", "50000")
f.set_tpsl("BTCUSDT", tp="60000", sl="45000")
f.close_position("BTCUSDT")
f.open_orders("BTCUSDT")
f.cancel_order("BTCUSDT", order_id)
f.order_history("BTCUSDT")
f.pnl_history()All methods return Bitget's parsed JSON. A non-00000 response code raises, so a
failed call never looks like a successful one.
pip install requestsFill in bitgetdemo/config.py:
API_KEY = "..."
API_SECRET = "..."
API_PASSPHRASE = "..."Then run any example:
python -m bitgetdemo.examples.balanceKeep real credentials out of version control —
config.pyis tracked, so either leave it empty and load from the environment, or add it to.gitignorebefore filling it in.
Cross margin, USDT-M perpetuals, synchronous requests. No WebSocket, no rate-limit
handling, no retries — this is a reference implementation of the REST surface, not a
trading framework.