|
| 1 | +# bitmex-python |
| 2 | +Python SDK (sync and async) for Bitmex cryptocurrency exchange with Rest and WS capabilities. |
| 3 | + |
| 4 | +- You can check the SDK docs here: [SDK](https://docs.ccxt.com/#/exchanges/bitmex) |
| 5 | +- You can check Bitmex's docs here: [Docs](https://www.google.com/search?q=google+bitmex+cryptocurrency+exchange+api+docs) |
| 6 | +- Github repo: https://github.com/ccxt/bitmex-python |
| 7 | +- Pypi package: https://pypi.org/project/bitmex-api |
| 8 | + |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +``` |
| 13 | +pip install bitmex-api |
| 14 | +``` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +### Sync |
| 19 | + |
| 20 | +```Python |
| 21 | +from bitmex import BitmexSync |
| 22 | + |
| 23 | +def main(): |
| 24 | + instance = BitmexSync({}) |
| 25 | + ob = instance.fetch_order_book("BTC/USDC") |
| 26 | + print(ob) |
| 27 | + # |
| 28 | + # balance = instance.fetch_balance() |
| 29 | + # order = instance.create_order("BTC/USDC", "limit", "buy", 1, 100000) |
| 30 | + |
| 31 | +main() |
| 32 | +``` |
| 33 | + |
| 34 | +### Async |
| 35 | + |
| 36 | +```Python |
| 37 | +import sys |
| 38 | +import asyncio |
| 39 | +from bitmex import BitmexAsync |
| 40 | + |
| 41 | +### on Windows, uncomment below: |
| 42 | +# if sys.platform == 'win32': |
| 43 | +# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) |
| 44 | + |
| 45 | +async def main(): |
| 46 | + instance = BitmexAsync({}) |
| 47 | + ob = await instance.fetch_order_book("BTC/USDC") |
| 48 | + print(ob) |
| 49 | + # |
| 50 | + # balance = await instance.fetch_balance() |
| 51 | + # order = await instance.create_order("BTC/USDC", "limit", "buy", 1, 100000) |
| 52 | + |
| 53 | + # once you are done with the exchange |
| 54 | + await instance.close() |
| 55 | + |
| 56 | +asyncio.run(main()) |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +### Websockets |
| 62 | + |
| 63 | +```Python |
| 64 | +import sys |
| 65 | +from bitmex import BitmexWs |
| 66 | + |
| 67 | +### on Windows, uncomment below: |
| 68 | +# if sys.platform == 'win32': |
| 69 | +# asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) |
| 70 | + |
| 71 | +async def main(): |
| 72 | + instance = BitmexWs({}) |
| 73 | + while True: |
| 74 | + ob = await instance.watch_order_book("BTC/USDC") |
| 75 | + print(ob) |
| 76 | + # orders = await instance.watch_orders("BTC/USDC") |
| 77 | + |
| 78 | + # once you are done with the exchange |
| 79 | + await instance.close() |
| 80 | + |
| 81 | +asyncio.run(main()) |
| 82 | +``` |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +#### Raw call |
| 89 | + |
| 90 | +You can also construct custom requests to available "implicit" endpoints |
| 91 | + |
| 92 | +```Python |
| 93 | + request = { |
| 94 | + 'type': 'candleSnapshot', |
| 95 | + 'req': { |
| 96 | + 'coin': coin, |
| 97 | + 'interval': tf, |
| 98 | + 'startTime': since, |
| 99 | + 'endTime': until, |
| 100 | + }, |
| 101 | + } |
| 102 | + response = await instance.public_post_info(request) |
| 103 | +``` |
| 104 | + |
| 105 | + |
| 106 | +## Available methods |
| 107 | + |
| 108 | +### REST Unified |
| 109 | + |
| 110 | +- `create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})` |
| 111 | +- `fetch_balance(self, params={})` |
| 112 | +- `fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 113 | +- `fetch_currencies(self, params={})` |
| 114 | +- `fetch_deposit_address(self, code: str, params={})` |
| 115 | +- `fetch_deposit_withdraw_fees(self, codes: Strings = None, params={})` |
| 116 | +- `fetch_deposits_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 117 | +- `fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 118 | +- `fetch_funding_rates(self, symbols: Strings = None, params={})` |
| 119 | +- `fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 120 | +- `fetch_leverages(self, symbols: Strings = None, params={})` |
| 121 | +- `fetch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={})` |
| 122 | +- `fetch_markets(self, params={})` |
| 123 | +- `fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 124 | +- `fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})` |
| 125 | +- `fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 126 | +- `fetch_order_book(self, symbol: str, limit: Int = None, params={})` |
| 127 | +- `fetch_order(self, id: str, symbol: Str = None, params={})` |
| 128 | +- `fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 129 | +- `fetch_positions(self, symbols: Strings = None, params={})` |
| 130 | +- `fetch_ticker(self, symbol: str, params={})` |
| 131 | +- `fetch_tickers(self, symbols: Strings = None, params={})` |
| 132 | +- `fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})` |
| 133 | +- `amount_to_precision(self, symbol, amount)` |
| 134 | +- `calculate_rate_limiter_cost(self, api, method, path, params, config={})` |
| 135 | +- `cancel_all_orders_after(self, timeout: Int, params={})` |
| 136 | +- `cancel_all_orders(self, symbol: Str = None, params={})` |
| 137 | +- `cancel_order(self, id: str, symbol: Str = None, params={})` |
| 138 | +- `cancel_orders(self, ids: List[str], symbol: Str = None, params={})` |
| 139 | +- `convert_from_raw_cost(self, symbol, rawQuantity)` |
| 140 | +- `convert_from_raw_quantity(self, symbol, rawQuantity, currencySide='base')` |
| 141 | +- `convert_from_real_amount(self, code, amount)` |
| 142 | +- `convert_to_real_amount(self, code: Str, amount: Str)` |
| 143 | +- `describe(self)` |
| 144 | +- `edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={})` |
| 145 | +- `nonce(self)` |
| 146 | +- `set_leverage(self, leverage: int, symbol: Str = None, params={})` |
| 147 | +- `set_margin_mode(self, marginMode: str, symbol: Str = None, params={})` |
| 148 | +- `withdraw(self, code: str, amount: float, address: str, tag: Str = None, params={})` |
| 149 | + |
| 150 | +### REST Raw |
| 151 | + |
| 152 | +- `public_get_announcement(request)` |
| 153 | +- `public_get_announcement_urgent(request)` |
| 154 | +- `public_get_chat(request)` |
| 155 | +- `public_get_chat_channels(request)` |
| 156 | +- `public_get_chat_connected(request)` |
| 157 | +- `public_get_chat_pinned(request)` |
| 158 | +- `public_get_funding(request)` |
| 159 | +- `public_get_guild(request)` |
| 160 | +- `public_get_instrument(request)` |
| 161 | +- `public_get_instrument_active(request)` |
| 162 | +- `public_get_instrument_activeandindices(request)` |
| 163 | +- `public_get_instrument_activeintervals(request)` |
| 164 | +- `public_get_instrument_compositeindex(request)` |
| 165 | +- `public_get_instrument_indices(request)` |
| 166 | +- `public_get_instrument_usdvolume(request)` |
| 167 | +- `public_get_insurance(request)` |
| 168 | +- `public_get_leaderboard(request)` |
| 169 | +- `public_get_liquidation(request)` |
| 170 | +- `public_get_orderbook_l2(request)` |
| 171 | +- `public_get_porl_nonce(request)` |
| 172 | +- `public_get_quote(request)` |
| 173 | +- `public_get_quote_bucketed(request)` |
| 174 | +- `public_get_schema(request)` |
| 175 | +- `public_get_schema_websockethelp(request)` |
| 176 | +- `public_get_settlement(request)` |
| 177 | +- `public_get_stats(request)` |
| 178 | +- `public_get_stats_history(request)` |
| 179 | +- `public_get_stats_historyusd(request)` |
| 180 | +- `public_get_trade(request)` |
| 181 | +- `public_get_trade_bucketed(request)` |
| 182 | +- `public_get_wallet_assets(request)` |
| 183 | +- `public_get_wallet_networks(request)` |
| 184 | +- `private_get_address(request)` |
| 185 | +- `private_get_apikey(request)` |
| 186 | +- `private_get_execution(request)` |
| 187 | +- `private_get_execution_tradehistory(request)` |
| 188 | +- `private_get_globalnotification(request)` |
| 189 | +- `private_get_leaderboard_name(request)` |
| 190 | +- `private_get_order(request)` |
| 191 | +- `private_get_porl_snapshots(request)` |
| 192 | +- `private_get_position(request)` |
| 193 | +- `private_get_user(request)` |
| 194 | +- `private_get_user_affiliatestatus(request)` |
| 195 | +- `private_get_user_checkreferralcode(request)` |
| 196 | +- `private_get_user_commission(request)` |
| 197 | +- `private_get_user_csa(request)` |
| 198 | +- `private_get_user_depositaddress(request)` |
| 199 | +- `private_get_user_executionhistory(request)` |
| 200 | +- `private_get_user_getwallettransferaccounts(request)` |
| 201 | +- `private_get_user_margin(request)` |
| 202 | +- `private_get_user_quotefillratio(request)` |
| 203 | +- `private_get_user_quotevalueratio(request)` |
| 204 | +- `private_get_user_staking(request)` |
| 205 | +- `private_get_user_staking_instruments(request)` |
| 206 | +- `private_get_user_staking_tiers(request)` |
| 207 | +- `private_get_user_tradingvolume(request)` |
| 208 | +- `private_get_user_unstakingrequests(request)` |
| 209 | +- `private_get_user_wallet(request)` |
| 210 | +- `private_get_user_wallethistory(request)` |
| 211 | +- `private_get_user_walletsummary(request)` |
| 212 | +- `private_get_useraffiliates(request)` |
| 213 | +- `private_get_userevent(request)` |
| 214 | +- `private_post_address(request)` |
| 215 | +- `private_post_chat(request)` |
| 216 | +- `private_post_guild(request)` |
| 217 | +- `private_post_guild_archive(request)` |
| 218 | +- `private_post_guild_join(request)` |
| 219 | +- `private_post_guild_kick(request)` |
| 220 | +- `private_post_guild_leave(request)` |
| 221 | +- `private_post_guild_sharestrades(request)` |
| 222 | +- `private_post_order(request)` |
| 223 | +- `private_post_order_cancelallafter(request)` |
| 224 | +- `private_post_order_closeposition(request)` |
| 225 | +- `private_post_position_isolate(request)` |
| 226 | +- `private_post_position_leverage(request)` |
| 227 | +- `private_post_position_risklimit(request)` |
| 228 | +- `private_post_position_transfermargin(request)` |
| 229 | +- `private_post_user_addsubaccount(request)` |
| 230 | +- `private_post_user_cancelwithdrawal(request)` |
| 231 | +- `private_post_user_communicationtoken(request)` |
| 232 | +- `private_post_user_confirmemail(request)` |
| 233 | +- `private_post_user_confirmwithdrawal(request)` |
| 234 | +- `private_post_user_logout(request)` |
| 235 | +- `private_post_user_preferences(request)` |
| 236 | +- `private_post_user_requestwithdrawal(request)` |
| 237 | +- `private_post_user_unstakingrequests(request)` |
| 238 | +- `private_post_user_updatesubaccount(request)` |
| 239 | +- `private_post_user_wallettransfer(request)` |
| 240 | +- `private_put_guild(request)` |
| 241 | +- `private_put_order(request)` |
| 242 | +- `private_delete_order(request)` |
| 243 | +- `private_delete_order_all(request)` |
| 244 | +- `private_delete_user_unstakingrequests(request)` |
| 245 | + |
| 246 | +### WS Unified |
| 247 | + |
| 248 | +- `describe(self)` |
| 249 | +- `watch_ticker(self, symbol: str, params={})` |
| 250 | +- `watch_tickers(self, symbols: Strings = None, params={})` |
| 251 | +- `watch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={})` |
| 252 | +- `watch_liquidations_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={})` |
| 253 | +- `watch_balance(self, params={})` |
| 254 | +- `watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})` |
| 255 | +- `authenticate(self, params={})` |
| 256 | +- `watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={})` |
| 257 | +- `watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 258 | +- `watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 259 | +- `watch_order_book(self, symbol: str, limit: Int = None, params={})` |
| 260 | +- `watch_order_book_for_symbols(self, symbols: List[str], limit: Int = None, params={})` |
| 261 | +- `watch_trades_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={})` |
| 262 | +- `watch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})` |
| 263 | +- `watch_heartbeat(self, params={})` |
| 264 | + |
| 265 | +## Contribution |
| 266 | +- Give us a star :star: |
| 267 | +- Fork and Clone! Awesome |
| 268 | +- Select existing issues or create a new issue. |
0 commit comments