๐ Key Features
- Futures Trading: Full support for USDT, COIN, and USDC margined futures.
- Account Management: Retrieve balances, leverage settings, and transaction history.
- Real-Time Data: Access tickers, candlesticks, depth charts, and funding rates.
- WebSocket Integration: Public market data streaming with async support.
- Error Handling: Custom exceptions for invalid requests or API failures.
๐ ๏ธ Installation
pip install bitget-python๐ง Quick Start
Public Market Data (No API Keys)
from bitpy import BitgetAPI
client = BitgetAPI()
ticker = client.market.get_ticker(symbol="BTCUSDT", product_type="USDT-FUTURES") Authenticated Requests
client = BitgetAPI(
api_key="YOUR_KEY",
secret_key="YOUR_SECRET",
api_passphrase="YOUR_PASSPHRASE"
)
account_info = client.account.get_account(symbol="BTCUSDT", margin_coin="USDT") ๐ Explore advanced trading strategies
๐ WebSocket Public Feeds
from bitpy import BitgetWebsocketAPI
import asyncio
async def handle_ticker(data):
print(f"Price: {data['data'][0]['lastPr']}")
async def main():
api = BitgetWebsocketAPI(is_private=False)
await api.websocket.connect()
await api.websocket.subscribe([{"instType": "SPOT", "channel": "ticker", "instId": "BTCUSDT"}], handle_ticker)
asyncio.run(main()) ๐ Supported Markets
| Market Type | Description |
|-------------------|---------------------------|
| USDT-FUTURES | USDT-margined futures |
| COIN-FUTURES | Coin-margined futures |
| USDC-FUTURES | USDC-margined futures |
โ ๏ธ Error Handling
try:
client.position.get_all_positions("INVALID-TYPE")
except InvalidProductTypeError:
print("Invalid product type specified.") ๐ Rate Limiting
- Automatic request throttling via token bucket algorithm.
- Tracks per-endpoint limits to avoid 429 errors.
๐ค FAQ
Q: How do I set leverage?
A: Use client.account.set_leverage(symbol="BTCUSDT", margin_coin="USDT", leverage=10).
Q: Can I fetch historical trades?
A: Yes, via client.market.get_history_trades(symbol="BTCUSDT", limit=100).
Q: Is WebSocket private data supported?
A: Currently, only public market feeds are available.
๐ License
MIT License. Contributions welcome!
### Keywords:
1. Bitget API Python
2. Futures Trading
3. WebSocket Market Data
4. Rate Limiting
5. Error Handling
6. Account Management
7. USDT-FUTURES