BloFin API SDK
Project description
BloFin API SDK
A Python SDK for the BloFin API, providing easy access to BloFin's trading platform functionalities.
Installation
You can install the BloFin API SDK using pip:
pip install blofin
Quick Start
Here's a quick example of how to use the BloFin API SDK:
from blofin import BloFinClient
# Initialize the client
client = 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 APIs
Usage
The SDK provides access to various APIs:
Public API
The Public API allows you to access public market data without authentication.
# Get instruments
instruments = client.public.get_instruments(inst_type='SWAP')
# Get tickers
tickers = client.public.get_tickers(inst_id='BTC-USDT')
# Get order book
order_book = client.public.get_order_book(inst_id='BTC-USDT', size=20)
# Get candlestick data
candles = client.public.get_candlesticks(inst_id='BTC-USDT', bar='1m', limit=100)
Account API
The Account API allows you to manage your account information and perform account-related operations.
# Get account balance
balance = client.account.get_balance(account_type='futures')
# Transfer funds
transfer = client.account.funds_transfer(
currency='USDT',
amount=100,
from_account='funding',
to_account='futures'
)
# Get deposit history
deposits = client.account.get_deposit_history(currency='USDT', limit=10)
Trading API
The Trading API allows you to place and manage orders, as well as retrieve trading-related information.
# Place an order
order = 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 positions
positions = client.trading.get_positions(inst_id='BTC-USDT')
# Cancel an order
cancel = client.trading.cancel_order(inst_id='BTC-USDT', order_id='123456')
# Get order history
history = client.trading.get_order_history(inst_id='BTC-USDT', limit=50)
Important Notes
-
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.
Contributing
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.
To Do:
- Websocket support
License
This project is licensed under the MIT License. See the LICENSE file for details.
Disclaimer
This SDK is not officially associated with BloFin.
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 blofin-0.5.0.tar.gz.
File metadata
- Download URL: blofin-0.5.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce4477a42f7b4f7bb16bc6f414129999251fa5de4161422717692c42b4237ff7
|
|
| MD5 |
aa8fe0e6f368ef2dd5623eea1db78eaf
|
|
| BLAKE2b-256 |
80dc9f00eadd5b53c88ed407dad052fe01831f7f25e5a869f4bae2ba6a7cfda7
|
File details
Details for the file blofin-0.5.0-py3-none-any.whl.
File metadata
- Download URL: blofin-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51514e6750d27b55c544f7b20f4bff6285116cca440e270eeee98b48c80aa36e
|
|
| MD5 |
1925c50c5784f713587559101c579c25
|
|
| BLAKE2b-256 |
8e8bd678c5ae67b52d048e3ece4c4da6bbb71445bc1b8b5cc0f35f9328b49650
|