Unified futures exchange client library for Hubble trading platform
Project description
Hubble Futures
Unified futures exchange client library for Hubble trading platform.
Features
- Unified Interface: Single API for multiple exchanges
- Exchange Support: Aster DEX, WEEX (Binance, OKX coming soon)
- Type Safe: Full type hints and mypy strict mode
- Adapter Pattern: Exchange-specific differences handled internally
- Retry Logic: Automatic retry with exponential backoff for rate limits
- Decimal Precision: Proper decimal formatting for all exchanges
Installation
pip install hubble-futures
Quick Start
from hubble_futures import create_client, ExchangeConfig
# Create exchange configuration
config = ExchangeConfig(
name="asterdex",
api_key="your_api_key",
api_secret="your_api_secret"
)
# Create client
client = create_client(config)
# Fetch market data
klines = client.get_klines("BTCUSDT", "1h", 200)
account = client.get_account()
positions = client.get_positions()
# Place order
order = client.place_order(
symbol="BTCUSDT",
side="BUY",
order_type="LIMIT",
quantity=0.01,
price=50000
)
Supported Exchanges
| Exchange | Name | Passphrase Required |
|---|---|---|
| Aster DEX | asterdex or aster |
No |
| WEEX | weex |
Yes |
WEEX Configuration
WEEX requires an additional passphrase parameter:
config = ExchangeConfig(
name="weex",
api_key="your_api_key",
api_secret="your_api_secret",
passphrase="your_passphrase" # Required for WEEX
)
API Reference
Market Data
get_klines(symbol, interval, limit)- Fetch candlestick dataget_mark_price(symbol)- Fetch mark price and funding rateget_depth(symbol, limit)- Fetch orderbookget_ticker_24hr(symbol)- Fetch 24h statisticsget_exchange_info()- Fetch exchange metadataget_symbol_filters(symbol)- Fetch trading rules
Account & Trading
get_account()- Fetch account informationget_positions(symbol)- Fetch open positionsget_balance()- Fetch balance summaryplace_order(...)- Place an ordercancel_order(symbol, order_id)- Cancel an orderget_open_orders(symbol)- Get open ordersset_leverage(symbol, leverage)- Set leverageclose_position(symbol, percent)- Close position
Development
Setup
# Clone repository
git clone https://github.com/hubble/hubble-futures.git
cd hubble-futures
# Install dependencies
pip install -e ".[dev]"
Running Tests
# Unit tests
pytest tests/unit -m unit
# Integration tests (mocked API)
pytest tests/integration -m integration
# E2E tests (requires .env with API credentials)
pytest tests/e2e -m e2e
Code Quality
# Format check
ruff check hubble_futures tests
# Type check
mypy hubble_futures
# Coverage
pytest --cov=hubble_futures --cov-report=html
Architecture
┌─────────────────────────────────────────────┐
│ User Code │
│ (Agent, Trading Bot, etc.) │
└─────────────────────────────────────────────┘
↓ uses
┌─────────────────────────────────────────────┐
│ Factory: create_client(config) │
└─────────────────────────────────────────────┘
↓ creates
┌─────────────────────────────────────────────┐
│ BaseFuturesClient (Abstract) │
│ - Unified interface │
│ - Common retry logic │
│ - Decimal formatting │
└─────────────────────────────────────────────┘
↓ implemented by
┌─────────────┬─────────────┬─────────────────┐
│ Aster │ WEEX │ Future │
│ Adapter │ Adapter │ Adapters │
│ │ │ (Binance, OKX) │
└─────────────┴─────────────┴─────────────────┘
Adapter Responsibilities
Each exchange adapter handles:
- API authentication (different signing methods)
- Symbol format conversion (e.g.,
BTCUSDT↔cmt_btcusdt) - Parameter mapping (e.g.,
side↔type) - Response normalization (unified return format)
License
MIT License - see LICENSE for details
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass (
pytest) - Submit a pull request
Support
For issues and questions:
- GitHub Issues: https://github.com/hubble/hubble-futures/issues
- Documentation: https://docs.hubble.com/futures-client
Project details
Release history Release notifications | RSS feed
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 hubble_futures-0.2.28.tar.gz.
File metadata
- Download URL: hubble_futures-0.2.28.tar.gz
- Upload date:
- Size: 104.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59c833f6adb3c41ef5afe042b8100617f85538f5396d16b356cf7ddb5f97e6e0
|
|
| MD5 |
1c73bb575ad9db547797379086b94b03
|
|
| BLAKE2b-256 |
e61b59fca23d4739756530f8083ef66a260feb0973115cd4f3c43b4a3e865140
|
File details
Details for the file hubble_futures-0.2.28-py3-none-any.whl.
File metadata
- Download URL: hubble_futures-0.2.28-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f34346443cf1e55434e1133179140d52130c04a0cb14cf978250b4d3e42fbfe3
|
|
| MD5 |
d924f7f80e5c92f827bf4e2ee3d4ba9b
|
|
| BLAKE2b-256 |
5a6ced47336434dc9b4b57a3fe318abfcb98988fe36d3208ade3a04915b361c2
|