Skip to content
This repository was archived by the owner on Oct 20, 2026. It is now read-only.

Commit 26bfc0f

Browse files
committed
pushback
1 parent b123a9b commit 26bfc0f

90 files changed

Lines changed: 30432 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
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_interests(self, symbols: Strings = None, params={})`
126+
- `fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
127+
- `fetch_order_book(self, symbol: str, limit: Int = None, params={})`
128+
- `fetch_order(self, id: str, symbol: Str = None, params={})`
129+
- `fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
130+
- `fetch_positions_adl_rank(self, symbols: Strings = None, params={})`
131+
- `fetch_positions(self, symbols: Strings = None, params={})`
132+
- `fetch_settlement_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
133+
- `fetch_ticker(self, symbol: str, params={})`
134+
- `fetch_tickers(self, symbols: Strings = None, params={})`
135+
- `fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})`
136+
- `amount_to_precision(self, symbol: Str, amount: object)`
137+
- `calculate_rate_limiter_cost(self, api: object, method: object, path: object, params: object, config={})`
138+
- `cancel_all_orders_after(self, timeout: Int, params={})`
139+
- `cancel_all_orders(self, symbol: Str = None, params={})`
140+
- `cancel_order(self, id: str, symbol: Str = None, params={})`
141+
- `cancel_orders(self, ids: list[str], symbol: Str = None, params={})`
142+
- `close_position(self, symbol: str, side: OrderSide = None, params={})`
143+
- `convert_from_raw_cost(self, symbol: object, rawQuantity: object)`
144+
- `convert_from_raw_quantity(self, symbol: object, rawQuantity: object, currencySide='base')`
145+
- `convert_from_real_amount(self, code: object, amount: object)`
146+
- `convert_to_real_amount(self, code: Str, amount: Str)`
147+
- `describe(self)`
148+
- `edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={})`
149+
- `nonce(self)`
150+
- `set_leverage(self, leverage: int, symbol: Str = None, params={})`
151+
- `set_margin_mode(self, marginMode: str, symbol: Str = None, params={})`
152+
- `withdraw(self, code: str, amount: float, address: str, tag: Str = None, params={})`
153+
154+
### REST Raw
155+
156+
- `public_get_announcement(request)`
157+
- `public_get_announcement_urgent(request)`
158+
- `public_get_chat(request)`
159+
- `public_get_chat_channels(request)`
160+
- `public_get_chat_connected(request)`
161+
- `public_get_chat_pinned(request)`
162+
- `public_get_funding(request)`
163+
- `public_get_guild(request)`
164+
- `public_get_instrument(request)`
165+
- `public_get_instrument_active(request)`
166+
- `public_get_instrument_activeandindices(request)`
167+
- `public_get_instrument_activeintervals(request)`
168+
- `public_get_instrument_compositeindex(request)`
169+
- `public_get_instrument_indices(request)`
170+
- `public_get_instrument_usdvolume(request)`
171+
- `public_get_insurance(request)`
172+
- `public_get_leaderboard(request)`
173+
- `public_get_liquidation(request)`
174+
- `public_get_orderbook_l2(request)`
175+
- `public_get_porl_nonce(request)`
176+
- `public_get_quote(request)`
177+
- `public_get_quote_bucketed(request)`
178+
- `public_get_schema(request)`
179+
- `public_get_schema_websockethelp(request)`
180+
- `public_get_settlement(request)`
181+
- `public_get_stats(request)`
182+
- `public_get_stats_history(request)`
183+
- `public_get_stats_historyusd(request)`
184+
- `public_get_trade(request)`
185+
- `public_get_trade_bucketed(request)`
186+
- `public_get_wallet_assets(request)`
187+
- `public_get_wallet_currencies(request)`
188+
- `public_get_wallet_haircuts(request)`
189+
- `public_get_wallet_networks(request)`
190+
- `private_get_address(request)`
191+
- `private_get_addressconfig(request)`
192+
- `private_get_apikey(request)`
193+
- `private_get_apikey_self(request)`
194+
- `private_get_execution(request)`
195+
- `private_get_execution_tradehistory(request)`
196+
- `private_get_globalnotification(request)`
197+
- `private_get_leaderboard_name(request)`
198+
- `private_get_leagueoftrader_myrankings(request)`
199+
- `private_get_managedsubaccountbinding_investor(request)`
200+
- `private_get_managedsubaccountbinding_tradingteam(request)`
201+
- `private_get_order(request)`
202+
- `private_get_porl_snapshots(request)`
203+
- `private_get_position(request)`
204+
- `private_get_referralcode(request)`
205+
- `private_get_referralcode_check_code(request)`
206+
- `private_get_referralcode_code_code(request)`
207+
- `private_get_referralcode_id(request)`
208+
- `private_get_user(request)`
209+
- `private_get_user_affiliatestatus(request)`
210+
- `private_get_user_checkreferralcode(request)`
211+
- `private_get_user_commission(request)`
212+
- `private_get_user_csa(request)`
213+
- `private_get_user_depositaddress(request)`
214+
- `private_get_user_depositaddressinformation(request)`
215+
- `private_get_user_executionhistory(request)`
216+
- `private_get_user_getwallettransferaccounts(request)`
217+
- `private_get_user_margin(request)`
218+
- `private_get_user_marginingmode(request)`
219+
- `private_get_user_quotefillratio(request)`
220+
- `private_get_user_quotevalueratio(request)`
221+
- `private_get_user_staking(request)`
222+
- `private_get_user_staking_instruments(request)`
223+
- `private_get_user_staking_tiers(request)`
224+
- `private_get_user_tradingsettings(request)`
225+
- `private_get_user_tradingvolume(request)`
226+
- `private_get_user_unstakingrequests(request)`
227+
- `private_get_user_wallet(request)`
228+
- `private_get_user_wallethistory(request)`
229+
- `private_get_user_walletsummary(request)`
230+
- `private_get_useraffiliates(request)`
231+
- `private_get_userevent(request)`
232+
- `private_get_userpricealert(request)`
233+
- `private_get_userstats_volumerank(request)`
234+
- `private_post_address(request)`
235+
- `private_post_chat(request)`
236+
- `private_post_guild(request)`
237+
- `private_post_guild_archive(request)`
238+
- `private_post_guild_join(request)`
239+
- `private_post_guild_kick(request)`
240+
- `private_post_guild_leave(request)`
241+
- `private_post_guild_sharestrades(request)`
242+
- `private_post_managedsubaccountbinding_approve(request)`
243+
- `private_post_managedsubaccountbinding_cancel(request)`
244+
- `private_post_managedsubaccountbinding_createmsa(request)`
245+
- `private_post_managedsubaccountbinding_reject(request)`
246+
- `private_post_managedsubaccountbinding_toggletradehistory(request)`
247+
- `private_post_managedsubaccountbinding_unbind(request)`
248+
- `private_post_order(request)`
249+
- `private_post_order_cancelallafter(request)`
250+
- `private_post_order_closeposition(request)`
251+
- `private_post_position_crossleverage(request)`
252+
- `private_post_position_isolate(request)`
253+
- `private_post_position_leverage(request)`
254+
- `private_post_position_risklimit(request)`
255+
- `private_post_position_transfermargin(request)`
256+
- `private_post_referralcode(request)`
257+
- `private_post_user_addsubaccount(request)`
258+
- `private_post_user_cancelwithdrawal(request)`
259+
- `private_post_user_communicationtoken(request)`
260+
- `private_post_user_confirmemail(request)`
261+
- `private_post_user_confirmwithdrawal(request)`
262+
- `private_post_user_createindependentsubaccount(request)`
263+
- `private_post_user_logout(request)`
264+
- `private_post_user_marginingmode(request)`
265+
- `private_post_user_positionmode(request)`
266+
- `private_post_user_preferences(request)`
267+
- `private_post_user_requestwithdrawal(request)`
268+
- `private_post_user_unstakingrequests(request)`
269+
- `private_post_user_updatesubaccount(request)`
270+
- `private_post_user_wallettransfer(request)`
271+
- `private_post_userpricealert(request)`
272+
- `private_put_address(request)`
273+
- `private_put_guild(request)`
274+
- `private_put_order(request)`
275+
- `private_put_referralcode_id(request)`
276+
- `private_put_userpricealert_id(request)`
277+
- `private_delete_order(request)`
278+
- `private_delete_order_all(request)`
279+
- `private_delete_referralcode_id(request)`
280+
- `private_delete_user_unstakingrequests(request)`
281+
- `private_delete_user_withdrawal(request)`
282+
- `private_delete_userpricealert(request)`
283+
- `private_delete_userpricealert_id(request)`
284+
285+
### WS Unified
286+
287+
- `describe(self)`
288+
- `watch_ticker(self, symbol: str, params={})`
289+
- `watch_tickers(self, symbols: Strings = None, params={})`
290+
- `watch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={})`
291+
- `watch_liquidations_for_symbols(self, symbols: list[str], since: Int = None, limit: Int = None, params={})`
292+
- `watch_balance(self, params={})`
293+
- `watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})`
294+
- `authenticate(self, params={})`
295+
- `watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={})`
296+
- `watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
297+
- `watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})`
298+
- `watch_order_book(self, symbol: str, limit: Int = None, params={})`
299+
- `watch_order_book_for_symbols(self, symbols: list[str], limit: Int = None, params={})`
300+
- `watch_trades_for_symbols(self, symbols: list[str], since: Int = None, limit: Int = None, params={})`
301+
- `watch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})`
302+
- `watch_heartbeat(self, params={})`
303+
304+
## Contribution
305+
- Give us a star :star:
306+
- Fork and Clone! Awesome
307+
- Select existing issues or create a new issue.

‎bitmex/__init__.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
import bitmex.ccxt as ccxt_module
3+
sys.modules['ccxt'] = ccxt_module
4+
5+
from bitmex.ccxt import bitmex as BitmexSync
6+
from bitmex.ccxt.async_support.bitmex import bitmex as BitmexAsync
7+
from bitmex.ccxt.pro.bitmex import bitmex as BitmexWs

0 commit comments

Comments
 (0)