Skip to main content

Discover leverage tiers for BingX perpetual futures contracts

Project description

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-leverages
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bingx_leverages-0.1.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bingx_leverages-0.1.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file bingx_leverages-0.1.3.tar.gz.

File metadata

  • Download URL: bingx_leverages-0.1.3.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for bingx_leverages-0.1.3.tar.gz
Algorithm Hash digest
SHA256 420f87138e66b34632ad960bfb0fdbba6a8364134ca6012819fe02c1c107ec95
MD5 2b0c624fbd8b4d2111e97ba93b6a4bf5
BLAKE2b-256 718322910ba555e528425c729542f8c7522da92ab7c62a21e05606da796b9886

See more details on using hashes here.

File details

Details for the file bingx_leverages-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bingx_leverages-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8544a3c6916e36b1521315df99cf25b7d18dafc657e48c2ff4eba5aa162f11f6
MD5 284aeda09af90ba9362497ec18859003
BLAKE2b-256 51f3f0c9c0d467746cdc37d8a76599f18a36a11f2adfc3e881c4a14408009f87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page