Package: bitmart-python-sdk-api
BitMart-Python-SDK-APIBitMart Exchange officialPython client for the BitMart Cloud API.FeatureProvides exchange quick trading APIEasier withdrawalEfficiency, higher speeds, and lower latenciesPriority in development and maintenanceDedicated and responsive technical supportProvide webSocket apis callsSupported APIs:/spot/*/contract/*/account/*Spot WebSocket Market StreamSpot User Data StreamContract User Data StreamContract WebSocket Market StreamTest cases and examplesInstallationpipinstallbitmart-python-sdk-apiDocumentationAPI DocumentationExampleSpot Public API Examplefrombitmart.api_spotimportAPISpotif__name__=='__main__':spotAPI=APISpot(timeout=(2,10))# Get a list of all cryptocurrencies on the platformspotAPI.get_currencies()# Querying aggregated tickers of a particular trading pairspotAPI.get_v3_ticker(symbol='BTC_USDT')# Get the latest trade records of the specified trading pairspotAPI.get_v3_trades(symbol='BTC_USDT',limit=10)Spot API Examplefrombitmart.api_spotimportAPISpotfrombitmart.libimportcloud_exceptionsfrombitmart.lib.cloud_logimportCloudLogif__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')exceptcloud_exceptions.APIExceptionasapiException:print("Error[HTTP<>200]:",apiException.response)exceptExceptionasexception:print("Error[Exception]:",exception)else:ifresponse[0]['code']==1000:print('Call Success:',response[0])else:print('Call Failed:',response[0]['message'])More Example:test_api_spot.pyMore Example:test_api_account.pySpot WebSocket Public Channel Examplefrombitmart.libimportcloud_constsfrombitmart.lib.cloud_ws_clientimportCloudWSClientfrombitmart.ws_spotimportcreate_channel,create_spot_subscribe_paramsclassWSTest(CloudWSClient):defon_message(self,message):print(f'[ReceiveServerMessage]-------->{message}')if__name__=='__main__':ws=WSTest(url=cloud_consts.WS_URL)ws.set_debug(False)channels=[# public channelcreate_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 Examplefrombitmart.libimportcloud_constsfrombitmart.lib.cloud_ws_clientimportCloudWSClientfrombitmart.ws_spotimportcreate_channel,create_spot_subscribe_paramsclassWSTest(CloudWSClient):defon_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 channelcreate_channel(cloud_consts.WS_USER_SPOT_ORDER,'BTC_USDT')]ws.spot_subscribe_with_login(create_spot_subscribe_params(channels))Contract Public API Examplefrombitmart.api_contractimportAPIContractif__name__=='__main__':contractAPI=APIContract(timeout=(2,10))# query contract detailscontractAPI.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 contractcontractAPI.get_open_interest(contract_symbol='ETHUSDT')# Applicable for checking the current funding rate of a specified contractcontractAPI.get_funding_rate(contract_symbol='ETHUSDT')# querying K-line datacontractAPI.get_kline(contract_symbol='ETHUSDT',step=5,start_time=1662518172,end_time=1662518172)Contract API Examplefrombitmart.api_contractimportAPIContractif__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.pyContract WebSocket Public Channel Examplefrombitmart.libimportcloud_constsfrombitmart.lib.cloud_ws_contract_clientimportCloudWSContractClientfrombitmart.ws_contractimportcreate_channel,create_contract_subscribe_paramsclassWSTest(CloudWSContractClient):defon_message(self,message):print(f'[ReceiveServerMessage]-------->{message}')if__name__=='__main__':ws=WSTest(cloud_consts.CONTRACT_WS_URL)ws.set_debug(False)channels=[# public channelcloud_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 Examplefrombitmart.libimportcloud_constsfrombitmart.lib.cloud_ws_contract_clientimportCloudWSContractClientfrombitmart.ws_contractimportcreate_channel,create_contract_subscribe_paramsclassWSTest(CloudWSContractClient):defon_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 channelcreate_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 OptionsAuthenticationHow to set API KEY?frombitmart.api_spotimportAPISpotfrombitmart.api_contractimportAPIContractspotAPI=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")TimeoutSet HTTPconnection timeoutandread timeout.frombitmart.api_spotimportAPISpotfrombitmart.api_contractimportAPIContractspotAPI=APISpot(timeout=(2,10))contractAPI=APIContract(timeout=(2,10))LoggingIf you want todebugthe data requested by the API and the corresponding data returned by the API,
you can set it like this:frombitmart.lib.cloud_logimportCloudLogCloudLog.set_logger_level('debug')DomainHow to set API domain name? The domain name parameter is optional,
the default domain name ishttps://api-cloud.bitmart.com.frombitmart.api_spotimportAPISpotfrombitmart.api_contractimportAPIContractspotAPI=APISpot(url='https://api-cloud.bitmart.com')contractAPI=APIContract(url='https://api-cloud.bitmart.com')