Skip to main content

bingx-python

Python SDK (sync and async) for Bingx cryptocurrency exchange with Rest and WS capabilities.

Installation

pip install bingx

Usage

Sync

from bingx import BingxSync

def main():
    instance = BingxSync({})
    ob =  instance.fetch_order_book("BTC/USDC")
    print(ob)
    #
    # balance = instance.fetch_balance()
    # order = instance.create_order("BTC/USDC", "limit", "buy", 1, 100000)

main()

Async

import sys
import asyncio
from bingx import BingxAsync

### on Windows, uncomment below:
# if sys.platform == 'win32':
# 	asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def main():
    instance = BingxAsync({})
    ob =  await instance.fetch_order_book("BTC/USDC")
    print(ob)
    #
    # balance = await instance.fetch_balance()
    # order = await instance.create_order("BTC/USDC", "limit", "buy", 1, 100000)

    # once you are done with the exchange
    await instance.close()

asyncio.run(main())

Websockets

import sys
from bingx import BingxWs

### on Windows, uncomment below:
# if sys.platform == 'win32':
# 	asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def main():
    instance = BingxWs({})
    while True:
        ob = await instance.watch_order_book("BTC/USDC")
        print(ob)
        # orders = await instance.watch_orders("BTC/USDC")

    # once you are done with the exchange
    await instance.close()

asyncio.run(main())

Raw call

You can also construct custom requests to available "implicit" endpoints

        request = {
            'type': 'candleSnapshot',
            'req': {
                'coin': coin,
                'interval': tf,
                'startTime': since,
                'endTime': until,
            },
        }
        response = await instance.public_post_info(request)

Available methods

REST Unified

  • create_market_buy_order_with_cost(self, symbol: str, cost: float, params: dict = {})
  • create_market_order_with_cost(self, symbol: str, side: OrderSide, cost: float, params: dict = {})
  • create_market_sell_order_with_cost(self, symbol: str, cost: float, params: dict = {})
  • create_order_request(self, symbol: Str, type: Str, side: Str, amount: Num, price: Num = None, params: dict = {})
  • create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params: dict = {})
  • create_orders(self, orders: list[OrderRequest], params: dict = {})
  • fetch_balance(self, params: dict = {})
  • fetch_bids_asks(self, symbols: Strings = None, params: dict = {})
  • fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_currencies(self, params: dict = {})
  • fetch_deposit_address(self, code: str, params: dict = {})
  • fetch_deposit_addresses_by_network(self, code: str, params: dict = {})
  • fetch_deposit_withdraw_fees(self, codes: Strings = None, params: dict = {})
  • fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_rate(self, symbol: str, params: dict = {})
  • fetch_funding_rates(self, symbols: Strings = None, params: dict = {})
  • fetch_inverse_swap_markets(self, params: object)
  • fetch_leverage(self, symbol: str, params: dict = {})
  • fetch_margin_mode(self, symbol: str, params: dict = {})
  • fetch_mark_price(self, symbol: str, params: dict = {})
  • fetch_mark_prices(self, symbols: Strings = None, params: dict = {})
  • fetch_market_leverage_tiers(self, symbol: str, params: dict = {})
  • fetch_markets(self, params: dict = {})
  • fetch_my_liquidations(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params: dict = {})
  • fetch_open_interest(self, symbol: str, params: dict = {})
  • fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_order_book(self, symbol: str, limit: Int = None, params: dict = {})
  • fetch_order(self, id: str, symbol: Str = None, params: dict = {})
  • fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_position_history(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_position_mode(self, symbol: Str = None, params: dict = {})
  • fetch_position(self, symbol: str, params: dict = {})
  • fetch_positions(self, symbols: Strings = None, params: dict = {})
  • fetch_spot_markets(self, params: object)
  • fetch_swap_markets(self, params: object)
  • fetch_ticker(self, symbol: str, params: dict = {})
  • fetch_tickers(self, symbols: Strings = None, params: dict = {})
  • fetch_time(self, params: dict = {})
  • fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_trading_fee(self, symbol: str, params: dict = {})
  • fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • add_margin(self, symbol: str, amount: float, params: dict = {})
  • cancel_all_orders_after(self, timeout: Int, params: dict = {})
  • cancel_all_orders(self, symbol: Str = None, params: dict = {})
  • cancel_order(self, id: str, symbol: Str = None, params: dict = {})
  • cancel_orders(self, ids: list[str], symbol: Str = None, params: dict = {})
  • close_all_positions(self, params: dict = {})
  • close_position(self, symbol: str, side: Str = None, params: dict = {})
  • custom_encode(self, params: dict)
  • describe(self)
  • edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params: dict = {})
  • encode_trigger_price_type(self, triggerPriceType: Str)
  • nonce(self)
  • reduce_margin(self, symbol: str, amount: float, params: dict = {})
  • set_leverage(self, leverage: int, symbol: Str = None, params: dict = {})
  • set_margin_mode(self, marginMode: str, symbol: Str = None, params: dict = {})
  • set_margin(self, symbol: str, amount: float, params: dict = {})
  • set_position_mode(self, hedged: bool, symbol: Str = None, params: dict = {})
  • set_sandbox_mode(self, enable: bool)
  • transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params: dict = {})
  • withdraw(self, code: str, amount: float, address: str, params: dict = {})

