A fully typed, validated async client for the Bitget API.
Project description
Typed Bitget
A fully typed, validated async client for the Bitget API
Use autocomplete instead of documentation.
from bitget import Bitget
async with Bitget.new() as client:
assets = await client.spot.account.assets()
for asset in assets:
print(f"{asset['coin']}: {asset['available']}")
Why Typed Bitget?
- 🎯 Precise Types: Literal types, not strings. Your IDE knows exactly what's valid.
- ✅ Automatic Validation: Pydantic-powered response validation catches API changes instantly.
- ⚡ Async First: Built on
httpxfor high-performance async operations. - 🔒 Type Safety: Full type hints throughout. Catch errors before runtime.
- 🎨 Beautiful DX: No unnecessary imports, sensible defaults, optional complexity.
- 📦 Batteries Included: Pagination helpers, decimal precision, timestamp parsing.
Installation
pip install typed-bitget
Quick Start
1. Set up API credentials
export BITGET_ACCESS_KEY="your_access_key"
export BITGET_SECRET_KEY="your_secret_key"
export BITGET_PASSPHRASE="your_passphrase"
2. Start trading
from bitget import Bitget
async with Bitget.new() as client:
# Get spot account assets
assets = await client.spot.account.assets()
# Get futures positions
positions = await client.futures.position.all_positions(
product_type='USDT-FUTURES'
)
# Check overall balance
overview = await client.common.assets.overview()
Features
No Unnecessary Imports
Notice something? You never imported Literal types. Just use strings:
# ❌ Other libraries
from some_sdk import ProductType
positions = await client.get_positions(product_type=ProductType.USDT_FUTURES)
# ✅ Typed Bitget
positions = await client.futures.position.all_positions(
product_type='USDT-FUTURES' # Your IDE autocompletes this!
)
Precise Type Annotations
Every field is precisely typed. Prices are Decimal, timestamps are datetime, enums are Literal types:
from decimal import Decimal
from datetime import datetime
assets = await client.spot.account.assets()
for asset in assets:
coin: str = asset['coin']
available: Decimal = asset['available'] # Not float!
updated: datetime = asset['uTime'] # Not int!
Automatic Validation
Response validation is on by default but can be disabled:
# Validated (default) - throws ValidationError if API response changes
assets = await client.spot.account.assets()
# Skip validation for maximum performance
assets = await client.spot.account.assets(validate=False)
Built-in Pagination
# Manual pagination
response = await client.futures.trade.fills(
product_type='USDT-FUTURES',
symbol='BTCUSDT',
limit=100
)
# Automatic pagination - yields chunks as they arrive
async for chunk in client.futures.trade.fills_paged(
product_type='USDT-FUTURES',
symbol='BTCUSDT'
):
for fill in chunk:
print(f"Trade: {fill['price']} @ {fill['baseVolume']}")
API Coverage
This library is a work in progress with many missing endpoints.
Current implementation includes ~40 methods across spot, futures, margin, earn, and copy trading. However, major functionality like order placement, order management, and WebSocket streams are not yet implemented.
📋 See API Overview for complete coverage details.
Documentation
- Quickstart Guide - Get up and running in 5 minutes
- Authentication - API credentials setup
- API Overview - Available endpoints and modules
- Examples - Common use cases and patterns
- Design Philosophy - Why we built it this way
Design Philosophy
Typed Bitget follows the principles outlined in this blog post:
- Inputs shouldn't require custom imports - Use string literals, not enums
- Annotate types precisely -
Literaltypes,Decimalfor prices,datetimefor timestamps - Avoid unnecessary complication - Sensible defaults, optional complexity
- Provide extra behavior optionally - Pagination and validation are opt-in
Details matter. Developer experience matters.
Examples
Portfolio Tracking
async with Bitget.new() as client:
overview = await client.common.assets.overview()
total_balance = sum(
account['usdtBalance']
for account in overview
)
print(f"Total Portfolio: ${total_balance:,.2f}")
Trading Bot
async with Bitget.new() as client:
# Get current positions
positions = await client.futures.position.all_positions(
product_type='USDT-FUTURES',
symbol='BTCUSDT'
)
# Get recent fills
fills = await client.futures.trade.fills(
product_type='USDT-FUTURES',
symbol='BTCUSDT',
limit=50
)
Tax Reporting
from datetime import datetime
async with Bitget.new() as client:
start = datetime(2024, 1, 1)
end = datetime(2024, 12, 31)
records = await client.common.tax.spot_transaction_records(
start=start,
end=end
)
Error Handling
from bitget import Bitget
from bitget.core import ApiError, ValidationError, NetworkError
async with Bitget.new() as client:
try:
assets = await client.spot.account.assets()
except ValidationError:
# API response doesn't match expected schema
pass
except ApiError as e:
# Bitget API returned an error
print(f"API Error: {e}")
except NetworkError:
# Network/connection issue
pass
Contributing
This is a work in progress! Contributions are welcome. The codebase is designed to be:
- Consistent: All endpoints follow the same patterns
- Type-safe: Everything is fully typed
- Validated: Pydantic models for all responses
Inspired by this blog post on building better API clients.
Built with ❤️ by Tribulnation
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 typed_bitget-0.1.3.tar.gz.
File metadata
- Download URL: typed_bitget-0.1.3.tar.gz
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f97550fa3954c240228ccb4fdd021ed13f8b07da62d0f283afb76a5628e1f43
|
|
| MD5 |
317d51b5698d4d14d17453063394b9e6
|
|
| BLAKE2b-256 |
7e5256185a13fc79940db5505751d348255d765200473c4bcb06f31da82e8687
|
File details
Details for the file typed_bitget-0.1.3-py3-none-any.whl.
File metadata
- Download URL: typed_bitget-0.1.3-py3-none-any.whl
- Upload date:
- Size: 91.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7794bdc0a15ad93236b4d679c01432094ee52283491a3dccc4c76a33e27dcc1
|
|
| MD5 |
a6fea041ec4b192984cb597a73997cff
|
|
| BLAKE2b-256 |
8517253e15c91f5661a8dd2827084e415c57a69d48496d75927052228f90775a
|