Skip to content

Commit c4f8fd8

Browse files
Merge branch '2.6.1' into 'master'
2.6.1 Feat(new and update sub-account endpoints) See merge request exchange/code/sdk/bitmart-python-sdk-api!28
2 parents 81bfc8e + a2b3ae5 commit c4f8fd8

10 files changed

Lines changed: 533 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
Changelog
22
=========================
33

4+
### v2.6.1 Release
5+
#### New Features
6+
- New (Spot Sub-Account)
7+
- `/account/sub-account/main/v1/sub-to-main` Sub-Account to Main-Account, For Main Account (SIGNED)
8+
- `/account/sub-account/sub/v1/sub-to-main` Sub-Account to Main-Account, For Sub Account (SIGNED)
9+
- `/account/sub-account/main/v1/main-to-sub` Main-Account to Sub-Account, For Main Account (SIGNED)
10+
- `/account/sub-account/main/v1/sub-to-sub` Sub-Account to Sub-Account, For Main Account (SIGNED)
11+
- `/account/sub-account/main/v1/transfer-list` Get Sub-Account Transfer History, For Main Account (KEYED)
12+
- `/account/sub-account/v1/transfer-history` Get Account Transfer History, For Main and Sub Account (KEYED)
13+
- `/account/sub-account/main/v1/wallet` Get Sub-Account Spot Wallet Balance, For Main Account (KEYED)
14+
- `/account/sub-account/main/v1/subaccount-list` Get Sub-Account List, For Main Account (KEYED)
15+
- New (Futures Sub-Account)
16+
- `/account/contract/sub-account/main/v1/sub-to-main` Sub-Account to Main-Account, For Main Account (SIGNED)
17+
- `/account/contract/sub-account/sub/v1/sub-to-main` Sub-Account to Main-Account, For Sub Account (SIGNED)
18+
- `/account/contract/sub-account/main/v1/main-to-sub` Main-Account to Sub-Account, For Main Account (SIGNED)
19+
- `/account/contract/sub-account/main/v1/transfer-list` Get Sub-Account Transfer History, For Main Account (KEYED)
20+
- `/account/contract/sub-account/v1/transfer-history` Get Account Transfer History, For Main and Sub Account (KEYED)
21+
- `/account/contract/sub-account/main/v1/wallet` Get Sub-Account Futures Wallet Balance, For Main Account (KEYED)
22+
23+
24+
---
25+
426
### v2.6.0 Release
527
#### New Features
628
- New

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ bitmart/
2020
api_spot.py # APISpot — /spot/* REST (24 methods)
2121
api_contract.py # APIContract — /contract/* futures REST (39 methods)
2222
api_account.py # APIAccount — /account/* REST (13 methods)
23+
api_spot_sub_account.py # APISpotSubAccount — /account/sub-account/* spot (8 methods, api-cloud domain)
24+
api_contract_sub_account.py # APIContractSubAccount — /account/contract/sub-account/* futures (6 methods, api-cloud-v2 domain)
2325
api_margin_loan.py # APIMarginLoan — /spot/v1/margin/isolated/* (6 methods)
2426
api_broker.py # APIBroker — /spot/v1/broker/* (3 methods)
2527
api_system.py # APISystem — /system/* (3 methods)