REST Raw

  • fund_v1_private_get_account_balance(request)
  • spot_v1_public_get_server_time(request)
  • spot_v1_public_get_common_symbols(request)
  • spot_v1_public_get_market_trades(request)
  • spot_v1_public_get_market_depth(request)
  • spot_v1_public_get_market_kline(request)
  • spot_v1_public_get_ticker_24hr(request)
  • spot_v1_public_get_ticker_price(request)
  • spot_v1_public_get_ticker_bookticker(request)
  • spot_v1_private_get_trade_query(request)
  • spot_v1_private_get_trade_openorders(request)
  • spot_v1_private_get_trade_historyorders(request)
  • spot_v1_private_get_trade_mytrades(request)
  • spot_v1_private_get_user_commissionrate(request)
  • spot_v1_private_get_account_balance(request)
  • spot_v1_private_get_oco_orderlist(request)
  • spot_v1_private_get_oco_openorderlist(request)
  • spot_v1_private_get_oco_historyorderlist(request)
  • spot_v1_private_post_trade_order(request)
  • spot_v1_private_post_trade_cancel(request)
  • spot_v1_private_post_trade_batchorders(request)
  • spot_v1_private_post_trade_order_cancelreplace(request)
  • spot_v1_private_post_trade_cancelorders(request)
  • spot_v1_private_post_trade_cancelopenorders(request)
  • spot_v1_private_post_trade_cancelallafter(request)
  • spot_v1_private_post_oco_order(request)
  • spot_v1_private_post_oco_cancel(request)
  • spot_v2_public_get_market_depth(request)
  • spot_v2_public_get_market_kline(request)
  • spot_v2_public_get_ticker_price(request)
  • spot_v2_public_get_quote_bookticker(request)
  • spot_v2_public_get_quote_depth(request)
  • spot_v2_public_get_quote_historicalklines(request)
  • spot_v2_public_get_quote_historicaltrades(request)
  • spot_v2_public_get_quote_klines(request)
  • spot_v2_public_get_quote_price(request)
  • spot_v2_public_get_quote_ticker(request)
  • spot_v2_public_get_quote_trades(request)
  • spot_v3_private_get_get_asset_transfer(request)
  • spot_v3_private_get_asset_transfer(request)
  • spot_v3_private_get_capital_deposit_hisrec(request)
  • spot_v3_private_get_capital_withdraw_history(request)
  • spot_v3_private_post_post_asset_transfer(request)
  • swap_v1_public_get_ticker_price(request)
  • swap_v1_public_get_market_historicaltrades(request)
  • swap_v1_public_get_market_markpriceklines(request)
  • swap_v1_public_get_trade_multiassetsrules(request)
  • swap_v1_public_get_tradingrules(request)
  • swap_v1_private_get_positionside_dual(request)
  • swap_v1_private_get_trade_batchcancelreplace(request)
  • swap_v1_private_get_trade_fullorder(request)
  • swap_v1_private_get_maintmarginratio(request)
  • swap_v1_private_get_trade_positionhistory(request)
  • swap_v1_private_get_positionmargin_history(request)
  • swap_v1_private_get_twap_openorders(request)
  • swap_v1_private_get_twap_historyorders(request)
  • swap_v1_private_get_twap_orderdetail(request)
  • swap_v1_private_get_trade_assetmode(request)
  • swap_v1_private_get_user_marginassets(request)
  • swap_v1_private_post_trade_amend(request)
  • swap_v1_private_post_trade_cancelreplace(request)
  • swap_v1_private_post_positionside_dual(request)
  • swap_v1_private_post_trade_batchcancelreplace(request)
  • swap_v1_private_post_trade_closeposition(request)
  • swap_v1_private_post_trade_getvst(request)
  • swap_v1_private_post_twap_order(request)
  • swap_v1_private_post_twap_cancelorder(request)
  • swap_v1_private_post_trade_assetmode(request)
  • swap_v1_private_post_trade_reverse(request)
  • swap_v1_private_post_trade_autoaddmargin(request)
  • swap_v2_public_get_server_time(request)
  • swap_v2_public_get_quote_contracts(request)
  • swap_v2_public_get_quote_price(request)
  • swap_v2_public_get_quote_depth(request)
  • swap_v2_public_get_quote_trades(request)
  • swap_v2_public_get_quote_premiumindex(request)
  • swap_v2_public_get_quote_fundingrate(request)
  • swap_v2_public_get_quote_klines(request)
  • swap_v2_public_get_quote_openinterest(request)
  • swap_v2_public_get_quote_ticker(request)
  • swap_v2_public_get_quote_bookticker(request)
  • swap_v2_private_get_user_balance(request)
  • swap_v2_private_get_user_positions(request)
  • swap_v2_private_get_user_income(request)
  • swap_v2_private_get_trade_openorders(request)
  • swap_v2_private_get_trade_openorder(request)
  • swap_v2_private_get_trade_order(request)
  • swap_v2_private_get_trade_margintype(request)
  • swap_v2_private_get_trade_leverage(request)
  • swap_v2_private_get_trade_forceorders(request)
  • swap_v2_private_get_trade_allorders(request)
  • swap_v2_private_get_trade_allfillorders(request)
  • swap_v2_private_get_trade_fillhistory(request)
  • swap_v2_private_get_trade_positionhistory(request)
  • swap_v2_private_get_user_income_export(request)
  • swap_v2_private_get_user_commissionrate(request)
  • swap_v2_private_get_quote_bookticker(request)
  • swap_v2_private_post_trade_getvst(request)
  • swap_v2_private_post_trade_order(request)
  • swap_v2_private_post_trade_batchorders(request)
  • swap_v2_private_post_trade_closeallpositions(request)
  • swap_v2_private_post_trade_cancelallafter(request)
  • swap_v2_private_post_trade_margintype(request)
  • swap_v2_private_post_trade_leverage(request)
  • swap_v2_private_post_trade_positionmargin(request)
  • swap_v2_private_post_trade_order_test(request)
  • swap_v2_private_delete_trade_order(request)
  • swap_v2_private_delete_trade_batchorders(request)
  • swap_v2_private_delete_trade_allopenorders(request)
  • swap_v3_public_get_quote_klines(request)
  • swap_v3_private_get_user_balance(request)
  • cswap_v1_public_get_market_contracts(request)
  • cswap_v1_public_get_market_premiumindex(request)
  • cswap_v1_public_get_market_openinterest(request)
  • cswap_v1_public_get_market_klines(request)
  • cswap_v1_public_get_market_depth(request)
  • cswap_v1_public_get_market_ticker(request)
  • cswap_v1_private_get_trade_leverage(request)
  • cswap_v1_private_get_trade_forceorders(request)
  • cswap_v1_private_get_trade_allfillorders(request)
  • cswap_v1_private_get_trade_openorders(request)
  • cswap_v1_private_get_trade_orderdetail(request)
  • cswap_v1_private_get_trade_orderhistory(request)
  • cswap_v1_private_get_trade_margintype(request)
  • cswap_v1_private_get_user_commissionrate(request)
  • cswap_v1_private_get_user_positions(request)
  • cswap_v1_private_get_user_balance(request)
  • cswap_v1_private_post_trade_order(request)
  • cswap_v1_private_post_trade_leverage(request)
  • cswap_v1_private_post_trade_allopenorders(request)
  • cswap_v1_private_post_trade_closeallpositions(request)
  • cswap_v1_private_post_trade_margintype(request)
  • cswap_v1_private_post_trade_positionmargin(request)
  • cswap_v1_private_delete_trade_allopenorders(request)
  • cswap_v1_private_delete_trade_cancelorder(request)
  • cswap_v2_private_post_trade_order(request)
  • contract_v1_private_get_allposition(request)
  • contract_v1_private_get_allorders(request)
  • contract_v1_private_get_balance(request)
  • wallets_v1_private_get_capital_config_getall(request)
  • wallets_v1_private_get_capital_deposit_address(request)
  • wallets_v1_private_get_capital_innertransfer_records(request)
  • wallets_v1_private_get_capital_subaccount_deposit_address(request)
  • wallets_v1_private_get_capital_deposit_subhisrec(request)
  • wallets_v1_private_get_capital_subaccount_innertransfer_records(request)
  • wallets_v1_private_get_capital_deposit_riskrecords(request)
  • wallets_v1_private_post_capital_withdraw_apply(request)
  • wallets_v1_private_post_capital_innertransfer_apply(request)
  • wallets_v1_private_post_capital_subaccountinnertransfer_apply(request)
  • wallets_v1_private_post_capital_deposit_createsubaddress(request)
  • subaccount_v1_private_get_list(request)
  • subaccount_v1_private_get_assets(request)
  • subaccount_v1_private_get_allaccountbalance(request)
  • subaccount_v1_private_post_create(request)
  • subaccount_v1_private_post_apikey_create(request)
  • subaccount_v1_private_post_apikey_edit(request)
  • subaccount_v1_private_post_apikey_del(request)
  • subaccount_v1_private_post_updatestatus(request)
  • account_v1_private_get_uid(request)
  • account_v1_private_get_apikey_query(request)
  • account_v1_private_get_account_apipermissions(request)
  • account_v1_private_get_account_apirestrictions(request)
  • account_v1_private_get_allaccountbalance(request)
  • account_v1_private_post_innertransfer_authorizesubaccount(request)
  • account_transfer_v1_private_get_subaccount_asset_transferhistory(request)
  • account_transfer_v1_private_post_subaccount_transferasset_supportcoins(request)
  • account_transfer_v1_private_post_subaccount_transferasset(request)
  • user_auth_private_post_userdatastream(request)
  • user_auth_private_put_userdatastream(request)
  • user_auth_private_delete_userdatastream(request)
  • copytrading_v1_private_get_pfutures_traderdetail(request)
  • copytrading_v1_private_get_pfutures_profithistorysummarys(request)
  • copytrading_v1_private_get_pfutures_profitdetail(request)
  • copytrading_v1_private_get_pfutures_tradingpairs(request)
  • copytrading_v1_private_get_spot_traderdetail(request)
  • copytrading_v1_private_get_spot_profithistorysummarys(request)
  • copytrading_v1_private_get_spot_profitdetail(request)
  • copytrading_v1_private_get_spot_historyorder(request)
  • copytrading_v1_private_post_swap_trace_settpsl(request)
  • copytrading_v1_private_post_pfutures_setcommission(request)
  • copytrading_v1_private_post_spot_trader_sellorder(request)
  • api_v3_private_get_asset_transfer(request)
  • api_v3_private_get_asset_transferrecord(request)
  • api_v3_private_get_capital_deposit_hisrec(request)
  • api_v3_private_get_capital_withdraw_history(request)
  • api_v3_private_post_post_asset_transfer(request)
  • api_asset_v1_private_get_transfer_supportcoins(request)
  • api_asset_v1_private_post_transfer(request)
  • agent_v1_private_get_account_inviteaccountlist(request)
  • agent_v1_private_get_reward_commissiondatalist(request)
  • agent_v1_private_get_account_inviterelationcheck(request)
  • agent_v1_private_get_asset_depositdetaillist(request)
  • agent_v1_private_get_reward_third_commissiondatalist(request)
  • agent_v1_private_get_asset_partnerdata(request)
  • agent_v1_private_get_commissiondatalist_referralcode(request)
  • agent_v1_private_get_account_superiorcheck(request)
  • wealth_v1_private_get_product_dual_currency_pre_order(request)
  • wealth_v1_private_get_product_dual_currency_position(request)
  • wealth_v1_private_get_product_dual_currency_order_records(request)
  • wealth_v1_private_post_product_dual_currency_invest_asset_list(request)
  • wealth_v1_private_post_product_dual_currency_order(request)

