Skip to content

Commit c8bad80

Browse files
committed
pushback
1 parent 81457c8 commit c8bad80

File tree

469 files changed

+108518
-2
lines changed

Some content is hidden

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

469 files changed

+108518
-2
lines changed

README.md

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
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.

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

bitmex/ccxt/__init__.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import sys
2+
import bitmex.ccxt as ccxt_module
3+
sys.modules['ccxt'] = ccxt_module
4+
5+
# -*- coding: utf-8 -*-
6+
7+
"""CCXT: CryptoCurrency eXchange Trading Library"""
8+
9+
# MIT License
10+
# Copyright (c) 2017 Igor Kroitor
11+
# Permission is hereby granted, free of charge, to any person obtaining a copy
12+
# of this software and associated documentation files (the "Software"), to deal
13+
# in the Software without restriction, including without limitation the rights
14+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
# copies of the Software, and to permit persons to whom the Software is
16+
# furnished to do so, subject to the following conditions:
17+
# The above copyright notice and this permission notice shall be included in all
18+
# copies or substantial portions of the Software.
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
# SOFTWARE.
26+
27+
# ----------------------------------------------------------------------------
28+
29+
__version__ = '4.5.23'
30+
31+
# ----------------------------------------------------------------------------
32+
33+
from ccxt.base.exchange import Exchange # noqa: F401
34+
from ccxt.base.precise import Precise # noqa: F401
35+
36+
from ccxt.base.decimal_to_precision import decimal_to_precision # noqa: F401
37+
from ccxt.base.decimal_to_precision import TRUNCATE # noqa: F401
38+
from ccxt.base.decimal_to_precision import ROUND # noqa: F401
39+
from ccxt.base.decimal_to_precision import ROUND_UP # noqa: F401
40+
from ccxt.base.decimal_to_precision import ROUND_DOWN # noqa: F401
41+
from ccxt.base.decimal_to_precision import DECIMAL_PLACES # noqa: F401
42+
from ccxt.base.decimal_to_precision import SIGNIFICANT_DIGITS # noqa: F401
43+
from ccxt.base.decimal_to_precision import TICK_SIZE # noqa: F401
44+
from ccxt.base.decimal_to_precision import NO_PADDING # noqa: F401
45+
from ccxt.base.decimal_to_precision import PAD_WITH_ZERO # noqa: F401
46+
47+
from ccxt.base import errors
48+
from ccxt.base.errors import BaseError # noqa: F401
49+
from ccxt.base.errors import ExchangeError # noqa: F401
50+
from ccxt.base.errors import AuthenticationError # noqa: F401
51+
from ccxt.base.errors import PermissionDenied # noqa: F401
52+
from ccxt.base.errors import AccountNotEnabled # noqa: F401
53+
from ccxt.base.errors import AccountSuspended # noqa: F401
54+
from ccxt.base.errors import ArgumentsRequired # noqa: F401
55+
from ccxt.base.errors import BadRequest # noqa: F401
56+
from ccxt.base.errors import BadSymbol # noqa: F401
57+
from ccxt.base.errors import OperationRejected # noqa: F401
58+
from ccxt.base.errors import NoChange # noqa: F401
59+
from ccxt.base.errors import MarginModeAlreadySet # noqa: F401
60+
from ccxt.base.errors import MarketClosed # noqa: F401
61+
from ccxt.base.errors import ManualInteractionNeeded # noqa: F401
62+
from ccxt.base.errors import RestrictedLocation # noqa: F401
63+
from ccxt.base.errors import InsufficientFunds # noqa: F401
64+
from ccxt.base.errors import InvalidAddress # noqa: F401
65+
from ccxt.base.errors import AddressPending # noqa: F401
66+
from ccxt.base.errors import InvalidOrder # noqa: F401
67+
from ccxt.base.errors import OrderNotFound # noqa: F401
68+
from ccxt.base.errors import OrderNotCached # noqa: F401
69+
from ccxt.base.errors import OrderImmediatelyFillable # noqa: F401
70+
from ccxt.base.errors import OrderNotFillable # noqa: F401
71+
from ccxt.base.errors import DuplicateOrderId # noqa: F401
72+
from ccxt.base.errors import ContractUnavailable # noqa: F401
73+
from ccxt.base.errors import NotSupported # noqa: F401
74+
from ccxt.base.errors import InvalidProxySettings # noqa: F401
75+
from ccxt.base.errors import ExchangeClosedByUser # noqa: F401
76+
from ccxt.base.errors import OperationFailed # noqa: F401
77+
from ccxt.base.errors import NetworkError # noqa: F401
78+
from ccxt.base.errors import DDoSProtection # noqa: F401
79+
from ccxt.base.errors import RateLimitExceeded # noqa: F401
80+
from ccxt.base.errors import ExchangeNotAvailable # noqa: F401
81+
from ccxt.base.errors import OnMaintenance # noqa: F401
82+
from ccxt.base.errors import InvalidNonce # noqa: F401
83+
from ccxt.base.errors import ChecksumError # noqa: F401
84+
from ccxt.base.errors import RequestTimeout # noqa: F401
85+
from ccxt.base.errors import BadResponse # noqa: F401
86+
from ccxt.base.errors import NullResponse # noqa: F401
87+
from ccxt.base.errors import CancelPending # noqa: F401
88+
from ccxt.base.errors import UnsubscribeError # noqa: F401
89+
from ccxt.base.errors import error_hierarchy # noqa: F401
90+
91+
from ccxt.bitmex import bitmex # noqa: F401
92+
93+
exchanges = [ 'bitmex',]
94+
95+
base = [
96+
'Exchange',
97+
'Precise',
98+
'exchanges',
99+
'decimal_to_precision',
100+
]
101+
102+
__all__ = base + errors.__all__ + exchanges

0 commit comments

Comments
 (0)