Git Product home page Git Product logo

py-bingx's Introduction

This is py-bingx

Updated 1st Oct 2023 ⏰

Star This Project

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.

Usage

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")

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 💹

  • get_all_contracts() - Gets a list of all contracts/trading pairs available on Bingx
  • get_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 💰

Account Data Functions 👤

  • 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 💸

Trading Functions 📈

  • 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 ❌

TODO 📝

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.

Disclaimer 📜

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.

py-bingx's People

Contributors

amirinsight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

py-bingx's Issues

Why are the addresses different from the main site?

Hello
Excuse my initial question...
But why are all the API addresses in this package different from the site itself?
Can I paste the URLs of the main site and use it like that?
What is the reason for this difference?
Thank you for answering

Expand the account data processing functions

Приветствую Вас!

Сможете расширить?
Account Data Functions
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

То есть, добавить - получить информацию размещенных лимитных ордеров, получить информацию размещенных рыночных ордеров.
get_my_trigger_market_order()
get_my_trigger_limit_order()
Сможете добавить?

place_trigger_market_order() or open_market_order()

Очень заинтересовала Ваша проделанная работа. Помогите пожалуйста отправлять запрос с помощью этой функции place_trigger_market_order() или open_market_order()

  1. Цель моей задачи, редактировать или устанавливать при открывание сделки TAKE_PROFIT или как я понял она еще называется tp.
  2. Но как можно TAKE_PROFIT отправить виде процента допустим 5%?

Благодарю за любую помощь!

Add better headers

Currently this package is using super simple headers for it's requests. I need to add better headers.

The location of this constant is in the following link:

py-bingx/bingx/api.py

Lines 17 to 18 in 9b2942c

self.HEADERS = {'User-Agent': 'Mozilla/5.0',
'X-BX-APIKEY': self.API_KEY}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.