WS Unified

  • describe(self)
  • un_watch(self, messageHash: str, subMessageHash: str, subscribeHash: str, dataType: str, topic: str, market: Market, methodName: str, params: dict = {})
  • watch_ticker(self, symbol: str, params: dict = {})
  • un_watch_ticker(self, symbol: str, params: dict = {})
  • get_order_book_limit_by_market_type(self, marketType: str, limit: Int = None)
  • get_message_hash(self, unifiedChannel: str, symbol: Str = None, extra: Str = None)
  • watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • un_watch_trades(self, symbol: str, params: dict = {})
  • watch_order_book(self, symbol: str, limit: Int = None, params: dict = {})
  • un_watch_order_book(self, symbol: str, params: dict = {})
  • watch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params: dict = {})
  • un_watch_ohlcv(self, symbol: str, timeframe: str = '1m', params: dict = {})
  • watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • watch_balance(self, params: dict = {})
  • set_balance_cache(self, client: Client, type: str, subType: Str, subscriptionHash: str, params: dict)
  • load_balance_snapshot(self, client: Client, messageHash: str, type: str, subType: Str)
  • watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params: dict = {})
  • set_positions_cache(self, client: Client, type: Str, symbols: Strings = None)
  • load_positions_snapshot(self, client: Client, messageHash: str, type: Str)
  • keep_alive_listen_key(self, params: dict = {})
  • authenticate(self, params: dict = {})
  • pong(self, client: Client, message: object)

