|
| 1 | +from bitmart.lib.cloud_client import CloudClient |
| 2 | +from bitmart.lib.cloud_consts import * |
| 3 | + |
| 4 | + |
| 5 | +class APIFinance(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 | + # ---------- Assets ---------- |
| 20 | + |
| 21 | + def get_earn_assets(self): |
| 22 | + """Get Earn Account Holdings (KEYED) |
| 23 | + Query the holdings of the finance (earn) account |
| 24 | +
|
| 25 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/earn |
| 26 | +
|
| 27 | + :return: |
| 28 | + """ |
| 29 | + return self._request_without_params(GET, API_FINANCE_EARN_URL, Auth.KEYED) |
| 30 | + |
| 31 | + # ---------- Flexible Savings ---------- |
| 32 | + |
| 33 | + def get_savings_product(self, current_page: int, size_page: int, coin_name: str = None): |
| 34 | + """Get Flexible Savings Product List (KEYED) |
| 35 | + Query the flexible savings product list |
| 36 | +
|
| 37 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/product |
| 38 | +
|
| 39 | + :param current_page: Current page number |
| 40 | + :param size_page: Records per page, max 100 |
| 41 | + :param coin_name: Filter by coin name (e.g. USDT) |
| 42 | + :return: |
| 43 | + """ |
| 44 | + param = { |
| 45 | + 'currentPage': current_page, |
| 46 | + 'sizePage': size_page |
| 47 | + } |
| 48 | + |
| 49 | + if coin_name: |
| 50 | + param['coinName'] = coin_name |
| 51 | + |
| 52 | + return self._request_with_params(GET, API_FINANCE_SAVING_PRODUCT_URL, param, Auth.KEYED) |
| 53 | + |
| 54 | + def post_savings_subscribe(self, product_id: str, amount: str, request_no: str): |
| 55 | + """Subscribe Flexible Savings (SIGNED) |
| 56 | + Subscribe to a flexible savings product |
| 57 | +
|
| 58 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/subscribe |
| 59 | +
|
| 60 | + :param product_id: Product ID |
| 61 | + :param amount: Subscribe amount |
| 62 | + :param request_no: Unique request number, 20-digit numeric, used for idempotency |
| 63 | + :return: |
| 64 | + """ |
| 65 | + param = { |
| 66 | + 'productId': product_id, |
| 67 | + 'amount': amount, |
| 68 | + 'requestNo': request_no |
| 69 | + } |
| 70 | + return self._request_with_params(POST, API_FINANCE_SAVING_SUBSCRIBE_URL, param, Auth.SIGNED) |
| 71 | + |
| 72 | + def post_savings_redeem(self, earn_id: str, amount: str, request_no: str): |
| 73 | + """Redeem Flexible Savings (SIGNED) |
| 74 | + Redeem a flexible savings holding |
| 75 | +
|
| 76 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/redeem |
| 77 | +
|
| 78 | + :param earn_id: Earn order ID |
| 79 | + :param amount: Redeem amount |
| 80 | + :param request_no: Unique request number, 20-digit numeric, used for idempotency |
| 81 | + :return: |
| 82 | + """ |
| 83 | + param = { |
| 84 | + 'earnId': earn_id, |
| 85 | + 'amount': amount, |
| 86 | + 'requestNo': request_no |
| 87 | + } |
| 88 | + return self._request_with_params(POST, API_FINANCE_SAVING_REDEEM_URL, param, Auth.SIGNED) |
| 89 | + |
| 90 | + def get_savings_holdings(self, current_page: int, size_page: int, coin_name: str = None, product_id: str = None): |
| 91 | + """Get Flexible Savings Holdings (KEYED) |
| 92 | + Query flexible savings holdings |
| 93 | +
|
| 94 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/earn |
| 95 | +
|
| 96 | + :param current_page: Current page number |
| 97 | + :param size_page: Records per page, max 100 |
| 98 | + :param coin_name: Filter by coin name (e.g. USDT) |
| 99 | + :param product_id: Filter by product ID |
| 100 | + :return: |
| 101 | + """ |
| 102 | + param = { |
| 103 | + 'currentPage': current_page, |
| 104 | + 'sizePage': size_page |
| 105 | + } |
| 106 | + |
| 107 | + if coin_name: |
| 108 | + param['coinName'] = coin_name |
| 109 | + |
| 110 | + if product_id: |
| 111 | + param['productId'] = product_id |
| 112 | + |
| 113 | + return self._request_with_params(GET, API_FINANCE_SAVING_EARN_URL, param, Auth.KEYED) |
| 114 | + |
| 115 | + def get_savings_records(self, type: str, current_page: int, size_page: int, |
| 116 | + start_time: int = None, end_time: int = None, coin_name: str = None): |
| 117 | + """Get Flexible Savings History Records (KEYED) |
| 118 | + Query flexible savings history records |
| 119 | +
|
| 120 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/record |
| 121 | +
|
| 122 | + :param type: Record type |
| 123 | + - subscribe |
| 124 | + - redeem |
| 125 | + - interest |
| 126 | + :param current_page: Current page number |
| 127 | + :param size_page: Records per page, max 100 |
| 128 | + :param start_time: Start time in milliseconds |
| 129 | + :param end_time: End time in milliseconds |
| 130 | + :param coin_name: Filter by coin name (e.g. USDT) |
| 131 | + :return: |
| 132 | + """ |
| 133 | + param = { |
| 134 | + 'type': type, |
| 135 | + 'currentPage': current_page, |
| 136 | + 'sizePage': size_page |
| 137 | + } |
| 138 | + |
| 139 | + if start_time: |
| 140 | + param['startTime'] = start_time |
| 141 | + |
| 142 | + if end_time: |
| 143 | + param['endTime'] = end_time |
| 144 | + |
| 145 | + if coin_name: |
| 146 | + param['coinName'] = coin_name |
| 147 | + |
| 148 | + return self._request_with_params(GET, API_FINANCE_SAVING_RECORD_URL, param, Auth.KEYED) |
| 149 | + |
| 150 | + # ---------- Fixed Savings ---------- |
| 151 | + |
| 152 | + def get_fixed_product(self, current_page: int, size_page: int, coin_name: str = None): |
| 153 | + """Get Fixed Savings Product List (KEYED) |
| 154 | + Query the fixed savings product list |
| 155 | +
|
| 156 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/fixed/product |
| 157 | +
|
| 158 | + :param current_page: Current page number, default 1 |
| 159 | + :param size_page: Records per page, default 1, max 100 |
| 160 | + :param coin_name: Coin name |
| 161 | + :return: |
| 162 | + """ |
| 163 | + param = { |
| 164 | + 'currentPage': current_page, |
| 165 | + 'sizePage': size_page |
| 166 | + } |
| 167 | + |
| 168 | + if coin_name: |
| 169 | + param['coinName'] = coin_name |
| 170 | + |
| 171 | + return self._request_with_params(GET, API_FINANCE_FIXED_PRODUCT_URL, param, Auth.KEYED) |
| 172 | + |
| 173 | + def post_fixed_subscribe(self, product_id: str, amount: str, request_no: str, auto_subscribe: str): |
| 174 | + """Subscribe Fixed Savings (SIGNED) |
| 175 | + Subscribe to a fixed savings product |
| 176 | +
|
| 177 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/fixed/subscribe |
| 178 | +
|
| 179 | + :param product_id: Product ID |
| 180 | + :param amount: Subscribe amount |
| 181 | + :param request_no: Unique request number, length 20, numeric 0-9 |
| 182 | + :param auto_subscribe: Auto subscribe type |
| 183 | + - OFF |
| 184 | + - REINVEST_FLEXIBLE |
| 185 | + - REINVEST_FIXED |
| 186 | + :return: |
| 187 | + """ |
| 188 | + param = { |
| 189 | + 'productId': product_id, |
| 190 | + 'amount': amount, |
| 191 | + 'requestNo': request_no, |
| 192 | + 'autoSubscribe': auto_subscribe |
| 193 | + } |
| 194 | + return self._request_with_params(POST, API_FINANCE_FIXED_SUBSCRIBE_URL, param, Auth.SIGNED) |
| 195 | + |
| 196 | + def get_fixed_holdings(self, current_page: int, size_page: int, coin_name: str = None, product_id: str = None): |
| 197 | + """Get Fixed Savings Holdings (KEYED) |
| 198 | + Query fixed savings holdings |
| 199 | +
|
| 200 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/fixed/earn |
| 201 | +
|
| 202 | + :param current_page: Current page number, default 1 |
| 203 | + :param size_page: Records per page, default 1, max 100 |
| 204 | + :param coin_name: Coin name |
| 205 | + :param product_id: Product ID |
| 206 | + :return: |
| 207 | + """ |
| 208 | + param = { |
| 209 | + 'currentPage': current_page, |
| 210 | + 'sizePage': size_page |
| 211 | + } |
| 212 | + |
| 213 | + if coin_name: |
| 214 | + param['coinName'] = coin_name |
| 215 | + |
| 216 | + if product_id: |
| 217 | + param['productId'] = product_id |
| 218 | + |
| 219 | + return self._request_with_params(GET, API_FINANCE_FIXED_EARN_URL, param, Auth.KEYED) |
| 220 | + |
| 221 | + def get_fixed_records(self, type: str, current_page: int, size_page: int, |
| 222 | + start_time: int = None, end_time: int = None, coin_name: str = None): |
| 223 | + """Get Fixed Savings History Records (KEYED) |
| 224 | + Query fixed savings history records |
| 225 | +
|
| 226 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/fixed/record |
| 227 | +
|
| 228 | + :param type: Record type |
| 229 | + - subscribe |
| 230 | + - redeem |
| 231 | + - interest |
| 232 | + :param current_page: Current page number, default 1 |
| 233 | + :param size_page: Records per page, default 1, max 100 |
| 234 | + :param start_time: Start time in milliseconds (e.g. 1681701557927) |
| 235 | + :param end_time: End time in milliseconds (e.g. 1681701557927) |
| 236 | + :param coin_name: Coin name |
| 237 | + :return: |
| 238 | + """ |
| 239 | + param = { |
| 240 | + 'type': type, |
| 241 | + 'currentPage': current_page, |
| 242 | + 'sizePage': size_page |
| 243 | + } |
| 244 | + |
| 245 | + if start_time: |
| 246 | + param['startTime'] = start_time |
| 247 | + |
| 248 | + if end_time: |
| 249 | + param['endTime'] = end_time |
| 250 | + |
| 251 | + if coin_name: |
| 252 | + param['coinName'] = coin_name |
| 253 | + |
| 254 | + return self._request_with_params(GET, API_FINANCE_FIXED_RECORD_URL, param, Auth.KEYED) |
| 255 | + |
| 256 | + def post_fixed_redeem(self, earn_id: str, request_no: str): |
| 257 | + """Early Redeem Fixed Savings (SIGNED) |
| 258 | + Redeem a fixed savings holding ahead of maturity |
| 259 | +
|
| 260 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/fixed/redeem |
| 261 | +
|
| 262 | + :param earn_id: Earn order ID |
| 263 | + :param request_no: Unique request number, length 20, numeric 0-9 |
| 264 | + :return: |
| 265 | + """ |
| 266 | + param = { |
| 267 | + 'earnId': earn_id, |
| 268 | + 'requestNo': request_no |
| 269 | + } |
| 270 | + return self._request_with_params(POST, API_FINANCE_FIXED_REDEEM_URL, param, Auth.SIGNED) |
| 271 | + |
| 272 | + def post_fixed_modify_auto_renewal(self, earn_id: str, auto_subscribe: str): |
| 273 | + """Modify Fixed Savings Auto-Renewal (SIGNED) |
| 274 | + Modify the auto-renewal (auto reinvest) setting of a fixed savings order |
| 275 | +
|
| 276 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/fixed/subscribe/operate |
| 277 | +
|
| 278 | + :param earn_id: Earn order ID |
| 279 | + :param auto_subscribe: Auto subscribe type |
| 280 | + - OFF |
| 281 | + - REINVEST_FLEXIBLE |
| 282 | + - REINVEST_FIXED |
| 283 | + :return: |
| 284 | + """ |
| 285 | + param = { |
| 286 | + 'earnId': earn_id, |
| 287 | + 'autoSubscribe': auto_subscribe |
| 288 | + } |
| 289 | + return self._request_with_params(POST, API_FINANCE_FIXED_SUBSCRIBE_OPERATE_URL, param, Auth.SIGNED) |
| 290 | + |
| 291 | + # ---------- Auto Earn ---------- |
| 292 | + |
| 293 | + def post_auto_subscribe_toggle(self, auto_subscribe: str): |
| 294 | + """Toggle Global Auto Earn (SIGNED) |
| 295 | + Enable or disable the global auto subscribe for flexible savings |
| 296 | +
|
| 297 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/subscribe/batch/operate |
| 298 | +
|
| 299 | + :param auto_subscribe: Auto subscribe switch |
| 300 | + - open |
| 301 | + - close |
| 302 | + :return: |
| 303 | + """ |
| 304 | + param = { |
| 305 | + 'autoSubscribe': auto_subscribe |
| 306 | + } |
| 307 | + return self._request_with_params(POST, API_FINANCE_SAVING_SUBSCRIBE_BATCH_OPERATE_URL, param, Auth.SIGNED) |
| 308 | + |
| 309 | + def get_auto_subscribe_status(self): |
| 310 | + """Get Global Auto Earn Status (KEYED) |
| 311 | + Query the global auto subscribe status |
| 312 | +
|
| 313 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/subscribe/batch |
| 314 | +
|
| 315 | + :return: |
| 316 | + """ |
| 317 | + return self._request_without_params(GET, API_FINANCE_SAVING_SUBSCRIBE_BATCH_URL, Auth.KEYED) |
| 318 | + |
| 319 | + def post_flexible_auto_subscribe_toggle(self, product_id: str, auto_subscribe: str): |
| 320 | + """Toggle Flexible Product Auto Subscribe (SIGNED) |
| 321 | + Enable or disable auto subscribe for a specific flexible savings product |
| 322 | +
|
| 323 | + POST https://api-cloud.bitmart.com/newearn/cloud/v1/saving/subscribe/operate |
| 324 | +
|
| 325 | + :param product_id: Product ID |
| 326 | + :param auto_subscribe: Auto subscribe switch |
| 327 | + - open |
| 328 | + - close |
| 329 | + :return: |
| 330 | + """ |
| 331 | + param = { |
| 332 | + 'productId': product_id, |
| 333 | + 'autoSubscribe': auto_subscribe |
| 334 | + } |
| 335 | + return self._request_with_params(POST, API_FINANCE_SAVING_SUBSCRIBE_OPERATE_URL, param, Auth.SIGNED) |
| 336 | + |
| 337 | + def get_flexible_auto_subscribe_status(self, product_id: str): |
| 338 | + """Get Flexible Product Auto Subscribe Status (KEYED) |
| 339 | + Query the auto subscribe status of a specific flexible savings product |
| 340 | +
|
| 341 | + GET https://api-cloud.bitmart.com/newearn/cloud/v1/saving/subscribe/status |
| 342 | +
|
| 343 | + :param product_id: Product ID |
| 344 | + :return: |
| 345 | + """ |
| 346 | + param = { |
| 347 | + 'productId': product_id |
| 348 | + } |
| 349 | + return self._request_with_params(GET, API_FINANCE_SAVING_SUBSCRIBE_STATUS_URL, param, Auth.KEYED) |
0 commit comments