bitmart/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.6.0"
1+
__version__ = "2.6.1"
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
from bitmart.lib.cloud_client import CloudClient
2+
from bitmart.lib.cloud_consts import *
3+
4+
5+
class APIContractSubAccount(CloudClient):
6+
7+
def __init__(self, api_key: str = "", secret_key: str = "", memo: str = "", url: str = API_V2_URL,
8+
timeout: tuple = TIMEOUT, headers=None, logger=None):
9+
"""
10+
Create api key from https://www.bitmart.com/api-config/en-US
11+
:param api_key: your access key
12+
:param secret_key: your secret key
13+
:param memo: your memo
14+
:param url: https://api-cloud-v2.bitmart.com
15+
:param timeout: (2, 10)
16+
"""
17+
CloudClient.__init__(self, api_key, secret_key, memo, url, timeout, headers, logger)
18+
19+
def post_sub_to_main(self, request_no: str, amount: str, currency: str, sub_account: str):
20+
"""Sub-Account to Main-Account Futures Asset Transfer (For Main Account) (SIGNED)
21+
Transfer from a sub-account futures wallet to the main-account futures wallet (for main account)
22+
23+
POST https://api-cloud-v2.bitmart.com/account/contract/sub-account/main/v1/sub-to-main
24+
25+
:param request_no: uuid or other universally unique identifier, max length 64
26+
:param amount: Transfer amount
27+
:param currency: Currency (only USDT supported currently)
28+
:param sub_account: Sub-account username
29+
:return:
30+
"""
31+
param = {
32+
'requestNo': request_no,
33+
'amount': amount,
34+
'currency': currency,
35+
'subAccount': sub_account
36+
}
37+
return self._request_with_params(POST, API_CONTRACT_SUB_TO_MAIN_URL, param, Auth.SIGNED)
38+
39+
def post_sub_to_main_from_sub_account(self, request_no: str, amount: str, currency: str):
40+
"""Sub-Account to Main-Account Futures Asset Transfer (For Sub Account) (SIGNED)
41+
Transfer from a sub-account futures wallet to the main-account futures wallet (for sub account)
42+
43+
POST https://api-cloud-v2.bitmart.com/account/contract/sub-account/sub/v1/sub-to-main
44+
45+
:param request_no: uuid or other universally unique identifier, max length 64
46+
:param amount: Transfer amount
47+
:param currency: Currency (only USDT supported currently)
48+
:return:
49+
"""
50+
param = {
51+
'requestNo': request_no,
52+
'amount': amount,
53+
'currency': currency
54+
}
55+
return self._request_with_params(POST, API_CONTRACT_SUB_TO_MAIN_FROM_SUB_URL, param, Auth.SIGNED)
56+
57+
def post_main_to_sub(self, request_no: str, amount: str, currency: str, sub_account: str):
58+
"""Main-Account to Sub-Account Futures Asset Transfer (For Main Account) (SIGNED)
59+
Transfer from the main-account futures wallet to a sub-account futures wallet (for main account)
60+
61+
POST https://api-cloud-v2.bitmart.com/account/contract/sub-account/main/v1/main-to-sub
62+
63+
:param request_no: uuid or other universally unique identifier, max length 64
64+
:param amount: Transfer amount
65+
:param currency: Currency (only USDT supported currently)
66+
:param sub_account: Sub-account username
67+
:return:
68+
"""
69+
param = {
70+
'requestNo': request_no,
71+
'amount': amount,
72+
'currency': currency,
73+
'subAccount': sub_account
74+
}
75+
return self._request_with_params(POST, API_CONTRACT_MAIN_TO_SUB_URL, param, Auth.SIGNED)
76+
77+
def get_sub_transfer_list(self, sub_account: str, limit: int):
78+
"""Get Sub-Account Futures Transfer History (For Main Account) (KEYED)
79+
Get the futures transfer history of a sub-account (for main account)
80+
81+
GET https://api-cloud-v2.bitmart.com/account/contract/sub-account/main/v1/transfer-list
82+
83+
:param sub_account: Sub-account username
84+
:param limit: Recent N records (value range 1-100)
85+
:return:
86+
"""
87+
param = {
88+
'subAccount': sub_account,
89+
'limit': limit
90+
}
91+
return self._request_with_params(GET, API_CONTRACT_SUB_TRANSFER_LIST_URL, param, Auth.KEYED)
92+
93+
def get_sub_transfer_history(self, limit: int):
94+
"""Get Account Futures Transfer History (For Main and Sub Account) (KEYED)
95+
Get account futures transfer history (for both main and sub account)
96+
97+
GET https://api-cloud-v2.bitmart.com/account/contract/sub-account/v1/transfer-history
98+
99+
:param limit: Recent N records (value range 1-100)
100+
:return:
101+
"""
102+
param = {
103+
'limit': limit
104+
}
105+
return self._request_with_params(GET, API_CONTRACT_SUB_TRANSFER_HISTORY_URL, param, Auth.KEYED)
106+
107+
def get_sub_wallet(self, sub_account: str, currency: str = None):
108+
"""Get Sub-Account Futures Wallet Balance (For Main Account) (KEYED)
109+
Get the futures wallet balance of a sub-account (for main account)
110+
111+
GET https://api-cloud-v2.bitmart.com/account/contract/sub-account/main/v1/wallet
112+
113+
:param sub_account: Sub-account username
114+
:param currency: Currency
115+
:return:
116+
"""
117+
param = {
118+
'subAccount': sub_account
119+
}
120+
121+
if currency:
122+
param['currency'] = currency
123+
124+
return self._request_with_params(GET, API_CONTRACT_SUB_WALLET_URL, param, Auth.KEYED)

bitmart/api_spot_sub_account.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
from bitmart.lib.cloud_client import CloudClient
2+
from bitmart.lib.cloud_consts import *
3+
4+
5+
class APISpotSubAccount(CloudClient):
6+
7+
def __init__(self, api_key: str = "", secret_key: str = "", memo: str = "", url: str = API_URL,
8+
timeout: tuple = TIMEOUT, headers=None, logger=None):
9+
"""
10+
Create api key from https://www.bitmart.com/api-config/en-US
11+
:param api_key: your access key
12+
:param secret_key: your secret key
13+
:param memo: your memo
14+
:param url: https://api-cloud.bitmart.com
15+
:param timeout: (2, 10)
16+
"""
17+
CloudClient.__init__(self, api_key, secret_key, memo, url, timeout, headers, logger)
18+
19+
def post_sub_to_main(self, request_no: str, amount: str, currency: str, sub_account: str):
20+
"""Sub-Account to Main-Account (For Main Account) (SIGNED)
21+
Transfer from a sub-account spot wallet to the main-account spot wallet (for main account)
22+
23+
POST https://api-cloud.bitmart.com/account/sub-account/main/v1/sub-to-main
24+
25+
:param request_no: uuid or other universally unique identifier, max length 64
26+
:param amount: Transfer amount
27+
:param currency: Currency
28+
:param sub_account: Sub-account username
29+
:return:
30+
"""
31+
param = {
32+
'requestNo': request_no,
33+
'amount': amount,
34+
'currency': currency,
35+
'subAccount': sub_account
36+
}
37+
return self._request_with_params(POST, API_ACCOUNT_SUB_TO_MAIN_URL, param, Auth.SIGNED)
38+
39+
def post_sub_to_main_from_sub_account(self, request_no: str, amount: str, currency: str):
40+
"""Sub-Account to Main-Account (For Sub Account) (SIGNED)
41+
Transfer from a sub-account spot wallet to the main-account spot wallet (for sub account)
42+
43+
POST https://api-cloud.bitmart.com/account/sub-account/sub/v1/sub-to-main
44+
45+
:param request_no: uuid or other universally unique identifier, max length 64
46+
:param amount: Transfer amount
47+
:param currency: Currency
48+
:return:
49+
"""
50+
param = {
51+
'requestNo': request_no,
52+
'amount': amount,
53+
'currency': currency
54+
}
55+
return self._request_with_params(POST, API_ACCOUNT_SUB_TO_MAIN_FROM_SUB_URL, param, Auth.SIGNED)
56+
57+
def post_main_to_sub(self, request_no: str, amount: str, currency: str, sub_account: str):
58+
"""Main-Account to Sub-Account (For Main Account) (SIGNED)
59+
Transfer from the main-account spot wallet to a sub-account spot wallet (for main account)
60+
61+
POST https://api-cloud.bitmart.com/account/sub-account/main/v1/main-to-sub
62+
63+
:param request_no: uuid or other universally unique identifier, max length 64
64+
:param amount: Transfer amount
65+
:param currency: Currency
66+
:param sub_account: Sub-account username
67+
:return:
68+
"""
69+
param = {
70+
'requestNo': request_no,
71+
'amount': amount,
72+
'currency': currency,
73+
'subAccount': sub_account
74+
}
75+
return self._request_with_params(POST, API_ACCOUNT_MAIN_TO_SUB_URL, param, Auth.SIGNED)
76+
77+
def post_sub_to_sub(self, request_no: str, amount: str, currency: str, from_account: str, to_account: str):
78+
"""Sub-Account to Sub-Account (For Main Account) (SIGNED)
79+
Transfer from a sub-account spot wallet to another sub-account spot wallet (for main account)
80+
81+
POST https://api-cloud.bitmart.com/account/sub-account/main/v1/sub-to-sub
82+
83+
:param request_no: uuid or other universally unique identifier, max length 64
84+
:param amount: Transfer amount
85+
:param currency: Currency
86+
:param from_account: Transfer-out sub-account username
87+
:param to_account: Transfer-in sub-account username
88+
:return:
89+
"""
90+
param = {
91+
'requestNo': request_no,
92+
'amount': amount,
93+
'currency': currency,
94+
'fromAccount': from_account,
95+
'toAccount': to_account
96+
}
97+
return self._request_with_params(POST, API_ACCOUNT_SUB_TO_SUB_URL, param, Auth.SIGNED)
98+
99+
def get_sub_transfer_list(self, move_type: str, n: int, account_name: str = None):
100+
"""Get Sub-Account Transfer History (For Main Account) (KEYED)
101+
Get the transfer history of sub-accounts (for main account)
102+
103+
GET https://api-cloud.bitmart.com/account/sub-account/main/v1/transfer-list
104+
105+
:param move_type: Transfer type, e.g. 'spot to spot'
106+
:param n: Recent N records (value range 1-100)
107+
:param account_name: Sub-account username (default: query all sub-accounts)
108+
:return:
109+
"""
110+
param = {
111+
'moveType': move_type,
112+
'N': n
113+
}
114+
115+
if account_name:
116+
param['accountName'] = account_name
117+
118+
return self._request_with_params(GET, API_ACCOUNT_SUB_TRANSFER_LIST_URL, param, Auth.KEYED)
119+
120+
def get_account_transfer_history(self, move_type: str, n: int):
121+
"""Get Account Transfer History (For Main and Sub Account) (KEYED)
122+
Get account transfer history (for both main and sub account)
123+
124+
GET https://api-cloud.bitmart.com/account/sub-account/v1/transfer-history
125+
126+
:param move_type: Transfer type, e.g. 'spot to spot'
127+
:param n: Recent N records (value range 1-100)
128+
:return:
129+
"""
130+
param = {
131+
'moveType': move_type,
132+
'N': n
133+
}
134+
return self._request_with_params(GET, API_ACCOUNT_SUB_TRANSFER_HISTORY_URL, param, Auth.KEYED)
135+
136+
def get_sub_spot_wallet(self, sub_account: str, currency: str = None):
137+
"""Get Sub-Account Spot Wallet Balance (For Main Account) (KEYED)
138+
Get the spot wallet balance of a sub-account (for main account)
139+
140+
GET https://api-cloud.bitmart.com/account/sub-account/main/v1/wallet
141+
142+
:param sub_account: Sub-account username
143+
:param currency: Currency
144+
:return:
145+
"""
146+
param = {
147+
'subAccount': sub_account
148+
}
149+
150+
if currency:
151+
param['currency'] = currency
152+
153+
return self._request_with_params(GET, API_ACCOUNT_SUB_WALLET_URL, param, Auth.KEYED)
154+
155+
def get_sub_account_list(self):
156+
"""Get Sub-Account List (For Main Account) (KEYED)
157+
Get the list of sub-accounts (for main account)
158+
159+
GET https://api-cloud.bitmart.com/account/sub-account/main/v1/subaccount-list
160+
161+
:return:
162+
"""
163+
return self._request_without_params(GET, API_ACCOUNT_SUB_LIST_URL, Auth.KEYED)

