A Python client for the Bitget API with comprehensive position management
Project description
🚀 Bitget API V2 Python Client
A comprehensive Python client for the Bitget API V2, providing extensive functionality for futures trading, account management, and market data access.
✨ Features
- 📊 Complete futures market trading capabilities
- 💼 Account management and settings
- 📈 Real-time and historical market data
- 🔄 Automatic rate limiting and request handling
- 🛡️ Comprehensive error handling and validation
- 📝 Detailed debug logging capabilities
- 🎯 Type hints and dataclass models for better code completion
🛠️ Installation
# Install using PIP
pip install git+https://github.com/Tentoxa/bitpy
🔧 Quick Start
from bitpy import BitgetAPI
# For market data only - no API keys needed
client = BitgetAPI(
api_key=None,
secret_key=None,
api_passphrase=None
)
# Get market data without authentication
ticker = client.market.get_ticker(
symbol="BTCUSDT",
product_type="USDT-FUTURES"
)
# Get candlestick data
candles = client.market.get_candlestick(
symbol="BTCUSDT",
product_type="USDT-FUTURES",
granularity="1m",
limit=100
)
For account and position operations, API keys are required:
# For trading operations - API keys required
client = BitgetAPI(
api_key="your_api_key",
secret_key="your_secret_key",
api_passphrase="your_passphrase",
debug=True
)
# Get account information (requires authentication)
account = client.account.get_account(
symbol="BTCUSDT",
product_type="USDT-FUTURES",
margin_coin="USDT"
)
🔑 Core Components
Account Management
- Account information and settings
- Leverage and margin configuration
- Position mode management
- Asset mode settings
- Interest and bill history
Position Management
- Position tracking and history
- Position tier information
- Multiple position modes support
Market Data
- Real-time tickers and depth
- Candlestick data with multiple timeframes
- Funding rates and open interest
- Historical transaction data
- Contract specifications
💹 Supported Markets
| Market Type | Description |
|---|---|
| USDT-FUTURES | USDT margined futures |
| COIN-FUTURES | Coin margined futures |
| USDC-FUTURES | USDC margined futures |
| SUSDT-FUTURES | Simulated USDT futures |
| SCOIN-FUTURES | Simulated coin futures |
| SUSDC-FUTURES | Simulated USDC futures |
⚠️ Error Handling
from bitpy.exceptions import InvalidProductTypeError, BitgetAPIError
try:
positions = client.position.get_all_positions("INVALID-TYPE")
except InvalidProductTypeError as e:
print(f"Invalid product type: {e}")
except BitgetAPIError as e:
print(f"API Error {e.code}: {e.message}")
🔄 Rate Limiting
The client implements a smart token bucket algorithm for rate limiting, automatically tracking and managing request limits per endpoint to ensure optimal API usage.
📊 Advanced Market Data
# Get candlestick data
candles = client.market.get_candlestick(
symbol="BTCUSDT",
product_type="USDT-FUTURES",
granularity="1m",
limit=100
)
# Get market depth
depth = client.market.get_merge_depth(
symbol="BTCUSDT",
product_type="USDT-FUTURES",
precision="0.1"
)
🤝 Contributing
Contributions are welcome! Feel free to submit a Pull Request. For feature requests or bug reports, please open an issue.
📄 License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitget_python-1.0.2.tar.gz.
File metadata
- Download URL: bitget_python-1.0.2.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
878411996116e0f40c899e5975b0eebfabb5da3d8c319d3aaa51b5243ac3284f
|
|
| MD5 |
576062c429ee41d4df2deac80b9669d6
|
|
| BLAKE2b-256 |
bb0fda7ccd069907843c505fe85415b7dd3bad27fbff3d7685afc8cb577bbc75
|
File details
Details for the file bitget_python-1.0.2-py3-none-any.whl.
File metadata
- Download URL: bitget_python-1.0.2-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f9ae666e9342943a7ca004eeaca42091870d78ba6373b914aa44c6bc823a429
|
|
| MD5 |
3594f73d9ab6d4d8fe9b9e5d01f90772
|
|
| BLAKE2b-256 |
993eed5f97f71217b6d604bb5dbe6d42f1e9249038888bbdfff5b0ca6a7ce915
|