A Python SDK for the BloFin API, providing easy access to BloFin's trading platform functionalities.
You can install the BloFin API SDK using pip:
pip install blofinHere's a quick example of how to use the BloFin API SDK:
fromblofinimportBloFinClient# Initialize the clientclient=BloFinClient(
api_key='your_api_key', api_secret='your_api_secret', passphrase='your_passphrase',
use_server_time=False, #Default: False - If you want to use BloFin's server time for requests
)
# Use the client to interact with different APIsThe SDK provides access to various APIs:
The Public API allows you to access public market data without authentication.
# Get instrumentsinstruments=client.public.get_instruments(inst_type='SWAP')
# Get tickerstickers=client.public.get_tickers(inst_id='BTC-USDT')
# Get order bookorder_book=client.public.get_order_book(inst_id='BTC-USDT', size=20)
# Get candlestick datacandles=client.public.get_candlesticks(inst_id='BTC-USDT', bar='1m', limit=100)The Account API allows you to manage your account information and perform account-related operations.
# Get account balancebalance=client.account.get_balance(account_type='futures')
# Transfer fundstransfer=client.account.funds_transfer(
currency='USDT',
amount=100,
from_account='funding',
to_account='futures'
)
# Get deposit historydeposits=client.account.get_deposit_history(currency='USDT', limit=10)The Trading API allows you to place and manage orders, as well as retrieve trading-related information.
# Place an orderorder=client.trading.place_order(
inst_id='BTC-USDT',
margin_mode='cross',
position_side='long',
side='buy',
order_type='limit',
price=30000,
size=0.01
)
# Get open positionspositions=client.trading.get_positions(inst_id='BTC-USDT')
# Cancel an ordercancel=client.trading.cancel_order(inst_id='BTC-USDT', order_id='123456')
# Get order historyhistory=client.trading.get_order_history(inst_id='BTC-USDT', limit=50)API Credentials: To use authenticated endpoints, you need to provide your BloFin API credentials (API key, API secret, and passphrase) when initializing the client.
Rate Limiting: Be aware of BloFin's rate limits for API requests. Exceeding these limits may result in temporary blocks or account suspension.
Error Handling: The SDK uses custom exceptions to handle various error scenarios. Always wrap your API calls in try-except blocks to handle potential errors gracefully.
Pagination: Some methods that return lists of items (e.g., order history) support pagination. Use the
before,after, andlimitparameters to navigate through large result sets.Server Time: If you experience timestamp-related issues, you can initialize the client with
use_server_time=Trueto use BloFin's server time for requests.
Contributions to the BloFin API SDK are welcome! Please refer to the project's GitHub repository for information on how to contribute, report issues, or request features.
- Websocket support
This project is licensed under the MIT License. See the LICENSE file for details.
This SDK is not officially associated with BloFin.