bitmart/lib/cloud_consts.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
API_ACCOUNT_DEPOSIT_WITHDRAW_HISTORY_V2_URL = '/account/v2/deposit-withdraw/history'
3838
API_ACCOUNT_DEPOSIT_WITHDRAW_DETAIL = '/account/v1/deposit-withdraw/detail'
3939

40+
# spot sub-account url
41+
API_ACCOUNT_SUB_TO_MAIN_URL = '/account/sub-account/main/v1/sub-to-main'
42+
API_ACCOUNT_SUB_TO_MAIN_FROM_SUB_URL = '/account/sub-account/sub/v1/sub-to-main'
43+
API_ACCOUNT_MAIN_TO_SUB_URL = '/account/sub-account/main/v1/main-to-sub'
44+
API_ACCOUNT_SUB_TO_SUB_URL = '/account/sub-account/main/v1/sub-to-sub'
45+
API_ACCOUNT_SUB_TRANSFER_LIST_URL = '/account/sub-account/main/v1/transfer-list'
46+
API_ACCOUNT_SUB_TRANSFER_HISTORY_URL = '/account/sub-account/v1/transfer-history'
47+
API_ACCOUNT_SUB_WALLET_URL = '/account/sub-account/main/v1/wallet'
48+
API_ACCOUNT_SUB_LIST_URL = '/account/sub-account/main/v1/subaccount-list'
49+
4050
# spot url
4151
API_SPOT_CURRENCIES_URL = '/spot/v1/currencies'
4252
API_SPOT_SYMBOLS_URL = '/spot/v1/symbols'
@@ -144,6 +154,14 @@
144154
API_CONTRACT_AFFILIATE_REBATE_LIST_URL = "/contract/private/affiliate/rebate-list"
145155
API_CONTRACT_AFFILIATE_TRADE_LIST_URL = "/contract/private/affiliate/trade-list"
146156

157+
# contract sub-account url
158+
API_CONTRACT_SUB_TO_MAIN_URL = "/account/contract/sub-account/main/v1/sub-to-main"
159+
API_CONTRACT_SUB_TO_MAIN_FROM_SUB_URL = "/account/contract/sub-account/sub/v1/sub-to-main"
160+
API_CONTRACT_MAIN_TO_SUB_URL = "/account/contract/sub-account/main/v1/main-to-sub"
161+
API_CONTRACT_SUB_TRANSFER_LIST_URL = "/account/contract/sub-account/main/v1/transfer-list"
162+
API_CONTRACT_SUB_TRANSFER_HISTORY_URL = "/account/contract/sub-account/v1/transfer-history"
163+
API_CONTRACT_SUB_WALLET_URL = "/account/contract/sub-account/main/v1/wallet"
164+
147165

148166
# websocket
149167
# spot public

0 commit comments

Comments
 (0)