Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

bitget

Minimal Python wrapper for the Bitget V2 USDT-M futures API —
request signing, account, positions, orders and TP/SL in ~180 lines.

Python 3.9+ Bitget API v2 Demo trading


Overview

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: 1 header, so requests hit Bitget's paper-trading environment. Remove that header in client.py to trade real funds — deliberately, not by accident.

Layout

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

Usage

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.

Setup

pip install requests

Fill in bitgetdemo/config.py:

API_KEY = "..."
API_SECRET = "..."
API_PASSPHRASE = "..."

Then run any example:

python -m bitgetdemo.examples.balance

Keep real credentials out of version control — config.py is tracked, so either leave it empty and load from the environment, or add it to .gitignore before filling it in.

Scope

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.

About

Minimal Python wrapper for the Bitget V2 USDT-M futures API — HMAC request signing, account, positions, orders and TP/SL, defaulting to demo trading

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages