A Python package to easily use BingX Perpetual Swap API. Can be used to automate trading on BingX.
================ This is py-bingx ================ Updated 1st Oct 2023 โฐ
.. image:: https://img.shields.io/pypi/v/py-bingx.svg :target: https://pypi.python.org/pypi/py-bingx
.. image:: https://img.shields.io/pypi/l/py-bingx.svg :target: https://pypi.python.org/pypi/py-bingx
.. image:: https://img.shields.io/github/stars/amirinsight/py-bingx.svg?style=social&label=Stars :target: https://github.com/amirinsight/py-bingx :alt: Star This Project
py-bingx is an unofficial Python wrapper for the BingX Perpetual Swap API <https://bingx-api.github.io/docs/swap/introduce.html>. You can use this package to create trading bots. Make sure to read my disclaimer <https://github.com/amirinsight/py-bingx#disclaimer> and consider starring this project.
Usage
Register an account on BingX <https://bingx.com/en-us/register>_.
Create an API <https://bingx.com/en-us/account/api>_ and make sure you copy your Secret Key before leaving the page. ๐
.. code:: bash
pip install py-bingx
.. code:: python
from bingx.api import BingxAPI
...
# Please note that it is smarter to use environment variables than hard coding your keys into your code. APIKEY = '
# It is faster and more efficient to use local timestamps. If you are getting an error try using "server" timestamp. bingx = BingxAPI(APIKEY, SECRETKEY, timestamp="local") orderdata = bingx.openmarket_order('FLOKI-USDT', 'LONG', 121220, tp="0.00001800", sl="0.00001700")
Functions ๐งฐ
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:
Market Data Functions ๐น
- `
getallcontracts()- Gets a list of all contracts/trading pairs available on Bingx getlatestprice(pair)- Gets the latest price for a trading pair ๐ฑgetmarketdepth(pair, limit)- Gets the order book depth data for a trading pair ๐getlatesttrade(pair)- Gets recent trades for a trading pair ๐ธgetlatestfunding(pair)- Gets latest funding rate for a trading pair ๐ตgetindexprice(pair)- Gets index price for a trading pair ๐getmarketprice(pair)- Gets market price for a trading pair ๐getfundinghistory(pair)- Gets historical funding rate data for a trading pair ๐getklinedata(pair, interval, starttime, endtime, limit)- Gets candlestick/kline data for a trading pair ๐ฏgetopenpositions(pair)- Gets open interest data for a trading pair ๐get_tiker(pair)- Gets ticker data including 24hr prices and volumes ๐ฃgetcurrentoptimal_price(pair)- Gets best bid and offer prices for a trading pair ๐ฐ
getperpetualbalance()- Get user account balance info ๐ณgetmyperpetualswappositions(pair)- Get user open positions for a trading pair ๐getfeerate()- Get fee rate for trading ๐ธ
openmarketorder()- Opens a market order to buy/sell a trading pair ๐นclosemarketorder()- Closes an open market order โplacetriggermarket_order()- Places a stop-trigger market order โฑopenlimitorder()- Opens a limit order for a trading pair ๐ฏcloselimitorder()- Closes an open limit order โplacetriggerlimit_order()- Places a stop-trigger limit order โฑplacetrailingstop_order()- Places a trailing stop order ๐placetestorder()- Places a test order that does not execute ๐งชcloseallpositions()- Closes all open positions for user โcancel_order()- Cancels a pending order โcancelallordersofsymbol()- Cancels all pending orders for a trading pair โcancelbatchorders()` - 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.