Python client for the BitMart Cloud API.
- Provides exchange quick trading API
- Easier withdrawal
- Efficiency, higher speeds, and lower latencies
- Priority in development and maintenance
- Dedicated and responsive technical support
- Provide webSocket apis calls
-
1.Python 3.6+ support
-
2.Clone
git clone https://github.com/bitmartexchange/bitmart-python-sdk-api.git
pip3 install -r requirements.txt
- 3.Copy
mv bitmart-python-sdk-api/bitmart /Your Working Directory
- An example of a spot trade API
- Replace it with your own API KEY
- Run
from bitmart.api_spot import APISpot
if __name__ == '__main__':
api_key = "Your API KEY"
secret_key = "Your Secret KEY"
memo = "Your Memo"
spotAPI = APISpot(api_key, secret_key, memo, timeout=(3, 10))
spotAPI.post_submit_limit_buy_order('BTC_USDT', size='0.01', price='8800')
from bitmart import cloud_consts
from bitmart.cloud_ws_client import CloudWSClient
from bitmart.ws_spot import create_channel, create_spot_subscribe_params
class WSTest(CloudWSClient):
def on_message(self, message):
print(f'[ReceiveServerMessage]-------->{message}')
if __name__ == '__main__':
ws = WSTest(cloud_consts.WS_URL, "", "", "")
ws.set_debug(True)
channels = [
# public channel
create_channel(cloud_consts.WS_PUBLIC_SPOT_TICKER, 'BTC_USDT'),
create_channel(cloud_consts.WS_PUBLIC_SPOT_KLINE_1M, 'BTC_USDT'),
create_channel(cloud_consts.WS_PUBLIC_SPOT_DEPTH5, 'BTC_USDT')
]
ws.spot_subscribe_without_login(create_spot_subscribe_params(channels))
from bitmart import cloud_consts
from bitmart.cloud_ws_client import CloudWSClient
from bitmart.ws_spot import create_channel, create_spot_subscribe_params
class WSTest(CloudWSClient):
def on_message(self, message):
print(f'[ReceiveServerMessage]-------->{message}')
if __name__ == '__main__':
ws = WSTest(cloud_consts.WS_URL_USER, api_key="Your API KEY", secret_key="Your Secret KEY", memo="Your Memo")
ws.set_debug(True)
channels = [
# private channel
create_channel(cloud_consts.WS_USER_SPOT_ORDER, 'BTC_USDT')
]
ws.spot_subscribe_with_login(create_spot_subscribe_params(channels))
from bitmart.api_contract import APIContract
if __name__ == '__main__':
api_key = "Your API KEY"
secret_key = "Your Secret KEY"
memo = "Your Memo"
contracAPI = APIContract(api_key, secret_key, memo, timeout=(3, 10))
contracAPI.get_depth('ETHUSDT')
from bitmart import cloud_consts
from bitmart.cloud_ws_contract_client import CloudWSContractClient
from bitmart.ws_contract import create_channel, create_contract_subscribe_params
class WSTest(CloudWSContractClient):
def on_message(self, message):
print(f'[ReceiveServerMessage]-------->{message}')
if __name__ == '__main__':
ws = WSTest(cloud_consts.CONTRACT_WS_URL, "", "", "")
ws.set_debug(True)
channels = [
# public channel
cloud_consts.WS_PUBLIC_CONTRACT_TICKER,
create_channel(cloud_consts.WS_PUBLIC_CONTRACT_DEPTH5, 'BTCUSDT'),
create_channel(cloud_consts.WS_PUBLIC_CONTRACT_KLINE_1M, 'BTCUSDT'),
]
ws.contract_subscribe_without_login(create_contract_subscribe_params(channels))
from bitmart import cloud_consts
from bitmart.cloud_ws_contract_client import CloudWSContractClient
from bitmart.ws_contract import create_channel, create_contract_subscribe_params
class WSTest(CloudWSContractClient):
def on_message(self, message):
print(f'[ReceiveServerMessage]-------->{message}')
if __name__ == '__main__':
ws = WSTest(cloud_consts.CONTRACT_WS_URL_USER, api_key="Your API KEY", secret_key="Your Secret KEY", memo="Your Memo")
ws.set_debug(True)
channels = [
# private channel
create_channel(cloud_consts.WS_USER_CONTRACT_ASSET, 'USDT'),
cloud_consts.WS_USER_CONTRACT_POSITION,
cloud_consts.WS_USER_CONTRACT_UNICAST,
]
ws.contract_subscribe_with_login(create_contract_subscribe_params(channels))
- Interface Spot API
Cancel Order
update to v2 version that isPOST https://api-cloud.bitmart.com/spot/v2/cancel_order
- UserAgent set "BitMart-Java-SDK/1.0.1"
- Interface Spot API
/spot/v1/symbols/book
addsize
parameter, which represents the number of depths
- New endpoints for Spot WebSocket
- Public - ticket channels
- Public - K channel
- Public - trading channels
- Public - depth channels
- Login
- User - Trading Channel
- Update endpoints for Spot WebSocket
- Public-Depth Channel:
- spot/depth20 20 Level Depth Channel
- spot/depth50 50 Level Depth Channel
- User-Trade Channel:
- Eligible pushes add new orders successfully
- Public-Depth Channel:
- New endpoints for Spot
/spot/v2/orders
Get User Order History V2/spot/v1/batch_orders
Batch Order
- Update endpoints for Spot
/spot/v1/symbols/kline
Add new field 'quote_volume'/spot/v1/symbols/trades
Add optional parameter N to return the number of items, the default is up to 50 items/spot/v1/order_detail
Add new field 'unfilled_volume'/spot/v1/submit_order
The request parameter type added limit_maker and ioc order types
- New endpoints for Account
/account/v2/deposit-withdraw/history
Get Deposit And Withdraw History V2
- Update endpoints for Account
/account/v1/wallet
Remove the account_type,Only respond to currency accounts; you can bring currency parameters (optional)
- websocket public channel address
wss://ws-manager-compress.bitmart.com?protocol=1.1
will be taken down on 2022-02-28 UTC time,The new address iswss://ws-manager-compress.bitmart.com/api?protocol=1.1
- Update endpoints for Spot
/spot/v1/symbols/details
Add a new respond parameter trade_status, to show the trading status of a trading pair symbol.
- New endpoints for Contract Market
/contract/public/details
Get contract details/contract/public/depth
Get contract depth/contract/public/open-interest
Get contract open interest/contract/public/funding-rate
Get contract funding rate/contract/public/kline
Get contract kline
- New endpoints for Contract Account
/contract/private/assets-detail
Get contract user assets detail
- New endpoints for Contract Trade
/contract/private/order
Get contract order detail/contract/private/order-history
Get contract order history/contract/private/position
Get contract position/contract/private/trades
Get contract trades/contract/private/submit_order
Post contract submit order/contract/private/cancel_order
Post contract cancel order/contract/private/cancel_orders
Post contract batch cancel orders
- Upgrade endpoints for Spot
/spot/v1/ticker
has been upgraded to/spot/v2/ticker
and/spot/v1/ticker_detail
/spot/v1/submit_order
has been upgraded to/spot/v2/submit_order
/spot/v1/batch_orders
has been upgraded to/spot/v2/batch_orders
/spot/v2/cancel_order
has been upgraded to/spot/v3/cancel_order
/spot/v1/order_detail
has been upgraded to/spot/v2/order_detail
/spot/v2/orders
has been upgraded to/spot/v3/orders
/spot/v1/trades
has been upgraded to/spot/v2/trades
- New endpoints for Spot & Margin
/spot/v1/margin/isolated/account
Applicable for isolated margin account inquiries/spot/v1/margin/isolated/transfer
For fund transfers between a margin account and spot account/spot/v1/user_fee
For querying the base rate of the current user/spot/v1/trade_fee
For the actual fee rate of the trading pairs/spot/v1/margin/submit_order
Applicable for margin order placement/spot/v1/margin/isolated/borrow
Applicable to isolated margin account borrowing operations/spot/v1/margin/isolated/repay
Applicable to isolated margin account repayment operations/spot/v1/margin/isolated/borrow_record
Applicable to the inquiry of borrowing records of an isolated margin account/spot/v1/margin/isolated/repay_record
Applicable to the inquiry of repayment records of isolated margin account/spot/v1/margin/isolated/pairs
Applicable for checking the borrowing rate and borrowing amount of trading pairs
- contract websocket public channel address
wss://openapi-ws.bitmart.com/api?protocol=1.1
- contract websocket private channel address
wss://openapi-ws.bitmart.com/user?protocol=1.1
- New endpoints for API Broker
/spot/v1/broker/rebate
Applicable to query API Broker's rebate records
- Update endpoints for Spot / Margin trading
/spot/v3/orders
/spot/v2/trades
add start_time and end_time field for flexible querying- add new order status 11 = Partially filled and canceled