Contribution

  • Give us a star ⭐
  • Fork and Clone! Awesome
  • Select existing issues or create a new issue.

Metadata

Release files for bingx 0.0.177

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bingx 0.0.177
File Size Uploaded Provenance Actions
bingx-0.0.177.tar.gz 352.7 kB Without provenance Details for bingx-0.0.177.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bingx 0.0.177
File Interpreter ABI Platform Actions
bingx-0.0.177-py3-none-any.whl Python 3 none any Details for bingx-0.0.177-py3-none-any.whl

Total release size: 741.6 kB

Release files / bingx-0.0.177.tar.gz

Download URL bingx-0.0.177.tar.gz
Size 352.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5ff0a5494b1aac4f8447a8e179aea30c6561d9bea851f3093206f93e43137098
BLAKE2b-256 checksum
How to use checksums
3e83649b25deb910e772bed60e2d3c60ae1bd2c5d51c44bdfe73d736977639c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / bingx-0.0.177-py3-none-any.whl

Download URL bingx-0.0.177-py3-none-any.whl
Size 388.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b412787c8a38382de7ffcb0182639d8633ce938f259a56120407d43e84c0e2c8
BLAKE2b-256 checksum
How to use checksums
79bcc4aca79084683f41caf4afe1ea04f75068eaf9e37e1dba86de8c0e863ad7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for bingx 0.0.177

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.177 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page