Skip to main content

bitmex crypto exchange api client

Project description

bitmex-python

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

Installation

pip install bitmex-api

Usage

Sync

from bitmex import BitmexSync

def main():
    instance = BitmexSync({})
    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 bitmex import BitmexAsync

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

async def main():
    instance = BitmexAsync({})
    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 bitmex import BitmexWs

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

async def main():
    instance = BitmexWs({})
    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_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})
  • fetch_balance(self, params={})
  • fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_currencies(self, params={})
  • fetch_deposit_address(self, code: str, params={})
  • fetch_deposit_withdraw_fees(self, codes: Strings = None, params={})
  • fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_funding_rates(self, symbols: Strings = None, params={})
  • fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_leverages(self, symbols: Strings = None, params={})
  • fetch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={})
  • fetch_markets(self, params={})
  • fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})
  • fetch_open_interests(self, symbols: Strings = None, params={})
  • fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_order_book(self, symbol: str, limit: Int = None, params={})
  • fetch_order(self, id: str, symbol: Str = None, params={})
  • fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_positions_adl_rank(self, symbols: Strings = None, params={})
  • fetch_positions(self, symbols: Strings = None, params={})
  • fetch_settlement_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • fetch_ticker(self, symbol: str, params={})
  • fetch_tickers(self, symbols: Strings = None, params={})
  • fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})
  • amount_to_precision(self, symbol, amount)
  • calculate_rate_limiter_cost(self, api, method, path, params, config={})
  • cancel_all_orders_after(self, timeout: Int, params={})
  • cancel_all_orders(self, symbol: Str = None, params={})
  • cancel_order(self, id: str, symbol: Str = None, params={})
  • cancel_orders(self, ids: List[str], symbol: Str = None, params={})
  • close_position(self, symbol: str, side: OrderSide = None, params={})
  • convert_from_raw_cost(self, symbol, rawQuantity)
  • convert_from_raw_quantity(self, symbol, rawQuantity, currencySide='base')
  • convert_from_real_amount(self, code, amount)
  • convert_to_real_amount(self, code: Str, amount: Str)
  • describe(self)
  • edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={})
  • nonce(self)
  • set_leverage(self, leverage: int, symbol: Str = None, params={})
  • set_margin_mode(self, marginMode: str, symbol: Str = None, params={})
  • withdraw(self, code: str, amount: float, address: str, tag: Str = None, params={})

