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