From b5bf6f2791018f119c79f8eb349788e39f16ac71 Mon Sep 17 00:00:00 2001 From: Jeremy <365354+2pd@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:02:34 +1100 Subject: [PATCH] Rc v3.6.0 (#290) * Fix typo (`loa*n*` vs `loa*d*`) (#275) * typo:spot/_auto_invest.py/get_target_asset_list (#278) * update margin endpoints * fix date typo --------- Co-authored-by: futpib Co-authored-by: Vasu <62256006+vasudevvaka@users.noreply.github.com> --- CHANGELOG.md | 26 ++ binance/spot/__init__.py | 15 +- binance/spot/_auto_invest.py | 2 +- binance/spot/_margin.py | 328 +++--------------- docs/source/CHANGELOG.rst | 37 +- docs/source/binance.spot.margin.rst | 48 +-- ...in_transfer_history.py => borrow_repay.py} | 5 +- ...margin_asset.py => borrow_repay_record.py} | 2 +- examples/spot/margin/dust_transfer.py | 25 -- ...t_assets_that_can_be_converted_into_bnb.py | 25 -- examples/spot/margin/isolated_margin_pair.py | 13 - .../spot/margin/isolated_margin_transfer.py | 21 -- examples/spot/margin/margin_borrow.py | 13 - examples/spot/margin/margin_dust_log.py | 23 -- examples/spot/margin/margin_load_record.py | 13 - examples/spot/margin/margin_pair.py | 13 - examples/spot/margin/margin_repay.py | 13 - examples/spot/margin/margin_repay_record.py | 13 - examples/spot/margin/margin_transfer.py | 13 - tests/spot/margin/test_borrow_repay.py | 85 +++++ tests/spot/margin/test_borrow_repay_record.py | 34 ++ tests/spot/margin/test_dust_transfer.py | 30 -- ...t_assets_that_can_be_converted_into_bnb.py | 30 -- .../spot/margin/test_isolated_margin_pair.py | 36 -- .../margin/test_isolated_margin_transfer.py | 115 ------ .../test_isolated_margin_transfer_history.py | 43 --- tests/spot/margin/test_margin_asset.py | 35 -- tests/spot/margin/test_margin_borrow.py | 46 --- tests/spot/margin/test_margin_dust_log.py | 28 -- tests/spot/margin/test_margin_load_record.py | 34 -- tests/spot/margin/test_margin_pair.py | 32 -- tests/spot/margin/test_margin_repay.py | 44 --- tests/spot/margin/test_margin_repay_record.py | 34 -- tests/spot/margin/test_margin_transfer.py | 56 --- 34 files changed, 243 insertions(+), 1087 deletions(-) rename examples/spot/margin/{isolated_margin_transfer_history.py => borrow_repay.py} (70%) rename examples/spot/margin/{margin_asset.py => borrow_repay_record.py} (83%) delete mode 100644 examples/spot/margin/dust_transfer.py delete mode 100644 examples/spot/margin/get_assets_that_can_be_converted_into_bnb.py delete mode 100644 examples/spot/margin/isolated_margin_pair.py delete mode 100644 examples/spot/margin/isolated_margin_transfer.py delete mode 100644 examples/spot/margin/margin_borrow.py delete mode 100644 examples/spot/margin/margin_dust_log.py delete mode 100644 examples/spot/margin/margin_load_record.py delete mode 100644 examples/spot/margin/margin_pair.py delete mode 100644 examples/spot/margin/margin_repay.py delete mode 100644 examples/spot/margin/margin_repay_record.py delete mode 100644 examples/spot/margin/margin_transfer.py create mode 100644 tests/spot/margin/test_borrow_repay.py create mode 100644 tests/spot/margin/test_borrow_repay_record.py delete mode 100644 tests/spot/margin/test_dust_transfer.py delete mode 100644 tests/spot/margin/test_get_assets_that_can_be_converted_into_bnb.py delete mode 100644 tests/spot/margin/test_isolated_margin_pair.py delete mode 100644 tests/spot/margin/test_isolated_margin_transfer.py delete mode 100644 tests/spot/margin/test_isolated_margin_transfer_history.py delete mode 100644 tests/spot/margin/test_margin_asset.py delete mode 100644 tests/spot/margin/test_margin_borrow.py delete mode 100644 tests/spot/margin/test_margin_dust_log.py delete mode 100644 tests/spot/margin/test_margin_load_record.py delete mode 100644 tests/spot/margin/test_margin_pair.py delete mode 100644 tests/spot/margin/test_margin_repay.py delete mode 100644 tests/spot/margin/test_margin_repay_record.py delete mode 100644 tests/spot/margin/test_margin_transfer.py diff --git a/CHANGELOG.md b/CHANGELOG.md index ab266c71..2f515043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Changelog +## 3.6.0 - 2024-01-22 +### Removed +- `POST /sapi/v1/margin/transfer` +- `POST /sapi/v1/margin/isolated/transfer` +- `POST /sapi/v1/margin/loan` +- `POST /sapi/v1/margin/repay` +- `GET /sapi/v1/margin/isolated/transfer` +- `GET /sapi/v1/margin/asset` +- `GET /sapi/v1/margin/pair` +- `GET /sapi/v1/margin/isolated/pair` +- `GET /sapi/v1/margin/loan` +- `GET /sapi/v1/margin/repay` +- `GET /sapi/v1/margin/dribblet` +- `GET /sapi/v1/margin/dust` +- `POST /sapi/v1/margin/dust` + +### Added +- `POST /sapi/v1/margin/borrow-repay` +- `GET /sapi/v1/margin/borrow-repay` + +### Updated +- `GET /sapi/v1/margin/transfer` add parameter `isolatedSymbol` +- `GET /sapi/v1/margin/allAssets` add parameter `asset` +- `GET /sapi/v1/margin/allPairs` add parameter `symbol` +- `GET /sapi/v1/margin/isolated/allPairs` add parameter `symbol` + ## 3.5.1 - 2023-11-17 ### Fixed - Set the default timeout value to None in WebSocket clients diff --git a/binance/spot/__init__.py b/binance/spot/__init__.py index 5bee31aa..e70930ab 100644 --- a/binance/spot/__init__.py +++ b/binance/spot/__init__.py @@ -54,19 +54,14 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._data_stream import close_isolated_margin_listen_key # MARGIN - from binance.spot._margin import margin_transfer - from binance.spot._margin import margin_borrow - from binance.spot._margin import margin_repay - from binance.spot._margin import margin_asset - from binance.spot._margin import margin_pair + from binance.spot._margin import borrow_repay from binance.spot._margin import margin_all_assets from binance.spot._margin import margin_all_pairs from binance.spot._margin import margin_pair_index from binance.spot._margin import new_margin_order from binance.spot._margin import cancel_margin_order from binance.spot._margin import margin_transfer_history - from binance.spot._margin import margin_load_record - from binance.spot._margin import margin_repay_record + from binance.spot._margin import borrow_repay_record from binance.spot._margin import margin_interest_history from binance.spot._margin import margin_force_liquidation_record from binance.spot._margin import margin_account @@ -77,10 +72,7 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._margin import margin_my_trades from binance.spot._margin import margin_max_borrowable from binance.spot._margin import margin_max_transferable - from binance.spot._margin import isolated_margin_transfer - from binance.spot._margin import isolated_margin_transfer_history from binance.spot._margin import isolated_margin_account - from binance.spot._margin import isolated_margin_pair from binance.spot._margin import isolated_margin_all_pairs from binance.spot._margin import toggle_bnbBurn from binance.spot._margin import bnbBurn_status @@ -97,14 +89,11 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._margin import isolated_margin_fee from binance.spot._margin import isolated_margin_tier from binance.spot._margin import margin_order_usage - from binance.spot._margin import margin_dust_log from binance.spot._margin import summary_of_margin_account from binance.spot._margin import cross_margin_collateral_ratio from binance.spot._margin import get_small_liability_exchange_coin_list from binance.spot._margin import get_small_liability_exchange_history from binance.spot._margin import get_a_future_hourly_interest_rate - from binance.spot._margin import get_assets_that_can_be_converted_into_bnb - from binance.spot._margin import dust_transfer from binance.spot._margin import adjust_cross_margin_max_leverage # Staking diff --git a/binance/spot/_auto_invest.py b/binance/spot/_auto_invest.py index f0496d54..6eb2ad0b 100644 --- a/binance/spot/_auto_invest.py +++ b/binance/spot/_auto_invest.py @@ -13,7 +13,7 @@ def get_target_asset_list(self, **kwargs): Keyword Args: targetAsset (str) - size (int, optional): Default:10 Max:100 + size (int, optional): Default:8 Max:100 current (int, optional): Current querying page. Start from 1. Default:1 recvWindow (int, optional): The value cannot be greater than 60000 """ diff --git a/binance/spot/_margin.py b/binance/spot/_margin.py index 5bc0c03f..da6aa946 100644 --- a/binance/spot/_margin.py +++ b/binance/spot/_margin.py @@ -3,132 +3,75 @@ from binance.error import ParameterArgumentError -def margin_transfer(self, asset: str, amount, type: int, **kwargs): - """Margin Account Transfer (MARGIN) - Execute transfer between spot account and margin account. - - POST /sapi/v1/margin/transfer - - https://binance-docs.github.io/apidocs/spot/en/#margin-account-transfer-margin - - Args: - asset (str): The asset being transferred, e.g., BTC. - amount (float): The amount to be transferred - type (int): 1: transfer from main account to cross margin account - 2: transfer from cross margin account to main account - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters([[asset, "asset"], [amount, "amount"], [type, "type"]]) - - payload = {"asset": asset, "amount": amount, "type": type, **kwargs} - return self.sign_request("POST", "/sapi/v1/margin/transfer", payload) - - -def margin_borrow(self, asset: str, amount, **kwargs): - """Margin Account Borrow (MARGIN) - Apply for a loan. - - POST /sapi/v1/margin/loan - - https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-margin - - Args: - asset (str): The asset being transferred, e.g., BTC. - amount (float): The amount to be transferred - Keyword Args: - isIsolated (str, optional): for isolated margin or not,"TRUE", "FALSE",default "FALSE". - symbol (str, optional): isolated symbol - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters([[asset, "asset"], [amount, "amount"]]) - - payload = {"asset": asset, "amount": amount, **kwargs} - return self.sign_request("POST", "/sapi/v1/margin/loan", payload) - +def borrow_repay( + self, asset: str, isIsolated: str, symbol: str, amount, type: str, **kwargs +): + """Margin account borrow/repay (MARGIN) -def margin_repay(self, asset: str, amount, **kwargs): - """Margin Account Repay(MARGIN) - Repay loan for margin account. + Margin account borrow/repay(MARGIN) - POST /sapi/v1/margin/repay + POST /sapi/v1/margin/borrow-repay - https://binance-docs.github.io/apidocs/spot/en/#margin-account-repay-margin + https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-repay-margin Args: asset (str): The asset being transferred, e.g., BTC. - amount (float): The amount to be transferred + isIsolated (str): for isolated margin or not,"TRUE", "FALSE", default "FALSE". + symbol (str): isolated symbol + amount (float): + type (str): BORROW or REPAY Keyword Args: - isIsolated (str, optional): for isolated margin or not,"TRUE", "FALSE",default "FALSE". - symbol (str, optional): isolated symbol recvWindow (int, optional): The value cannot be greater than 60000 """ - check_required_parameters([[asset, "asset"], [amount, "amount"]]) - - payload = {"asset": asset, "amount": amount, **kwargs} - return self.sign_request("POST", "/sapi/v1/margin/repay", payload) - - -def margin_asset(self, asset: str): - """Query Margin Asset (MARKET_DATA) - - GET /sapi/v1/margin/asset - - https://binance-docs.github.io/apidocs/spot/en/#query-margin-asset-market_data - - Args: - asset (str): The asset being transferred, e.g., BTC. - - """ - - check_required_parameter(asset, "asset") - - payload = {"asset": asset} - return self.limit_request("GET", "/sapi/v1/margin/asset", payload) - - -def margin_pair(self, symbol: str): - """Query Margin Pair (MARKET_DATA) - - GET /sapi/v1/margin/pair - - https://binance-docs.github.io/apidocs/spot/en/#query-margin-pair-market_data - - Args: - symbol (str) - """ - - check_required_parameter(symbol, "symbol") + check_required_parameters( + [ + [asset, "asset"], + [amount, "amount"], + [type, "type"], + [isIsolated, "isIsolated"], + [symbol, "symbol"], + ] + ) - payload = {"symbol": symbol} - return self.limit_request("GET", "/sapi/v1/margin/pair", payload) + payload = { + "asset": asset, + "amount": amount, + "type": type, + "isIsolated": isIsolated, + "symbol": symbol, + **kwargs, + } + return self.sign_request("POST", "/sapi/v1/margin/borrow-repay", payload) -def margin_all_assets(self): +def margin_all_assets(self, **kwargs): """Get All Margin Assets (MARKET_DATA) GET /sapi/v1/margin/allAssets https://binance-docs.github.io/apidocs/spot/en/#get-all-margin-assets-market_data + + Keyword Args: + asset (str, optional) """ - return self.limit_request("GET", "/sapi/v1/margin/allAssets") + return self.limit_request("GET", "/sapi/v1/margin/allAssets", kwargs) -def margin_all_pairs(self): +def margin_all_pairs(self, **kwargs): """Get All Margin Pairs (MARKET_DATA) GET /sapi/v1/margin/allPairs https://binance-docs.github.io/apidocs/spot/en/#get-all-margin-pairs-market_data + Keyword Args: + symbol (str, optional) """ - return self.limit_request("GET", "/sapi/v1/margin/allPairs") + return self.limit_request("GET", "/sapi/v1/margin/allPairs", kwargs) def margin_pair_index(self, symbol: str, **kwargs): @@ -225,7 +168,7 @@ def margin_transfer_history(self, asset: str, **kwargs): endTime (int, optional) current (int, optional): Currently querying page. Start from 1. Default:1 size (int, optional): Default:10 Max:100 - archived (str, optional): Default: false. Set to true for archived data from 6 months ago + isolatedSymbol (str, optional): Symbol in Isolated Margin recvWindow (int, optional): The value cannot be greater than 60000 """ check_required_parameter(asset, "asset") @@ -233,54 +176,29 @@ def margin_transfer_history(self, asset: str, **kwargs): return self.sign_request("GET", "/sapi/v1/margin/transfer", payload) -def margin_load_record(self, asset: str, **kwargs): - """Query Loan Record (USER_DATA) +def borrow_repay_record(self, type: str, **kwargs): + """Query borrow/repay records in Margin account (USER_DATA) - GET /sapi/v1/margin/loan + GET /sapi/v1/margin/borrow-repay - https://binance-docs.github.io/apidocs/spot/en/#query-loan-record-user_data + https://binance-docs.github.io/apidocs/spot/en/#query-borrow-repay-records-in-margin-account-user_data Args: - asset (str) + type (str): BORROW or REPAY Keyword Args: + asset (str, optional) isolatedSymbol (str, optional): isolated symbol txId (int, optional): the tranId in POST /sapi/v1/margin/loan startTime (int, optional) endTime (int, optional) current (int, optional): Currently querying page. Start from 1. Default:1 size (int, optional): Default:10 Max:100 - archived (str, optional): Default: false. Set to true for archived data from 6 months ago recvWindow (int, optional): The value cannot be greater than 60000 """ - check_required_parameter(asset, "asset") - payload = {"asset": asset, **kwargs} - return self.sign_request("GET", "/sapi/v1/margin/loan", payload) - - -def margin_repay_record(self, asset: str, **kwargs): - """Query Repay Record (USER_DATA) - - GET /sapi/v1/margin/repay - - https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data - - Args: - asset (str) - Keyword Args: - isolatedSymbol (str, optional): isolated symbol - txId (int, optional): return of /sapi/v1/margin/repay - startTime (int, optional) - endTime (int, optional) - current (int, optional): Currently querying page. Start from 1. Default:1 - size (int, optional): Default:10 Max:100 - archived (str, optional): Default: false. Set to true for archived data from 6 months ago - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameter(asset, "asset") - payload = {"asset": asset, **kwargs} - return self.sign_request("GET", "/sapi/v1/margin/repay", payload) + check_required_parameter(type, "type") + payload = {"type": type, **kwargs} + return self.sign_request("GET", "/sapi/v1/margin/borrow-repay", payload) def margin_interest_history(self, **kwargs): @@ -479,72 +397,6 @@ def margin_max_transferable(self, asset: str, **kwargs): return self.sign_request("GET", "/sapi/v1/margin/maxTransferable", payload) -def isolated_margin_transfer( - self, asset: str, symbol: str, transFrom: str, transTo: str, amount, **kwargs -): - """Isolated Margin Account Transfer (MARGIN) - - POST /sapi/v1/margin/isolated/transfer - - https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin - - Args: - asset (str) - symbol (str) - amount (float) - transFrom (str): "SPOT", "ISOLATED_MARGIN" - transTo (str): "SPOT", "ISOLATED_MARGIN" - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters( - [ - [asset, "asset"], - [symbol, "symbol"], - [transFrom, "transFrom"], - [transTo, "transTo"], - [amount, "amount"], - ] - ) - - payload = { - "asset": asset, - "symbol": symbol, - "transFrom": transFrom, - "transTo": transTo, - "amount": amount, - **kwargs, - } - return self.sign_request("POST", "/sapi/v1/margin/isolated/transfer", payload) - - -def isolated_margin_transfer_history(self, symbol: str, **kwargs): - """Get Isolated Margin Transfer History (USER_DATA) - - GET /sapi/v1/margin/isolated/transfer - - https://binance-docs.github.io/apidocs/spot/en/#get-isolated-margin-transfer-history-user_data - - Args: - symbol (str) - Keyword Args: - asset (str, optional): asset,such as BTC - transFrom (str, optional): "SPOT", "ISOLATED_MARGIN" - transTo (str, optional): "SPOT", "ISOLATED_MARGIN" - startTime (int, optional) - endTime (int, optional) - current (int, optional): Currently querying page. Start from 1. Default:1 - size (int, optional): Default:10 Max:100 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameter(symbol, "symbol") - - payload = {"symbol": symbol, **kwargs} - return self.sign_request("GET", "/sapi/v1/margin/isolated/transfer", payload) - - def isolated_margin_account(self, **kwargs): """Query Isolated Margin Account Info (USER_DATA) @@ -560,26 +412,6 @@ def isolated_margin_account(self, **kwargs): return self.sign_request("GET", "/sapi/v1/margin/isolated/account", kwargs) -def isolated_margin_pair(self, symbol: str, **kwargs): - """Query Isolated Margin Symbol (USER_DATA) - - GET /sapi/v1/margin/isolated/pair - - https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-account-info-user_data - - Args: - symbol (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameter(symbol, "symbol") - - payload = {"symbol": symbol, **kwargs} - - return self.sign_request("GET", "/sapi/v1/margin/isolated/pair", payload) - - def isolated_margin_all_pairs(self, **kwargs): """Get All Isolated Margin Symbol(USER_DATA) @@ -588,6 +420,7 @@ def isolated_margin_all_pairs(self, **kwargs): https://binance-docs.github.io/apidocs/spot/en/#get-all-isolated-margin-symbol-user_data Keyword Args: + symbol (str, optional) recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -924,27 +757,6 @@ def margin_order_usage(self, **kwargs): return self.sign_request("GET", "/sapi/v1/margin/rateLimit/order", kwargs) -def margin_dust_log(self, **kwargs): - """Margin Dust Log (USER_DATA) - - Query the historical information of user's margin account small-value asset conversion BNB. - - Weight(IP): 1 - - GET /sapi/v1/margin/dribblet - - https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user_data - - Keyword Args: - startTime (int, optional): UTC timestamp in ms - endTime (int, optional): UTC timestamp in ms - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - url_path = "/sapi/v1/margin/dribblet" - return self.sign_request("GET", url_path, {**kwargs}) - - def summary_of_margin_account(self, **kwargs): """Get Summary of Margin account (USER_DATA) Get personal margin level information @@ -1048,48 +860,6 @@ def get_a_future_hourly_interest_rate(self, assets: str, isIsolated: bool, **kwa return self.sign_request("GET", url_path, params) -def get_assets_that_can_be_converted_into_bnb(self, **kwargs): - """Get Assets That Can Be Converted Into BNB (USER_DATA) - - Get assets that can be converted into BNB. - - Weight(IP): 100 - - GET /sapi/v1/margin/dust - - https://binance-docs.github.io/apidocs/spot/en/#get-assets-that-can-be-converted-into-bnb-user_data-2 - - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - url_path = "/sapi/v1/margin/dust" - return self.sign_request("GET", url_path, {**kwargs}) - - -def dust_transfer(self, asset: str, **kwargs): - """Dust Transfer (TRADE) - - Convert dust assets to BNB - - Weight(UID): 3000 - - POST /sapi/v1/margin/dust - - https://binance-docs.github.io/apidocs/spot/en/#dust-transfer-trade - - Args: - asset (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameter(asset, "asset") - - params = {"asset": asset, **kwargs} - url_path = "/sapi/v1/margin/dust" - return self.sign_request("POST", url_path, params) - - def adjust_cross_margin_max_leverage(self, maxLeverage: int, **kwargs): """Adjust cross margin max leverage (USER_DATA) diff --git a/docs/source/CHANGELOG.rst b/docs/source/CHANGELOG.rst index f94948cc..7e9b13fa 100644 --- a/docs/source/CHANGELOG.rst +++ b/docs/source/CHANGELOG.rst @@ -2,11 +2,46 @@ Changelog ========= +3.6.0 - 2024-01-22 +------------------ + +Removed +^^^^^^^ + +* ``POST /sapi/v1/margin/transfer`` +* ``POST /sapi/v1/margin/isolated/transfer`` +* ``POST /sapi/v1/margin/loan`` +* ``POST /sapi/v1/margin/repay`` +* ``GET /sapi/v1/margin/isolated/transfer`` +* ``GET /sapi/v1/margin/asset`` +* ``GET /sapi/v1/margin/pair`` +* ``GET /sapi/v1/margin/isolated/pair`` +* ``GET /sapi/v1/margin/loan`` +* ``GET /sapi/v1/margin/repay`` +* ``GET /sapi/v1/margin/dribblet`` +* ``GET /sapi/v1/margin/dust`` +* ``POST /sapi/v1/margin/dust`` + +Added +^^^^^ + +* ``POST /sapi/v1/margin/borrow-repay`` +* ``GET /sapi/v1/margin/borrow-repay`` + +Updated +^^^^^^^ + +* ``GET /sapi/v1/margin/transfer`` add parameter ``isolatedSymbol`` +* ``GET /sapi/v1/margin/allAssets`` add parameter ``asset`` +* ``GET /sapi/v1/margin/allPairs`` add parameter ``symbol`` +* ``GET /sapi/v1/margin/isolated/allPairs`` add parameter ``symbol`` + + 3.5.1 - 2023-11-17 ------------------ Fixed -^^^^^^^ +^^^^^ * Set the default timeout value to None in WebSocket clients diff --git a/docs/source/binance.spot.margin.rst b/docs/source/binance.spot.margin.rst index 9012b83c..1914e6b0 100644 --- a/docs/source/binance.spot.margin.rst +++ b/docs/source/binance.spot.margin.rst @@ -1,25 +1,9 @@ Margin Endpoints ================ -Margin Account Transfer (MARGIN) --------------------------------- -.. autofunction:: binance.spot.Spot.margin_transfer - -Margin Account Borrow (MARGIN) ------------------------------- -.. autofunction:: binance.spot.Spot.margin_borrow - -Margin Account Repay(MARGIN) ----------------------------- -.. autofunction:: binance.spot.Spot.margin_repay - -Query Margin Asset (MARKET_DATA) --------------------------------- -.. autofunction:: binance.spot.Spot.margin_asset - -Query Margin Pair (MARKET_DATA) -------------------------------- -.. autofunction:: binance.spot.Spot.margin_pair +Margin Account Borrow/Repay (MARGIN) +------------------------------------ +.. autofunction:: binance.spot.Spot.borrow_repay Get All Margin Assets (MARKET_DATA) ----------------------------------- @@ -45,13 +29,9 @@ Get Transfer History (USER_DATA) -------------------------------- .. autofunction:: binance.spot.Spot.margin_transfer_history -Query Loan Record (USER_DATA) ------------------------------ -.. autofunction:: binance.spot.Spot.margin_load_record - -Query Repay Record (USER_DATA) --------------------------------- -.. autofunction:: binance.spot.Spot.margin_repay_record +Query borrow/repay records in Margin account (USER_DATA) +-------------------------------------------------------- +.. autofunction:: binance.spot.Spot.borrow_repay_record Get Interest History (USER_DATA) -------------------------------- @@ -93,22 +73,10 @@ Query Max Transfer-Out Amount (USER_DATA) ----------------------------------------- .. autofunction:: binance.spot.Spot.margin_max_transferable -Isolated Margin Account Transfer (MARGIN) ------------------------------------------ -.. autofunction:: binance.spot.Spot.isolated_margin_transfer - -Get Isolated Margin Transfer History (USER_DATA) ------------------------------------------------- -.. autofunction:: binance.spot.Spot.isolated_margin_transfer_history - Query Isolated Margin Account Info (USER_DATA) ---------------------------------------------- .. autofunction:: binance.spot.Spot.isolated_margin_account -Query Isolated Margin Symbol (USER_DATA) ----------------------------------------- -.. autofunction:: binance.spot.Spot.isolated_margin_pair - Get All Isolated Margin Symbol(USER_DATA) ----------------------------------------- .. autofunction:: binance.spot.Spot.isolated_margin_all_pairs @@ -173,10 +141,6 @@ Query Current Margin Order Count Usage (TRADE) ---------------------------------------------- .. autofunction:: binance.spot.Spot.margin_order_usage -Margin Dust Log (USER_DATA) ---------------------------- -.. autofunction:: binance.spot.Spot.margin_dust_log - Get Summary of Margin account (USER_DATA) ----------------------------------------- .. autofunction:: binance.spot.Spot.summary_of_margin_account diff --git a/examples/spot/margin/isolated_margin_transfer_history.py b/examples/spot/margin/borrow_repay.py similarity index 70% rename from examples/spot/margin/isolated_margin_transfer_history.py rename to examples/spot/margin/borrow_repay.py index c4210336..1e44b419 100644 --- a/examples/spot/margin/isolated_margin_transfer_history.py +++ b/examples/spot/margin/borrow_repay.py @@ -10,8 +10,9 @@ api_key, api_secret = get_api_key() client = Client(api_key, api_secret) + logging.info( - client.isolated_margin_transfer_history( - asset="USDT", symbol="BTCUSDT", transFrom="SPOT", transTo="ISOLATED_MARGIN" + client.borrow_repay( + asset="BNB", isIsolated="TRUE", symbol="BNBUSDT", amount="0.001", type="BORROW" ) ) diff --git a/examples/spot/margin/margin_asset.py b/examples/spot/margin/borrow_repay_record.py similarity index 83% rename from examples/spot/margin/margin_asset.py rename to examples/spot/margin/borrow_repay_record.py index 14ad77cf..318db2a0 100644 --- a/examples/spot/margin/margin_asset.py +++ b/examples/spot/margin/borrow_repay_record.py @@ -10,4 +10,4 @@ api_key, api_secret = get_api_key() client = Client(api_key, api_secret) -logging.info(client.margin_asset(asset="BNB")) +logging.info(client.borrow_repay_record(type="BORROW")) diff --git a/examples/spot/margin/dust_transfer.py b/examples/spot/margin/dust_transfer.py deleted file mode 100644 index 702c122f..00000000 --- a/examples/spot/margin/dust_transfer.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError - -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) -logger = logging.getLogger(__name__) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.dust_transfer("SHIB,TRX", recvWindow=5000) - logger.info(response) -except ClientError as error: - logger.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/margin/get_assets_that_can_be_converted_into_bnb.py b/examples/spot/margin/get_assets_that_can_be_converted_into_bnb.py deleted file mode 100644 index 90867717..00000000 --- a/examples/spot/margin/get_assets_that_can_be_converted_into_bnb.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError - -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) -logger = logging.getLogger(__name__) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.get_assets_that_can_be_converted_into_bnb(recvWindow=5000) - logger.info(response) -except ClientError as error: - logger.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/margin/isolated_margin_pair.py b/examples/spot/margin/isolated_margin_pair.py deleted file mode 100644 index 8ef54214..00000000 --- a/examples/spot/margin/isolated_margin_pair.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.isolated_margin_pair(symbol="BTCUSDT")) diff --git a/examples/spot/margin/isolated_margin_transfer.py b/examples/spot/margin/isolated_margin_transfer.py deleted file mode 100644 index 18c36a2c..00000000 --- a/examples/spot/margin/isolated_margin_transfer.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info( - client.isolated_margin_transfer( - asset="USDT", - symbol="BTCUSDT", - transFrom="SPOT", - transTo="ISOLATED_MARGIN", - amount=1, - ) -) diff --git a/examples/spot/margin/margin_borrow.py b/examples/spot/margin/margin_borrow.py deleted file mode 100644 index 501a9723..00000000 --- a/examples/spot/margin/margin_borrow.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.margin_borrow(asset="BNB", amount="0.001")) diff --git a/examples/spot/margin/margin_dust_log.py b/examples/spot/margin/margin_dust_log.py deleted file mode 100644 index 2bf34faa..00000000 --- a/examples/spot/margin/margin_dust_log.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.margin_dust_log(recvWindow=5000) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/margin/margin_load_record.py b/examples/spot/margin/margin_load_record.py deleted file mode 100644 index 963f23fc..00000000 --- a/examples/spot/margin/margin_load_record.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.margin_load_record(asset="BNB", startTime="1580982895748")) diff --git a/examples/spot/margin/margin_pair.py b/examples/spot/margin/margin_pair.py deleted file mode 100644 index f3f1db72..00000000 --- a/examples/spot/margin/margin_pair.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.margin_pair(symbol="BNBUSDT")) diff --git a/examples/spot/margin/margin_repay.py b/examples/spot/margin/margin_repay.py deleted file mode 100644 index 5f01d260..00000000 --- a/examples/spot/margin/margin_repay.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.margin_repay(asset="BNB", amount="0.001")) diff --git a/examples/spot/margin/margin_repay_record.py b/examples/spot/margin/margin_repay_record.py deleted file mode 100644 index 96764d83..00000000 --- a/examples/spot/margin/margin_repay_record.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.margin_repay_record(asset="BNB", startTime="1580982895748")) diff --git a/examples/spot/margin/margin_transfer.py b/examples/spot/margin/margin_transfer.py deleted file mode 100644 index 2bfcfaf9..00000000 --- a/examples/spot/margin/margin_transfer.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) -logging.info(client.margin_transfer(asset="BNB", amount="0.001", type=1)) diff --git a/tests/spot/margin/test_borrow_repay.py b/tests/spot/margin/test_borrow_repay.py new file mode 100644 index 00000000..86478156 --- /dev/null +++ b/tests/spot/margin/test_borrow_repay.py @@ -0,0 +1,85 @@ +import responses + +from urllib.parse import urlencode +from tests.util import random_str +from tests.util import mock_http_response +from binance.spot import Spot as Client +from binance.error import ParameterRequiredError + +mock_item = {"key_1": "value_1", "key_2": "value_2"} + +key = random_str() +secret = random_str() + +asset = "BNB" +amount = "100" +isIsolated = "TRUE" +symbol = "BNBUSDT" +type = "BORROW" + +params = { + "asset": asset, + "amount": amount, + "type": type, + "isIsolated": isIsolated, + "symbol": symbol, +} + + +def test_borrow_repay_without_asset(): + """Tests the API endpoint to margin borrow without asset""" + + client = Client(key, secret) + client.borrow_repay.when.called_with( + "", isIsolated, symbol, amount, type + ).should.throw(ParameterRequiredError) + + +def test_borrow_repay_without_isIsolated(): + """Tests the API endpoint to margin borrow isIsolated""" + + client = Client(key, secret) + client.borrow_repay.when.called_with(asset, "", symbol, amount, type).should.throw( + ParameterRequiredError + ) + + +def test_borrow_repay_without_symbol(): + """Tests the API endpoint to margin borrow symbol""" + + client = Client(key, secret) + client.borrow_repay.when.called_with( + asset, isIsolated, "", amount, type + ).should.throw(ParameterRequiredError) + + +def test_borrow_repay_without_amount(): + """Tests the API endpoint to margin borrow without amount""" + + client = Client(key, secret) + client.borrow_repay.when.called_with( + asset, isIsolated, symbol, "", type + ).should.throw(ParameterRequiredError) + + +def test_borrow_repay_without_type(): + """Tests the API endpoint to margin borrow without type""" + + client = Client(key, secret) + client.borrow_repay.when.called_with( + asset, isIsolated, symbol, amount, "" + ).should.throw(ParameterRequiredError) + + +@mock_http_response( + responses.POST, + "/sapi/v1/margin/borrow-repay\\?" + urlencode(params), + mock_item, + 200, +) +def test_borrow_repay(): + """Tests the API endpoint to margin borrow""" + + client = Client(key, secret) + response = client.borrow_repay(**params) + response.should.equal(mock_item) diff --git a/tests/spot/margin/test_borrow_repay_record.py b/tests/spot/margin/test_borrow_repay_record.py new file mode 100644 index 00000000..d21e0fce --- /dev/null +++ b/tests/spot/margin/test_borrow_repay_record.py @@ -0,0 +1,34 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from urllib.parse import urlencode +from tests.util import mock_http_response +from binance.error import ParameterRequiredError + +mock_item = {"key_1": "value_1", "key_2": "value_2"} +mock_exception = {"code": -1, "msg": "error message"} + +key = random_str() +secret = random_str() + +params = {"type": "BORROW", "recvWindow": 1000} + + +@mock_http_response(responses.GET, "/sapi/v1/margin/borrow-repay", mock_exception, 400) +def test_borrow_repay_record_without_type(): + """Tests the API endpoint to query borrow repay records without type""" + + client = Client(key, secret) + client.borrow_repay_record.when.called_with("").should.throw(ParameterRequiredError) + + +@mock_http_response( + responses.GET, "/sapi/v1/margin/borrow-repay\\?" + urlencode(params), mock_item, 200 +) +def test_borrow_repay_record(): + """Tests the API endpoint to query borrow repay record""" + + client = Client(key, secret) + response = client.borrow_repay_record(**params) + response.should.equal(mock_item) diff --git a/tests/spot/margin/test_dust_transfer.py b/tests/spot/margin/test_dust_transfer.py deleted file mode 100644 index d13d1d46..00000000 --- a/tests/spot/margin/test_dust_transfer.py +++ /dev/null @@ -1,30 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = {"asset": "BTC", "recvWindow": 5000} -expected_params = {"asset": "BTC", "recvWindow": 5000} - - -@mock_http_response( - responses.POST, - "/sapi/v1/margin/dust\\?" + urlencode(expected_params), - mock_item, - 200, -) -def test_dust_transfer(): - """Tests the API endpoint to dust transfer""" - - client = Client(key, secret) - response = client.dust_transfer(**send_params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_get_assets_that_can_be_converted_into_bnb.py b/tests/spot/margin/test_get_assets_that_can_be_converted_into_bnb.py deleted file mode 100644 index 8a233c34..00000000 --- a/tests/spot/margin/test_get_assets_that_can_be_converted_into_bnb.py +++ /dev/null @@ -1,30 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = {"recvWindow": 5000} -expected_params = {"recvWindow": 5000} - - -@mock_http_response( - responses.GET, - "/sapi/v1/margin/dust\\?" + urlencode(expected_params), - mock_item, - 200, -) -def test_get_assets_that_can_be_converted_into_bnb(): - """Tests the API endpoint to get assets that can be converted into bnb""" - - client = Client(key, secret) - response = client.get_assets_that_can_be_converted_into_bnb(**send_params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_isolated_margin_pair.py b/tests/spot/margin/test_isolated_margin_pair.py deleted file mode 100644 index d86e35e1..00000000 --- a/tests/spot/margin/test_isolated_margin_pair.py +++ /dev/null @@ -1,36 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": 'Parameter "orderId" was empty.'} - -key = random_str() -secret = random_str() - - -def test_isolated_margin_pair_without_symbol(): - """Tests the API endpoint to query isolated margin pair without symbol""" - - client = Client(key, secret) - client.isolated_margin_pair.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/margin/isolated/pair\\?" + urlencode({"symbol": "BTCUSDT"}), - mock_item, - 200, -) -def test_isolated_margin_pair(): - """Tests the API endpoint to query isolated margin pair""" - - client = Client(key, secret) - response = client.isolated_margin_pair("BTCUSDT") - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_isolated_margin_transfer.py b/tests/spot/margin/test_isolated_margin_transfer.py deleted file mode 100644 index 6b6f940d..00000000 --- a/tests/spot/margin/test_isolated_margin_transfer.py +++ /dev/null @@ -1,115 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": 'Parameter "orderId" was empty.'} - -key = random_str() -secret = random_str() - -param = { - "asset": "BTC", - "symbol": "BTCUSDT", - "transFrom": "SPOT", - "transTo": "ISOLATED_MARGIN", - "amount": "1", -} - - -def test_isolated_margin_transfer_without_asset(): - """Tests the API endpoint to transfer isolated margin without asset""" - - params = { - "asset": "", - "symbol": "BTCUSDT", - "transFrom": "SPOT", - "transTo": "ISOLATED_MARGIN", - "amount": "1", - } - client = Client(key, secret) - client.isolated_margin_transfer.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -def test_isolated_margin_transfer_without_symbol(): - """Tests the API endpoint to transfer isolated margin without symbol""" - - params = { - "asset": "USDT", - "symbol": "", - "transFrom": "SPOT", - "transTo": "ISOLATED_MARGIN", - "amount": "1", - } - client = Client(key, secret) - client.isolated_margin_transfer.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -def test_isolated_margin_transfer_without_transForm(): - """Tests the API endpoint to transfer isolated margin without transForm""" - - params = { - "asset": "USDT", - "symbol": "BTCUSDT", - "transFrom": "", - "transTo": "ISOLATED_MARGIN", - "amount": "1", - } - client = Client(key, secret) - client.isolated_margin_transfer.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -def test_isolated_margin_transfer_without_transTo(): - """Tests the API endpoint to transfer isolated margin without transTo""" - - params = { - "asset": "USDT", - "symbol": "BTCUSDT", - "transFrom": "SPOT", - "transTo": "", - "amount": "1", - } - client = Client(key, secret) - client.isolated_margin_transfer.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -def test_isolated_margin_transfer_without_amount(): - """Tests the API endpoint to transfer isolated margin without amount""" - - params = { - "asset": "USDT", - "symbol": "BTCUSDT", - "transFrom": "SPOT", - "transTo": "ISOLATED_MARGIN", - "amount": "", - } - client = Client(key, secret) - client.isolated_margin_transfer.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, - "/sapi/v1/margin/isolated/transfer\\?" + urlencode(param), - mock_item, - 200, -) -def test_isolated_margin_transfer(): - """Tests the API endpoint to transfer isolated margin""" - - client = Client(key, secret) - response = client.isolated_margin_transfer(**param) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_isolated_margin_transfer_history.py b/tests/spot/margin/test_isolated_margin_transfer_history.py deleted file mode 100644 index 893d54aa..00000000 --- a/tests/spot/margin/test_isolated_margin_transfer_history.py +++ /dev/null @@ -1,43 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": 'Parameter "orderId" was empty.'} - -key = random_str() -secret = random_str() - -param = { - "symbol": "BTCUSDT", - "asset": "BTC", - "transFrom": "SPOT", - "transTo": "ISOLATED_MARGIN", -} - - -def test_isolated_margin_transfer_history_without_symbol(): - """Tests the API endpoint to transfer isolated margin history without asset""" - - client = Client(key, secret) - client.isolated_margin_transfer_history.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/margin/isolated/transfer\\?" + urlencode(param), - mock_item, - 200, -) -def test_isolated_margin_transfer_history(): - """Tests the API endpoint to transfer isolated margin history""" - - client = Client(key, secret) - response = client.isolated_margin_transfer_history(**param) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_asset.py b/tests/spot/margin/test_margin_asset.py deleted file mode 100644 index 790eed63..00000000 --- a/tests/spot/margin/test_margin_asset.py +++ /dev/null @@ -1,35 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - -asset = "BNB" -amount = "100" - -params = {"asset": asset} - - -def test_margin_asset_without_asset(): - """Tests the API endpoint to margin asset without asset""" - - client = Client(key, secret) - client.margin_asset.when.called_with("").should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.GET, "/sapi/v1/margin/asset\\?" + urlencode(params), mock_item, 200 -) -def test_margin_asset(): - """Tests the API endpoint to margin asset""" - - client = Client(key, secret) - response = client.margin_asset(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_borrow.py b/tests/spot/margin/test_margin_borrow.py deleted file mode 100644 index 5c855081..00000000 --- a/tests/spot/margin/test_margin_borrow.py +++ /dev/null @@ -1,46 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - -asset = "BNB" -amount = "100" - -params = {"asset": asset, "amount": amount} - - -def test_margin_borrow_without_asset(): - """Tests the API endpoint to margin borrow without asset""" - - client = Client(key, secret) - client.margin_borrow.when.called_with("", amount).should.throw( - ParameterRequiredError - ) - - -def test_margin_borrow_without_amount(): - """Tests the API endpoint to margin borrow without amount""" - - client = Client(key, secret) - client.margin_borrow.when.called_with(asset, "").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, "/sapi/v1/margin/loan\\?" + urlencode(params), mock_item, 200 -) -def test_margin_borrow(): - """Tests the API endpoint to margin borrow""" - - client = Client(key, secret) - response = client.margin_borrow(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_dust_log.py b/tests/spot/margin/test_margin_dust_log.py deleted file mode 100644 index bddabe4d..00000000 --- a/tests/spot/margin/test_margin_dust_log.py +++ /dev/null @@ -1,28 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -params = {"recvWindow": 5000} - - -@mock_http_response( - responses.GET, - "/sapi/v1/margin/dribblet\\?" + urlencode(params), - mock_item, - 200, -) -def test_margin_dust_log(): - """Tests the API endpoint to margin dustlog""" - - client = Client(key, secret) - response = client.margin_dust_log(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_load_record.py b/tests/spot/margin/test_margin_load_record.py deleted file mode 100644 index 7559ef7e..00000000 --- a/tests/spot/margin/test_margin_load_record.py +++ /dev/null @@ -1,34 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -params = {"asset": "BNB", "txId": "txid", "size": 10, "recvWindow": 1000} - - -@mock_http_response(responses.GET, "/sapi/v1/margin/loan", mock_exception, 400) -def test_margin_load_record_without_asset(): - """Tests the API endpoint to query margin loan record without asset""" - - client = Client(key, secret) - client.margin_load_record.when.called_with("").should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.GET, "/sapi/v1/margin/loan\\?" + urlencode(params), mock_item, 200 -) -def test_margin_load_record(): - """Tests the API endpoint to query margin loan record""" - - client = Client(key, secret) - response = client.margin_load_record(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_pair.py b/tests/spot/margin/test_margin_pair.py deleted file mode 100644 index 96ad1dfd..00000000 --- a/tests/spot/margin/test_margin_pair.py +++ /dev/null @@ -1,32 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - -params = {"symbol": "BNBUSDT"} - - -def test_margin_pair_without_asset(): - """Tests the API endpoint to margin pair without asset""" - - client = Client(key, secret) - client.margin_pair.when.called_with("").should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.GET, "/sapi/v1/margin/pair\\?" + urlencode(params), mock_item, 200 -) -def test_margin_pair(): - """Tests the API endpoint to margin pair""" - - client = Client(key, secret) - response = client.margin_pair(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_repay.py b/tests/spot/margin/test_margin_repay.py deleted file mode 100644 index d72f4019..00000000 --- a/tests/spot/margin/test_margin_repay.py +++ /dev/null @@ -1,44 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - -asset = "BNB" -amount = "100" - -params = {"asset": asset, "amount": amount} - - -def test_margin_repay_without_asset(): - """Tests the API endpoint to margin repay without asset""" - - client = Client(key, secret) - client.margin_repay.when.called_with("", amount).should.throw( - ParameterRequiredError - ) - - -def test_margin_repay_without_amount(): - """Tests the API endpoint to margin repay without amount""" - - client = Client(key, secret) - client.margin_repay.when.called_with(asset, "").should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.POST, "/sapi/v1/margin/repay\\?" + urlencode(params), mock_item, 200 -) -def test_margin_repay(): - """Tests the API endpoint to margin repay""" - - client = Client(key, secret) - response = client.margin_repay(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_repay_record.py b/tests/spot/margin/test_margin_repay_record.py deleted file mode 100644 index 67f904e3..00000000 --- a/tests/spot/margin/test_margin_repay_record.py +++ /dev/null @@ -1,34 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -params = {"asset": "BNB", "txId": "txid", "size": 10, "recvWindow": 1000} - - -@mock_http_response(responses.GET, "/sapi/v1/margin/repay", mock_exception, 400) -def test_margin_repay_record_without_asset(): - """Tests the API endpoint to query margin repay record without asset""" - - client = Client(key, secret) - client.margin_repay_record.when.called_with("").should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.GET, "/sapi/v1/margin/repay\\?" + urlencode(params), mock_item, 200 -) -def test_margin_repay_record(): - """Tests the API endpoint to query margin repay record""" - - client = Client(key, secret) - response = client.margin_repay_record(**params) - response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_transfer.py b/tests/spot/margin/test_margin_transfer.py deleted file mode 100644 index 866fb5ac..00000000 --- a/tests/spot/margin/test_margin_transfer.py +++ /dev/null @@ -1,56 +0,0 @@ -import responses - -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - -asset = "BNB" -amount = "100" -type = 1 - -params = {"asset": asset, "amount": amount, "type": type} - - -def test_margin_transfer_without_asset(): - """Tests the API endpoint to margin tranfer without asset""" - - client = Client(key, secret) - client.margin_transfer.when.called_with("", amount, type).should.throw( - ParameterRequiredError - ) - - -def test_margin_transfer_without_amount(): - """Tests the API endpoint to margin tranfer without amount""" - - client = Client(key, secret) - client.margin_transfer.when.called_with("", amount, type).should.throw( - ParameterRequiredError - ) - - -def test_margin_transfer_without_type(): - """Tests the API endpoint to margin tranfer without type""" - - client = Client(key, secret) - client.margin_transfer.when.called_with("", amount, type).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, "/sapi/v1/margin/transfer\\?" + urlencode(params), mock_item, 200 -) -def test_margin_transfer(): - """Tests the API endpoint to margin tranfer""" - - client = Client(key, secret) - response = client.margin_transfer(**params) - response.should.equal(mock_item)