|
| 1 | +# bitmart-python |
| 2 | +Python SDK (sync and async) for Bitmart cryptocurrency exchange with Rest and WS capabilities. |
| 3 | + |
| 4 | +- You can check the SDK docs here: [SDK](https://docs.ccxt.com/#/exchanges/bitmart) |
| 5 | +- You can check Bitmart's docs here: [Docs](https://www.google.com/search?q=google+bitmart+cryptocurrency+exchange+api+docs) |
| 6 | +- Github repo: https://github.com/ccxt/bitmart-python |
| 7 | +- Pypi package: https://pypi.org/project/bitmart |
| 8 | + |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +``` |
| 13 | +pip install bitmart |
| 14 | +``` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +### Sync |
| 19 | + |
| 20 | +```Python |
| 21 | +from bitmart import BitmartSync |
| 22 | + |
| 23 | +def main(): |
| 24 | + instance = BitmartSync({}) |
| 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 bitmart import BitmartAsync |
| 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 = BitmartAsync({}) |
| 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 bitmart import BitmartWs |
| 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 = BitmartWs({}) |
| 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_market_buy_order_with_cost(self, symbol: str, cost: float, params={})` |
| 111 | +- `create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})` |
| 112 | +- `create_orders(self, orders: List[OrderRequest], params={})` |
| 113 | +- `create_spot_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})` |
| 114 | +- `create_swap_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})` |
| 115 | +- `fetch_balance(self, params={})` |
| 116 | +- `fetch_borrow_interest(self, code: Str = None, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 117 | +- `fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 118 | +- `fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 119 | +- `fetch_contract_markets(self, params={})` |
| 120 | +- `fetch_currencies(self, params={})` |
| 121 | +- `fetch_deposit_address(self, code: str, params={})` |
| 122 | +- `fetch_deposit_withdraw_fee(self, code: str, params={})` |
| 123 | +- `fetch_deposit(self, id: str, code: Str = None, params={})` |
| 124 | +- `fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 125 | +- `fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 126 | +- `fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 127 | +- `fetch_funding_rate(self, symbol: str, params={})` |
| 128 | +- `fetch_isolated_borrow_rate(self, symbol: str, params={})` |
| 129 | +- `fetch_isolated_borrow_rates(self, params={})` |
| 130 | +- `fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 131 | +- `fetch_markets(self, params={})` |
| 132 | +- `fetch_my_liquidations(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 133 | +- `fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 134 | +- `fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={})` |
| 135 | +- `fetch_open_interest(self, symbol: str, params={})` |
| 136 | +- `fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 137 | +- `fetch_order_book(self, symbol: str, limit: Int = None, params={})` |
| 138 | +- `fetch_order_trades(self, id: str, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 139 | +- `fetch_order(self, id: str, symbol: Str = None, params={})` |
| 140 | +- `fetch_orders_by_status(self, status, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 141 | +- `fetch_position_mode(self, symbol: Str = None, params={})` |
| 142 | +- `fetch_position(self, symbol: str, params={})` |
| 143 | +- `fetch_positions(self, symbols: Strings = None, params={})` |
| 144 | +- `fetch_spot_markets(self, params={})` |
| 145 | +- `fetch_status(self, params={})` |
| 146 | +- `fetch_ticker(self, symbol: str, params={})` |
| 147 | +- `fetch_tickers(self, symbols: Strings = None, params={})` |
| 148 | +- `fetch_time(self, params={})` |
| 149 | +- `fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})` |
| 150 | +- `fetch_trading_fee(self, symbol: str, params={})` |
| 151 | +- `fetch_transaction_fee(self, code: str, params={})` |
| 152 | +- `fetch_transactions_by_type(self, type, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 153 | +- `fetch_transactions_request(self, flowType: Int = None, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 154 | +- `fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 155 | +- `fetch_withdraw_addresses(self, code: str, note=None, networkCode=None, params={})` |
| 156 | +- `fetch_withdrawal(self, id: str, code: Str = None, params={})` |
| 157 | +- `fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={})` |
| 158 | +- `borrow_isolated_margin(self, symbol: str, code: str, amount: float, params={})` |
| 159 | +- `cancel_all_orders(self, symbol: Str = None, params={})` |
| 160 | +- `cancel_order(self, id: str, symbol: Str = None, params={})` |
| 161 | +- `cancel_orders(self, ids: List[str], symbol: Str = None, params={})` |
| 162 | +- `custom_parse_balance(self, response, marketType)` |
| 163 | +- `describe(self)` |
| 164 | +- `edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={})` |
| 165 | +- `get_currency_id_from_code_and_network(self, currencyCode: Str, networkCode: Str)` |
| 166 | +- `nonce(self)` |
| 167 | +- `repay_isolated_margin(self, symbol: str, code: str, amount, params={})` |
| 168 | +- `set_leverage(self, leverage: Int, symbol: Str = None, params={})` |
| 169 | +- `set_position_mode(self, hedged: bool, symbol: Str = None, params={})` |
| 170 | +- `transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params={})` |
| 171 | +- `withdraw(self, code: str, amount: float, address: str, tag=None, params={})` |
| 172 | + |
| 173 | +### REST Raw |
| 174 | + |
| 175 | +- `public_get_system_time(request)` |
| 176 | +- `public_get_system_service(request)` |
| 177 | +- `public_get_spot_v1_currencies(request)` |
| 178 | +- `public_get_spot_v1_symbols(request)` |
| 179 | +- `public_get_spot_v1_symbols_details(request)` |
| 180 | +- `public_get_spot_quotation_v3_tickers(request)` |
| 181 | +- `public_get_spot_quotation_v3_ticker(request)` |
| 182 | +- `public_get_spot_quotation_v3_lite_klines(request)` |
| 183 | +- `public_get_spot_quotation_v3_klines(request)` |
| 184 | +- `public_get_spot_quotation_v3_books(request)` |
| 185 | +- `public_get_spot_quotation_v3_trades(request)` |
| 186 | +- `public_get_spot_v1_ticker(request)` |
| 187 | +- `public_get_spot_v2_ticker(request)` |
| 188 | +- `public_get_spot_v1_ticker_detail(request)` |
| 189 | +- `public_get_spot_v1_steps(request)` |
| 190 | +- `public_get_spot_v1_symbols_kline(request)` |
| 191 | +- `public_get_spot_v1_symbols_book(request)` |
| 192 | +- `public_get_spot_v1_symbols_trades(request)` |
| 193 | +- `public_get_contract_v1_tickers(request)` |
| 194 | +- `public_get_contract_public_details(request)` |
| 195 | +- `public_get_contract_public_depth(request)` |
| 196 | +- `public_get_contract_public_open_interest(request)` |
| 197 | +- `public_get_contract_public_funding_rate(request)` |
| 198 | +- `public_get_contract_public_funding_rate_history(request)` |
| 199 | +- `public_get_contract_public_kline(request)` |
| 200 | +- `public_get_account_v1_currencies(request)` |
| 201 | +- `public_get_contract_public_markprice_kline(request)` |
| 202 | +- `private_get_account_sub_account_v1_transfer_list(request)` |
| 203 | +- `private_get_account_sub_account_v1_transfer_history(request)` |
| 204 | +- `private_get_account_sub_account_main_v1_wallet(request)` |
| 205 | +- `private_get_account_sub_account_main_v1_subaccount_list(request)` |
| 206 | +- `private_get_account_contract_sub_account_main_v1_wallet(request)` |
| 207 | +- `private_get_account_contract_sub_account_main_v1_transfer_list(request)` |
| 208 | +- `private_get_account_contract_sub_account_v1_transfer_history(request)` |
| 209 | +- `private_get_account_v1_wallet(request)` |
| 210 | +- `private_get_account_v1_currencies(request)` |
| 211 | +- `private_get_spot_v1_wallet(request)` |
| 212 | +- `private_get_account_v1_deposit_address(request)` |
| 213 | +- `private_get_account_v1_withdraw_charge(request)` |
| 214 | +- `private_get_account_v2_deposit_withdraw_history(request)` |
| 215 | +- `private_get_account_v1_deposit_withdraw_detail(request)` |
| 216 | +- `private_get_account_v1_withdraw_address_list(request)` |
| 217 | +- `private_get_spot_v1_order_detail(request)` |
| 218 | +- `private_get_spot_v2_orders(request)` |
| 219 | +- `private_get_spot_v1_trades(request)` |
| 220 | +- `private_get_spot_v2_trades(request)` |
| 221 | +- `private_get_spot_v3_orders(request)` |
| 222 | +- `private_get_spot_v2_order_detail(request)` |
| 223 | +- `private_get_spot_v1_margin_isolated_borrow_record(request)` |
| 224 | +- `private_get_spot_v1_margin_isolated_repay_record(request)` |
| 225 | +- `private_get_spot_v1_margin_isolated_pairs(request)` |
| 226 | +- `private_get_spot_v1_margin_isolated_account(request)` |
| 227 | +- `private_get_spot_v1_trade_fee(request)` |
| 228 | +- `private_get_spot_v1_user_fee(request)` |
| 229 | +- `private_get_spot_v1_broker_rebate(request)` |
| 230 | +- `private_get_contract_private_assets_detail(request)` |
| 231 | +- `private_get_contract_private_order(request)` |
| 232 | +- `private_get_contract_private_order_history(request)` |
| 233 | +- `private_get_contract_private_position(request)` |
| 234 | +- `private_get_contract_private_position_v2(request)` |
| 235 | +- `private_get_contract_private_get_open_orders(request)` |
| 236 | +- `private_get_contract_private_current_plan_order(request)` |
| 237 | +- `private_get_contract_private_trades(request)` |
| 238 | +- `private_get_contract_private_position_risk(request)` |
| 239 | +- `private_get_contract_private_affilate_rebate_list(request)` |
| 240 | +- `private_get_contract_private_affilate_trade_list(request)` |
| 241 | +- `private_get_contract_private_transaction_history(request)` |
| 242 | +- `private_get_contract_private_get_position_mode(request)` |
| 243 | +- `private_post_account_sub_account_main_v1_sub_to_main(request)` |
| 244 | +- `private_post_account_sub_account_sub_v1_sub_to_main(request)` |
| 245 | +- `private_post_account_sub_account_main_v1_main_to_sub(request)` |
| 246 | +- `private_post_account_sub_account_sub_v1_sub_to_sub(request)` |
| 247 | +- `private_post_account_sub_account_main_v1_sub_to_sub(request)` |
| 248 | +- `private_post_account_contract_sub_account_main_v1_sub_to_main(request)` |
| 249 | +- `private_post_account_contract_sub_account_main_v1_main_to_sub(request)` |
| 250 | +- `private_post_account_contract_sub_account_sub_v1_sub_to_main(request)` |
| 251 | +- `private_post_account_v1_withdraw_apply(request)` |
| 252 | +- `private_post_spot_v1_submit_order(request)` |
| 253 | +- `private_post_spot_v1_batch_orders(request)` |
| 254 | +- `private_post_spot_v2_cancel_order(request)` |
| 255 | +- `private_post_spot_v1_cancel_orders(request)` |
| 256 | +- `private_post_spot_v4_query_order(request)` |
| 257 | +- `private_post_spot_v4_query_client_order(request)` |
| 258 | +- `private_post_spot_v4_query_open_orders(request)` |
| 259 | +- `private_post_spot_v4_query_history_orders(request)` |
| 260 | +- `private_post_spot_v4_query_trades(request)` |
| 261 | +- `private_post_spot_v4_query_order_trades(request)` |
| 262 | +- `private_post_spot_v4_cancel_orders(request)` |
| 263 | +- `private_post_spot_v4_cancel_all(request)` |
| 264 | +- `private_post_spot_v4_batch_orders(request)` |
| 265 | +- `private_post_spot_v3_cancel_order(request)` |
| 266 | +- `private_post_spot_v2_batch_orders(request)` |
| 267 | +- `private_post_spot_v2_submit_order(request)` |
| 268 | +- `private_post_spot_v1_margin_submit_order(request)` |
| 269 | +- `private_post_spot_v1_margin_isolated_borrow(request)` |
| 270 | +- `private_post_spot_v1_margin_isolated_repay(request)` |
| 271 | +- `private_post_spot_v1_margin_isolated_transfer(request)` |
| 272 | +- `private_post_account_v1_transfer_contract_list(request)` |
| 273 | +- `private_post_account_v1_transfer_contract(request)` |
| 274 | +- `private_post_contract_private_submit_order(request)` |
| 275 | +- `private_post_contract_private_cancel_order(request)` |
| 276 | +- `private_post_contract_private_cancel_orders(request)` |
| 277 | +- `private_post_contract_private_submit_plan_order(request)` |
| 278 | +- `private_post_contract_private_cancel_plan_order(request)` |
| 279 | +- `private_post_contract_private_submit_leverage(request)` |
| 280 | +- `private_post_contract_private_submit_tp_sl_order(request)` |
| 281 | +- `private_post_contract_private_modify_plan_order(request)` |
| 282 | +- `private_post_contract_private_modify_preset_plan_order(request)` |
| 283 | +- `private_post_contract_private_modify_limit_order(request)` |
| 284 | +- `private_post_contract_private_modify_tp_sl_order(request)` |
| 285 | +- `private_post_contract_private_submit_trail_order(request)` |
| 286 | +- `private_post_contract_private_cancel_trail_order(request)` |
| 287 | +- `private_post_contract_private_set_position_mode(request)` |
| 288 | + |
| 289 | +### WS Unified |
| 290 | + |
| 291 | +- `describe(self)` |
| 292 | +- `subscribe(self, channel, symbol, type, params={})` |
| 293 | +- `subscribe_multiple(self, channel: str, type: str, symbols: Strings = None, params={})` |
| 294 | +- `watch_balance(self, params={})` |
| 295 | +- `set_balance_cache(self, client: Client, type, subscribeHash)` |
| 296 | +- `load_balance_snapshot(self, client, messageHash, type)` |
| 297 | +- `watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={})` |
| 298 | +- `watch_trades_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={})` |
| 299 | +- `get_params_for_multiple_sub(self, methodName: str, symbols: List[str], limit: Int = None, params={})` |
| 300 | +- `watch_ticker(self, symbol: str, params={})` |
| 301 | +- `watch_tickers(self, symbols: Strings = None, params={})` |
| 302 | +- `watch_bids_asks(self, symbols: Strings = None, params={})` |
| 303 | +- `watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={})` |
| 304 | +- `watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={})` |
| 305 | +- `watch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={})` |
| 306 | +- `watch_order_book(self, symbol: str, limit: Int = None, params={})` |
| 307 | +- `watch_order_book_for_symbols(self, symbols: List[str], limit: Int = None, params={})` |
| 308 | +- `authenticate(self, type, params={})` |
| 309 | + |
| 310 | +## Contribution |
| 311 | +- Give us a star :star: |
| 312 | +- Fork and Clone! Awesome |
| 313 | +- Select existing issues or create a new issue. |
0 commit comments