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_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(self, symbols: Strings = 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={})
  • 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.122.tar.gz (727.4 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.122-py3-none-any.whl (990.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bitmex_api-0.0.122.tar.gz
Algorithm Hash digest
SHA256 b924e203233424e843264fa92f795014caf162fa83a505084327b30574792da7
MD5 7dfbb1b57a14a06ed6eff0fd233a33d4
BLAKE2b-256 b48384d22b427c244f97176248d92fa1ee0e275173d1df04909575aed650b7f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bitmex_api-0.0.122-py3-none-any.whl
  • Upload date:
  • Size: 990.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for bitmex_api-0.0.122-py3-none-any.whl
Algorithm Hash digest
SHA256 b9667cae247b9edba366d21eaa3650fec25836a06d8317ddbe78f133f1663236
MD5 8f5436bf44aa27f6a5785d2f7f922d55
BLAKE2b-256 944e1b1129689239fe87b0dfb80b4b123a3425131428658dbc08030376950e12

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