Skip to main content

bingx-leverages

PyPI version Python 3.8+ License: MIT

Discover leverage tiers for BingX perpetual futures contracts.

Problem: BingX lacks a dedicated leverage bracket endpoint (unlike Binance /leverageBracket or Bybit). This library discovers tier boundaries by probing the API.

Installation

pip install bingx-leverages

Quick Start

from bingx_leverages import BingXClient

# Initialize client with API keys
client = BingXClient(
    api_key="your_api_key",
    api_secret="your_api_secret"
)

# Discover leverage tiers for BTC-USDT
tiers = client.discover_leverage_tiers("BTC-USDT")

for tier in tiers:
    print(f"{tier['leverage']}X: max {tier['max_position_val']:,} USDT")

Output:

150X: max 300,000 USDT
100X: max 800,000 USDT
75X: max 3,000,000 USDT
...

Features

  • Discover leverage tiers via API probing
  • Reference data from BingX website (15 trading pairs)
  • Validation tools to compare API vs reference data
  • Public endpoints for contract info, market data, funding rates

Supported Trading Pairs

Reference data available for: BTC, ETH, SOL, BNB, XRP, ADA, DOGE, LTC, AVAX, LINK, UNI, ATOM, SHIB, OP, AR (all USDT pairs)

from bingx_leverages import get_supported_symbols

print(get_supported_symbols())
# ['ADA-USDT', 'AR-USDT', 'ATOM-USDT', 'AVAX-USDT', 'BNB-USDT', ...]

Configuration

Set API keys via environment variables or pass directly:

# Option 1: Environment variables
import os
os.environ["BINGX_API_KEY"] = "your_key"
os.environ["BINGX_API_SECRET"] = "your_secret"

client = BingXClient()

# Option 2: Direct parameters
client = BingXClient(api_key="your_key", api_secret="your_secret")

Get API keys at: https://bingx.com/en/account/api/

Command Line Usage

# Fetch leverage data for a symbol
python -m bingx_leverages BTC-USDT

# List supported symbols
python -m bingx_leverages --list

# Validate against reference data
python -m bingx_leverages --validate BTC-USDT

Or use the installed command:

bingx-leverages BTC-USDT
bingx-leverages --list

API Reference

BingXClient

from bingx_leverages import BingXClient

client = BingXClient(api_key="...", api_secret="...")

# Discover leverage tiers (requires auth)
tiers = client.discover_leverage_tiers("BTC-USDT")

# Public endpoints (no auth required)
contracts = client.get_contracts()
ticker = client.get_ticker("BTC-USDT")
funding = client.get_funding_rate("BTC-USDT")
depth = client.get_depth("BTC-USDT", limit=20)

# Private endpoints (require auth)
balance = client.get_account_balance()
positions = client.get_positions()
leverage = client.get_leverage("BTC-USDT")

Reference Data

from bingx_leverages import (
    get_reference_tiers,
    get_supported_symbols,
    REFERENCE_TIERS
)

# Get reference tiers for a symbol
tiers = get_reference_tiers("BTC-USDT")
# [(1, 0, 300000, 150), (2, 300000, 800000, 100), ...]

# All reference data
print(REFERENCE_TIERS.keys())

Validation

from bingx_leverages import BingXClient, validate_symbol

client = BingXClient(api_key="...", api_secret="...")
results = validate_symbol(client, "BTC-USDT")

print(f"Accuracy: {results['boundary_matches']}/{results['total_boundaries']}")

How It Works

Since BingX has no /leverageBracket endpoint, the library uses probing:

  1. Calls set_leverage with different values (150, 125, 100, 75, ... 1)
  2. API returns maxPositionLongVal - max position size for that leverage
  3. When maxPositionLongVal changes, a tier boundary is found
  4. Original leverage is restored after probing

Safe: No orders are created, only leverage setting is temporarily changed.

Important Notes

  • KYC/VIP affects leverage: Unverified accounts may see lower max leverage
  • Data changes: BingX updates tier boundaries based on market conditions
  • API rate limits: 10 req/s for trading endpoints
  • Boundaries approximate: API may return slightly different values than website

Development

# Clone repository
git clone https://github.com/suenot/bingx-fetch-leverage-tiers
cd bingx-leverages

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
python test_leverage_tiers.py --offline

License

MIT License - see LICENSE file.

Metadata

Release files for bingx-leverages 0.1.4

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-leverages 0.1.4
File Size Uploaded Provenance
bingx_leverages-0.1.4.tar.gz 12.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 27.4 kB

Release files / bingx_leverages-0.1.4.tar.gz

Download URL bingx_leverages-0.1.4.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
feb66177ed54344b233ffd96cced9c9095f6f31a348ed6a1a5b39f8c8e4b19fa
BLAKE2b-256 checksum
How to use checksums
28290c39f772a3e4e040083a8b73f1774321e651f70f1993567e755a731b3e9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / bingx_leverages-0.1.4-py3-none-any.whl

Download URL bingx_leverages-0.1.4-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b8dd3df20cde5f133a6cbd117df535d40c1e9916a6d2846054a97dc431468cd
BLAKE2b-256 checksum
How to use checksums
fb77ca86fd1beab98f1966dbe013e97ec53649641333ccb96688f17386005b6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for bingx-leverages 0.1.4

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.

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