Python SDK for interacting with the BloFin API.
pip install -e .
from blofin.client import Client, DemoClient
from blofin.rest_trading import TradingAPI
from blofin.rest_market import MarketAPI
from blofin.rest_affiliate import AffiliateAPI
from blofin.rest_copytrading import CopyTradingAPI
# Initialize production client
client = Client(
apiKey="your-api-key",
apiSecret="your-api-secret",
passphrase="your-passphrase"
)
# Or initialize demo trading client
demo_client = DemoClient(
apiKey="your-api-key",
apiSecret="your-api-secret",
passphrase="your-passphrase"
)
# Initialize APIs (works with both production and demo clients)
trading = TradingAPI(client) # or TradingAPI(demo_client)
market = MarketAPI(client) # or MarketAPI(demo_client)
affiliate = AffiliateAPI(client) # or AffiliateAPI(demo_client)
copytrading = CopyTradingAPI(client) # or CopyTradingAPI(demo_client)
from blofin.websocket_client import BlofinWsClient, BlofinWsPublicClient, BlofinWsPrivateClient, BlofinWsCopytradingClient
# Public WebSocket (no authentication required)
public_client = BlofinWsPublicClient() # For production
demo_public_client = BlofinWsPublicClient(isDemo=True) # For demo trading
# Private WebSocket (authentication required)
private_client = BlofinWsPrivateClient(
apiKey="your-api-key",
secret="your-api-secret",
passphrase="your-passphrase"
) # For production
demo_private_client = BlofinWsPrivateClient(
apiKey="your-api-key",
secret="your-api-secret",
passphrase="your-passphrase",
isDemo=True
) # For demo trading
# Copytrading WebSocket
copytrading_client = BlofinWsCopytradingClient(
apiKey="your-api-key",
secret="your-api-secret",
passphrase="your-passphrase"
) # For production
For detailed usage examples, please refer to the examples directory.
BloFin provides a demo trading environment for testing and development. To use the demo environment:
-
REST API:
- Use the
DemoClient
class instead ofClient
- Or set
isDemo=True
when initializing a regularClient
- Demo trading base URL:
https://demo-trading-openapi.blofin.com
- Use the
-
WebSocket API:
- Set
isDemo=True
when initializing WebSocket clients - Demo WebSocket URLs:
- Public:
wss://demo-trading-openapi.blofin.com/ws/public
- Private:
wss://demo-trading-openapi.blofin.com/ws/private
- Public:
- Set
-
Features:
- Test trading strategies without real funds
- Same API interface as production
- Simulated market conditions
- Practice risk management
For detailed API documentation, please refer to the BloFin API Documentation.
- Account management
- Trading operations
- Position management
- Order management
- Asset operations
- Market data
- Affiliate system
- Copytrading
- Real-time market data
- Real-time order updates
- Real-time position updates
- Real-time account updates
- Copytrading functionality
Run the test suite:
python -m pytest
This project is licensed under the Apache License.
Never share your API credentials. Always store them securely and never commit them to version control.