REST Raw

  • public_get_announcement(request)
  • public_get_announcement_urgent(request)
  • public_get_chat(request)
  • public_get_chat_channels(request)
  • public_get_chat_connected(request)
  • public_get_chat_pinned(request)
  • public_get_funding(request)
  • public_get_guild(request)
  • public_get_instrument(request)
  • public_get_instrument_active(request)
  • public_get_instrument_activeandindices(request)
  • public_get_instrument_activeintervals(request)
  • public_get_instrument_compositeindex(request)
  • public_get_instrument_indices(request)
  • public_get_instrument_usdvolume(request)
  • public_get_insurance(request)
  • public_get_leaderboard(request)
  • public_get_liquidation(request)
  • public_get_orderbook_l2(request)
  • public_get_porl_nonce(request)
  • public_get_quote(request)
  • public_get_quote_bucketed(request)
  • public_get_schema(request)
  • public_get_schema_websockethelp(request)
  • public_get_settlement(request)
  • public_get_stats(request)
  • public_get_stats_history(request)
  • public_get_stats_historyusd(request)
  • public_get_trade(request)
  • public_get_trade_bucketed(request)
  • public_get_wallet_assets(request)
  • public_get_wallet_networks(request)
  • private_get_address(request)
  • private_get_apikey(request)
  • private_get_execution(request)
  • private_get_execution_tradehistory(request)
  • private_get_globalnotification(request)
  • private_get_leaderboard_name(request)
  • private_get_order(request)
  • private_get_porl_snapshots(request)
  • private_get_position(request)
  • private_get_user(request)
  • private_get_user_affiliatestatus(request)
  • private_get_user_checkreferralcode(request)
  • private_get_user_commission(request)
  • private_get_user_csa(request)
  • private_get_user_depositaddress(request)
  • private_get_user_executionhistory(request)
  • private_get_user_getwallettransferaccounts(request)
  • private_get_user_margin(request)
  • private_get_user_quotefillratio(request)
  • private_get_user_quotevalueratio(request)
  • private_get_user_staking(request)
  • private_get_user_staking_instruments(request)
  • private_get_user_staking_tiers(request)
  • private_get_user_tradingvolume(request)
  • private_get_user_unstakingrequests(request)
  • private_get_user_wallet(request)
  • private_get_user_wallethistory(request)
  • private_get_user_walletsummary(request)
  • private_get_useraffiliates(request)
  • private_get_userevent(request)
  • private_post_address(request)
  • private_post_chat(request)
  • private_post_guild(request)
  • private_post_guild_archive(request)
  • private_post_guild_join(request)
  • private_post_guild_kick(request)
  • private_post_guild_leave(request)
  • private_post_guild_sharestrades(request)
  • private_post_order(request)
  • private_post_order_cancelallafter(request)
  • private_post_order_closeposition(request)
  • private_post_position_isolate(request)
  • private_post_position_leverage(request)
  • private_post_position_risklimit(request)
  • private_post_position_transfermargin(request)
  • private_post_user_addsubaccount(request)
  • private_post_user_cancelwithdrawal(request)
  • private_post_user_communicationtoken(request)
  • private_post_user_confirmemail(request)
  • private_post_user_confirmwithdrawal(request)
  • private_post_user_logout(request)
  • private_post_user_preferences(request)
  • private_post_user_requestwithdrawal(request)
  • private_post_user_unstakingrequests(request)
  • private_post_user_updatesubaccount(request)
  • private_post_user_wallettransfer(request)
  • private_put_guild(request)
  • private_put_order(request)
  • private_delete_order(request)
  • private_delete_order_all(request)
  • private_delete_user_unstakingrequests(request)

WS Unified

  • describe(self)
  • watch_ticker(self, symbol: str, params={})
  • watch_tickers(self, symbols: Strings = None, params={})
  • watch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={})
  • watch_liquidations_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={})
  • watch_balance(self, params={})
  • watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})
  • authenticate(self, params={})
  • watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={})
  • watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})
  • watch_order_book(self, symbol: str, limit: Int = None, params={})
  • watch_order_book_for_symbols(self, symbols: List[str], limit: Int = None, params={})
  • watch_trades_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={})
  • watch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})
  • watch_heartbeat(self, params={})

Contribution

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

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

bitmex_api-0.0.131.tar.gz (740.5 kB view details)

Uploaded Source

Built Distribution

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

bitmex_api-0.0.131-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file bitmex_api-0.0.131.tar.gz.

File metadata

  • Download URL: bitmex_api-0.0.131.tar.gz
  • Upload date:
  • Size: 740.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for bitmex_api-0.0.131.tar.gz
Algorithm Hash digest
SHA256 507c50680e51bf63b18d5a491e06ac3b8b1f0ea5a6cb53a1e11528fe67950aea
MD5 b1986d8db05548c6a3535faafef4adb6
BLAKE2b-256 015486ce3777bc6d5673091bb1324649207bc0f5807453e5cea7bb8cbbd5be64

See more details on using hashes here.

File details

Details for the file bitmex_api-0.0.131-py3-none-any.whl.

File metadata

  • Download URL: bitmex_api-0.0.131-py3-none-any.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for bitmex_api-0.0.131-py3-none-any.whl
Algorithm Hash digest
SHA256 e1afe86629f22ff9d0f5b7fe4e3f06c792a065c2a5de64e5b9c52838f8a494be
MD5 a213c5f5bac7d2dabd561b2676d3a5db
BLAKE2b-256 a76cac173f2be900eb1cc18ca76bbdbfa6933f6288ec497a39b39a259db5045a

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