-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
This guide provides a concise walkthrough to get you up and running with the BingX Python SDK. In just a few simple steps, you will be able to install the library, authenticate with the API, and start making your first API calls.
The first step is to install the SDK using pip, the Python package installer. Open your terminal and run the following command:
pip install bingx-pythonThis will download and install the latest version of the SDK and its dependencies.
Next, you need to initialize the BingXClient with your API keys. This is a crucial step, as the client handles the authentication and signing of your requests.
from bingx import BingXClient
# Initialize the client with your API credentials
client = BingXClient(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET"
)For a more detailed explanation of how to obtain your API keys, please refer to the Authentication guide.
With the client initialized, you are now ready to interact with the BingX API. Let's start by fetching the latest price of the BTC-USDT trading pair.
from bingx.exceptions import BingXException
try:
# Fetch the latest price using the MarketService
price_data = client.market().get_latest_price("BTC-USDT")
price = price_data['data']['price']
print(f"The latest price of BTC-USDT is: {price}")
except BingXException as e:
print(f"An error occurred: {e}")This example also demonstrates basic error handling. For more information on how to handle API errors, please see the Error Handling guide.
The SDK is designed with a modular architecture, organized into various services that correspond to different areas of the BingX API. For example, the AccountService is used for account-related operations.
Here is how you can retrieve your account balance:
try:
# Get your account balance using the AccountService
balance_data = client.account().get_balance()
balance = balance_data['data']['balance']
print(f"Your account balance: {balance}")
except BingXException as e:
print(f"An error occurred: {e}")To learn more about the available services and their functionalities, please refer to the Services documentation.