BitMart Exchange official(https://bitmart.com) Python client for the BitMart Cloud API
Project description
BitMart-Python-SDK-API
BitMart Exchange official Python client for the BitMart Cloud API.
Feature
- 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
- Supported APIs:
/spot/*
/contract/*
/account/*
- Spot WebSocket Market Stream
- Spot User Data Stream
- Contract User Data Stream
- Contract WebSocket Market Stream
- Test cases and examples
Installation
pip install bitmart-python-sdk-api
Documentation
Example
Spot Public API Example
from bitmart.api_spot import APISpot
if __name__ == '__main__':
spotAPI = APISpot(timeout=(2, 10))
# Get a list of all cryptocurrencies on the platform
spotAPI.get_currencies()
# Querying aggregated tickers of a particular trading pair
spotAPI.get_v3_ticker(symbol='BTC_USDT')
# Get the latest trade records of the specified trading pair
spotAPI.get_v3_trades(symbol='BTC_USDT', limit=10)
Spot API Example
from bitmart.api_spot import APISpot
from bitmart.lib import cloud_exceptions
from bitmart.lib.cloud_log import CloudLog
if __name__ == '__main__':
api_key = "Your API KEY"
secret_key = "Your Secret KEY"
memo = "Your Memo"
try:
spotAPI = APISpot(api_key, secret_key, memo, timeout=(3, 10))
CloudLog.set_logger_level('info')
response = spotAPI.post_submit_order(
symbol='BTC_USDT',
side='sell',
type='limit',
size='10000',
price='1000000'
)
except cloud_exceptions.APIException as apiException:
print("Error[HTTP<>200]:", apiException.response)
except Exception as exception:
print("Error[Exception]:", exception)
else:
if response[0]['code'] == 1000:
print('Call Success:', response[0])
else:
print('Call Failed:', response[0]['message'])
More Example: test_api_spot.py More Example: test_api_account.py
Spot WebSocket Public Channel Example
from bitmart.lib import cloud_consts
from bitmart.lib.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(url=cloud_consts.WS_URL)
ws.set_debug(False)
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')
# or public channel
#"spot/ticker:BTC_USDT",
#"spot/kline1m:BTC_USDT",
#"spot/depth5:BTC_USDT"
]
ws.spot_subscribe_without_login(create_spot_subscribe_params(channels))
Spot WebSocket Private Channel Example
from bitmart.lib import cloud_consts
from bitmart.lib.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))
Contract Public API Example
from bitmart.api_contract import APIContract
if __name__ == '__main__':
contractAPI = APIContract(timeout=(2, 10))
# query contract details
contractAPI.get_details(contract_symbol='ETHUSDT')
# Get full depth of trading pairs.
contractAPI.get_depth(contract_symbol='ETHUSDT')
# Querying the open interest and open interest value data of the specified contract
contractAPI.get_open_interest(contract_symbol='ETHUSDT')
# Applicable for checking the current funding rate of a specified contract
contractAPI.get_funding_rate(contract_symbol='ETHUSDT')
# querying K-line data
contractAPI.get_kline(contract_symbol='ETHUSDT', step=5, start_time=1662518172, end_time=1662518172)
Contract API Example
from bitmart.api_contract import APIContract
if __name__ == '__main__':
api_key = "Your API KEY"
secret_key = "Your Secret KEY"
memo = "Your Memo"
contractAPI = APIContract(api_key, secret_key, memo, timeout=(3, 10))
contractAPI.post_submit_order(contract_symbol='BTCUSDT',
side=4,
type='limit',
leverage='1',
open_type='isolated',
size=10,
price='20000')
More Example: test_api_contract.py
Contract WebSocket Public Channel Example
from bitmart.lib import cloud_consts
from bitmart.lib.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(False)
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))
Contract WebSocket Private Channel Example
from bitmart.lib import cloud_consts
from bitmart.lib.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(False)
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))
Extra Options
Authentication
How to set API KEY?
from bitmart.api_spot import APISpot
from bitmart.api_contract import APIContract
spotAPI = APISpot(api_key="your api access key", secret_key="your api secret key", memo="your api memo")
contractAPI = APIContract(api_key="your api access key", secret_key="your api secret key", memo="your api memo")
Timeout
Set HTTP connection timeout
and read timeout
.
from bitmart.api_spot import APISpot
from bitmart.api_contract import APIContract
spotAPI = APISpot(timeout=(2, 10))
contractAPI = APIContract(timeout=(2, 10))
Logging
If you want to debug
the data requested by the API and the corresponding data returned by the API,
you can set it like this:
from bitmart.lib.cloud_log import CloudLog
CloudLog.set_logger_level('debug')
Domain
How to set API domain name? The domain name parameter is optional,
the default domain name is https://api-cloud.bitmart.com
.
from bitmart.api_spot import APISpot
from bitmart.api_contract import APIContract
spotAPI = APISpot(url='https://api-cloud.bitmart.com')
contractAPI = APIContract(url='https://api-cloud.bitmart.com')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for bitmart-python-sdk-api-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47e82fd84ff60999c369334b2565890765e13769628c4021428dc7562e4c4ac2 |
|
MD5 | 3c8b74a3fb98b79f08f738ce06f87437 |
|
BLAKE2b-256 | 162c27f3498f65272b9a98a196ba91424bdc48acd9bf049c1ad6efae0faa454a |
Close
Hashes for bitmart_python_sdk_api-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f609298d5133cc939c9acb03ed5e841ad5c378c80504acc57339bb6f643d3d5b |
|
MD5 | a283e53679a5e5092647a34d4bc65b8f |
|
BLAKE2b-256 | a734a04096b1dd652681c2378bb87e9d81745f49d67d46d4b81c21aadd0b5023 |