|
| 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) |
0 commit comments