Updated 1st Oct 2023 โฐ
py-bingx is an unofficial Python wrapper for the BingX Perpetual Swap API. You can use this package to create trading bots. Make sure to read my disclaimer and consider starring this project.
Register an account on BingX.
Create an API and make sure you copy your Secret Key before leaving the page. ๐
pip install py-bingx
from bingx.api import BingxAPI
...
# Please note that it is smarter to use environment variables than hard coding your keys into your code.
API_KEY = '<api_public_key>'
SECRET_KEY = '<api_secret_key>'
# It is faster and more efficient to use local timestamps. If you are getting an error try using "server" timestamp.
bingx = BingxAPI(API_KEY, SECRET_KEY, timestamp="local")
order_data = bingx.open_market_order('FLOKI-USDT', 'LONG', 121220, tp="0.00001800", sl="0.00001700")
py-bingx was written with the goal of being user-friendly. Feel free to ask your questions and state any bugs/issues with the code.
You can find the list of py-bingx functions below:
get_all_contracts()
- Gets a list of all contracts/trading pairs available on Bingxget_latest_price(pair)
- Gets the latest price for a trading pair ๐ฑget_market_depth(pair, limit)
- Gets the order book depth data for a trading pair ๐get_latest_trade(pair)
- Gets recent trades for a trading pair ๐ธget_latest_funding(pair)
- Gets latest funding rate for a trading pair ๐ตget_index_price(pair)
- Gets index price for a trading pair ๐get_market_price(pair)
- Gets market price for a trading pair ๐get_funding_history(pair)
- Gets historical funding rate data for a trading pair ๐get_kline_data(pair, interval, start_time, end_time, limit)
- Gets candlestick/kline data for a trading pair ๐ฏget_open_positions(pair)
- Gets open interest data for a trading pair ๐get_tiker(pair)
- Gets ticker data including 24hr prices and volumes ๐ฃget_current_optimal_price(pair)
- Gets best bid and offer prices for a trading pair ๐ฐ
get_perpetual_balance()
- Get user account balance info ๐ณget_my_perpetual_swap_positions(pair)
- Get user open positions for a trading pair ๐get_fee_rate()
- Get fee rate for trading ๐ธ
open_market_order()
- Opens a market order to buy/sell a trading pair ๐นclose_market_order()
- Closes an open market order โplace_trigger_market_order()
- Places a stop-trigger market order โฑopen_limit_order()
- Opens a limit order for a trading pair ๐ฏclose_limit_order()
- Closes an open limit order โplace_trigger_limit_order()
- Places a stop-trigger limit order โฑplace_trailing_stop_order()
- Places a trailing stop order ๐place_test_order()
- Places a test order that does not execute ๐งชclose_all_positions()
- Closes all open positions for user โcancel_order()
- Cancels a pending order โcancel_all_orders_of_symbol()
- Cancels all pending orders for a trading pair โcancel_batch_orders()
- Cancels multiple pending orders โ
This package is functional but the following list should be achieved pre release:
- Add Response exception handling. ๐ฅ
- Implement the remaining less important endpoints. ๐ง
- Leverage async/await (Use async methods and aiohttp to make requests asynchronously rather than blocking.) โก
- Add proper logging. (Add a structured logger like loguru to log requests, errors etc.) ๐
- Write tests. (Add unit and integration tests using pytest) โ
- Refactor code to be more pythonic and modular. ๐
- Add WS support to report order updates.
This open source code is provided "as is" without warranty of any kind. The author makes no representations or warranties about the accuracy, completeness, or suitability of this code for any purpose. Use of this code is at your own risk.
The author is not affiliated with BingX and is not liable for any damages arising from the use of this code. Cryptocurrency trading involves substantial risk of loss. You should not rely on this code as your sole method of trading. No promises or guarantees are made regarding the performance of any trades executed using this code. Always do your own research and due diligence before executing any trades.
This code is still under developement and may contain bugs and errors. Use at your own discretion.