diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 01f5133b..7b75cf6f 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -18,12 +18,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - uses: actions/cache@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2b8d4439..bd6c6406 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} - - name: Post release cleaning + - name: Post release cleaning run: | python setup.py clean --all - rm dist/* \ No newline at end of file + rm dist/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 02f6ff4c..f0067b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,107 @@ # Changelog +## 3.4.0 - 2023-10-07 +### Added +- Portfolio endpoints: + - `POST /sapi/v1/portfolio/interest-history` + - `POST /sapi/v1/portfolio/asset-index-price` + - `POST /sapi/v1/portfolio/auto-collection` + - `POST /sapi/v1/portfolio/bnb-transfer` + - `POST /sapi/v1/portfolio/repay-futures-switch` + - `GET /sapi/v1/portfolio/repay-futures-switch` + - `POST /sapi/v1/portfolio/repay-futures-negative-balance` + - `POST /sapi/v1/portfolio/asset-collection` +- Convert + - `GET /sapi/v1/convert/exchangeInfo` + - `GET /sapi/v1/convert/assetInfo` + - `POST /sapi/v1/convert/getQuote` + - `POST /sapi/v1/convert/acceptQuote` + - `GET /sapi/v1/convert/orderStatus` +- Crypto Loan + - `POST /sapi/v1/loan/flexible/borrow` + - `GET /sapi/v1/loan/flexible/ongoing/order` + - `GET /sapi/v1/loan/flexible/borrow/history` + - `POST /sapi/v1/loan/flexible/repay` + - `GET /sapi/v1/loan/flexible/repay/history` + - `POST /sapi/v1/loan/flexible/adjust/ltv` + - `GET /sapi/v1/loan/flexible/ltv/adjustment/history` + - `GET /sapi/v1/loan/flexible/loanable/data` + - `GET /sapi/v1/loan/flexible/collateral/data` +- Margin + - `GET /sapi/v1/margin/crossMarginCollateralRatio` + - `GET /sapi/v1/margin/exchange-small-liability` + - `GET /sapi/v1/margin/exchange-small-liability-history` + - `GET /sapi/v1/margin/next-hourly-interest-rate` + - `GET /sapi/v1/margin/dust` + - `POST /sapi/v1/margin/dust` + - `GET /sapi/v1/margin/max-leverage` +- SubAccount + - `POST /sapi/v4/sub-account/assets` + - `POST /sapi/v1/sub-account/eoptions/enable` + - `GET /sapi/v1/sub-account/transaction-statistics` + - `GET /sapi/v1/managed-subaccount/query-trans-log` + - `GET /sapi/v1/managed-subaccount/info` + - `GET /sapi/v1/managed-subaccount/marginAsset` + - `GET /sapi/v1/managed-subaccount/fetch-future-asset` + - `GET /sapi/v1/sub-account/futures/positionRisk` + - `GET /sapi/v1/sub-account/futures/accountSummary` + - `GET /sapi/v1/sub-account/futures/account` +- Trade + - `GET /api/v3/myPreventedMatches` +- Wallet + - `POST /sapi/v1/capital/deposit/credit-apply` +- Simple Earn + - `GET /sapi/v1/simple-earn/flexible/list` + - `GET /sapi/v1/simple-earn/locked/list` + - `POST /sapi/v1/simple-earn/flexible/subscribe` + - `POST /sapi/v1/simple-earn/locked/subscribe` + - `POST /sapi/v1/simple-earn/flexible/redeem` + - `POST /sapi/v1/simple-earn/locked/redeem` + - `GET /sapi/v1/simple-earn/flexible/position` + - `GET /sapi/v1/simple-earn/locked/position` + - `GET /sapi/v1/simple-earn/account` + - `GET /sapi/v1/simple-earn/flexible/history/subscriptionRecord` + - `GET /sapi/v1/simple-earn/locked/history/subscriptionRecord` + - `GET /sapi/v1/simple-earn/flexible/history/redemptionRecord` + - `GET /sapi/v1/simple-earn/locked/history/redemptionRecord` + - `GET /sapi/v1/simple-earn/flexible/history/rewardsRecord` + - `GET /sapi/v1/simple-earn/locked/history/rewardsRecord` + - `POST /sapi/v1/simple-earn/flexible/setAutoSubscribe` + - `POST /sapi/v1/simple-earn/locked/setAutoSubscribe` + - `GET /sapi/v1/simple-earn/flexible/personalLeftQuota` + - `GET /sapi/v1/simple-earn/locked/personalLeftQuota` + - `GET /sapi/v1/simple-earn/flexible/subscriptionPreview` + - `GET /sapi/v1/simple-earn/locked/subscriptionPreview` + - `GET /sapi/v1/simple-earn/flexible/history/rateHistory` + - `GET /sapi/v1/simple-earn/flexible/history/collateralRecord` +- All Auto-Invest endpoints + +### Deleted +- `GET /sapi/v1/lending/daily/product/list` +- `GET /sapi/v1/lending/daily/userLeftQuota` +- `POST /sapi/v1/lending/daily/purchase` +- `GET /sapi/v1/lending/daily/userRedemptionQuota` +- `POST /sapi/v1/lending/daily/redeem` +- `GET /sapi/v1/lending/daily/token/position` +- `GET /sapi/v1/lending/union/account` +- `GET /sapi/v1/lending/union/purchaseRecord` +- `GET /sapi/v1/lending/union/redemptionRecord` +- `GET /sapi/v1/lending/union/interestHistory` +- `GET /sapi/v1/lending/project/list` +- `POST /sapi/v1/lending/customizedFixed/purchase` +- `GET /sapi/v1/lending/project/position/list` +- `POST /sapi/v1/lending/positionChanged` +- `GET /sapi/v1/futures/loan/borrow/history` +- `GET /sapi/v1/futures/loan/repay/history` +- `GET /sapi/v2/futures/loan/wallet` +- `GET /sapi/v1/futures/loan/adjustCollateral/history` +- `GET /sapi/v1/futures/loan/liquidationHistory` +- `GET /sapi/v1/futures/loan/interestHistory` + +### Changed +- Change `Loan` module name to `Crypto Loan` +- Pump dependencies + ## 3.3.1 - 2023-08-23 ### Changed diff --git a/binance/__version__.py b/binance/__version__.py index ff041687..903a158a 100644 --- a/binance/__version__.py +++ b/binance/__version__.py @@ -1 +1 @@ -__version__ = "3.3.1" +__version__ = "3.4.0" diff --git a/binance/spot/__init__.py b/binance/spot/__init__.py index 6d49fba2..e84884ce 100644 --- a/binance/spot/__init__.py +++ b/binance/spot/__init__.py @@ -40,6 +40,7 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._trade import account from binance.spot._trade import my_trades from binance.spot._trade import get_order_rate_limit + from binance.spot._trade import query_prevented_matches # STREAMS from binance.spot._data_stream import new_listen_key @@ -98,22 +99,13 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): 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 - - # SAVINGS - from binance.spot._savings import savings_flexible_products - from binance.spot._savings import savings_flexible_user_left_quota - from binance.spot._savings import savings_purchase_flexible_product - from binance.spot._savings import savings_flexible_user_redemption_quota - from binance.spot._savings import savings_flexible_redeem - from binance.spot._savings import savings_flexible_product_position - from binance.spot._savings import savings_project_list - from binance.spot._savings import savings_purchase_project - from binance.spot._savings import savings_project_position - from binance.spot._savings import savings_account - from binance.spot._savings import savings_purchase_record - from binance.spot._savings import savings_redemption_record - from binance.spot._savings import savings_interest_history - from binance.spot._savings import savings_change_position + 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 from binance.spot._staking import staking_product_list @@ -152,6 +144,7 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._wallet import cloud_mining_trans_history from binance.spot._wallet import convert_transfer from binance.spot._wallet import convert_history + from binance.spot._wallet import one_click_arrival_deposit_apply # MINING from binance.spot._mining import mining_algo_list @@ -204,16 +197,22 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._sub_account import managed_sub_account_investor_trans_log from binance.spot._sub_account import managed_sub_account_trading_trans_log from binance.spot._sub_account import managed_sub_account_deposit_address + from binance.spot._sub_account import query_sub_account_assets + from binance.spot._sub_account import enable_options_for_sub_account + from binance.spot._sub_account import query_sub_account_transaction_statistics + from binance.spot._sub_account import query_managed_sub_account_margin_asset_details + from binance.spot._sub_account import query_managed_sub_account_list + from binance.spot._sub_account import ( + query_managed_sub_account_futures_asset_details, + ) + from binance.spot._sub_account import futures_position_risk_of_sub_account + from binance.spot._sub_account import summary_of_sub_account_s_futures_account + from binance.spot._sub_account import detail_on_sub_account_s_futures_account + from binance.spot._sub_account import query_managed_sub_account_transfer_log # FUTURES from binance.spot._futures import futures_transfer from binance.spot._futures import futures_transfer_history - from binance.spot._futures import futures_loan_borrow_history - from binance.spot._futures import futures_loan_repay_history - from binance.spot._futures import futures_loan_wallet - from binance.spot._futures import futures_loan_adjust_collateral_history - from binance.spot._futures import futures_loan_liquidation_history - from binance.spot._futures import futures_loan_interest_history # BLVTs from binance.spot._blvt import blvt_info @@ -246,29 +245,43 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): # C2C from binance.spot._c2c import c2c_trade_history - # LOANS - from binance.spot._loan import loan_history - from binance.spot._loan import loan_borrow - from binance.spot._loan import loan_borrow_history - from binance.spot._loan import loan_ongoing_orders - from binance.spot._loan import loan_repay - from binance.spot._loan import loan_repay_history - from binance.spot._loan import loan_adjust_ltv - from binance.spot._loan import loan_adjust_ltv_history - from binance.spot._loan import loan_vip_ongoing_orders - from binance.spot._loan import loan_vip_repay - from binance.spot._loan import loan_vip_repay_history - from binance.spot._loan import loan_vip_collateral_account - from binance.spot._loan import loan_loanable_data - from binance.spot._loan import loan_collateral_data - from binance.spot._loan import loan_collateral_rate - from binance.spot._loan import loan_customize_margin_call + # Crypto LOANS + from binance.spot._crypto_loan import loan_history + from binance.spot._crypto_loan import loan_borrow + from binance.spot._crypto_loan import loan_borrow_history + from binance.spot._crypto_loan import loan_ongoing_orders + from binance.spot._crypto_loan import loan_repay + from binance.spot._crypto_loan import loan_repay_history + from binance.spot._crypto_loan import loan_adjust_ltv + from binance.spot._crypto_loan import loan_adjust_ltv_history + from binance.spot._crypto_loan import loan_vip_ongoing_orders + from binance.spot._crypto_loan import loan_vip_repay + from binance.spot._crypto_loan import loan_vip_repay_history + from binance.spot._crypto_loan import loan_vip_collateral_account + from binance.spot._crypto_loan import loan_loanable_data + from binance.spot._crypto_loan import loan_collateral_data + from binance.spot._crypto_loan import loan_collateral_rate + from binance.spot._crypto_loan import loan_customize_margin_call + from binance.spot._crypto_loan import flexible_loan_adjust_ltv + from binance.spot._crypto_loan import flexible_loan_assets_data + from binance.spot._crypto_loan import flexible_loan_borrow_history + from binance.spot._crypto_loan import flexible_loan_borrow + from binance.spot._crypto_loan import flexible_loan_collateral_assets_data + from binance.spot._crypto_loan import flexible_loan_ltv_adjustment_history + from binance.spot._crypto_loan import flexible_loan_ongoing_orders + from binance.spot._crypto_loan import flexible_loan_repay + from binance.spot._crypto_loan import flexible_loan_repayment_history # PAY from binance.spot._pay import pay_history # CONVERT - from binance.spot._convert import convert_trade_history + from binance.spot._convert import list_all_convert_pairs + from binance.spot._convert import query_order_quantity_precision_per_asset + from binance.spot._convert import send_quote_request + from binance.spot._convert import accept_quote + from binance.spot._convert import order_status + from binance.spot._convert import get_convert_trade_history # REBATE from binance.spot._rebate import rebate_spot_history @@ -292,3 +305,55 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._portfolio_margin import portfolio_margin_collateral_rate from binance.spot._portfolio_margin import portfolio_margin_bankruptcy_loan_amount from binance.spot._portfolio_margin import portfolio_margin_bankruptcy_loan_repay + from binance.spot._portfolio_margin import ( + query_classic_portfolio_margin_negative_balance_interest_history, + ) + from binance.spot._portfolio_margin import query_portfolio_margin_asset_index_price + from binance.spot._portfolio_margin import fund_auto_collection + from binance.spot._portfolio_margin import bnb_transfer + from binance.spot._portfolio_margin import change_auto_repay_futures_status + from binance.spot._portfolio_margin import get_auto_repay_futures_status + from binance.spot._portfolio_margin import repay_futures_negative_balance + from binance.spot._portfolio_margin import fund_collection_by_asset + + # Simple Earn + from binance.spot._simple_earn import get_simple_earn_flexible_product_list + from binance.spot._simple_earn import get_simple_earn_locked_product_list + from binance.spot._simple_earn import subscribe_flexible_product + from binance.spot._simple_earn import subscribe_locked_product + from binance.spot._simple_earn import redeem_flexible_product + from binance.spot._simple_earn import redeem_locked_product + from binance.spot._simple_earn import get_flexible_product_position + from binance.spot._simple_earn import get_locked_product_position + from binance.spot._simple_earn import simple_account + from binance.spot._simple_earn import get_flexible_subscription_record + from binance.spot._simple_earn import get_locked_subscription_record + from binance.spot._simple_earn import get_flexible_redemption_record + from binance.spot._simple_earn import get_locked_redemption_record + from binance.spot._simple_earn import get_flexible_rewards_history + from binance.spot._simple_earn import get_locked_rewards_history + from binance.spot._simple_earn import set_flexible_auto_subscribe + from binance.spot._simple_earn import set_locked_auto_subscribe + from binance.spot._simple_earn import get_flexible_personal_left_quota + from binance.spot._simple_earn import get_locked_personal_left_quota + from binance.spot._simple_earn import get_flexible_subscription_preview + from binance.spot._simple_earn import get_locked_subscription_preview + from binance.spot._simple_earn import get_rate_history + from binance.spot._simple_earn import get_collateral_record + + # Auto-Invest + from binance.spot._auto_invest import get_target_asset_list + from binance.spot._auto_invest import get_target_asset_roi_data + from binance.spot._auto_invest import query_all_source_asset_and_target_asset + from binance.spot._auto_invest import query_source_asset_list + from binance.spot._auto_invest import change_plan_status + from binance.spot._auto_invest import get_list_of_plans + from binance.spot._auto_invest import query_holding_details_of_the_plan + from binance.spot._auto_invest import query_subscription_transaction_history + from binance.spot._auto_invest import query_index_details + from binance.spot._auto_invest import query_index_linked_plan_position_details + from binance.spot._auto_invest import one_time_transaction + from binance.spot._auto_invest import query_one_time_transaction_status + from binance.spot._auto_invest import index_linked_plan_redemption + from binance.spot._auto_invest import get_index_linked_plan_redemption_history + from binance.spot._auto_invest import index_linked_plan_rebalance_details diff --git a/binance/spot/_auto_invest.py b/binance/spot/_auto_invest.py new file mode 100644 index 00000000..f0496d54 --- /dev/null +++ b/binance/spot/_auto_invest.py @@ -0,0 +1,387 @@ +from binance.lib.utils import check_required_parameter +from binance.lib.utils import check_required_parameters + + +def get_target_asset_list(self, **kwargs): + """Get target asset list (USER_DATA) + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/target-asset/list + + https://binance-docs.github.io/apidocs/spot/en/#get-target-asset-list-user_data + + Keyword Args: + targetAsset (str) + size (int, optional): Default:10 Max:100 + current (int, optional): Current querying page. Start from 1. Default:1 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/lending/auto-invest/target-asset/list" + return self.sign_request("GET", url_path, kwargs) + + +def get_target_asset_roi_data(self, targetAsset: str, hisRoiType: str, **kwargs): + """Get target asset ROI data (USER_DATA) + + ROI return list for target asset + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/target-asset/roi/list + + https://binance-docs.github.io/apidocs/spot/en/#get-target-asset-roi-data-user_data + + Args: + targetAsset (str) + hisRoiType (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [[targetAsset, "targetAsset"], [hisRoiType, "hisRoiType"]] + ) + + params = {"targetAsset": targetAsset, "hisRoiType": hisRoiType, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/target-asset/roi/list" + return self.sign_request("GET", url_path, params) + + +def query_all_source_asset_and_target_asset(self, **kwargs): + """Query all source asset and target asset (USER_DATA) + + Query all source assets and target assets + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/all/asset + + https://binance-docs.github.io/apidocs/spot/en/#query-all-source-asset-and-target-asset-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/lending/auto-invest/all/asset" + return self.sign_request("GET", url_path, {**kwargs}) + + +def query_source_asset_list(self, usageType: str, **kwargs): + """Query source asset list (USER_DATA) + + Query Source Asset to be used for investment + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/source-asset/list + + https://binance-docs.github.io/apidocs/spot/en/#query-source-asset-list-user_data + + Args: + usageType (str) + Keyword Args: + targetAsset (array, optional) + indexId (int, optional) + flexibleAllowedToUse (boolean, optional) + sourceType (str, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(usageType, "usageType") + + params = {"usageType": usageType, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/source-asset/list" + return self.sign_request("GET", url_path, params) + + +def change_plan_status(self, planId: int, status: str, **kwargs): + """Change Plan Status (TRADE) + + Change Plan Status + + Weight(IP): 1 + + POST /sapi/v1/lending/auto-invest/plan/edit-status + + https://binance-docs.github.io/apidocs/spot/en/#change-plan-status-trade + + Args: + planId (int) + status (Status) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[planId, "planId"], [status, "status"]]) + + params = {"planId": planId, "status": status, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/plan/edit-status" + return self.sign_request("POST", url_path, params) + + +def get_list_of_plans(self, planType: str, **kwargs): + """Get list of plans (USER_DATA) + + Query plan lists + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/plan/list + + https://binance-docs.github.io/apidocs/spot/en/#get-list-of-plans-user_data + + Args: + planType (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(planType, "planType") + + params = {"planType": planType, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/plan/list" + return self.sign_request("GET", url_path, params) + + +def query_holding_details_of_the_plan(self, **kwargs): + """Query holding details of the plan (USER_DATA) + + Query holding details of the plan + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/plan/id + + https://binance-docs.github.io/apidocs/spot/en/#query-holding-details-of-the-plan-user_data + + Keyword Args: + planId (int, optional) + requestId (str, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/lending/auto-invest/plan/id" + return self.sign_request("GET", url_path, {**kwargs}) + + +def query_subscription_transaction_history(self, **kwargs): + """Query subscription transaction history (USER_DATA) + + Query subscription transaction history of a plan + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/history/list + + https://binance-docs.github.io/apidocs/spot/en/#query-subscription-transaction-history-user_data + + Keyword Args: + planType (str, optional) + planId (int, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + targetAsset (float, optional) + size (int, optional): Default:10 Max:100 + current (int, optional): Current querying page. Start from 1. Default:1 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + url_path = "/sapi/v1/lending/auto-invest/history/list" + return self.sign_request("GET", url_path, kwargs) + + +def query_index_details(self, indexId: int, **kwargs): + """Query Index Details (USER_DATA) + + Query index details + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/index/info + + https://binance-docs.github.io/apidocs/spot/en/#query-index-details-user_data + + Args: + indexId (int) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(indexId, "indexId") + + params = {"indexId": indexId, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/index/info" + return self.sign_request("GET", url_path, params) + + +def query_index_linked_plan_position_details(self, indexId: int, **kwargs): + """Query Index Linked Plan Position Details (USER_DATA) + + Details on users Index-Linked plan position details + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/index/user-summary + + https://binance-docs.github.io/apidocs/spot/en/#query-index-linked-plan-position-details-user_data + + Args: + indexId (int) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(indexId, "indexId") + + params = {"indexId": indexId, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/index/user-summary" + return self.sign_request("GET", url_path, params) + + +def one_time_transaction( + self, sourceType: str, subscriptionAmount: float, sourceAsset: str, **kwargs +): + """One Time Transaction (TRADE) + + One time transaction + + Weight(IP): 1 + + POST /sapi/v1/lending/auto-invest/one-off + + https://binance-docs.github.io/apidocs/spot/en/#one-time-transaction-trade + + Args: + sourceType (str) + subscriptionAmount (float) + sourceAsset (str) + Keyword Args: + requestId (str, optional) + flexibleAllowedToUse (boolean, optional) + planId (int, optional) + indexId (int, optional) + details (list, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [ + [sourceType, "sourceType"], + [subscriptionAmount, "subscriptionAmount"], + [sourceAsset, "sourceAsset"], + ] + ) + + params = { + "sourceType": sourceType, + "subscriptionAmount": subscriptionAmount, + "sourceAsset": sourceAsset, + **kwargs, + } + url_path = "/sapi/v1/lending/auto-invest/one-off" + return self.sign_request("POST", url_path, params) + + +def query_one_time_transaction_status(self, transactionId: int, **kwargs): + """Query One-Time Transaction Status (USER_DATA) + + Transaction status for one-time transaction + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/one-off/status + + https://binance-docs.github.io/apidocs/spot/en/#query-one-time-transaction-status-user_data + + Args: + transactionId (int) + Keyword Args: + requestId (str, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(transactionId, "transactionId") + + params = {"transactionId": transactionId, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/one-off/status" + return self.sign_request("GET", url_path, params) + + +def index_linked_plan_redemption( + self, indexId: int, redemptionPercentage: int, **kwargs +): + """Index Linked Plan Redemption (TRADE) + + To redeem index-Linked plan holdings + + Weight(IP): 1 + + POST /sapi/v1/lending/auto-invest/redeem + + https://binance-docs.github.io/apidocs/spot/en/#index-linked-plan-redemption-trade + + Args: + indexId (int) + redemptionPercentage (int) + Keyword Args: + requestId (str, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [[indexId, "indexId"], [redemptionPercentage, "redemptionPercentage"]] + ) + + params = { + "indexId": indexId, + "redemptionPercentage": redemptionPercentage, + **kwargs, + } + url_path = "/sapi/v1/lending/auto-invest/redeem" + return self.sign_request("POST", url_path, params) + + +def get_index_linked_plan_redemption_history(self, requestId: int, **kwargs): + """Index Linked Plan Redemption (USER_DATA) + + Get the history of Index Linked Plan Redemption transactions + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/redeem/history + + https://binance-docs.github.io/apidocs/spot/en/#index-linked-plan-redemption-user_data + + Args: + requestId (int) + Keyword Args: + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current 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(requestId, "requestId") + + params = {"requestId": requestId, **kwargs} + url_path = "/sapi/v1/lending/auto-invest/redeem/history" + return self.sign_request("GET", url_path, params) + + +def index_linked_plan_rebalance_details(self, **kwargs): + """Index Linked Plan Rebalance Details (USER_DATA) + + Get the history of Index Linked Plan Redemption transactions + + Max 30 day difference between startTime and endTime + If no startTime and endTime, default to show past 30 day records + + Weight(IP): 1 + + GET /sapi/v1/lending/auto-invest/rebalance/history + + https://binance-docs.github.io/apidocs/spot/en/#index-linked-plan-rebalance-details-user_data + + Keyword Args: + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/lending/auto-invest/rebalance/history" + return self.sign_request("GET", url_path, {**kwargs}) diff --git a/binance/spot/_convert.py b/binance/spot/_convert.py index 5f6a9f8d..6be48255 100644 --- a/binance/spot/_convert.py +++ b/binance/spot/_convert.py @@ -1,24 +1,140 @@ +from binance.lib.utils import ( + check_required_parameter, +) from binance.lib.utils import check_required_parameters -def convert_trade_history(self, startTime: int, endTime: int, **kwargs): - """Convert Trade History (USER_DATA) +def list_all_convert_pairs(self, **kwargs): + """List All Convert Pairs - Get convert history for a specific account. + Query for all convertible token pairs and the tokens’ respective upper/lower limits + + Weight(IP): 3000 + + GET /sapi/v1/convert/exchangeInfo + + https://binance-docs.github.io/apidocs/spot/en/#list-all-convert-pairs + + Keyword Args: + fromAsset (str, optional): User spends coin + toAsset (str, optional): User receives coin + """ + + url_path = "/sapi/v1/convert/exchangeInfo" + return self.query(url_path, {**kwargs}) + + +def query_order_quantity_precision_per_asset(self, **kwargs): + """Query order quantity precision per asset (USER_DATA) + + Query for supported asset precision information + + Weight(IP): 100 + + GET /sapi/v1/convert/assetInfo + + https://binance-docs.github.io/apidocs/spot/en/#query-order-quantity-precision-per-asset-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/convert/assetInfo" + return self.sign_request("GET", url_path, {**kwargs}) + + +def send_quote_request(self, fromAsset: str, toAsset: str, **kwargs): + """Send quote request (USER_DATA) + + Request a quote for the requested token pairs + + Weight(UID): 200 + + POST /sapi/v1/convert/getQuote + + https://binance-docs.github.io/apidocs/spot/en/#send-quote-request-user_data + + Args: + fromAsset (str) + toAsset (str) + Keyword Args: + fromAmount (float, optional): When specified, it is the amount you will be debited after the conversion + toAmount (float, optional): When specified, it is the amount you will be debited after the conversion + validTime (str, optional): 10s, 30s, 1m, 2m, default 10s + walletType (str, optional): SPOT or FUNDING. Default is SPOT + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[fromAsset, "fromAsset"], [toAsset, "toAsset"]]) + + params = {"fromAsset": fromAsset, "toAsset": toAsset, **kwargs} + url_path = "/sapi/v1/convert/getQuote" + return self.sign_request("POST", url_path, params) + + +def accept_quote(self, quoteId: str, **kwargs): + """Accept Quote (TRADE) + + Accept the offered quote by quote ID. + + Weight(UID): 500 + + POST /sapi/v1/convert/acceptQuote + + https://binance-docs.github.io/apidocs/spot/en/#accept-quote-trade + + Args: + quoteId (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(quoteId, "quoteId") + + params = {"quoteId": quoteId, **kwargs} + url_path = "/sapi/v1/convert/acceptQuote" + return self.sign_request("POST", url_path, params) + + +def order_status(self, **kwargs): + """Order status (USER_DATA) + + Query order status by order ID. + + Weight(UID): 100 + + GET /sapi/v1/convert/orderStatus + + https://binance-docs.github.io/apidocs/spot/en/#order-status-user_data + + Keyword Args: + orderId (str, optional) + quoteId (str, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/convert/orderStatus" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_convert_trade_history(self, startTime: int, endTime: int, **kwargs): + """Get Convert Trade History (USER_DATA) + + - The max interval between startTime and endTime is 30 days. + + Weight(UID): 3000 GET /sapi/v1/convert/tradeFlow - https://binance-docs.github.io/apidocs/spot/en/#convert-endpoints + https://binance-docs.github.io/apidocs/spot/en/#get-convert-trade-history-user_data Args: startTime (int) endTime (int) Keyword Args: - limit (int, optional): Default Value: 100; Max Value: 1000 - recvWindow (int, optional) + limit (int, optional): default 100, max 1000 + recvWindow (int, optional): The value cannot be greater than 60000 """ check_required_parameters([[startTime, "startTime"], [endTime, "endTime"]]) + params = {"startTime": startTime, "endTime": endTime, **kwargs} url_path = "/sapi/v1/convert/tradeFlow" - payload = {"startTime": startTime, "endTime": endTime, **kwargs} - return self.sign_request("GET", url_path, payload) + return self.sign_request("GET", url_path, params) diff --git a/binance/spot/_loan.py b/binance/spot/_crypto_loan.py similarity index 59% rename from binance/spot/_loan.py rename to binance/spot/_crypto_loan.py index dc329337..0185adbf 100644 --- a/binance/spot/_loan.py +++ b/binance/spot/_crypto_loan.py @@ -348,3 +348,249 @@ def loan_customize_margin_call(self, marginCall: float, **kwargs): payload = {"marginCall": marginCall, **kwargs} return self.sign_request("POST", "/sapi/v1/loan/customize/margin_call", payload) + + +def flexible_loan_borrow(self, loanCoin: str, collateralCoin: str, **kwargs): + """Borrow - Flexible Loan Borrow (TRADE) + + Weight(UID): 6000 + + POST /sapi/v1/loan/flexible/borrow + + https://binance-docs.github.io/apidocs/spot/en/#borrow-flexible-loan-borrow + + Args: + loanCoin (str, optional): Coin loaned + collateralCoin (str, optional): Coin used as collateral + Keyword Args: + loanAmount (float, optional): Loan amount + collateralAmount (float, optional) Mandatory when loanAmount is empty + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + check_required_parameters( + [[loanCoin, "loanCoin"], [collateralCoin, "collateralCoin"]] + ) + + payload = { + "loanCoin": loanCoin, + "collateralCoin": collateralCoin, + **kwargs, + } + + url_path = "/sapi/v1/loan/flexible/borrow" + return self.sign_request("POST", url_path, payload) + + +def flexible_loan_ongoing_orders(self, **kwargs): + """Borrow - Get Flexible Loan Ongoing Orders (USER_DATA) + + Weight(IP): 300 + + GET /sapi/v1/loan/flexible/ongoing/orders + + https://binance-docs.github.io/apidocs/spot/en/#borrow-get-flexible-loan-ongoing-orders-user_data + + Keyword Args: + loanCoin (str, optional): Coin loaned + collateralCoin (str, optional): Coin used as collateral + current (int, optional): Current querying page. Start from 1. Default:1 + limit (int, optional): Default 500; max 1000. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/loan/flexible/ongoing/orders" + return self.sign_request("GET", url_path, {**kwargs}) + + +def flexible_loan_borrow_history(self, **kwargs): + """Borrow - Get Flexible Loan Borrow History (USER_DATA) + + Weight(IP): 400 + + GET /sapi/v1/loan/flexible/borrow/history + + https://binance-docs.github.io/apidocs/spot/en/#borrow-get-flexible-loan-borrow-history-user_data + + Keyword Args: + loanCoin (str, optional): Coin loaned + collateralCoin (str, optional): Coin used as collateral + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + limit (int, optional): Default 500; max 1000. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/loan/flexible/borrow/history" + return self.sign_request("GET", url_path, {**kwargs}) + + +def flexible_loan_repay( + self, loanCoin: str, collateralCoin: str, repayAmount: float, **kwargs +): + """Repay - Flexible Loan Repay (TRADE) + + Weight(IP): 6000 + + POST /sapi/v1/loan/flexible/repay + + https://binance-docs.github.io/apidocs/spot/en/#repay-flexible-loan-repay-trade + + Args: + loanCoin (str, optional): Coin loaned + collateralCoin (str, optional): Coin used as collateral + repayAmount (float) + Keyword Args: + collateralReturn (boolean, optional) + fullRepayment (boolean, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [ + [repayAmount, "repayAmount"], + [collateralCoin, "collateralCoin"], + [loanCoin, "loanCoin"], + ] + ) + + payload = { + "repayAmount": repayAmount, + "collateralCoin": collateralCoin, + "loanCoin": loanCoin, + **kwargs, + } + url_path = "/sapi/v1/loan/flexible/repay" + return self.sign_request("POST", url_path, payload) + + +def flexible_loan_repayment_history(self, **kwargs): + """Repay - Get Flexible Loan Repayment History (USER_DATA) + + + Weight(IP): 400 + + GET /sapi/v1/loan/flexible/repay/history + + https://binance-docs.github.io/apidocs/spot/en/#repay-get-flexible-loan-repayment-history-user_data + + Keyword Args: + loanCoin (str, optional): Coin loaned + collateralCoin (str, optional): Coin used as collateral + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + limit (int, optional): Default 500; max 1000. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/loan/flexible/repay/history" + return self.sign_request("GET", url_path, {**kwargs}) + + +def flexible_loan_adjust_ltv( + self, + loanCoin: str, + collateralCoin: str, + adjustmentAmount: float, + direction: str, + **kwargs +): + """Adjust LTV - Flexible Loan Adjust LTV (TRADE) + + + Weight(UID): 6000 + + POST /sapi/v1/loan/flexible/adjust/ltv + + https://binance-docs.github.io/apidocs/spot/en/#adjust-ltv-flexible-loan-adjust-ltv-trade + + Args: + loanCoin (str) + collateralCoin (str) + adjustmentAmount (float) + direction (Direction) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [ + [loanCoin, "loanCoin"], + [collateralCoin, "collateralCoin"], + [adjustmentAmount, "adjustmentAmount"], + [direction, "direction"], + ] + ) + + payload = { + "loanCoin": loanCoin, + "collateralCoin": collateralCoin, + "adjustmentAmount": adjustmentAmount, + "direction": direction, + **kwargs, + } + url_path = "/sapi/v1/loan/flexible/adjust/ltv" + return self.sign_request("POST", url_path, payload) + + +def flexible_loan_ltv_adjustment_history(self, **kwargs): + """Adjust LTV - Get Flexible Loan LTV Adjustment History (USER_DATA) + + Weight(IP): 400 + + GET /sapi/v1/loan/flexible/ltv/adjustment/history + + https://binance-docs.github.io/apidocs/spot/en/#adjust-ltv-get-flexible-loan-ltv-adjustment-history-user_data + + Keyword Args: + loanCoin (str, optional): Coin loaned + collateralCoin (str, optional): Coin used as collateral + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + limit (int, optional): Default 500; max 1000. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/loan/flexible/ltv/adjustment/history" + return self.sign_request("GET", url_path, {**kwargs}) + + +def flexible_loan_assets_data(self, **kwargs): + """Get Flexible Loan Assets Data (USER_DATA) + + Get interest rate and borrow limit of flexible loanable assets. The borrow limit is shown in USD value. + + Weight(IP): 400 + + GET /sapi/v1/loan/flexible/loanable/data + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-loan-assets-data-user_data + + Keyword Args: + loanCoin (str, optional): Coin loaned + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/loan/flexible/loanable/data" + return self.sign_request("GET", url_path, {**kwargs}) + + +def flexible_loan_collateral_assets_data(self, **kwargs): + """Get Flexible Loan Collateral Assets Data (USER_DATA) + + Get LTV information and collateral limit of flexible loan's collateral assets. The collateral limit is shown in USD value. + + Weight(IP): 400 + + GET /sapi/v1/loan/flexible/collateral/data + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-loan-collateral-assets-data-user_data + + Keyword Args: + collateralCoin (str, optional): Coin used as collateral + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/loan/flexible/collateral/data" + return self.sign_request("GET", url_path, {**kwargs}) diff --git a/binance/spot/_futures.py b/binance/spot/_futures.py index bdb2e905..a2ebf8d5 100644 --- a/binance/spot/_futures.py +++ b/binance/spot/_futures.py @@ -53,112 +53,3 @@ def futures_transfer_history(self, asset: str, startTime, **kwargs): payload = {"asset": asset, "startTime": startTime, **kwargs} return self.sign_request("GET", "/sapi/v1/futures/transfer", payload) - - -def futures_loan_borrow_history(self, **kwargs): - """Cross-Collateral Borrow History (USER_DATA) - - GET /sapi/v1/futures/loan/borrow/history - - https://binance-docs.github.io/apidocs/spot/en/#cross-collateral-borrow-history-user_data - - Keyword Args: - coin (str, optional) - startTime (int, optional) - endTime (int, optional) - limit (int, optional): default 500, max 1000 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/futures/loan/borrow/history", kwargs) - - -def futures_loan_repay_history(self, **kwargs): - """Cross-Collateral Repayment History (USER_DATA) - - GET /sapi/v1/futures/loan/repay/history - - https://binance-docs.github.io/apidocs/spot/en/#cross-collateral-repayment-history-user_data - - Keyword Args: - coin (str, optional) - startTime (int, optional) - endTime (int, optional) - limit (int, optional): default 500, max 1000 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/futures/loan/repay/history", kwargs) - - -def futures_loan_wallet(self, **kwargs): - """Cross-Collateral Wallet (USER_DATA) - - GET /sapi/v2/futures/loan/wallet - - https://binance-docs.github.io/apidocs/spot/en/#cross-collateral-wallet-v2-user_data - - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v2/futures/loan/wallet", kwargs) - - -def futures_loan_adjust_collateral_history(self, **kwargs): - """Adjust Cross-Collateral LTV History (USER_DATA) - - GET /sapi/v1/futures/loan/adjustCollateral/history - - https://binance-docs.github.io/apidocs/spot/en/#adjust-cross-collateral-ltv-history-user_data - - Keyword Args: - loanCoin (str, optional) - collateralCoin (str, optional) - startTime (int, optional) - endTime (int, optional) - limit (int, optional): default 500, max 1000 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request( - "GET", "/sapi/v1/futures/loan/adjustCollateral/history", kwargs - ) - - -def futures_loan_liquidation_history(self, **kwargs): - """Cross-Collateral Liquidation History (USER_DATA) - - GET /sapi/v1/futures/loan/liquidationHistory - - https://binance-docs.github.io/apidocs/spot/en/#cross-collateral-liquidation-history-user_data - - Keyword Args: - loanCoin (str, optional) - collateralCoin (str, optional) - startTime (int, optional) - endTime (int, optional) - limit (int, optional): default 500, max 1000 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/futures/loan/liquidationHistory", kwargs) - - -def futures_loan_interest_history(self, **kwargs): - """Cross-Collateral Interest History (USER_DATA) - - GET /sapi/v1/futures/loan/interestHistory - - https://binance-docs.github.io/apidocs/spot/en/#cross-collateral-interest-history-user_data - - Keyword Args: - collateralCoin (str, optional) - startTime (int, optional) - endTime (int, optional) - current (int, optional): Currently querying page. Start from 1. Default:1 - limit (int, optional): default 500, max 1000 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/futures/loan/interestHistory", kwargs) diff --git a/binance/spot/_margin.py b/binance/spot/_margin.py index 52748753..5bc0c03f 100644 --- a/binance/spot/_margin.py +++ b/binance/spot/_margin.py @@ -30,7 +30,7 @@ def margin_borrow(self, asset: str, amount, **kwargs): """Margin Account Borrow (MARGIN) Apply for a loan. - POST /sapi/v1/margin/load + POST /sapi/v1/margin/loan https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-margin @@ -211,7 +211,7 @@ def cancel_margin_order(self, symbol: str, **kwargs): def margin_transfer_history(self, asset: str, **kwargs): - """Get Transfer History (USER_DATA) + """Get Cross Margin Transfer History (USER_DATA) GET /sapi/v1/margin/transfer @@ -957,3 +957,157 @@ def summary_of_margin_account(self, **kwargs): recvWindow (int, optional): The value cannot be greater than 60000 """ return self.sign_request("GET", "/sapi/v1/margin/tradeCoeff", kwargs) + + +def cross_margin_collateral_ratio(self): + """Cross margin collateral ratio (MARKET_DATA) + + + Weight(IP): 100 + + GET /sapi/v1/margin/crossMarginCollateralRatio + + https://binance-docs.github.io/apidocs/spot/en/#cross-margin-collateral-ratio-market_data + + """ + + url_path = "/sapi/v1/margin/crossMarginCollateralRatio" + return self.limit_request("GET", url_path) + + +def get_small_liability_exchange_coin_list(self, **kwargs): + """Get Small Liability Exchange Coin List (USER_DATA) + + Query the coins which can be small liability exchange + + Weight(UID): 100 + + GET /sapi/v1/margin/exchange-small-liability + + https://binance-docs.github.io/apidocs/spot/en/#get-small-liability-exchange-coin-list-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/margin/exchange-small-liability" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_small_liability_exchange_history(self, current: int, size: int, **kwargs): + """Get Small Liability Exchange History (USER_DATA) + + Get Small liability Exchange History + + Weight(UID): 100 + + GET /sapi/v1/margin/exchange-small-liability-history + + https://binance-docs.github.io/apidocs/spot/en/#get-small-liability-exchange-history-user_data + + Args: + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + 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 + """ + + check_required_parameters([[current, "current"], [size, "size"]]) + payload = {"current": current, "size": size, **kwargs} + url_path = "/sapi/v1/margin/exchange-small-liability-history" + return self.sign_request("GET", url_path, payload) + + +def get_a_future_hourly_interest_rate(self, assets: str, isIsolated: bool, **kwargs): + """Get a future hourly interest rate (USER_DATA) + + Get user the next hourly estimate interest + + Weight(UID): 100 + + GET /sapi/v1/margin/next-hourly-interest-rate + + https://binance-docs.github.io/apidocs/spot/en/#get-a-future-hourly-interest-rate-user_data + + Args: + assets (str, optional): List of assets, separated by commas, up to 20 + isIsolated (IsIsolated, optional): for isolated margin or not, "TRUE", "FALSE" + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[assets, "assets"], [isIsolated, "isIsolated"]]) + + if isIsolated: + isIsolated = "TRUE" + else: + isIsolated = "FALSE" + params = {"assets": assets, "isIsolated": isIsolated, **kwargs} + url_path = "/sapi/v1/margin/next-hourly-interest-rate" + 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) + + Adjust cross margin max leverage + + Weight(IP): 3000 + + POST /sapi/v1/margin/max-leverage + + https://binance-docs.github.io/apidocs/spot/en/#adjust-cross-margin-max-leverage-user_data + + Args: + maxLeverage (int) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(maxLeverage, "maxLeverage") + + params = {"maxLeverage": maxLeverage, **kwargs} + url_path = "/sapi/v1/margin/max-leverage" + return self.sign_request("POST", url_path, params) diff --git a/binance/spot/_portfolio_margin.py b/binance/spot/_portfolio_margin.py index ca36261e..1d1f1dd7 100644 --- a/binance/spot/_portfolio_margin.py +++ b/binance/spot/_portfolio_margin.py @@ -1,15 +1,26 @@ +from binance.lib.utils import ( + check_required_parameter, +) +from binance.lib.utils import check_required_parameters + + def portfolio_margin_account(self, **kwargs): - """Get Portfolio Margin Account Info (USER_DATA) + """Get Classic Portfolio Margin Account Info (USER_DATA) + + Get the account info + + 'Weight(IP): 1' GET /sapi/v1/portfolio/account - https://binance-docs.github.io/apidocs/spot/en/#get-portfolio-margin-account-info-user_data + https://binance-docs.github.io/apidocs/spot/en/#get-classic-portfolio-margin-account-info-user_data Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 + recvWindow (int, optional): The value cannot be greater than 60000 """ - return self.sign_request("GET", "/sapi/v1/portfolio/account", {**kwargs}) + url_path = "/sapi/v1/portfolio/account" + return self.sign_request("GET", url_path, {**kwargs}) def portfolio_margin_collateral_rate(self): @@ -30,15 +41,15 @@ def portfolio_margin_collateral_rate(self): def portfolio_margin_bankruptcy_loan_amount(self, **kwargs): - """Query Portfolio Margin Bankruptcy Loan Amount (USER_DATA) + """Query Classic Portfolio Margin Bankruptcy Loan Amount (USER_DATA) - Query Portfolio Margin Bankruptcy Loan Amount. + Query Classic Portfolio Margin Bankruptcy Loan Amount (USER_DATA) Weight(UID): 500 GET /sapi/v1/portfolio/pmLoan - https://binance-docs.github.io/apidocs/spot/en/#query-portfolio-margin-bankruptcy-loan-amount-user_data + https://binance-docs.github.io/apidocs/spot/en/#classic-portfolio-margin-collateral-rate-market_data Keyword Args: recvWindow (int, optional): The value cannot be greater than 60000 @@ -65,3 +76,179 @@ def portfolio_margin_bankruptcy_loan_repay(self, **kwargs): url_path = "/sapi/v1/portfolio/repay" return self.sign_request("POST", url_path, {**kwargs}) + + +def query_classic_portfolio_margin_negative_balance_interest_history( + self, asset: str, **kwargs +): + """Query Classic Portfolio Margin Negative Balance Interest History (USER_DATA) + + Query interest history of negative balance for portfolio margin. + + Weight(IP): 50 + + GET /sapi/v1/portfolio/interest-history + + https://binance-docs.github.io/apidocs/spot/en/#query-classic-portfolio-margin-negative-balance-interest-history-user_data + + Args: + asset (str) + Keyword Args: + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(asset, "asset") + + params = {"asset": asset, **kwargs} + url_path = "/sapi/v1/portfolio/interest-history" + return self.sign_request("GET", url_path, params) + + +def query_portfolio_margin_asset_index_price(self, **kwargs): + """Query Portfolio Margin Asset Index Price (MARKET_DATA) + + Query Portfolio Margin Asset Index Price + + Weight(IP): + - 1 if send asset + - 50 if not send asset + + GET /sapi/v1/portfolio/asset-index-price + + https://binance-docs.github.io/apidocs/spot/en/#query-portfolio-margin-asset-index-price-market_data + + Keyword Args: + asset (str, optional) + """ + + url_path = "/sapi/v1/portfolio/asset-index-price" + return self.limit_request("GET", url_path, kwargs) + + +def fund_auto_collection(self, **kwargs): + """Fund Auto-collection (USER_DATA) + + Transfers all assets from Futures Account to Margin account + + Weight(IP): 1500 + + POST /sapi/v1/portfolio/auto-collection + + https://binance-docs.github.io/apidocs/spot/en/#fund-auto-collection-usdr_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/portfolio/auto-collection" + return self.sign_request("POST", url_path, {**kwargs}) + + +def bnb_transfer(self, transferSide: str, amount: float, **kwargs): + """BNB Transfer (USER_DATA) + + BNB transfer can be between Margin Account and USDM Account + + Weight(IP): 1500 + + POST /sapi/v1/portfolio/bnb-transfer + + https://binance-docs.github.io/apidocs/spot/en/#bnb-transfer-usdr_data + + Args: + transferSide (str) + amount (float) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[transferSide, "transferSide"], [amount, "amount"]]) + + params = {"transferSide": transferSide, "amount": amount, **kwargs} + url_path = "/sapi/v1/portfolio/bnb-transfer" + return self.sign_request("POST", url_path, params) + + +def change_auto_repay_futures_status(self, autoRepay: bool, **kwargs): + """Change Auto-repay-futures Status (TRADE) + + Change Auto-repay-futures Status + + Weight(IP): 1500 + + POST /sapi/v1/portfolio/repay-futures-switch + + https://binance-docs.github.io/apidocs/spot/en/#change-auto-repay-futures-status-trade + + Args: + autoRepay (boolean) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(autoRepay, "autoRepay") + + params = {"autoRepay": autoRepay, **kwargs} + url_path = "/sapi/v1/portfolio/repay-futures-switch" + return self.sign_request("POST", url_path, params) + + +def get_auto_repay_futures_status(self, **kwargs): + """Get Auto-repay-futures Status (USER_DATA) + + Query Auto-repay-futures Status + + Weight(IP): 30 + + GET /sapi/v1/portfolio/repay-futures-switch + + https://binance-docs.github.io/apidocs/spot/en/#get-auto-repay-futures-status-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/portfolio/repay-futures-switch" + return self.sign_request("GET", url_path, {**kwargs}) + + +def repay_futures_negative_balance(self, **kwargs): + """Repay futures Negative Balance (USER_DATA) + + Repay futures Negative Balance + + Weight(IP): 1500 + + POST /sapi/v1/portfolio/repay-futures-negative-balance + + https://binance-docs.github.io/apidocs/spot/en/#repay-futures-negative-balance-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/portfolio/repay-futures-negative-balance" + return self.sign_request("POST", url_path, {**kwargs}) + + +def fund_collection_by_asset(self, asset: str, **kwargs): + """Fund Collection by Asset (USER_DATA) + + Transfers specific asset from Futures Account to Margin account + + Weight(IP): 60 + + POST /sapi/v1/portfolio/asset-collection + + https://binance-docs.github.io/apidocs/spot/en/#fund-collection-by-asset-usdr_data + + 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/portfolio/asset-collection" + return self.sign_request("POST", url_path, params) diff --git a/binance/spot/_savings.py b/binance/spot/_savings.py deleted file mode 100644 index 323f4a97..00000000 --- a/binance/spot/_savings.py +++ /dev/null @@ -1,283 +0,0 @@ -from binance.lib.utils import check_required_parameter -from binance.lib.utils import check_required_parameters - - -def savings_flexible_products(self, **kwargs): - """Get Flexible Product List (USER_DATA) - - GET /sapi/v1/lending/daily/product/list - - https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-list-user_data - - Keyword Args: - status (str, optional): "ALL", "SUBSCRIBABLE", "UNSUBSCRIBABLE"; default "ALL" - featured (str, optional): "ALL", "true"; default "ALL" - current (int, optional): Current query page. Default: 1, Min: 1 - size (int, optional): Default: 50, Max: 100 - recvWindow (int, optional): The value cannot be greater than 60000 - - """ - - return self.sign_request("GET", "/sapi/v1/lending/daily/product/list", kwargs) - - -def savings_flexible_user_left_quota(self, productId: str, **kwargs): - """Get Left Daily Purchase Quota of Flexible Product (USER_DATA) - - GET /sapi/v1/lending/daily/userLeftQuota - - https://binance-docs.github.io/apidocs/spot/en/#get-left-daily-purchase-quota-of-flexible-product-user_data - - Args: - productId (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - - """ - - check_required_parameter(productId, "productId") - payload = {"productId": productId, **kwargs} - return self.sign_request("GET", "/sapi/v1/lending/daily/userLeftQuota", payload) - - -def savings_purchase_flexible_product(self, productId: str, amount: float, **kwargs): - """POST Purchase Flexible Product (USER_DATA) - - POST /sapi/v1/lending/daily/purchase - - https://binance-docs.github.io/apidocs/spot/en/#purchase-flexible-product-user_data - - Args: - productId (str) - amount (float) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - - """ - - check_required_parameters([[productId, "productId"], [amount, "amount"]]) - payload = {"productId": productId, "amount": amount, **kwargs} - return self.sign_request("POST", "/sapi/v1/lending/daily/purchase", payload) - - -def savings_flexible_user_redemption_quota(self, productId: str, type: str, **kwargs): - """Get Left Daily Redemption Quota of Flexible Product (USER_DATA) - - GET /sapi/v1/lending/daily/userRedemptionQuota - - https://binance-docs.github.io/apidocs/spot/en/#get-left-daily-redemption-quota-of-flexible-product-user_data - - Args: - productId (str) - type (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters([[productId, "productId"], [type, "type"]]) - payload = {"productId": productId, "type": type, **kwargs} - return self.sign_request( - "GET", "/sapi/v1/lending/daily/userRedemptionQuota", payload - ) - - -def savings_flexible_redeem(self, productId: str, amount: float, type: str, **kwargs): - """Redeem Flexible Product (USER_DATA) - - POST /sapi/v1/lending/daily/redeem - - https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-user_data - - Args: - productId (str) - amount (float) - type (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters( - [[productId, "productId"], [amount, "amount"], [type, "type"]] - ) - payload = {"productId": productId, "amount": amount, "type": type, **kwargs} - return self.sign_request("POST", "/sapi/v1/lending/daily/redeem", payload) - - -def savings_flexible_product_position(self, **kwargs): - """Get Flexible Product Position (USER_DATA) - - GET /sapi/v1/lending/daily/token/position - - https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-position-user_data - - Keyword Args: - asset (str) - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/lending/daily/token/position", kwargs) - - -def savings_project_list(self, type: str, **kwargs): - """Get Fixed and Activity Project List(USER_DATA) - - GET /sapi/v1/lending/project/list - - https://binance-docs.github.io/apidocs/spot/en/#get-fixed-and-activity-project-list-user_data - - Args: - type (str) - Keyword Args: - asset (str, optional) - status (str, optional): "ALL", "SUBSCRIBABLE", "UNSUBSCRIBABLE"; default "ALL" - isSortAsc (bool, optional): By default, it's True - sortBy (str, optional): "START_TIME", "LOT_SIZE", "INTEREST_RATE", "DURATION"; default "START_TIME" - 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(type, "type") - payload = {"type": type, **kwargs} - return self.sign_request("GET", "/sapi/v1/lending/project/list", payload) - - -def savings_purchase_project(self, projectId: str, lot: int, **kwargs): - """Purchase Fixed/Activity Project (USER_DATA) - - POST /sapi/v1/lending/customizedFixed/purchase - - https://binance-docs.github.io/apidocs/spot/en/#purchase-fixed-activity-project-user_data - - Args: - projectId (str) - lot (int) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters([[projectId, "projectId"], [lot, "lot"]]) - payload = {"projectId": projectId, "lot": lot, **kwargs} - return self.sign_request( - "POST", "/sapi/v1/lending/customizedFixed/purchase", payload - ) - - -def savings_project_position(self, **kwargs): - """Get Fixed/Activity Project Position (USER_DATA) - - GET /sapi/v1/lending/project/position/list - - https://binance-docs.github.io/apidocs/spot/en/#get-fixed-activity-project-position-user_data - - Keyword Args: - asset (str, optional) - projectId (str, optional) - status (str, optional): "HOLDING", "REDEEMED" - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/lending/project/position/list", kwargs) - - -def savings_account(self, **kwargs): - """Lending Account (USER_DATA) - - GET /sapi/v1/lending/union/account - - https://binance-docs.github.io/apidocs/spot/en/#lending-account-user_data - - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/lending/union/account", kwargs) - - -def savings_purchase_record(self, lendingType: str, **kwargs): - """Get Purchase Record (USER_DATA) - - GET /sapi/v1/lending/union/purchaseRecord - - https://binance-docs.github.io/apidocs/spot/en/#get-purchase-record-user_data - - Args: - lendingType (str): "DAILY" for flexible, "ACTIVITY" for activity, "CUSTOMIZED_FIXED" for fixed - Keyword Args: - asset (str, optional) - 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(lendingType, "lendingType") - payload = {"lendingType": lendingType, **kwargs} - return self.sign_request("GET", "/sapi/v1/lending/union/purchaseRecord", payload) - - -def savings_redemption_record(self, lendingType: str, **kwargs): - """Get Redemption Record (USER_DATA) - - GET /sapi/v1/lending/union/redemptionRecord - - https://binance-docs.github.io/apidocs/spot/en/#get-redemption-record-user_data - - Args: - lendingType (str): "DAILY" for flexible, "ACTIVITY" for activity, "CUSTOMIZED_FIXED" for fixed - Keyword Args: - asset (str, optional) - 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(lendingType, "lendingType") - payload = {"lendingType": lendingType, **kwargs} - return self.sign_request("GET", "/sapi/v1/lending/union/redemptionRecord", payload) - - -def savings_interest_history(self, lendingType: str, **kwargs): - """Get Interest History (USER_DATA) - - GET /sapi/v1/lending/union/interestHistory - - https://binance-docs.github.io/apidocs/spot/en/#get-interest-history-user_data-2 - - Args: - lendingType (str): "DAILY" for flexible, "ACTIVITY" for activity, "CUSTOMIZED_FIXED" for fixed - Keyword Args: - asset (str, optional) - 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(lendingType, "lendingType") - payload = {"lendingType": lendingType, **kwargs} - return self.sign_request("GET", "/sapi/v1/lending/union/interestHistory", payload) - - -def savings_change_position(self, projectId: str, lot: int, **kwargs): - """Change Fixed/Activity Position to Daily Position(USER_DATA) - - POST /sapi/v1/lending/positionChanged - - https://binance-docs.github.io/apidocs/spot/en/#change-fixed-activity-position-to-daily-position-user_data - - Args: - projectId (str) - lot (int) - Keyword Args: - positionId (int, optional): for fixed position - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters([[projectId, "projectId"], [lot, "lot"]]) - payload = {"projectId": projectId, "lot": lot, **kwargs} - return self.sign_request("POST", "/sapi/v1/lending/positionChanged", payload) diff --git a/binance/spot/_simple_earn.py b/binance/spot/_simple_earn.py new file mode 100644 index 00000000..e480dbad --- /dev/null +++ b/binance/spot/_simple_earn.py @@ -0,0 +1,530 @@ +from binance.lib.utils import ( + check_required_parameter, +) +from binance.lib.utils import check_required_parameters + + +def get_simple_earn_flexible_product_list(self, **kwargs): + """Get Simple Earn Flexible Product List (USER_DATA) + + Get available Simple Earn flexible product list + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/list + + https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-flexible-product-list-user_data + + Keyword Args: + asset (str, optional) + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/flexible/list" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_simple_earn_locked_product_list(self, **kwargs): + """Get Simple Earn Locked Product List (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/list + + https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-locked-product-list-user_data + + Keyword Args: + asset (str, optional) + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/locked/list" + return self.sign_request("GET", url_path, {**kwargs}) + + +def subscribe_flexible_product(self, productId: str, amount: float, **kwargs): + """Subscribe Flexible Product (TRADE) + + Weight(IP): 1 + + Rate Limit: 1/3s per account + + POST /sapi/v1/simple-earn/flexible/subscribe + + https://binance-docs.github.io/apidocs/spot/en/#subscribe-flexible-product-trade + + Args: + productId (str) + amount (float) + Keyword Args: + autoSubscribe (boolean, optional): true or false, default true. + sourceAccount (str, optional): SPOT,FUND,ALL, default SPOT + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[productId, "productId"], [amount, "amount"]]) + + params = {"productId": productId, "amount": amount, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/subscribe" + return self.sign_request("POST", url_path, params) + + +def subscribe_locked_product(self, projectId: str, amount: float, **kwargs): + """Subscribe Locked Product (TRADE) + + Weight(IP): 1 + + Rate Limit: 1/3s per account + + POST /sapi/v1/simple-earn/locked/subscribe + + https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade + + Args: + projectId (str) + amount (float) + Keyword Args: + autoSubscribe (boolean, optional): true or false, default true. + sourceAccount (str, optional): SPOT,FUND,ALL, default SPOT + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[projectId, "projectId"], [amount, "amount"]]) + + params = {"projectId": projectId, "amount": amount, **kwargs} + url_path = "/sapi/v1/simple-earn/locked/subscribe" + return self.sign_request("POST", url_path, params) + + +def redeem_flexible_product(self, productId: str, **kwargs): + """Redeem Flexible Product (TRADE) + + Weight(IP): 1 + + Rate Limit: 1/3s per account + + POST /sapi/v1/simple-earn/flexible/redeem + + https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-trade + + Args: + productId (str) + Keyword Args: + redeemAll (boolean, optional): true or false, default to false + amount (float, optional): if redeemAll is false, amount is mandatory + destAccount (str, optional): SPOT,FUND,ALL, default SPOT + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(productId, "productId") + + params = {"productId": productId, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/redeem" + return self.sign_request("POST", url_path, params) + + +def redeem_locked_product(self, positionId: str, **kwargs): + """Redeem Locked Product (TRADE) + + Weight(IP): 1 + + Rate Limit: 1/3s per account + + POST /sapi/v1/simple-earn/locked/redeem + + https://binance-docs.github.io/apidocs/spot/en/#redeem-locked-product-trade + + Args: + positionId (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(positionId, "positionId") + + params = {"positionId": positionId, **kwargs} + url_path = "/sapi/v1/simple-earn/locked/redeem" + return self.sign_request("POST", url_path, params) + + +def get_flexible_product_position(self, **kwargs): + """Get Flexible Product Position (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/position + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-position-user_data + + Keyword Args: + asset (str, optional) + productId (str, optional) + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/flexible/position" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_locked_product_position(self, **kwargs): + """Get Locked Product Position (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/position + + https://binance-docs.github.io/apidocs/spot/en/#get-locked-product-position-user_data + + Keyword Args: + asset (str, optional) + positionId (str, optional) + projectId (str, optional) + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/locked/position" + return self.sign_request("GET", url_path, {**kwargs}) + + +def simple_account(self, **kwargs): + """Simple Account (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/account + + https://binance-docs.github.io/apidocs/spot/en/#simple-account-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/account" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_flexible_subscription_record(self, **kwargs): + """Get Flexible Subscription Record (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/history/subscriptionRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-subscription-record-user_data + + Keyword Args: + productId (str, optional) + purchaseId (str, optional) + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/flexible/history/subscriptionRecord" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_locked_subscription_record(self, **kwargs): + """Get Locked Subscription Record (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/history/subscriptionRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-locked-subscription-record-user_data + + Keyword Args: + purchaseId (str, optional) + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/locked/history/subscriptionRecord" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_flexible_redemption_record(self, **kwargs): + """Get Flexible Redemption Record (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/history/redemptionRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-redemption-record-user_data + + Keyword Args: + productId (str, optional) + redeemId (str, optional) + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + """ + + url_path = "/sapi/v1/simple-earn/flexible/history/redemptionRecord" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_locked_redemption_record(self, **kwargs): + """Get Locked Redemption Record (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/history/redemptionRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-locked-redemption-record-user_data + + Keyword Args: + positionId (str, optional) + redeemId (str, optional) + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/locked/history/redemptionRecord" + return self.sign_request("GET", url_path, {**kwargs}) + + +def get_flexible_rewards_history(self, type: str, **kwargs): + """Get Flexible Rewards History (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/history/rewardsRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-rewards-history-user_data + + Args: + type (str) + Keyword Args: + productId (str, optional) + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + """ + check_required_parameter(type, "type") + + params = {"type": type, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/history/rewardsRecord" + return self.sign_request("GET", url_path, params) + + +def get_locked_rewards_history(self, **kwargs): + """Get Locked Rewards History (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/history/rewardsRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-locked-rewards-history-user_data + + Keyword Args: + positionId (str, optional) + asset (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Currently querying the page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/locked/history/rewardsRecord" + return self.sign_request("GET", url_path, {**kwargs}) + + +def set_flexible_auto_subscribe(self, productId: str, autoSubscribe: bool, **kwargs): + """Set Flexible Auto Subscribe (USER_DATA) + + Weight(IP): 150 + + POST /sapi/v1/simple-earn/flexible/setAutoSubscribe + + https://binance-docs.github.io/apidocs/spot/en/#set-flexible-auto-subscribe-user_data + + Args: + productId (str) + autoSubscribe (boolean) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [[productId, "productId"], [autoSubscribe, "autoSubscribe"]] + ) + + params = {"productId": productId, "autoSubscribe": autoSubscribe, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/setAutoSubscribe" + return self.sign_request("POST", url_path, params) + + +def set_locked_auto_subscribe(self, positionId: str, autoSubscribe: bool, **kwargs): + """Set Locked Auto Subscribe (USER_DATA) + + Weight(IP): 150 + + POST /sapi/v1/simple-earn/locked/setAutoSubscribe + + https://binance-docs.github.io/apidocs/spot/en/#set-locked-auto-subscribe-user_data + + Args: + positionId (str) + autoSubscribe (boolean) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [[positionId, "positionId"], [autoSubscribe, "autoSubscribe"]] + ) + + params = {"positionId": positionId, "autoSubscribe": autoSubscribe, **kwargs} + url_path = "/sapi/v1/simple-earn/locked/setAutoSubscribe" + return self.sign_request("POST", url_path, params) + + +def get_flexible_personal_left_quota(self, productId: str, **kwargs): + """Get Flexible Personal Left Quota (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/personalLeftQuota + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-personal-left-quota-user_data + + Args: + productId (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(productId, "productId") + + params = {"productId": productId, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/personalLeftQuota" + return self.sign_request("GET", url_path, params) + + +def get_locked_personal_left_quota(self, projectId: str, **kwargs): + """Get Locked Personal Left Quota (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/personalLeftQuota + + https://binance-docs.github.io/apidocs/spot/en/#get-locked-personal-left-quota-user_data + + Args: + projectId (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(projectId, "projectId") + + params = {"projectId": projectId, **kwargs} + url_path = "/sapi/v1/simple-earn/locked/personalLeftQuota" + return self.sign_request("GET", url_path, params) + + +def get_flexible_subscription_preview(self, productId: str, amount: float, **kwargs): + """Get Flexible Subscription Preview (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/subscriptionPreview + + https://binance-docs.github.io/apidocs/spot/en/#get-flexible-subscription-preview-user_data + + Args: + productId (str) + amount (float) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[productId, "productId"], [amount, "amount"]]) + + params = {"productId": productId, "amount": amount, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/subscriptionPreview" + return self.sign_request("GET", url_path, params) + + +def get_locked_subscription_preview(self, projectId: str, amount: float, **kwargs): + """Get Locked Subscription Preview (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/locked/subscriptionPreview + + https://binance-docs.github.io/apidocs/spot/en/#get-locked-subscription-preview-user_data + + Args: + projectId (str) + amount (float) + Keyword Args: + autoSubscribe (boolean, optional): true or false, default true. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[projectId, "projectId"], [amount, "amount"]]) + + params = {"projectId": projectId, "amount": amount, **kwargs} + url_path = "/sapi/v1/simple-earn/locked/subscriptionPreview" + return self.sign_request("GET", url_path, params) + + +def get_rate_history(self, productId: str, **kwargs): + """Get Rate History (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/history/rateHistory + + https://binance-docs.github.io/apidocs/spot/en/#get-rate-history-user_data + + Args: + productId (str) + Keyword Args: + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current 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(productId, "productId") + + params = {"productId": productId, **kwargs} + url_path = "/sapi/v1/simple-earn/flexible/history/rateHistory" + return self.sign_request("GET", url_path, params) + + +def get_collateral_record(self, **kwargs): + """Get Collateral Record (USER_DATA) + + Weight(IP): 150 + + GET /sapi/v1/simple-earn/flexible/history/collateralRecord + + https://binance-docs.github.io/apidocs/spot/en/#get-collateral-record-user_data + + Keyword Args: + productId (str, optional) + startTime (int, optional): UTC timestamp in ms + endTime (int, optional): UTC timestamp in ms + current (int, optional): Current querying page. Start from 1. Default:1 + size (int, optional): Default:10 Max:100 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/simple-earn/flexible/history/collateralRecord" + return self.sign_request("GET", url_path, {**kwargs}) diff --git a/binance/spot/_sub_account.py b/binance/spot/_sub_account.py index 7af9ae99..0ca20a0f 100644 --- a/binance/spot/_sub_account.py +++ b/binance/spot/_sub_account.py @@ -212,7 +212,7 @@ def sub_account_futures_transfer( ): """Futures Transfer for Sub-account(For Master Account) - GET /sapi/v1/sub-account/futures/transfer + POST /sapi/v1/sub-account/futures/transfer https://binance-docs.github.io/apidocs/spot/en/#futures-transfer-for-sub-account-for-master-account @@ -237,7 +237,7 @@ def sub_account_margin_transfer( ): """Margin Transfer for Sub-account(For Master Account) - GET /sapi/v1/sub-account/margin/transfer + POST /sapi/v1/sub-account/margin/transfer https://binance-docs.github.io/apidocs/spot/en/#margin-transfer-for-sub-account-for-master-account @@ -307,7 +307,7 @@ def sub_account_transfer_to_master(self, asset: str, amount: float, **kwargs): def sub_account_transfer_sub_account_history(self, **kwargs): """Sub-account Transfer History (For Sub-account) - POST /sapi/v1/sub-account/transfer/subUserHistory + GET /sapi/v1/sub-account/transfer/subUserHistory https://binance-docs.github.io/apidocs/spot/en/#sub-account-transfer-history-for-sub-account @@ -518,7 +518,7 @@ def sub_account_futures_account_summary(self, futuresType: int, **kwargs): GET /sapi/v2/sub-account/futures/accountSummary - https://binance-docs.github.io/apidocs/spot/en/#get-detail-on-sub-account-39-s-futures-account-v2-for-master-account + https://binance-docs.github.io/apidocs/spot/en/#get-summary-of-sub-account-39-s-futures-account-v2-for-master-account Args: futuresType (int): 1 : USDT-maringed Futues, 2: Coin-margined Futures @@ -927,3 +927,245 @@ def managed_sub_account_deposit_address(self, email: str, coin: str, **kwargs): return self.limited_encoded_sign_request( "GET", "/sapi/v1/managed-subaccount/deposit/address", payload ) + + +def query_sub_account_assets(self, email: str, **kwargs): + """Query Sub-account Assets (For Master Account) (USER_DATA) + + Fetch sub-account assets + + Weight(UID): 60 + + GET /sapi/v4/sub-account/assets + + https://binance-docs.github.io/apidocs/spot/en/#query-sub-account-assets-for-master-account-user_data + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v4/sub-account/assets" + return self.sign_request("GET", url_path, params) + + +def enable_options_for_sub_account(self, email: str, **kwargs): + """Enable Options for Sub-account (For Master Account) (USER_DATA) + + Weight(IP): 1 + + POST /sapi/v1/sub-account/eoptions/enable + + https://binance-docs.github.io/apidocs/spot/en/#enable-options-for-sub-account-for-master-account-user_data + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v1/sub-account/eoptions/enable" + return self.sign_request("POST", url_path, params) + + +def query_sub_account_transaction_statistics(self, email: str, **kwargs): + """Query Sub-account Transaction Statistics (For Master Account) (USER_DATA) + + Weight(UID): 60 + + GET /sapi/v1/sub-account/transaction-statistics + + https://binance-docs.github.io/apidocs/spot/en/#query-sub-account-transaction-statistics-for-master-account-user_data + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v1/sub-account/transaction-statistics" + return self.sign_request("GET", url_path, params) + + +def query_managed_sub_account_transfer_log( + self, startTime: int, endTime: int, page: int, limit: int, **kwargs +): + """Query Managed Sub Account Transfer Log (For Trading Team Sub Account) + + Query Managed Sub Account Transfer Log (For Trading Team Sub Account) + + Weight(UID): 60 + + GET /sapi/v1/managed-subaccount/query-trans-log + + https://binance-docs.github.io/apidocs/spot/en/#query-managed-sub-account-transfer-log-for-trading-team-sub-account-user_data + + Args: + startTime (int): UTC timestamp in ms + endTime (int): UTC timestamp in ms + page (int): Default 1 + limit (int): Default 500; max 1000. + Keyword Args: + transfers (str, optional) + transferFunctionAccountType (str, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [ + [startTime, "startTime"], + [endTime, "endTime"], + [page, "page"], + [limit, "limit"], + ] + ) + + params = { + "startTime": startTime, + "endTime": endTime, + "page": page, + "limit": limit, + **kwargs, + } + url_path = "/sapi/v1/managed-subaccount/query-trans-log" + return self.sign_request("GET", url_path, params) + + +def query_managed_sub_account_list(self, **kwargs): + """Query Managed Sub-account List (For Investor) (USER_DATA) + + Get investor's managed sub-account list. + + Weight(UID): 60 + + GET /sapi/v1/managed-subaccount/info + + https://binance-docs.github.io/apidocs/spot/en/#query-managed-sub-account-list-for-investor-user_data + + Keyword Args: + email (str, optional) + page (int, optional): Default 1 + limit (int, optional): Default 500; max 1000. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/managed-subaccount/info" + return self.sign_request("GET", url_path, kwargs) + + +def query_managed_sub_account_margin_asset_details(self, email: str, **kwargs): + """Query Managed Sub-account Margin Asset Details (For Investor Master Account) + + Investor can use this api to query managed sub account margin asset details + + Weight(IP): 1 + + GET /sapi/v1/managed-subaccount/marginAsset + + https://binance-docs.github.io/apidocs/spot/en/#query-managed-sub-account-margin-asset-details-for-investor-master-account-user_data + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v1/managed-subaccount/marginAsset" + return self.sign_request("GET", url_path, params) + + +def query_managed_sub_account_futures_asset_details(self, email: str, **kwargs): + """Query Managed Sub-account Futures Asset Details (For Investor Master Account) + + Investor can use this api to query managed sub account futures asset details + + Weight(UID): 60 + + GET /sapi/v1/managed-subaccount/fetch-future-asset + + https://binance-docs.github.io/apidocs/spot/en/#query-managed-sub-account-futures-asset-details-for-investor-master-account-user_data + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v1/managed-subaccount/fetch-future-asset" + return self.sign_request("GET", url_path, params) + + +def futures_position_risk_of_sub_account(self, email: str, **kwargs): + """Get Futures Position-Risk of Sub-account (For Master Account) + + Weight(IP): 10 + + GET /sapi/v1/sub-account/futures/positionRisk + + https://binance-docs.github.io/apidocs/spot/en/#get-futures-position-risk-of-sub-account-for-master-account + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v1/sub-account/futures/positionRisk" + return self.sign_request("GET", url_path, params) + + +def summary_of_sub_account_s_futures_account(self, futuresType: int, **kwargs): + """Get Summary of Sub-account's Futures Account V2 (For Master Account) + + Weight(IP): 10 + + GET /sapi/v2/sub-account/futures/accountSummary + + https://binance-docs.github.io/apidocs/spot/en/#get-summary-of-sub-account-39-s-futures-account-v2-for-master-account + + Args: + futuresType (int): 1:USDT Margined Futures, 2:COIN Margined Futures + Keyword Args: + page (int, optional): default:1 + limit (int, optional): default 10, max 20 + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + check_required_parameter(futuresType, "futuresType") + + params = {"futuresType": futuresType, **kwargs} + url_path = "/sapi/v2/sub-account/futures/accountSummary" + return self.sign_request("GET", url_path, params) + + +def detail_on_sub_account_s_futures_account(self, email: str, **kwargs): + """Detail on Sub-account's Futures Account (For Master Account) + + Weight(IP): 10 + + GET /sapi/v1/sub-account/futures/account + + https://binance-docs.github.io/apidocs/spot/en/#get-detail-on-sub-account-39-s-futures-account-for-master-account + + Args: + email (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(email, "email") + + params = {"email": email, **kwargs} + url_path = "/sapi/v1/sub-account/futures/account" + return self.sign_request("GET", url_path, params) diff --git a/binance/spot/_trade.py b/binance/spot/_trade.py index 5351d855..398f06f4 100644 --- a/binance/spot/_trade.py +++ b/binance/spot/_trade.py @@ -439,3 +439,44 @@ def get_order_rate_limit(self, **kwargs): url_path = "/api/v3/rateLimit/order" return self.sign_request("GET", url_path, {**kwargs}) + + +def query_prevented_matches(self, symbol: str, **kwargs): + """Query Prevented Matches + + Displays the list of orders that were expired because of STP. + + For additional information on what a Prevented match is, as well as Self Trade Prevention (STP), please refer to our STP FAQ page. + + These are the combinations supported: + + * symbol + preventedMatchId + * symbol + orderId + * symbol + orderId + fromPreventedMatchId (limit will default to 500) + * symbol + orderId + fromPreventedMatchId + limit + + Weight(IP): + + Case Weight + If symbol is invalid: 2 + Querying by preventedMatchId: 2 + Querying by orderId: 20 + + GET /api/v3/myPreventedMatches + + https://binance-docs.github.io/apidocs/spot/en/#query-prevented-matches-user_data + + Args: + symbol (str) + Keyword Args: + preventedMatchId (int, optional) + orderId (int, optional): Order id + fromPreventedMatchId (int, optional) + limit (int, optional): Default 500; max 1000. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(symbol, "symbol") + + params = {"symbol": symbol, **kwargs} + url_path = "/api/v3/myPreventedMatches" + return self.sign_request("GET", url_path, params) diff --git a/binance/spot/_wallet.py b/binance/spot/_wallet.py index d3bf3148..78bc4701 100644 --- a/binance/spot/_wallet.py +++ b/binance/spot/_wallet.py @@ -270,7 +270,7 @@ def user_universal_transfer_history(self, type: str, **kwargs): return self.sign_request("GET", "/sapi/v1/asset/transfer", payload) -def transfer_dust(self, asset, **kwargs): +def transfer_dust(self, asset: list, **kwargs): """Dust Transfer (USER_DATA) Convert dust assets to BNB. @@ -285,7 +285,8 @@ def transfer_dust(self, asset, **kwargs): """ check_required_parameter(asset, "asset") - payload = {"asset": asset, **kwargs} + + payload = {"asset": ",".join(asset), **kwargs} return self.sign_request("POST", "/sapi/v1/asset/dust", payload) @@ -524,3 +525,26 @@ def convert_history(self, startTime: int, endTime: int, **kwargs): url_path = "/sapi/v1/asset/convert-transfer/queryByPage" payload = {"startTime": startTime, "endTime": endTime, **kwargs} return self.sign_request("GET", url_path, payload) + + +def one_click_arrival_deposit_apply(self, **kwargs): + """One click arrival deposit apply (USER_DATA) + + Apply deposit credit for expired address (One click arrival) + + Weight(IP): 1 + + POST /sapi/v1/capital/deposit/credit-apply + + https://binance-docs.github.io/apidocs/spot/en/#one-click-arrival-deposit-apply-user_data + + Keyword Args: + depositId (int, optional): Deposit record Id, priority use + txId (str, optional): Deposit txId, used when depositId is not specified + subAccountId (int, optional) + subUserId (int, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/capital/deposit/credit-apply" + return self.sign_request("POST", url_path, {**kwargs}) diff --git a/binance/websocket/binance_socket_manager.py b/binance/websocket/binance_socket_manager.py index 61567cf2..6bf6e7de 100644 --- a/binance/websocket/binance_socket_manager.py +++ b/binance/websocket/binance_socket_manager.py @@ -97,7 +97,7 @@ def read_data(self): def close(self): if not self.ws.connected: - self.logger.warn("Websocket already closed") + self.logger.warning("Websocket already closed") else: self.ws.send_close() return diff --git a/binance/websocket/spot/websocket_api/__init__.py b/binance/websocket/spot/websocket_api/__init__.py index 6f09f994..a7bbc0c0 100644 --- a/binance/websocket/spot/websocket_api/__init__.py +++ b/binance/websocket/spot/websocket_api/__init__.py @@ -15,6 +15,7 @@ def __init__( on_error=None, on_ping=None, on_pong=None, + logger=None, proxies: Optional[dict] = None, ): self.api_key = api_key @@ -28,6 +29,7 @@ def __init__( on_error=on_error, on_ping=on_ping, on_pong=on_pong, + logger=logger, proxies=proxies, ) diff --git a/binance/websocket/spot/websocket_stream.py b/binance/websocket/spot/websocket_stream.py index b1640b1c..0e294180 100644 --- a/binance/websocket/spot/websocket_stream.py +++ b/binance/websocket/spot/websocket_stream.py @@ -13,6 +13,7 @@ def __init__( on_error=None, on_ping=None, on_pong=None, + logger=None, is_combined=False, proxies: Optional[dict] = None, ): @@ -28,6 +29,7 @@ def __init__( on_error=on_error, on_ping=on_ping, on_pong=on_pong, + logger=logger, proxies=proxies, ) diff --git a/docs/source/CHANGELOG.rst b/docs/source/CHANGELOG.rst index 5b528518..9a4d6c91 100644 --- a/docs/source/CHANGELOG.rst +++ b/docs/source/CHANGELOG.rst @@ -2,6 +2,133 @@ Changelog ========= + +3.4.0 - 2023-10-07 +------------------ + +Added +^^^^^ + +* Portfolio endpoints: + + * ``POST /sapi/v1/portfolio/interest-history`` + * ``POST /sapi/v1/portfolio/asset-index-price`` + * ``POST /sapi/v1/portfolio/auto-collection`` + * ``POST /sapi/v1/portfolio/bnb-transfer`` + * ``POST /sapi/v1/portfolio/repay-futures-switch`` + * ``GET /sapi/v1/portfolio/repay-futures-switch`` + * ``POST /sapi/v1/portfolio/repay-futures-negative-balance`` + * ``POST /sapi/v1/portfolio/asset-collection`` + +* Convert + + * ``GET /sapi/v1/convert/exchangeInfo`` + * ``GET /sapi/v1/convert/assetInfo`` + * ``POST /sapi/v1/convert/getQuote`` + * ``POST /sapi/v1/convert/acceptQuote`` + * ``GET /sapi/v1/convert/orderStatus`` + +* Crypto Loan + + * ``POST /sapi/v1/loan/flexible/borrow`` + * ``GET /sapi/v1/loan/flexible/ongoing/order`` + * ``GET /sapi/v1/loan/flexible/borrow/history`` + * ``POST /sapi/v1/loan/flexible/repay`` + * ``GET /sapi/v1/loan/flexible/repay/history`` + * ``POST /sapi/v1/loan/flexible/adjust/ltv`` + * ``GET /sapi/v1/loan/flexible/ltv/adjustment/history`` + * ``GET /sapi/v1/loan/flexible/loanable/data`` + * ``GET /sapi/v1/loan/flexible/collateral/data`` + +* Margin + + * ``GET /sapi/v1/margin/crossMarginCollateralRatio`` + * ``GET /sapi/v1/margin/exchange-small-liability`` + * ``GET /sapi/v1/margin/exchange-small-liability-history`` + * ``GET /sapi/v1/margin/next-hourly-interest-rate`` + * ``GET /sapi/v1/margin/dust`` + * ``POST /sapi/v1/margin/dust`` + * ``GET /sapi/v1/margin/max-leverage`` + +* SubAccount + + * ``POST /sapi/v4/sub-account/assets`` + * ``POST /sapi/v1/sub-account/eoptions/enable`` + * ``GET /sapi/v1/sub-account/transaction-statistics`` + * ``GET /sapi/v1/managed-subaccount/query-trans-log`` + * ``GET /sapi/v1/managed-subaccount/info`` + * ``GET /sapi/v1/managed-subaccount/marginAsset`` + * ``GET /sapi/v1/managed-subaccount/fetch-future-asset`` + * ``GET /sapi/v1/sub-account/futures/positionRisk`` + * ``GET /sapi/v1/sub-account/futures/accountSummary`` + * ``GET /sapi/v1/sub-account/futures/account`` + +* Trade + + * ``GET /api/v3/myPreventedMatches`` + +* Wallet + + * ``POST /sapi/v1/capital/deposit/credit-apply`` + +* Simple Earn + + * ``GET /sapi/v1/simple-earn/flexible/list`` + * ``GET /sapi/v1/simple-earn/locked/list`` + * ``POST /sapi/v1/simple-earn/flexible/subscribe`` + * ``POST /sapi/v1/simple-earn/locked/subscribe`` + * ``POST /sapi/v1/simple-earn/flexible/redeem`` + * ``POST /sapi/v1/simple-earn/locked/redeem`` + * ``GET /sapi/v1/simple-earn/flexible/position`` + * ``GET /sapi/v1/simple-earn/locked/position`` + * ``GET /sapi/v1/simple-earn/account`` + * ``GET /sapi/v1/simple-earn/flexible/history/subscriptionRecord`` + * ``GET /sapi/v1/simple-earn/locked/history/subscriptionRecord`` + * ``GET /sapi/v1/simple-earn/flexible/history/redemptionRecord`` + * ``GET /sapi/v1/simple-earn/locked/history/redemptionRecord`` + * ``GET /sapi/v1/simple-earn/flexible/history/rewardsRecord`` + * ``GET /sapi/v1/simple-earn/locked/history/rewardsRecord`` + * ``POST /sapi/v1/simple-earn/flexible/setAutoSubscribe`` + * ``POST /sapi/v1/simple-earn/locked/setAutoSubscribe`` + * ``GET /sapi/v1/simple-earn/flexible/personalLeftQuota`` + * ``GET /sapi/v1/simple-earn/locked/personalLeftQuota`` + * ``GET /sapi/v1/simple-earn/flexible/subscriptionPreview`` + * ``GET /sapi/v1/simple-earn/locked/subscriptionPreview`` + * ``GET /sapi/v1/simple-earn/flexible/history/rateHistory`` + * ``GET /sapi/v1/simple-earn/flexible/history/collateralRecord`` + +Deleted +^^^^^^^ + +* ``GET /sapi/v1/lending/daily/product/list`` +* ``GET /sapi/v1/lending/daily/userLeftQuota`` +* ``POST /sapi/v1/lending/daily/purchase`` +* ``GET /sapi/v1/lending/daily/userRedemptionQuota`` +* ``POST /sapi/v1/lending/daily/redeem`` +* ``GET /sapi/v1/lending/daily/token/position`` +* ``GET /sapi/v1/lending/union/account`` +* ``GET /sapi/v1/lending/union/purchaseRecord`` +* ``GET /sapi/v1/lending/union/redemptionRecord`` +* ``GET /sapi/v1/lending/union/interestHistory`` +* ``GET /sapi/v1/lending/project/list`` +* ``POST /sapi/v1/lending/customizedFixed/purchase`` +* ``GET /sapi/v1/lending/project/position/list`` +* ``POST /sapi/v1/lending/positionChanged`` +* ``GET /sapi/v1/futures/loan/borrow/history`` +* ``GET /sapi/v1/futures/loan/repay/history`` +* ``GET /sapi/v2/futures/loan/wallet`` +* ``GET /sapi/v1/futures/loan/adjustCollateral/history`` +* ``GET /sapi/v1/futures/loan/liquidationHistory`` +* ``GET /sapi/v1/futures/loan/interestHistory`` + + +Changed +^^^^^^^ + +* Change ``Loan`` module name to ``Crypto Loan`` +* Pump dependencies + + 3.3.1 - 2023-08-23 ------------------ diff --git a/docs/source/binance.spot.convert.rst b/docs/source/binance.spot.convert.rst index b30ad0ce..31941a9c 100644 --- a/docs/source/binance.spot.convert.rst +++ b/docs/source/binance.spot.convert.rst @@ -2,6 +2,26 @@ Convert Endpoints ================= +List All Convert Pairs +---------------------- +.. autofunction:: binance.spot.Spot.list_all_convert_pairs + +Query order quantity precision per asset (USER_DATA) +---------------------------------------------------- +.. autofunction:: binance.spot.Spot.query_order_quantity_precision_per_asset + +Send quote request (USER_DATA) +------------------------------ +.. autofunction:: binance.spot.Spot.send_quote_request + +Accept Quote (TRADE) +-------------------- +.. autofunction:: binance.spot.Spot.accept_quote + +Order status (USER_DATA) +------------------------ +.. autofunction:: binance.spot.Spot.order_status + Get Convert Trade History (USER_DATA) ------------------------------------- -.. autofunction:: binance.spot.Spot.convert_trade_history +.. autofunction:: binance.spot.Spot.get_convert_trade_history diff --git a/docs/source/binance.spot.loan.rst b/docs/source/binance.spot.crypto_loan.rst similarity index 100% rename from docs/source/binance.spot.loan.rst rename to docs/source/binance.spot.crypto_loan.rst diff --git a/docs/source/binance.spot.futures.rst b/docs/source/binance.spot.futures.rst index 292d2c9c..ddc34d89 100644 --- a/docs/source/binance.spot.futures.rst +++ b/docs/source/binance.spot.futures.rst @@ -8,27 +8,3 @@ New Future Account Transfer (USER_DATA) Get Future Account Transaction History List (USER_DATA) ------------------------------------------------------- .. autofunction:: binance.spot.Spot.futures_transfer_history - -Cross-Collateral Borrow History (USER_DATA) -------------------------------------------- -.. autofunction:: binance.spot.Spot.futures_loan_borrow_history - -Cross-Collateral Repayment History (USER_DATA) ----------------------------------------------- -.. autofunction:: binance.spot.Spot.futures_loan_repay_history - -Cross-Collateral Wallet (USER_DATA) ------------------------------------ -.. autofunction:: binance.spot.Spot.futures_loan_wallet - -Adjust Cross-Collateral LTV History (USER_DATA) ------------------------------------------------ -.. autofunction:: binance.spot.Spot.futures_loan_adjust_collateral_history - -Cross-Collateral Liquidation History (USER_DATA) ------------------------------------------------- -.. autofunction:: binance.spot.Spot.futures_loan_liquidation_history - -Cross-Collateral Interest History (USER_DATA) ---------------------------------------------- -.. autofunction:: binance.spot.Spot.futures_loan_interest_history diff --git a/docs/source/binance.spot.portfolio_margin.rst b/docs/source/binance.spot.portfolio_margin.rst index 03dde79e..9fb0aa7d 100644 --- a/docs/source/binance.spot.portfolio_margin.rst +++ b/docs/source/binance.spot.portfolio_margin.rst @@ -1,15 +1,50 @@ Portfolio Margin Endpoints ========================== - -Get Portfolio Margin Account Info (USER_DATA) ---------------------------------------------- +Portfolio Margin Account (USER_DATA) +------------------------------------ .. autofunction:: binance.spot.Spot.portfolio_margin_account -Query Portfolio Margin Bankruptcy Loan Amount (USER_DATA) ---------------------------------------------------------- +Portfolio Margin Collateral Rate (MARKET_DATA) +---------------------------------------------- +.. autofunction:: binance.spot.Spot.portfolio_margin_collateral_rate + +Portfolio Margin Bankruptcy Loan Amount (USER_DATA) +--------------------------------------------------- .. autofunction:: binance.spot.Spot.portfolio_margin_bankruptcy_loan_amount Portfolio Margin Bankruptcy Loan Repay (USER_DATA) -------------------------------------------------- .. autofunction:: binance.spot.Spot.portfolio_margin_bankruptcy_loan_repay + +Query Classic Portfolio Margin Negative Balance Interest History (USER_DATA) +---------------------------------------------------------------------------- +.. autofunction:: binance.spot.Spot.query_classic_portfolio_margin_negative_balance_interest_history + +Query Portfolio Margin Asset Index Price (MARKET_DATA) +------------------------------------------------------ +.. autofunction:: binance.spot.Spot.query_portfolio_margin_asset_index_price + +Fund Auto-collection (USER_DATA) +-------------------------------- +.. autofunction:: binance.spot.Spot.fund_auto_collection + +BNB Transfer (USER_DATA) +------------------------ +.. autofunction:: binance.spot.Spot.bnb_transfer + +Change Auto-repay-futures Status (USER_DATA) +-------------------------------------------- +.. autofunction:: binance.spot.Spot.change_auto_repay_futures_status + +Get Auto-repay-futures Status (USER_DATA) +----------------------------------------- +.. autofunction:: binance.spot.Spot.get_auto_repay_futures_status + +Repay futures Negative Balance (USER_DATA) +------------------------------------------ +.. autofunction:: binance.spot.Spot.repay_futures_negative_balance + +Fund Collection by Asset (USER_DATA) +------------------------------------ +.. autofunction:: binance.spot.Spot.fund_collection_by_asset diff --git a/docs/source/binance.spot.rst b/docs/source/binance.spot.rst index 957bfb05..6fe8b6c3 100644 --- a/docs/source/binance.spot.rst +++ b/docs/source/binance.spot.rst @@ -12,7 +12,7 @@ Spot APIs binance.spot.fiat binance.spot.futures binance.spot.gift_card - binance.spot.loan + binance.spot.crypto_loan binance.spot.margin binance.spot.market binance.spot.mining @@ -20,8 +20,8 @@ Spot APIs binance.spot.pay binance.spot.portfolio_margin binance.spot.rebate - binance.spot.savings binance.spot.staking binance.spot.sub_account binance.spot.trade binance.spot.wallet + binance.spot.simple_earn diff --git a/docs/source/binance.spot.savings.rst b/docs/source/binance.spot.savings.rst deleted file mode 100644 index b962101f..00000000 --- a/docs/source/binance.spot.savings.rst +++ /dev/null @@ -1,58 +0,0 @@ -Savings Endpoints -================= - -Get Flexible Product List (USER_DATA) -------------------------------------- -.. autofunction:: binance.spot.Spot.savings_flexible_products - -Get Left Daily Purchase Quota of Flexible Product (USER_DATA) -------------------------------------------------------------- -.. autofunction:: binance.spot.Spot.savings_flexible_user_left_quota - -POST Purchase Flexible Product (USER_DATA) ------------------------------------------- -.. autofunction:: binance.spot.Spot.savings_purchase_flexible_product - -Get Left Daily Redemption Quota of Flexible Product (USER_DATA) ---------------------------------------------------------------- -.. autofunction:: binance.spot.Spot.savings_flexible_user_redemption_quota - -Redeem Flexible Product (USER_DATA) ------------------------------------ -.. autofunction:: binance.spot.Spot.savings_flexible_redeem - -Get Flexible Product Position (USER_DATA) ------------------------------------------ -.. autofunction:: binance.spot.Spot.savings_flexible_product_position - -Get Fixed and Activity Project List(USER_DATA) ----------------------------------------------- -.. autofunction:: binance.spot.Spot.savings_project_list - -Purchase Fixed/Activity Project (USER_DATA) -------------------------------------------- -.. autofunction:: binance.spot.Spot.savings_purchase_project - -Get Fixed/Activity Project Position (USER_DATA) ------------------------------------------------- -.. autofunction:: binance.spot.Spot.savings_project_position - -Lending Account (USER_DATA) ---------------------------- -.. autofunction:: binance.spot.Spot.savings_account - -Get Purchase Record (USER_DATA) -------------------------------- -.. autofunction:: binance.spot.Spot.savings_purchase_record - -Get Redemption Record (USER_DATA) ---------------------------------- -.. autofunction:: binance.spot.Spot.savings_redemption_record - -Get Interest History (USER_DATA) --------------------------------- -.. autofunction:: binance.spot.Spot.savings_interest_history - -Change Fixed/Activity Position to Daily Position(USER_DATA) ------------------------------------------------------------ -.. autofunction:: binance.spot.Spot.savings_change_position diff --git a/docs/source/binance.spot.simple_earn.rst b/docs/source/binance.spot.simple_earn.rst new file mode 100644 index 00000000..3b0d52f5 --- /dev/null +++ b/docs/source/binance.spot.simple_earn.rst @@ -0,0 +1,94 @@ +Simple Earn Endpoints +===================== + +Get Simple Earn Flexible Product List (USER_DATA) +------------------------------------------------- +.. autofunction:: binance.spot.Spot.get_simple_earn_flexible_product_list + +Get Simple Earn Locked Product List (USER_DATA) +----------------------------------------------- +.. autofunction:: binance.spot.Spot.get_simple_earn_locked_product_list + +Subscribe Flexible Product (TRADE) +---------------------------------- +.. autofunction:: binance.spot.Spot.subscribe_flexible_product + +Subscribe Locked Product (TRADE) +-------------------------------- +.. autofunction:: binance.spot.Spot.subscribe_locked_product + +Redeem Flexible Product (TRADE) +------------------------------- +.. autofunction:: binance.spot.Spot.redeem_flexible_product + +Redeem Locked Product (TRADE) +----------------------------- +.. autofunction:: binance.spot.Spot.redeem_locked_product + +Get Flexible Product Position (USER_DATA) +----------------------------------------- +.. autofunction:: binance.spot.Spot.get_flexible_product_position + +Get Locked Product Position (USER_DATA) +--------------------------------------- +.. autofunction:: binance.spot.Spot.get_locked_product_position + +Simple Account (USER_DATA) +-------------------------- +.. autofunction:: binance.spot.Spot.simple_account + +Get Flexible Subscription Record (USER_DATA) +-------------------------------------------- +.. autofunction:: binance.spot.Spot.get_flexible_subscription_record + +Get Locked Subscription Record (USER_DATA) +------------------------------------------ +.. autofunction:: binance.spot.Spot.get_locked_subscription_record + +Get Flexible Redemption Record (USER_DATA) +------------------------------------------ +.. autofunction:: binance.spot.Spot.get_flexible_redemption_record + +Get Locked Redemption Record (USER_DATA) +---------------------------------------- +.. autofunction:: binance.spot.Spot.get_locked_redemption_record + +Get Flexible Rewards History (USER_DATA) +---------------------------------------- +.. autofunction:: binance.spot.Spot.get_flexible_rewards_history + +Get Locked Rewards History (USER_DATA) +-------------------------------------- +.. autofunction:: binance.spot.Spot.get_locked_rewards_history + +Set Flexible Auto Subscribe (USER_DATA) +--------------------------------------- +.. autofunction:: binance.spot.Spot.set_flexible_auto_subscribe + +Set Locked Auto Subscribe (USER_DATA) +------------------------------------- +.. autofunction:: binance.spot.Spot.set_locked_auto_subscribe + +Get Flexible Personal Left Quota (USER_DATA) +-------------------------------------------- +.. autofunction:: binance.spot.Spot.get_flexible_personal_left_quota + +Get Locked Personal Left Quota (USER_DATA) +------------------------------------------ +.. autofunction:: binance.spot.Spot.get_locked_personal_left_quota + +Get Flexible Subscription Preview (USER_DATA) +--------------------------------------------- +.. autofunction:: binance.spot.Spot.get_flexible_subscription_preview + +Get Locked Subscription Preview (USER_DATA) +------------------------------------------- +.. autofunction:: binance.spot.Spot.get_locked_subscription_preview + +Get Rate History (USER_DATA) +---------------------------- +.. autofunction:: binance.spot.Spot.get_rate_history + +Get Collateral Record (USER_DATA) +--------------------------------- +.. autofunction:: binance.spot.Spot.get_collateral_record diff --git a/docs/source/binance.spot.sub_account.rst b/docs/source/binance.spot.sub_account.rst index 5db0d9b5..7d2ee0a9 100644 --- a/docs/source/binance.spot.sub_account.rst +++ b/docs/source/binance.spot.sub_account.rst @@ -140,3 +140,43 @@ Query Managed Sub Account Transfer Log (Trading Team) (USER_DATA) Get Managed Sub-account Deposit Address (For Investor Master Account) (USER_DATA) --------------------------------------------------------------------------------- .. autofunction:: binance.spot.Spot.managed_sub_account_deposit_address + +Query Sub-account Assets (For Master Account) +--------------------------------------------- +.. autofunction:: binance.spot.Spot.query_sub_account_assets + +Enable Options for Sub-account (For Master Account) +--------------------------------------------------- +.. autofunction:: binance.spot.Spot.enable_options_for_sub_account + +Query Sub-account Transaction Statistics (For Master Account) +------------------------------------------------------------- +.. autofunction:: binance.spot.Spot.query_sub_account_transaction_statistics + +Query Managed Sub-account Margin Asset Details (For Investor Master Account) +---------------------------------------------------------------------------- +.. autofunction:: binance.spot.Spot.query_managed_sub_account_margin_asset_details + +Query Managed Sub-account List (For Investor) +--------------------------------------------- +.. autofunction:: binance.spot.Spot.query_managed_sub_account_list + +Query Managed Sub-account Futures Asset Details (For Investor Master Account) +----------------------------------------------------------------------------- +.. autofunction:: binance.spot.Spot.query_managed_sub_account_futures_asset_details + +Futures Position-Risk of Sub-account (For Master Account) +--------------------------------------------------------- +.. autofunction:: binance.spot.Spot.futures_position_risk_of_sub_account + +Summary of Sub-account's Futures Account V2 (For Master Account) +---------------------------------------------------------------- +.. autofunction:: binance.spot.Spot.summary_of_sub_account_s_futures_account + +Detail on Sub-account's Futures Account (For Master Account) +------------------------------------------------------------ +.. autofunction:: binance.spot.Spot.detail_on_sub_account_s_futures_account + +Query Managed Sub Account Transfer Log (For Trading Team Sub Account)(USER_DATA) +-------------------------------------------------------------------------------- +.. autofunction:: binance.spot.Spot.query_managed_sub_account_transfer_log diff --git a/docs/source/binance.spot.trade.rst b/docs/source/binance.spot.trade.rst index 3b203aca..df9bf6cc 100644 --- a/docs/source/binance.spot.trade.rst +++ b/docs/source/binance.spot.trade.rst @@ -65,3 +65,7 @@ Account Trade List (USER_DATA) Query Current Order Count Usage (TRADE) --------------------------------------- .. autofunction:: binance.spot.Spot.get_order_rate_limit + +Query Prevented Matches +----------------------- +.. autofunction:: binance.spot.Spot.query_prevented_matches diff --git a/docs/source/binance.spot.wallet.rst b/docs/source/binance.spot.wallet.rst index 1c3619be..779ce45f 100644 --- a/docs/source/binance.spot.wallet.rst +++ b/docs/source/binance.spot.wallet.rst @@ -108,3 +108,7 @@ BUSD Convert (USER_DATA) BUSD Convert History (USER_DATA) -------------------------------- .. autofunction:: binance.spot.Spot.convert_history + +One click arrival deposit apply (USER_DATA) +------------------------------------------- +.. autofunction:: binance.spot.Spot.one_click_arrival_deposit_apply diff --git a/examples/spot/auto_invest/change_plan_status.py b/examples/spot/auto_invest/change_plan_status.py new file mode 100644 index 00000000..0e97400a --- /dev/null +++ b/examples/spot/auto_invest/change_plan_status.py @@ -0,0 +1,25 @@ +#!/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.change_plan_status(1234, "ONGOING", 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/auto_invest/get_index_linked_plan_redemption_history.py b/examples/spot/auto_invest/get_index_linked_plan_redemption_history.py new file mode 100644 index 00000000..99ca6f71 --- /dev/null +++ b/examples/spot/auto_invest/get_index_linked_plan_redemption_history.py @@ -0,0 +1,25 @@ +#!/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_index_linked_plan_redemption_history(12345, 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/auto_invest/get_list_of_plans.py b/examples/spot/auto_invest/get_list_of_plans.py new file mode 100644 index 00000000..e3fb57d3 --- /dev/null +++ b/examples/spot/auto_invest/get_list_of_plans.py @@ -0,0 +1,25 @@ +#!/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_list_of_plans("SINGLE", 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/auto_invest/get_target_asset_list.py b/examples/spot/auto_invest/get_target_asset_list.py new file mode 100644 index 00000000..cad33459 --- /dev/null +++ b/examples/spot/auto_invest/get_target_asset_list.py @@ -0,0 +1,27 @@ +#!/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_target_asset_list( + targetAsset="BTC", size=100, current=1, 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/auto_invest/get_target_asset_roi_data.py b/examples/spot/auto_invest/get_target_asset_roi_data.py new file mode 100644 index 00000000..93233c88 --- /dev/null +++ b/examples/spot/auto_invest/get_target_asset_roi_data.py @@ -0,0 +1,25 @@ +#!/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_target_asset_roi_data("BTC", "FIVE_YEAR", 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/auto_invest/index_linked_plan_rebalance_details.py b/examples/spot/auto_invest/index_linked_plan_rebalance_details.py new file mode 100644 index 00000000..983a0695 --- /dev/null +++ b/examples/spot/auto_invest/index_linked_plan_rebalance_details.py @@ -0,0 +1,27 @@ +#!/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.index_linked_plan_rebalance_details( + current=1, size=100, 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/auto_invest/index_linked_plan_redemption.py b/examples/spot/auto_invest/index_linked_plan_redemption.py new file mode 100644 index 00000000..e96cb61b --- /dev/null +++ b/examples/spot/auto_invest/index_linked_plan_redemption.py @@ -0,0 +1,25 @@ +#!/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.index_linked_plan_redemption(12345, 10, 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/auto_invest/one_time_transaction.py b/examples/spot/auto_invest/one_time_transaction.py new file mode 100644 index 00000000..fdbfff63 --- /dev/null +++ b/examples/spot/auto_invest/one_time_transaction.py @@ -0,0 +1,25 @@ +#!/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.one_time_transaction("MAIN_SITE", 10.1, "USDT", 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/auto_invest/query_all_source_asset_and_target_asset.py b/examples/spot/auto_invest/query_all_source_asset_and_target_asset.py new file mode 100644 index 00000000..b128911b --- /dev/null +++ b/examples/spot/auto_invest/query_all_source_asset_and_target_asset.py @@ -0,0 +1,25 @@ +#!/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.query_all_source_asset_and_target_asset(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/auto_invest/query_holding_details_of_the_plan.py b/examples/spot/auto_invest/query_holding_details_of_the_plan.py new file mode 100644 index 00000000..9fa9b1c8 --- /dev/null +++ b/examples/spot/auto_invest/query_holding_details_of_the_plan.py @@ -0,0 +1,25 @@ +#!/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.query_holding_details_of_the_plan(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/auto_invest/query_index_details.py b/examples/spot/auto_invest/query_index_details.py new file mode 100644 index 00000000..4ba4eb23 --- /dev/null +++ b/examples/spot/auto_invest/query_index_details.py @@ -0,0 +1,25 @@ +#!/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.query_index_details(1234, 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/auto_invest/query_index_linked_plan_position_details.py b/examples/spot/auto_invest/query_index_linked_plan_position_details.py new file mode 100644 index 00000000..5037a106 --- /dev/null +++ b/examples/spot/auto_invest/query_index_linked_plan_position_details.py @@ -0,0 +1,25 @@ +#!/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.query_index_linked_plan_position_details(1234, 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/auto_invest/query_one_time_transaction_status.py b/examples/spot/auto_invest/query_one_time_transaction_status.py new file mode 100644 index 00000000..6105eece --- /dev/null +++ b/examples/spot/auto_invest/query_one_time_transaction_status.py @@ -0,0 +1,27 @@ +#!/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.query_one_time_transaction_status( + 12345, requestId="TR12354859", 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/auto_invest/query_source_asset_list.py b/examples/spot/auto_invest/query_source_asset_list.py new file mode 100644 index 00000000..6e0d55b6 --- /dev/null +++ b/examples/spot/auto_invest/query_source_asset_list.py @@ -0,0 +1,25 @@ +#!/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.query_source_asset_list("RECURRING", 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/auto_invest/query_subscription_transaction_history.py b/examples/spot/auto_invest/query_subscription_transaction_history.py new file mode 100644 index 00000000..ea68ee64 --- /dev/null +++ b/examples/spot/auto_invest/query_subscription_transaction_history.py @@ -0,0 +1,25 @@ +#!/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.query_subscription_transaction_history(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/convert/accept_quote.py b/examples/spot/convert/accept_quote.py new file mode 100644 index 00000000..96f34c11 --- /dev/null +++ b/examples/spot/convert/accept_quote.py @@ -0,0 +1,25 @@ +#!/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.accept_quote("1000", 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/convert/convert.py b/examples/spot/convert/convert.py deleted file mode 100644 index 64f7ed21..00000000 --- a/examples/spot/convert/convert.py +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- - -import logging -from binance.spot import Spot -from binance.lib.utils import config_logging -from datetime import datetime -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -spot_client = Spot(api_key, api_secret) - -# datetime uses POSIX timestamp -start = int(datetime(2021, 11, 15, 23, 59, 59).timestamp() * 1000) -end = int(datetime(2021, 12, 7, 23, 59, 59).timestamp() * 1000) - -converts = spot_client.convert_trade_history(startTime=start, endTime=end) - -logging.info(converts) diff --git a/examples/spot/convert/get_convert_trade_history.py b/examples/spot/convert/get_convert_trade_history.py new file mode 100644 index 00000000..e635633e --- /dev/null +++ b/examples/spot/convert/get_convert_trade_history.py @@ -0,0 +1,27 @@ +#!/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_convert_trade_history( + 1624248872184, 1624248872185, 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/convert/list_all_convert_pairs.py b/examples/spot/convert/list_all_convert_pairs.py new file mode 100644 index 00000000..3870a39f --- /dev/null +++ b/examples/spot/convert/list_all_convert_pairs.py @@ -0,0 +1,23 @@ +#!/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 + + +config_logging(logging, logging.DEBUG) +logger = logging.getLogger(__name__) + + +client = Client() + +try: + response = client.list_all_convert_pairs(fromAsset="BTC", toAsset="USDT") + 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/convert/order_status.py b/examples/spot/convert/order_status.py new file mode 100644 index 00000000..6800b240 --- /dev/null +++ b/examples/spot/convert/order_status.py @@ -0,0 +1,25 @@ +#!/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.order_status(orderId="1000", quoteId="1000", 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/convert/query_order_quantity_precision_per_asset.py b/examples/spot/convert/query_order_quantity_precision_per_asset.py new file mode 100644 index 00000000..69b0ea19 --- /dev/null +++ b/examples/spot/convert/query_order_quantity_precision_per_asset.py @@ -0,0 +1,25 @@ +#!/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.query_order_quantity_precision_per_asset(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/convert/send_quote_request.py b/examples/spot/convert/send_quote_request.py new file mode 100644 index 00000000..298c0e12 --- /dev/null +++ b/examples/spot/convert/send_quote_request.py @@ -0,0 +1,33 @@ +#!/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.send_quote_request( + "BTC", + "USDT", + fromAmount=1, + toAmount=1, + validTime="10s", + walletType="SPOT", + 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/futures/futures_loan_adjust_collateral_history.py b/examples/spot/futures/futures_loan_adjust_collateral_history.py deleted file mode 100644 index 6d45a5a7..00000000 --- a/examples/spot/futures/futures_loan_adjust_collateral_history.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.futures_loan_adjust_collateral_history(collateralCoin="BTC")) diff --git a/examples/spot/futures/futures_loan_borrow_history.py b/examples/spot/futures/futures_loan_borrow_history.py deleted file mode 100644 index f6de1db8..00000000 --- a/examples/spot/futures/futures_loan_borrow_history.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.futures_loan_borrow_history(coin="USDT")) diff --git a/examples/spot/futures/futures_loan_interest_history.py b/examples/spot/futures/futures_loan_interest_history.py deleted file mode 100644 index 6271dc2a..00000000 --- a/examples/spot/futures/futures_loan_interest_history.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.futures_loan_interest_history()) diff --git a/examples/spot/futures/futures_loan_liquidation_history.py b/examples/spot/futures/futures_loan_liquidation_history.py deleted file mode 100644 index 1b4cf89f..00000000 --- a/examples/spot/futures/futures_loan_liquidation_history.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.futures_loan_liquidation_history(collateralCoin="BTC")) diff --git a/examples/spot/futures/futures_loan_repay_history.py b/examples/spot/futures/futures_loan_repay_history.py deleted file mode 100644 index 4b4dc1a8..00000000 --- a/examples/spot/futures/futures_loan_repay_history.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.futures_loan_repay_history(coin="USDT")) diff --git a/examples/spot/futures/futures_loan_wallet.py b/examples/spot/futures/futures_loan_wallet.py deleted file mode 100644 index 4ebe0b88..00000000 --- a/examples/spot/futures/futures_loan_wallet.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.futures_loan_wallet()) diff --git a/examples/spot/loan/flexible_loan_adjust_ltv.py b/examples/spot/loan/flexible_loan_adjust_ltv.py new file mode 100644 index 00000000..a4a01ec6 --- /dev/null +++ b/examples/spot/loan/flexible_loan_adjust_ltv.py @@ -0,0 +1,27 @@ +#!/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.flexible_loan_adjust_ltv( + "BTC", "USDT", 1.01, "ADDITIONAL", 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/loan/flexible_loan_assets_data.py b/examples/spot/loan/flexible_loan_assets_data.py new file mode 100644 index 00000000..96c4a77f --- /dev/null +++ b/examples/spot/loan/flexible_loan_assets_data.py @@ -0,0 +1,25 @@ +#!/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.flexible_loan_assets_data(loanCoin="BUSD", 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/loan/flexible_loan_borrow.py b/examples/spot/loan/flexible_loan_borrow.py new file mode 100644 index 00000000..78ddea90 --- /dev/null +++ b/examples/spot/loan/flexible_loan_borrow.py @@ -0,0 +1,30 @@ +#!/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.flexible_loan_borrow( + loanCoin="BUSD", + loanAmount=100.1, + collateralCoin="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/loan/flexible_loan_borrow_history.py b/examples/spot/loan/flexible_loan_borrow_history.py new file mode 100644 index 00000000..c5a704c0 --- /dev/null +++ b/examples/spot/loan/flexible_loan_borrow_history.py @@ -0,0 +1,27 @@ +#!/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.flexible_loan_borrow_history( + loanCoin="BUSD", collateralCoin="BNB", current=1, limit=5, 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/loan/flexible_loan_collateral_assets_data.py b/examples/spot/loan/flexible_loan_collateral_assets_data.py new file mode 100644 index 00000000..e8f1d8f1 --- /dev/null +++ b/examples/spot/loan/flexible_loan_collateral_assets_data.py @@ -0,0 +1,27 @@ +#!/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.flexible_loan_collateral_assets_data( + collateralCoin="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/loan/flexible_loan_ltv_adjustment_history.py b/examples/spot/loan/flexible_loan_ltv_adjustment_history.py new file mode 100644 index 00000000..27f17d52 --- /dev/null +++ b/examples/spot/loan/flexible_loan_ltv_adjustment_history.py @@ -0,0 +1,32 @@ +#!/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.flexible_loan_ltv_adjustment_history( + orderId=10, + loanCoin="BUSD", + collateralCoin="BNB", + current=1, + limit=10, + 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/loan/flexible_loan_ongoing_orders.py b/examples/spot/loan/flexible_loan_ongoing_orders.py new file mode 100644 index 00000000..91ce2654 --- /dev/null +++ b/examples/spot/loan/flexible_loan_ongoing_orders.py @@ -0,0 +1,27 @@ +#!/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.flexible_loan_ongoing_orders( + loanCoin="BUSD", collateralCoin="BNB", current=1, limit=5, 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/loan/flexible_loan_repay.py b/examples/spot/loan/flexible_loan_repay.py new file mode 100644 index 00000000..9c9e8f38 --- /dev/null +++ b/examples/spot/loan/flexible_loan_repay.py @@ -0,0 +1,25 @@ +#!/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.flexible_loan_repay("BTC", "USDT", 1.01, 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/loan/flexible_loan_repayment_history.py b/examples/spot/loan/flexible_loan_repayment_history.py new file mode 100644 index 00000000..a1fda393 --- /dev/null +++ b/examples/spot/loan/flexible_loan_repayment_history.py @@ -0,0 +1,27 @@ +#!/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.flexible_loan_repayment_history( + loanCoin="BUSD", collateralCoin="BNB", current=1, limit=5, 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/adjust_cross_margin_max_leverage.py b/examples/spot/margin/adjust_cross_margin_max_leverage.py new file mode 100644 index 00000000..190ce0ee --- /dev/null +++ b/examples/spot/margin/adjust_cross_margin_max_leverage.py @@ -0,0 +1,25 @@ +#!/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.adjust_cross_margin_max_leverage(3, 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/cross_margin_collateral_ratio.py b/examples/spot/margin/cross_margin_collateral_ratio.py new file mode 100644 index 00000000..d57803a5 --- /dev/null +++ b/examples/spot/margin/cross_margin_collateral_ratio.py @@ -0,0 +1,25 @@ +#!/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, _ = get_api_key() + +client = Client(api_key) + +try: + response = client.cross_margin_collateral_ratio() + 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/dust_transfer.py b/examples/spot/margin/dust_transfer.py new file mode 100644 index 00000000..702c122f --- /dev/null +++ b/examples/spot/margin/dust_transfer.py @@ -0,0 +1,25 @@ +#!/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_a_future_hourly_interest_rate.py b/examples/spot/margin/get_a_future_hourly_interest_rate.py new file mode 100644 index 00000000..f36adafc --- /dev/null +++ b/examples/spot/margin/get_a_future_hourly_interest_rate.py @@ -0,0 +1,26 @@ +#!/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_a_future_hourly_interest_rate( + "BTC,ETH", True, 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 new file mode 100644 index 00000000..90867717 --- /dev/null +++ b/examples/spot/margin/get_assets_that_can_be_converted_into_bnb.py @@ -0,0 +1,25 @@ +#!/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/get_small_liability_exchange_coin_list.py b/examples/spot/margin/get_small_liability_exchange_coin_list.py new file mode 100644 index 00000000..1f705936 --- /dev/null +++ b/examples/spot/margin/get_small_liability_exchange_coin_list.py @@ -0,0 +1,25 @@ +#!/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_small_liability_exchange_coin_list(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_small_liability_exchange_history.py b/examples/spot/margin/get_small_liability_exchange_history.py new file mode 100644 index 00000000..a27ac86f --- /dev/null +++ b/examples/spot/margin/get_small_liability_exchange_history.py @@ -0,0 +1,25 @@ +#!/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_small_liability_exchange_history(1, 100, 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/portfolio_margin/bnb_transfer.py b/examples/spot/portfolio_margin/bnb_transfer.py new file mode 100644 index 00000000..ff00b7db --- /dev/null +++ b/examples/spot/portfolio_margin/bnb_transfer.py @@ -0,0 +1,24 @@ +#!/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.bnb_transfer("TO_UM", 1.01, 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/portfolio_margin/change_auto_repay_futures_status.py b/examples/spot/portfolio_margin/change_auto_repay_futures_status.py new file mode 100644 index 00000000..219905ce --- /dev/null +++ b/examples/spot/portfolio_margin/change_auto_repay_futures_status.py @@ -0,0 +1,25 @@ +#!/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.change_auto_repay_futures_status(True, 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/portfolio_margin/fund_auto_collection.py b/examples/spot/portfolio_margin/fund_auto_collection.py new file mode 100644 index 00000000..ff7cf611 --- /dev/null +++ b/examples/spot/portfolio_margin/fund_auto_collection.py @@ -0,0 +1,25 @@ +#!/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.fund_auto_collection(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/portfolio_margin/fund_collection_by_asset.py b/examples/spot/portfolio_margin/fund_collection_by_asset.py new file mode 100644 index 00000000..7f9f33f3 --- /dev/null +++ b/examples/spot/portfolio_margin/fund_collection_by_asset.py @@ -0,0 +1,25 @@ +#!/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.fund_collection_by_asset("BTC", 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/portfolio_margin/get_auto_repay_futures_status.py b/examples/spot/portfolio_margin/get_auto_repay_futures_status.py new file mode 100644 index 00000000..d42db736 --- /dev/null +++ b/examples/spot/portfolio_margin/get_auto_repay_futures_status.py @@ -0,0 +1,25 @@ +#!/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_auto_repay_futures_status(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/portfolio_margin/portfolio_margin_account.py b/examples/spot/portfolio_margin/portfolio_margin_account.py index b918c3f7..58c6199c 100644 --- a/examples/spot/portfolio_margin/portfolio_margin_account.py +++ b/examples/spot/portfolio_margin/portfolio_margin_account.py @@ -4,17 +4,19 @@ 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) -logger = logging.getLogger(__name__) try: - logger.info(client.portfolio_margin_account()) + response = client.portfolio_margin_account(recvWindow=5000) + logger.info(response) except ClientError as error: logger.error( "Found error. status: {}, error code: {}, error message: {}".format( diff --git a/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_amount.py b/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_amount.py index 0becfedc..fe834a15 100644 --- a/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_amount.py +++ b/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_amount.py @@ -4,9 +4,11 @@ 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() @@ -14,9 +16,9 @@ try: response = client.portfolio_margin_bankruptcy_loan_amount(recvWindow=5000) - logging.info(response) + logger.info(response) except ClientError as error: - logging.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/portfolio_margin/portfolio_margin_bankruptcy_loan_repay.py b/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_repay.py index 14d400c2..ce8030be 100644 --- a/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_repay.py +++ b/examples/spot/portfolio_margin/portfolio_margin_bankruptcy_loan_repay.py @@ -4,9 +4,11 @@ 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() @@ -14,9 +16,9 @@ try: response = client.portfolio_margin_bankruptcy_loan_repay(recvWindow=5000) - logging.info(response) + logger.info(response) except ClientError as error: - logging.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/portfolio_margin/portfolio_margin_collateral_rate.py b/examples/spot/portfolio_margin/portfolio_margin_collateral_rate.py index 683517b7..de0fb860 100644 --- a/examples/spot/portfolio_margin/portfolio_margin_collateral_rate.py +++ b/examples/spot/portfolio_margin/portfolio_margin_collateral_rate.py @@ -4,9 +4,11 @@ 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, _ = get_api_key() @@ -14,9 +16,9 @@ try: response = client.portfolio_margin_collateral_rate() - logging.info(response) + logger.info(response) except ClientError as error: - logging.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/portfolio_margin/query_classic_portfolio_margin_negative_balance_interest_history.py b/examples/spot/portfolio_margin/query_classic_portfolio_margin_negative_balance_interest_history.py new file mode 100644 index 00000000..e1f2ec4d --- /dev/null +++ b/examples/spot/portfolio_margin/query_classic_portfolio_margin_negative_balance_interest_history.py @@ -0,0 +1,27 @@ +#!/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.query_classic_portfolio_margin_negative_balance_interest_history( + "BTC", size=100, 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/portfolio_margin/query_portfolio_margin_asset_index_price.py b/examples/spot/portfolio_margin/query_portfolio_margin_asset_index_price.py new file mode 100644 index 00000000..76046c3b --- /dev/null +++ b/examples/spot/portfolio_margin/query_portfolio_margin_asset_index_price.py @@ -0,0 +1,25 @@ +#!/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, _ = get_api_key() + +client = Client(api_key) + +try: + response = client.query_portfolio_margin_asset_index_price(asset="BTC") + 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/portfolio_margin/repay_futures_negative_balance.py b/examples/spot/portfolio_margin/repay_futures_negative_balance.py new file mode 100644 index 00000000..7de57c6c --- /dev/null +++ b/examples/spot/portfolio_margin/repay_futures_negative_balance.py @@ -0,0 +1,25 @@ +#!/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.repay_futures_negative_balance(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/savings/savings_account.py b/examples/spot/savings/savings_account.py deleted file mode 100644 index dceec4d2..00000000 --- a/examples/spot/savings/savings_account.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.savings_account()) diff --git a/examples/spot/savings/savings_change_position.py b/examples/spot/savings/savings_change_position.py deleted file mode 100644 index 8c882471..00000000 --- a/examples/spot/savings/savings_change_position.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.savings_change_position(projectId="USDT001", lot=1)) diff --git a/examples/spot/savings/savings_flexible_product_position.py b/examples/spot/savings/savings_flexible_product_position.py deleted file mode 100644 index 2419b528..00000000 --- a/examples/spot/savings/savings_flexible_product_position.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.savings_flexible_product_position()) diff --git a/examples/spot/savings/savings_flexible_products.py b/examples/spot/savings/savings_flexible_products.py deleted file mode 100644 index 880dd45c..00000000 --- a/examples/spot/savings/savings_flexible_products.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.savings_flexible_products()) diff --git a/examples/spot/savings/savings_flexible_redeem.py b/examples/spot/savings/savings_flexible_redeem.py deleted file mode 100644 index 9c4f3ca9..00000000 --- a/examples/spot/savings/savings_flexible_redeem.py +++ /dev/null @@ -1,15 +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.savings_flexible_redeem(productId="BTC001", amount="0.01", type="NORMAL") -) diff --git a/examples/spot/savings/savings_flexible_user_left_quota.py b/examples/spot/savings/savings_flexible_user_left_quota.py deleted file mode 100644 index 57f572a4..00000000 --- a/examples/spot/savings/savings_flexible_user_left_quota.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.savings_flexible_user_left_quota(productId="BTC001")) diff --git a/examples/spot/savings/savings_flexible_user_redemption_quota.py b/examples/spot/savings/savings_flexible_user_redemption_quota.py deleted file mode 100644 index bb1380cb..00000000 --- a/examples/spot/savings/savings_flexible_user_redemption_quota.py +++ /dev/null @@ -1,15 +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.savings_flexible_user_redemption_quota(productId="BTC001", type="NORMAL") -) diff --git a/examples/spot/savings/savings_interest_history.py b/examples/spot/savings/savings_interest_history.py deleted file mode 100644 index 2bfb62d3..00000000 --- a/examples/spot/savings/savings_interest_history.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.savings_interest_history(lendingType="DAILY")) diff --git a/examples/spot/savings/savings_project_list.py b/examples/spot/savings/savings_project_list.py deleted file mode 100644 index 6c6a243f..00000000 --- a/examples/spot/savings/savings_project_list.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.savings_project_list(type="REGULAR")) diff --git a/examples/spot/savings/savings_project_position.py b/examples/spot/savings/savings_project_position.py deleted file mode 100644 index f03aa25b..00000000 --- a/examples/spot/savings/savings_project_position.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.savings_project_position()) diff --git a/examples/spot/savings/savings_purchase_flexible_product.py b/examples/spot/savings/savings_purchase_flexible_product.py deleted file mode 100644 index 31a402c8..00000000 --- a/examples/spot/savings/savings_purchase_flexible_product.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.savings_purchase_flexible_product(productId="BTC001", amount=0.01)) diff --git a/examples/spot/savings/savings_purchase_project.py b/examples/spot/savings/savings_purchase_project.py deleted file mode 100644 index 494fa3d3..00000000 --- a/examples/spot/savings/savings_purchase_project.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.savings_purchase_project(projectId="USDT14DAYSS001", lot=1)) diff --git a/examples/spot/savings/savings_purchase_record.py b/examples/spot/savings/savings_purchase_record.py deleted file mode 100644 index 2ff126e9..00000000 --- a/examples/spot/savings/savings_purchase_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.savings_purchase_record(lendingType="DAILY")) diff --git a/examples/spot/savings/savings_redemption_record.py b/examples/spot/savings/savings_redemption_record.py deleted file mode 100644 index 3493347c..00000000 --- a/examples/spot/savings/savings_redemption_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.savings_redemption_record(lendingType="DAILY")) diff --git a/examples/spot/simple_earn/get_collateral_record.py b/examples/spot/simple_earn/get_collateral_record.py new file mode 100644 index 00000000..fbac1864 --- /dev/null +++ b/examples/spot/simple_earn/get_collateral_record.py @@ -0,0 +1,25 @@ +#!/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_collateral_record(current=1, size=100, 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/simple_earn/get_flexible_personal_left_quota.py b/examples/spot/simple_earn/get_flexible_personal_left_quota.py new file mode 100644 index 00000000..b1c1aed2 --- /dev/null +++ b/examples/spot/simple_earn/get_flexible_personal_left_quota.py @@ -0,0 +1,25 @@ +#!/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_flexible_personal_left_quota("product_001", 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/simple_earn/get_flexible_product_position.py b/examples/spot/simple_earn/get_flexible_product_position.py new file mode 100644 index 00000000..6569cce4 --- /dev/null +++ b/examples/spot/simple_earn/get_flexible_product_position.py @@ -0,0 +1,27 @@ +#!/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_flexible_product_position( + current=1, size=100, 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/simple_earn/get_flexible_redemption_record.py b/examples/spot/simple_earn/get_flexible_redemption_record.py new file mode 100644 index 00000000..f1dfe98c --- /dev/null +++ b/examples/spot/simple_earn/get_flexible_redemption_record.py @@ -0,0 +1,25 @@ +#!/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_flexible_redemption_record(current=1, size=100) + 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/simple_earn/get_flexible_rewards_history.py b/examples/spot/simple_earn/get_flexible_rewards_history.py new file mode 100644 index 00000000..28f3862a --- /dev/null +++ b/examples/spot/simple_earn/get_flexible_rewards_history.py @@ -0,0 +1,25 @@ +#!/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_flexible_rewards_history("REWARDS") + 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/simple_earn/get_flexible_subscription_preview.py b/examples/spot/simple_earn/get_flexible_subscription_preview.py new file mode 100644 index 00000000..e413fb01 --- /dev/null +++ b/examples/spot/simple_earn/get_flexible_subscription_preview.py @@ -0,0 +1,27 @@ +#!/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_flexible_subscription_preview( + "product_001", 100, 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/simple_earn/get_flexible_subscription_record.py b/examples/spot/simple_earn/get_flexible_subscription_record.py new file mode 100644 index 00000000..cba620d6 --- /dev/null +++ b/examples/spot/simple_earn/get_flexible_subscription_record.py @@ -0,0 +1,27 @@ +#!/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_flexible_subscription_record( + current=1, size=100, 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/simple_earn/get_locked_personal_left_quota.py b/examples/spot/simple_earn/get_locked_personal_left_quota.py new file mode 100644 index 00000000..d1aeb230 --- /dev/null +++ b/examples/spot/simple_earn/get_locked_personal_left_quota.py @@ -0,0 +1,25 @@ +#!/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_locked_personal_left_quota("product_001", 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/simple_earn/get_locked_product_position.py b/examples/spot/simple_earn/get_locked_product_position.py new file mode 100644 index 00000000..44929967 --- /dev/null +++ b/examples/spot/simple_earn/get_locked_product_position.py @@ -0,0 +1,25 @@ +#!/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_locked_product_position(current=1, size=100, 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/simple_earn/get_locked_redemption_record.py b/examples/spot/simple_earn/get_locked_redemption_record.py new file mode 100644 index 00000000..79eb2ad0 --- /dev/null +++ b/examples/spot/simple_earn/get_locked_redemption_record.py @@ -0,0 +1,25 @@ +#!/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_locked_redemption_record(current=1, size=100, 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/simple_earn/get_locked_rewards_history.py b/examples/spot/simple_earn/get_locked_rewards_history.py new file mode 100644 index 00000000..98027b1c --- /dev/null +++ b/examples/spot/simple_earn/get_locked_rewards_history.py @@ -0,0 +1,25 @@ +#!/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_locked_rewards_history(size=100, 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/simple_earn/get_locked_subscription_preview.py b/examples/spot/simple_earn/get_locked_subscription_preview.py new file mode 100644 index 00000000..2fe0148e --- /dev/null +++ b/examples/spot/simple_earn/get_locked_subscription_preview.py @@ -0,0 +1,27 @@ +#!/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_locked_subscription_preview( + "project_001", 100, 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/simple_earn/get_locked_subscription_record.py b/examples/spot/simple_earn/get_locked_subscription_record.py new file mode 100644 index 00000000..0f239f71 --- /dev/null +++ b/examples/spot/simple_earn/get_locked_subscription_record.py @@ -0,0 +1,27 @@ +#!/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_locked_subscription_record( + current=1, size=100, 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/simple_earn/get_rate_history.py b/examples/spot/simple_earn/get_rate_history.py new file mode 100644 index 00000000..2fd41b52 --- /dev/null +++ b/examples/spot/simple_earn/get_rate_history.py @@ -0,0 +1,27 @@ +#!/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_rate_history( + "product_001", current=1, size=100, 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/simple_earn/get_simple_earn_flexible_product_list.py b/examples/spot/simple_earn/get_simple_earn_flexible_product_list.py new file mode 100644 index 00000000..dcb8f624 --- /dev/null +++ b/examples/spot/simple_earn/get_simple_earn_flexible_product_list.py @@ -0,0 +1,27 @@ +#!/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_simple_earn_flexible_product_list( + asset="BTC", current=1, size=100, 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/simple_earn/get_simple_earn_locked_product_list.py b/examples/spot/simple_earn/get_simple_earn_locked_product_list.py new file mode 100644 index 00000000..28242c23 --- /dev/null +++ b/examples/spot/simple_earn/get_simple_earn_locked_product_list.py @@ -0,0 +1,27 @@ +#!/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_simple_earn_locked_product_list( + asset="BNB", current=1, size=100, 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/simple_earn/redeem_flexible_product.py b/examples/spot/simple_earn/redeem_flexible_product.py new file mode 100644 index 00000000..a526eb5d --- /dev/null +++ b/examples/spot/simple_earn/redeem_flexible_product.py @@ -0,0 +1,27 @@ +#!/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.redeem_flexible_product( + "product_001", amount=100, 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/simple_earn/redeem_locked_product.py b/examples/spot/simple_earn/redeem_locked_product.py new file mode 100644 index 00000000..0701bd54 --- /dev/null +++ b/examples/spot/simple_earn/redeem_locked_product.py @@ -0,0 +1,25 @@ +#!/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.redeem_locked_product("123", 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/simple_earn/set_flexible_auto_subscribe.py b/examples/spot/simple_earn/set_flexible_auto_subscribe.py new file mode 100644 index 00000000..378c317b --- /dev/null +++ b/examples/spot/simple_earn/set_flexible_auto_subscribe.py @@ -0,0 +1,25 @@ +#!/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.set_flexible_auto_subscribe("product_001", True, 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/simple_earn/set_locked_auto_subscribe.py b/examples/spot/simple_earn/set_locked_auto_subscribe.py new file mode 100644 index 00000000..da225ee4 --- /dev/null +++ b/examples/spot/simple_earn/set_locked_auto_subscribe.py @@ -0,0 +1,25 @@ +#!/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.set_locked_auto_subscribe("product_001", True, 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/simple_earn/simple_account.py b/examples/spot/simple_earn/simple_account.py new file mode 100644 index 00000000..4f9f898d --- /dev/null +++ b/examples/spot/simple_earn/simple_account.py @@ -0,0 +1,25 @@ +#!/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.simple_account(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/simple_earn/subscribe_flexible_product.py b/examples/spot/simple_earn/subscribe_flexible_product.py new file mode 100644 index 00000000..3c877c72 --- /dev/null +++ b/examples/spot/simple_earn/subscribe_flexible_product.py @@ -0,0 +1,25 @@ +#!/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.subscribe_flexible_product("product_001", 100, 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/simple_earn/subscribe_locked_product.py b/examples/spot/simple_earn/subscribe_locked_product.py new file mode 100644 index 00000000..fe6f8f5b --- /dev/null +++ b/examples/spot/simple_earn/subscribe_locked_product.py @@ -0,0 +1,25 @@ +#!/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.subscribe_locked_product("product_001", 100, 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/sub_account/detail_on_sub_account_s_futures_account.py b/examples/spot/sub_account/detail_on_sub_account_s_futures_account.py new file mode 100644 index 00000000..66553989 --- /dev/null +++ b/examples/spot/sub_account/detail_on_sub_account_s_futures_account.py @@ -0,0 +1,27 @@ +#!/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.detail_on_sub_account_s_futures_account( + "alice@test.com", 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/sub_account/enable_options_for_sub_account.py b/examples/spot/sub_account/enable_options_for_sub_account.py new file mode 100644 index 00000000..36c14f88 --- /dev/null +++ b/examples/spot/sub_account/enable_options_for_sub_account.py @@ -0,0 +1,25 @@ +#!/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.enable_options_for_sub_account("alice@test.com", 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/sub_account/futures_position_risk_of_sub_account.py b/examples/spot/sub_account/futures_position_risk_of_sub_account.py new file mode 100644 index 00000000..ebcac7a6 --- /dev/null +++ b/examples/spot/sub_account/futures_position_risk_of_sub_account.py @@ -0,0 +1,27 @@ +#!/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.futures_position_risk_of_sub_account( + "alice@test.com", 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/sub_account/query_managed_sub_account_futures_asset_details.py b/examples/spot/sub_account/query_managed_sub_account_futures_asset_details.py new file mode 100644 index 00000000..194cb054 --- /dev/null +++ b/examples/spot/sub_account/query_managed_sub_account_futures_asset_details.py @@ -0,0 +1,27 @@ +#!/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.query_managed_sub_account_futures_asset_details( + "alice@test.com", 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/sub_account/query_managed_sub_account_list.py b/examples/spot/sub_account/query_managed_sub_account_list.py new file mode 100644 index 00000000..6c9a680d --- /dev/null +++ b/examples/spot/sub_account/query_managed_sub_account_list.py @@ -0,0 +1,27 @@ +#!/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.query_managed_sub_account_list( + email="alice@test.com", page=1, limit=5, 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/sub_account/query_managed_sub_account_margin_asset_details.py b/examples/spot/sub_account/query_managed_sub_account_margin_asset_details.py new file mode 100644 index 00000000..57627ec3 --- /dev/null +++ b/examples/spot/sub_account/query_managed_sub_account_margin_asset_details.py @@ -0,0 +1,27 @@ +#!/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.query_managed_sub_account_margin_asset_details( + "alice@test.com", 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/sub_account/query_managed_sub_account_transfer_log.py b/examples/spot/sub_account/query_managed_sub_account_transfer_log.py new file mode 100644 index 00000000..876cd884 --- /dev/null +++ b/examples/spot/sub_account/query_managed_sub_account_transfer_log.py @@ -0,0 +1,27 @@ +#!/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.query_managed_sub_account_transfer_log( + "1679416673000", "1679456673000", 1, 1 + ) + 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/sub_account/query_sub_account_assets.py b/examples/spot/sub_account/query_sub_account_assets.py new file mode 100644 index 00000000..9f6c2f08 --- /dev/null +++ b/examples/spot/sub_account/query_sub_account_assets.py @@ -0,0 +1,25 @@ +#!/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.query_sub_account_assets("alice@test.com", 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/sub_account/query_sub_account_transaction_statistics.py b/examples/spot/sub_account/query_sub_account_transaction_statistics.py new file mode 100644 index 00000000..7f5ec8d4 --- /dev/null +++ b/examples/spot/sub_account/query_sub_account_transaction_statistics.py @@ -0,0 +1,27 @@ +#!/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.query_sub_account_transaction_statistics( + "alice@test.com", 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/sub_account/summary_of_sub_account_s_futures_account.py b/examples/spot/sub_account/summary_of_sub_account_s_futures_account.py new file mode 100644 index 00000000..d56a9c8d --- /dev/null +++ b/examples/spot/sub_account/summary_of_sub_account_s_futures_account.py @@ -0,0 +1,25 @@ +#!/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.summary_of_sub_account_s_futures_account(1, 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/trade/query_prevented_matches.py b/examples/spot/trade/query_prevented_matches.py new file mode 100644 index 00000000..3d3498a5 --- /dev/null +++ b/examples/spot/trade/query_prevented_matches.py @@ -0,0 +1,26 @@ +#!/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.query_prevented_matches( + "BNBUSDT", preventedMatchId=1, 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/wallet/one_click_arrival_deposit_apply.py b/examples/spot/wallet/one_click_arrival_deposit_apply.py new file mode 100644 index 00000000..522522cc --- /dev/null +++ b/examples/spot/wallet/one_click_arrival_deposit_apply.py @@ -0,0 +1,25 @@ +#!/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.one_click_arrival_deposit_apply(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/requirements/common.txt b/requirements/common.txt index 06cdc6ba..93bfe21d 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -1,3 +1,3 @@ -requests>=2.25.1 -websocket-client>=1.5.0 -pycryptodome>=3.15.0 \ No newline at end of file +requests>=2.31.0 +websocket-client>=1.6.3 +pycryptodome>=3.15.0 diff --git a/tests/spot/auto_invest/test_change_plan_status.py b/tests/spot/auto_invest/test_change_plan_status.py new file mode 100644 index 00000000..c63851a2 --- /dev/null +++ b/tests/spot/auto_invest/test_change_plan_status.py @@ -0,0 +1,29 @@ +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 = {"planId": 1234, "status": random_str(), "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/lending/auto-invest/plan/edit-status\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_change_plan_status(): + """Tests the API endpoint to change plan status""" + + client = Client(key, secret) + response = client.change_plan_status(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_get_index_linked_plan_redemption_history.py b/tests/spot/auto_invest/test_get_index_linked_plan_redemption_history.py new file mode 100644 index 00000000..063c4cd3 --- /dev/null +++ b/tests/spot/auto_invest/test_get_index_linked_plan_redemption_history.py @@ -0,0 +1,29 @@ +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 = {"requestId": 12345, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/redeem/history\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_get_index_linked_plan_redemption_history(): + """Tests the API endpoint to index linked plan redemption""" + + client = Client(key, secret) + response = client.get_index_linked_plan_redemption_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/futures/test_futures_loan_borrow_history.py b/tests/spot/auto_invest/test_get_list_of_plans.py similarity index 54% rename from tests/spot/futures/test_futures_loan_borrow_history.py rename to tests/spot/auto_invest/test_get_list_of_plans.py index 5aaf133a..d923f4c7 100644 --- a/tests/spot/futures/test_futures_loan_borrow_history.py +++ b/tests/spot/auto_invest/test_get_list_of_plans.py @@ -1,28 +1,29 @@ import responses -from urllib.parse import urlencode +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.spot import Spot as Client + mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": "error message."} +mock_exception = {"code": -1, "msg": "error message"} key = random_str() secret = random_str() -params = {"coin": "BTC", "startTime": "1597130241000"} +send_params = {"planType": random_str(), "recvWindow": 5000} @mock_http_response( responses.GET, - "/sapi/v1/futures/loan/borrow/history\\?" + urlencode(params), + "/sapi/v1/lending/auto-invest/plan/list\\?" + urlencode(send_params), mock_item, 200, ) -def test_futures_transfer_history(): - """Tests the API endpoint to get load borrow history""" +def test_get_list_of_plans(): + """Tests the API endpoint to get list of plans""" client = Client(key, secret) - response = client.futures_loan_borrow_history(**params) + response = client.get_list_of_plans(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_get_target_asset_list.py b/tests/spot/auto_invest/test_get_target_asset_list.py new file mode 100644 index 00000000..96b400d9 --- /dev/null +++ b/tests/spot/auto_invest/test_get_target_asset_list.py @@ -0,0 +1,30 @@ +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 = {"targetAsset": "BTC", "size": 100, "current": 1, "recvWindow": 5000} +expected_params = {"targetAsset": "BTC", "size": 100, "current": 1, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/target-asset/list\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_target_asset_list(): + """Tests the API endpoint to get target asset list""" + + client = Client(key, secret) + response = client.get_target_asset_list(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_get_target_asset_roi_data.py b/tests/spot/auto_invest/test_get_target_asset_roi_data.py new file mode 100644 index 00000000..b7681b3f --- /dev/null +++ b/tests/spot/auto_invest/test_get_target_asset_roi_data.py @@ -0,0 +1,31 @@ +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 = {"targetAsset": "BTC", "hisRoiType": "FIVE_YEAR", "recvWindow": 5000} +expected_params = {"targetAsset": "BTC", "hisRoiType": "FIVE_YEAR", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/target-asset/roi/list\\?" + + urlencode(expected_params), + mock_item, + 200, +) +def test_get_target_asset_roi_data(): + """Tests the API endpoint to get target asset roi data""" + + client = Client(key, secret) + response = client.get_target_asset_roi_data(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_index_linked_plan_rebalance_details.py b/tests/spot/auto_invest/test_index_linked_plan_rebalance_details.py new file mode 100644 index 00000000..56ffabea --- /dev/null +++ b/tests/spot/auto_invest/test_index_linked_plan_rebalance_details.py @@ -0,0 +1,30 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/rebalance/history\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_index_linked_plan_rebalance_details(): + """Tests the API endpoint to index linked plan rebalance details""" + + client = Client(key, secret) + response = client.index_linked_plan_rebalance_details(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_index_linked_plan_redemption.py b/tests/spot/auto_invest/test_index_linked_plan_redemption.py new file mode 100644 index 00000000..59b5b673 --- /dev/null +++ b/tests/spot/auto_invest/test_index_linked_plan_redemption.py @@ -0,0 +1,29 @@ +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 = {"indexId": 12345, "redemptionPercentage": 10, "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/lending/auto-invest/redeem\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_index_linked_plan_redemption(): + """Tests the API endpoint to index linked plan redemption""" + + client = Client(key, secret) + response = client.index_linked_plan_redemption(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_one_time_transaction.py b/tests/spot/auto_invest/test_one_time_transaction.py new file mode 100644 index 00000000..c5287355 --- /dev/null +++ b/tests/spot/auto_invest/test_one_time_transaction.py @@ -0,0 +1,33 @@ +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 = { + "sourceType": "MAIN_SITE", + "subscriptionAmount": 10.1, + "sourceAsset": "USDT", +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/lending/auto-invest/one-off\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_one_time_transaction(): + """Tests the API endpoint to one time transaction""" + + client = Client(key, secret) + response = client.one_time_transaction(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_query_all_source_asset_and_target_asset.py b/tests/spot/auto_invest/test_query_all_source_asset_and_target_asset.py new file mode 100644 index 00000000..323db3a5 --- /dev/null +++ b/tests/spot/auto_invest/test_query_all_source_asset_and_target_asset.py @@ -0,0 +1,30 @@ +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/lending/auto-invest/all/asset\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_all_source_asset_and_target_asset(): + """Tests the API endpoint to query all source asset and target asset""" + + client = Client(key, secret) + response = client.query_all_source_asset_and_target_asset(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_query_holding_details_of_the_plan.py b/tests/spot/auto_invest/test_query_holding_details_of_the_plan.py new file mode 100644 index 00000000..6f834b22 --- /dev/null +++ b/tests/spot/auto_invest/test_query_holding_details_of_the_plan.py @@ -0,0 +1,30 @@ +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/lending/auto-invest/plan/id\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_holding_details_of_the_plan(): + """Tests the API endpoint to query holding details of the plan""" + + client = Client(key, secret) + response = client.query_holding_details_of_the_plan(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/futures/test_futures_loan_repay_history.py b/tests/spot/auto_invest/test_query_index_details.py similarity index 51% rename from tests/spot/futures/test_futures_loan_repay_history.py rename to tests/spot/auto_invest/test_query_index_details.py index 3998d462..3d08d76b 100644 --- a/tests/spot/futures/test_futures_loan_repay_history.py +++ b/tests/spot/auto_invest/test_query_index_details.py @@ -1,32 +1,29 @@ import responses -from urllib.parse import urlencode +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.spot import Spot as Client + mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": "error message."} +mock_exception = {"code": -1, "msg": "error message"} key = random_str() secret = random_str() -params = { - "coin": "BTC", - "startTime": "1597130241000", - "endTime": "1597130241001", -} +send_params = {"indexId": 1234, "recvWindow": 5000} @mock_http_response( responses.GET, - "/sapi/v1/futures/loan/repay/history\\?" + urlencode(params), + "/sapi/v1/lending/auto-invest/index/info\\?" + urlencode(send_params), mock_item, 200, ) -def test_futures_loan_repay_history(): - """Tests the API endpoint to get repay history""" +def test_query_index_details(): + """Tests the API endpoint to query index details""" client = Client(key, secret) - response = client.futures_loan_repay_history(**params) + response = client.query_index_details(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_query_index_linked_plan_position_details.py b/tests/spot/auto_invest/test_query_index_linked_plan_position_details.py new file mode 100644 index 00000000..83a9c82a --- /dev/null +++ b/tests/spot/auto_invest/test_query_index_linked_plan_position_details.py @@ -0,0 +1,29 @@ +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 = {"indexId": 1234, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/index/user-summary\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_query_index_linked_plan_position_details(): + """Tests the API endpoint to query index linked plan position details""" + + client = Client(key, secret) + response = client.query_index_linked_plan_position_details(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_query_one_time_transaction_status.py b/tests/spot/auto_invest/test_query_one_time_transaction_status.py new file mode 100644 index 00000000..9ccf74c8 --- /dev/null +++ b/tests/spot/auto_invest/test_query_one_time_transaction_status.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 + + +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 = {"transactionId": 12345, "requestId": "TR12354859", "recvWindow": 5000} +expected_params = { + "transactionId": 12345, + "requestId": "TR12354859", + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/one-off/status\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_one_time_transaction_status(): + """Tests the API endpoint to query one-time transaction status""" + + client = Client(key, secret) + response = client.query_one_time_transaction_status(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_query_source_asset_list.py b/tests/spot/auto_invest/test_query_source_asset_list.py new file mode 100644 index 00000000..2cec642f --- /dev/null +++ b/tests/spot/auto_invest/test_query_source_asset_list.py @@ -0,0 +1,29 @@ +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 = {"usageType": "RECURRING", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/source-asset/list\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_query_source_asset_list(): + """Tests the API endpoint to query source asset list""" + + client = Client(key, secret) + response = client.query_source_asset_list(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/auto_invest/test_query_subscription_transaction_history.py b/tests/spot/auto_invest/test_query_subscription_transaction_history.py new file mode 100644 index 00000000..ef3561c4 --- /dev/null +++ b/tests/spot/auto_invest/test_query_subscription_transaction_history.py @@ -0,0 +1,30 @@ +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 = {"size": 100, "current": 1, "recvWindow": 5000} +expected_params = {"size": 100, "current": 1, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/lending/auto-invest/history/list\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_subscription_transaction_history(): + """Tests the API endpoint to query subscription transaction history""" + + client = Client(key, secret) + response = client.query_subscription_transaction_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/convert/test_accept_quote.py b/tests/spot/convert/test_accept_quote.py new file mode 100644 index 00000000..e3dae4c2 --- /dev/null +++ b/tests/spot/convert/test_accept_quote.py @@ -0,0 +1,30 @@ +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 = {"quoteId": "1000", "recvWindow": 5000} +expected_params = {"quoteId": "1000", "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/convert/acceptQuote\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_accept_quote(): + """Tests the API endpoint to accept quote""" + + client = Client(key, secret) + response = client.accept_quote(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/convert/test_convert_trade_history.py b/tests/spot/convert/test_convert_trade_history.py deleted file mode 100644 index 8be46679..00000000 --- a/tests/spot/convert/test_convert_trade_history.py +++ /dev/null @@ -1,45 +0,0 @@ -import responses -from urllib.parse import urlencode -from tests.util import random_str -from tests.util import mock_http_response -from tests.util import current_timestamp -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 = { - "startTime": current_timestamp(), - "endTime": current_timestamp(), -} - -client = Client(key, secret) - - -def test_convert_trade_history_without_startTime(): - """Tests the API endpoint to retrieve convert trade history without startTime""" - - client.convert_trade_history.when.called_with( - startTime="", endTime=1597130241000 - ).should.throw(ParameterRequiredError) - - -def test_convert_trade_history_without_endTime(): - """Tests the API endpoint to retrieve convert trade history without endTime""" - - client.convert_trade_history.when.called_with( - startTime=1597130241000, endTime="" - ).should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.GET, "/sapi/v1/convert/tradeFlow\\?" + urlencode(params), mock_item, 200 -) -def test_convert_trade_history(): - """Tests the API endpoint to retrieve convert trade history""" - - response = client.convert_trade_history(**params) - response.should.equal(mock_item) diff --git a/tests/spot/convert/test_get_convert_trade_history.py b/tests/spot/convert/test_get_convert_trade_history.py new file mode 100644 index 00000000..538559f4 --- /dev/null +++ b/tests/spot/convert/test_get_convert_trade_history.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 + + +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 = {"startTime": 1624248872184, "endTime": 1624248872185, "recvWindow": 5000} +expected_params = { + "startTime": 1624248872184, + "endTime": 1624248872185, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/convert/tradeFlow\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_convert_trade_history(): + """Tests the API endpoint to get convert trade history""" + + client = Client(key, secret) + response = client.get_convert_trade_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/convert/test_list_all_convert_pairs.py b/tests/spot/convert/test_list_all_convert_pairs.py new file mode 100644 index 00000000..ca24c408 --- /dev/null +++ b/tests/spot/convert/test_list_all_convert_pairs.py @@ -0,0 +1,30 @@ +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 = {"fromAsset": "BTC", "toAsset": "USDT"} +expected_params = {"fromAsset": "BTC", "toAsset": "USDT"} + + +@mock_http_response( + responses.GET, + "/sapi/v1/convert/exchangeInfo\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_list_all_convert_pairs(): + """Tests the API endpoint to list all convert pairs""" + + client = Client(key, secret) + response = client.list_all_convert_pairs(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/convert/test_order_status.py b/tests/spot/convert/test_order_status.py new file mode 100644 index 00000000..8f17ef49 --- /dev/null +++ b/tests/spot/convert/test_order_status.py @@ -0,0 +1,30 @@ +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 = {"orderId": "1000", "quoteId": "1000", "recvWindow": 5000} +expected_params = {"orderId": "1000", "quoteId": "1000", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/convert/orderStatus\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_order_status(): + """Tests the API endpoint to order status""" + + client = Client(key, secret) + response = client.order_status(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/convert/test_query_order_quantity_precision_per_asset.py b/tests/spot/convert/test_query_order_quantity_precision_per_asset.py new file mode 100644 index 00000000..14aafa06 --- /dev/null +++ b/tests/spot/convert/test_query_order_quantity_precision_per_asset.py @@ -0,0 +1,30 @@ +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/convert/assetInfo\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_order_quantity_precision_per_asset(): + """Tests the API endpoint to query order quantity precision per asset""" + + client = Client(key, secret) + response = client.query_order_quantity_precision_per_asset(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/convert/test_send_quote_request.py b/tests/spot/convert/test_send_quote_request.py new file mode 100644 index 00000000..674318c6 --- /dev/null +++ b/tests/spot/convert/test_send_quote_request.py @@ -0,0 +1,46 @@ +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 = { + "fromAsset": "BTC", + "toAsset": "USDT", + "fromAmount": 1, + "toAmount": 1, + "validTime": "10s", + "walletType": "SPOT", + "recvWindow": 5000, +} +expected_params = { + "fromAsset": "BTC", + "toAsset": "USDT", + "fromAmount": 1, + "toAmount": 1, + "validTime": "10s", + "walletType": "SPOT", + "recvWindow": 5000, +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/convert/getQuote\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_send_quote_request(): + """Tests the API endpoint to send quote request""" + + client = Client(key, secret) + response = client.send_quote_request(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/futures/test_futures_loan_adjust_collateral_history.py b/tests/spot/futures/test_futures_loan_adjust_collateral_history.py deleted file mode 100644 index a91deb5a..00000000 --- a/tests/spot/futures/test_futures_loan_adjust_collateral_history.py +++ /dev/null @@ -1,21 +0,0 @@ -import responses - -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - - -@mock_http_response( - responses.GET, "/sapi/v1/futures/loan/adjustCollateral/history", mock_item, 200 -) -def test_futures_loan_adjust_collateral_history(): - """Tests the API endpoint to Adjust Cross-Collateral LTV History""" - - client = Client(key, secret) - response = client.futures_loan_adjust_collateral_history() - response.should.equal(mock_item) diff --git a/tests/spot/futures/test_futures_loan_interest_history.py b/tests/spot/futures/test_futures_loan_interest_history.py deleted file mode 100644 index b30bdb08..00000000 --- a/tests/spot/futures/test_futures_loan_interest_history.py +++ /dev/null @@ -1,22 +0,0 @@ -import responses - -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": "error message."} - -key = random_str() -secret = random_str() - - -@mock_http_response( - responses.GET, "/sapi/v1/futures/loan/interestHistory", mock_item, 200 -) -def test_futures_loan_interest_history(): - """Tests the API endpoint to get Cross-Collateral Interest History""" - - client = Client(key, secret) - response = client.futures_loan_interest_history() - response.should.equal(mock_item) diff --git a/tests/spot/futures/test_futures_loan_liquidation_history.py b/tests/spot/futures/test_futures_loan_liquidation_history.py deleted file mode 100644 index 6cc65d44..00000000 --- a/tests/spot/futures/test_futures_loan_liquidation_history.py +++ /dev/null @@ -1,21 +0,0 @@ -import responses - -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - - -@mock_http_response( - responses.GET, "/sapi/v1/futures/loan/liquidationHistory", mock_item, 200 -) -def test_futures_loan_liquidation_history(): - """Tests the API endpoint to Cross-Collateral Liquidation History""" - - client = Client(key, secret) - response = client.futures_loan_liquidation_history() - response.should.equal(mock_item) diff --git a/tests/spot/futures/test_futures_loan_wallet.py b/tests/spot/futures/test_futures_loan_wallet.py deleted file mode 100644 index c20c9514..00000000 --- a/tests/spot/futures/test_futures_loan_wallet.py +++ /dev/null @@ -1,20 +0,0 @@ -import responses - -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1105, "msg": "error message."} - -key = random_str() -secret = random_str() - - -@mock_http_response(responses.GET, "/sapi/v2/futures/loan/wallet", mock_item, 200) -def test_futures_loan_wallet(): - """Tests the API endpoint to get loan wallet""" - - client = Client(key, secret) - response = client.futures_loan_wallet() - response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_adjust_ltv.py b/tests/spot/loan/test_flexible_loan_adjust_ltv.py new file mode 100644 index 00000000..2c2a92d3 --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_adjust_ltv.py @@ -0,0 +1,35 @@ +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 = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "adjustmentAmount": 1.01, + "direction": "ADDTIONAL", + "recvWindow": 5000, +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/loan/flexible/adjust/ltv\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_flexible_loan_adjust_ltv(): + """Tests the API endpoint to adjust ltv - flexible loan adjust ltv""" + + client = Client(key, secret) + response = client.flexible_loan_adjust_ltv(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_assets_data.py b/tests/spot/loan/test_flexible_loan_assets_data.py new file mode 100644 index 00000000..67d9b2bc --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_assets_data.py @@ -0,0 +1,30 @@ +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 = {"loanCoin": "BUSD", "recvWindow": 5000} +expected_params = {"loanCoin": "BUSD", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/loan/flexible/loanable/data\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_assets_data(): + """Tests the API endpoint to get flexible loan assets data""" + + client = Client(key, secret) + response = client.flexible_loan_assets_data(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_borrow.py b/tests/spot/loan/test_flexible_loan_borrow.py new file mode 100644 index 00000000..37cad1ef --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_borrow.py @@ -0,0 +1,40 @@ +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 = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "loanAmount": 100.1, + "recvWindow": 5000, +} +expected_params = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "loanAmount": 100.1, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/loan/flexible/borrow\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_borrow(): + """Tests the API endpoint to borrow - flexible loan borrow""" + + client = Client(key, secret) + response = client.flexible_loan_borrow(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_borrow_history.py b/tests/spot/loan/test_flexible_loan_borrow_history.py new file mode 100644 index 00000000..e6222457 --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_borrow_history.py @@ -0,0 +1,42 @@ +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 = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} +expected_params = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/loan/flexible/borrow/history\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_borrow_history(): + """Tests the API endpoint to borrow - get flexible loan borrow history""" + + client = Client(key, secret) + response = client.flexible_loan_borrow_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_collateral_assets_data.py b/tests/spot/loan/test_flexible_loan_collateral_assets_data.py new file mode 100644 index 00000000..955eb309 --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_collateral_assets_data.py @@ -0,0 +1,30 @@ +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 = {"collateralCoin": "BNB", "recvWindow": 5000} +expected_params = {"collateralCoin": "BNB", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/loan/flexible/collateral/data\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_collateral_assets_data(): + """Tests the API endpoint to get flexible loan collateral assets data""" + + client = Client(key, secret) + response = client.flexible_loan_collateral_assets_data(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_ltv_adjustment_history.py b/tests/spot/loan/test_flexible_loan_ltv_adjustment_history.py new file mode 100644 index 00000000..8eaab7a4 --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_ltv_adjustment_history.py @@ -0,0 +1,42 @@ +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 = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} +expected_params = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/loan/flexible/ltv/adjustment/history\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_ltv_adjustment_history(): + """Tests the API endpoint to adjust ltv - get flexible loan ltv adjustment history""" + + client = Client(key, secret) + response = client.flexible_loan_ltv_adjustment_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_ongoing_orders.py b/tests/spot/loan/test_flexible_loan_ongoing_orders.py new file mode 100644 index 00000000..4587358a --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_ongoing_orders.py @@ -0,0 +1,42 @@ +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 = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} +expected_params = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/loan/flexible/ongoing/orders\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_ongoing_orders(): + """Tests the API endpoint to borrow - get flexible loan ongoing orders""" + + client = Client(key, secret) + response = client.flexible_loan_ongoing_orders(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_repay.py b/tests/spot/loan/test_flexible_loan_repay.py new file mode 100644 index 00000000..8c6ba0cd --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_repay.py @@ -0,0 +1,29 @@ +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 = {"repayAmount": 100, "collateralCoin": "USDT", "loanCoin": "BTC"} + + +@mock_http_response( + responses.POST, + "/sapi/v1/loan/flexible/repay\\?" + urlencode(send_params), + mock_item, + 200, +) +def test_flexible_loan_repay(): + """Tests the API endpoint to repay - flexible loan repay""" + + client = Client(key, secret) + response = client.flexible_loan_repay(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_repayment_history.py b/tests/spot/loan/test_flexible_loan_repayment_history.py new file mode 100644 index 00000000..2eeb9797 --- /dev/null +++ b/tests/spot/loan/test_flexible_loan_repayment_history.py @@ -0,0 +1,42 @@ +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 = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} +expected_params = { + "loanCoin": "BUSD", + "collateralCoin": "BNB", + "current": 1, + "limit": 5, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/loan/flexible/repay/history\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_flexible_loan_repayment_history(): + """Tests the API endpoint to repay - get flexible loan repayment history""" + + client = Client(key, secret) + response = client.flexible_loan_repayment_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/margin/test_adjust_cross_margin_max_leverage.py b/tests/spot/margin/test_adjust_cross_margin_max_leverage.py new file mode 100644 index 00000000..a206b9c8 --- /dev/null +++ b/tests/spot/margin/test_adjust_cross_margin_max_leverage.py @@ -0,0 +1,30 @@ +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 = {"maxLeverage": 3, "recvWindow": 5000} +expected_params = {"maxLeverage": 3, "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/margin/max-leverage\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_adjust_cross_margin_max_leverage(): + """Tests the API endpoint to adjust cross margin max leverage""" + + client = Client(key, secret) + response = client.adjust_cross_margin_max_leverage(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_flexible_product_position.py b/tests/spot/margin/test_cross_margin_collateral_ratio.py similarity index 51% rename from tests/spot/savings/test_savings_flexible_product_position.py rename to tests/spot/margin/test_cross_margin_collateral_ratio.py index f8e15738..1709775c 100644 --- a/tests/spot/savings/test_savings_flexible_product_position.py +++ b/tests/spot/margin/test_cross_margin_collateral_ratio.py @@ -1,21 +1,26 @@ import responses +from binance.spot import Spot as Client from tests.util import random_str from tests.util import mock_http_response -from binance.spot import Spot as Client + mock_item = {"key_1": "value_1", "key_2": "value_2"} +mock_exception = {"code": -1, "msg": "error message"} key = random_str() secret = random_str() @mock_http_response( - responses.GET, "/sapi/v1/lending/daily/token/position\\?asset=1", mock_item, 200 + responses.GET, + "/sapi/v1/margin/crossMarginCollateralRatio", + mock_item, + 200, ) -def test_savings_flexible_product_position(): - """Tests the API endpoint to get flexible product position""" +def test_cross_margin_collateral_ratio(): + """Tests the API endpoint to cross margin collateral ratio""" client = Client(key, secret) - response = client.savings_flexible_product_position(asset=1) + response = client.cross_margin_collateral_ratio() response.should.equal(mock_item) diff --git a/tests/spot/margin/test_dust_transfer.py b/tests/spot/margin/test_dust_transfer.py new file mode 100644 index 00000000..d13d1d46 --- /dev/null +++ b/tests/spot/margin/test_dust_transfer.py @@ -0,0 +1,30 @@ +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_a_future_hourly_interest_rate.py b/tests/spot/margin/test_get_a_future_hourly_interest_rate.py new file mode 100644 index 00000000..ccd5a52e --- /dev/null +++ b/tests/spot/margin/test_get_a_future_hourly_interest_rate.py @@ -0,0 +1,29 @@ +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 = {"assets": "BTC,ETH", "isIsolated": True, "recvWindow": 5000} +expected_params = {"assets": "BTC,ETH", "isIsolated": "TRUE", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/margin/next-hourly-interest-rate\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_a_future_hourly_interest_rate(): + """Tests the API endpoint to get a future hourly interest rate""" + + client = Client(key, secret) + response = client.get_a_future_hourly_interest_rate(**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 new file mode 100644 index 00000000..8a233c34 --- /dev/null +++ b/tests/spot/margin/test_get_assets_that_can_be_converted_into_bnb.py @@ -0,0 +1,30 @@ +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_get_small_liability_exchange_coin_list.py b/tests/spot/margin/test_get_small_liability_exchange_coin_list.py new file mode 100644 index 00000000..016280e3 --- /dev/null +++ b/tests/spot/margin/test_get_small_liability_exchange_coin_list.py @@ -0,0 +1,30 @@ +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/exchange-small-liability\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_small_liability_exchange_coin_list(): + """Tests the API endpoint to get small liability exchange coin list""" + + client = Client(key, secret) + response = client.get_small_liability_exchange_coin_list(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/margin/test_get_small_liability_exchange_history.py b/tests/spot/margin/test_get_small_liability_exchange_history.py new file mode 100644 index 00000000..5ff8e241 --- /dev/null +++ b/tests/spot/margin/test_get_small_liability_exchange_history.py @@ -0,0 +1,30 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/margin/exchange-small-liability-history\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_small_liability_exchange_history(): + """Tests the API endpoint to get small liability exchange history""" + + client = Client(key, secret) + response = client.get_small_liability_exchange_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_bnb_transfer.py b/tests/spot/portfolio_margin/test_bnb_transfer.py new file mode 100644 index 00000000..0079b8d6 --- /dev/null +++ b/tests/spot/portfolio_margin/test_bnb_transfer.py @@ -0,0 +1,33 @@ +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 = {"transferSide": "TO_UM", "amount": 1.01, "recvWindow": 5000} +expected_params = { + "transferSide": "TO_UM", + "amount": 1.01, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/portfolio/bnb-transfer\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_bnb_transfer(): + """Tests the API endpoint to bnb transfer""" + + client = Client(key, secret) + response = client.bnb_transfer(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_change_auto_repay_futures_status.py b/tests/spot/portfolio_margin/test_change_auto_repay_futures_status.py new file mode 100644 index 00000000..34efd88a --- /dev/null +++ b/tests/spot/portfolio_margin/test_change_auto_repay_futures_status.py @@ -0,0 +1,30 @@ +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 = {"autoRepay": True, "recvWindow": 5000} +expected_params = {"autoRepay": True, "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/portfolio/repay-futures-switch\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_change_auto_repay_futures_status(): + """Tests the API endpoint to change auto-repay-futures status""" + + client = Client(key, secret) + response = client.change_auto_repay_futures_status(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_fund_auto_collection.py b/tests/spot/portfolio_margin/test_fund_auto_collection.py new file mode 100644 index 00000000..1000fce8 --- /dev/null +++ b/tests/spot/portfolio_margin/test_fund_auto_collection.py @@ -0,0 +1,30 @@ +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.POST, + "/sapi/v1/portfolio/auto-collection\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_fund_auto_collection(): + """Tests the API endpoint to fund auto-collection""" + + client = Client(key, secret) + response = client.fund_auto_collection(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_fund_collection_by_asset.py b/tests/spot/portfolio_margin/test_fund_collection_by_asset.py new file mode 100644 index 00000000..c135fb3d --- /dev/null +++ b/tests/spot/portfolio_margin/test_fund_collection_by_asset.py @@ -0,0 +1,30 @@ +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/portfolio/asset-collection\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_fund_collection_by_asset(): + """Tests the API endpoint to fund collection by asset""" + + client = Client(key, secret) + response = client.fund_collection_by_asset(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_get_auto_repay_futures_status.py b/tests/spot/portfolio_margin/test_get_auto_repay_futures_status.py new file mode 100644 index 00000000..6bd28a12 --- /dev/null +++ b/tests/spot/portfolio_margin/test_get_auto_repay_futures_status.py @@ -0,0 +1,30 @@ +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/portfolio/repay-futures-switch\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_auto_repay_futures_status(): + """Tests the API endpoint to get auto-repay-futures status""" + + client = Client(key, secret) + response = client.get_auto_repay_futures_status(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_portfolio_margin_account.py b/tests/spot/portfolio_margin/test_portfolio_margin_account.py index 1b721ef9..d7168f68 100644 --- a/tests/spot/portfolio_margin/test_portfolio_margin_account.py +++ b/tests/spot/portfolio_margin/test_portfolio_margin_account.py @@ -1,17 +1,30 @@ import responses + from binance.spot import Spot as Client -from tests.util import mock_http_response 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/portfolio/account", mock_item, 200) +@mock_http_response( + responses.GET, + "/sapi/v1/portfolio/account\\?" + urlencode(expected_params), + mock_item, + 200, +) def test_portfolio_margin_account(): - """Tests the API endpoint to get portfolio margin account info""" + """Tests the API endpoint to portfolio margin account""" client = Client(key, secret) - response = client.portfolio_margin_account() + response = client.portfolio_margin_account(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_amount.py b/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_amount.py index 2df6ae19..afc161b8 100644 --- a/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_amount.py +++ b/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_amount.py @@ -5,18 +5,20 @@ 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} +send_params = {"recvWindow": 5000} +expected_params = {"recvWindow": 5000} @mock_http_response( responses.GET, - "/sapi/v1/portfolio/pmLoan\\?" + urlencode(params), + "/sapi/v1/portfolio/pmLoan\\?" + urlencode(expected_params), mock_item, 200, ) @@ -24,5 +26,5 @@ def test_portfolio_margin_bankruptcy_loan_amount(): """Tests the API endpoint to portfolio margin bankruptcy loan amount""" client = Client(key, secret) - response = client.portfolio_margin_bankruptcy_loan_amount(**params) + response = client.portfolio_margin_bankruptcy_loan_amount(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_repay.py b/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_repay.py index 60e2b0fc..f6d295c3 100644 --- a/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_repay.py +++ b/tests/spot/portfolio_margin/test_portfolio_margin_bankruptcy_loan_repay.py @@ -5,18 +5,20 @@ 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} +send_params = {"recvWindow": 5000} +expected_params = {"recvWindow": 5000} @mock_http_response( responses.POST, - "/sapi/v1/portfolio/repay\\?" + urlencode(params), + "/sapi/v1/portfolio/repay\\?" + urlencode(expected_params), mock_item, 200, ) @@ -24,5 +26,5 @@ def test_portfolio_margin_bankruptcy_loan_repay(): """Tests the API endpoint to portfolio margin bankruptcy loan repay""" client = Client(key, secret) - response = client.portfolio_margin_bankruptcy_loan_repay(**params) + response = client.portfolio_margin_bankruptcy_loan_repay(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_portfolio_margin_collateral_rate.py b/tests/spot/portfolio_margin/test_portfolio_margin_collateral_rate.py index dbb91f62..aaea4c01 100644 --- a/tests/spot/portfolio_margin/test_portfolio_margin_collateral_rate.py +++ b/tests/spot/portfolio_margin/test_portfolio_margin_collateral_rate.py @@ -4,6 +4,7 @@ from tests.util import random_str from tests.util import mock_http_response + mock_item = {"key_1": "value_1", "key_2": "value_2"} mock_exception = {"code": -1, "msg": "error message"} diff --git a/tests/spot/portfolio_margin/test_query_classic_portfolio_margin_negative_balance_interest_history.py b/tests/spot/portfolio_margin/test_query_classic_portfolio_margin_negative_balance_interest_history.py new file mode 100644 index 00000000..82651797 --- /dev/null +++ b/tests/spot/portfolio_margin/test_query_classic_portfolio_margin_negative_balance_interest_history.py @@ -0,0 +1,32 @@ +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", "size": 100, "recvWindow": 5000} +expected_params = {"asset": "BTC", "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/portfolio/interest-history\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_classic_portfolio_margin_negative_balance_interest_history(): + """Tests the API endpoint to query classic portfolio margin negative balance interest history""" + + client = Client(key, secret) + response = client.query_classic_portfolio_margin_negative_balance_interest_history( + **send_params + ) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_query_portfolio_margin_asset_index_price.py b/tests/spot/portfolio_margin/test_query_portfolio_margin_asset_index_price.py new file mode 100644 index 00000000..c189cbc4 --- /dev/null +++ b/tests/spot/portfolio_margin/test_query_portfolio_margin_asset_index_price.py @@ -0,0 +1,30 @@ +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"} +expected_params = {"asset": "BTC"} + + +@mock_http_response( + responses.GET, + "/sapi/v1/portfolio/asset-index-price\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_portfolio_margin_asset_index_price(): + """Tests the API endpoint to query portfolio margin asset index price""" + + client = Client(key, secret) + response = client.query_portfolio_margin_asset_index_price(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/portfolio_margin/test_repay_futures_negative_balance.py b/tests/spot/portfolio_margin/test_repay_futures_negative_balance.py new file mode 100644 index 00000000..0c31a159 --- /dev/null +++ b/tests/spot/portfolio_margin/test_repay_futures_negative_balance.py @@ -0,0 +1,30 @@ +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.POST, + "/sapi/v1/portfolio/repay-futures-negative-balance\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_repay_futures_negative_balance(): + """Tests the API endpoint to repay futures negative balance""" + + client = Client(key, secret) + response = client.repay_futures_negative_balance(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_account.py b/tests/spot/savings/test_savings_account.py deleted file mode 100644 index 3c048b30..00000000 --- a/tests/spot/savings/test_savings_account.py +++ /dev/null @@ -1,19 +0,0 @@ -import responses - -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - - -@mock_http_response(responses.GET, "/sapi/v1/lending/union/account", mock_item, 200) -def test_savings_account(): - """Tests the API endpoint to get lending account""" - - client = Client(key, secret) - response = client.savings_account() - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_change_position.py b/tests/spot/savings/test_savings_change_position.py deleted file mode 100644 index e4232bbd..00000000 --- a/tests/spot/savings/test_savings_change_position.py +++ /dev/null @@ -1,43 +0,0 @@ -import responses - -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() - - -def test_change_fixed_activity_position_to_daily_position_without_projectId(): - """Tests the API endpoint to change Fixed/Activity Position to Daily Position without projectId""" - - client = Client(key, secret) - client.savings_change_position.when.called_with("", "1").should.throw( - ParameterRequiredError - ) - - -def test_change_fixed_activity_position_to_daily_position_without_lot(): - """Tests the API endpoint to change Fixed/Activity Position to Daily Position without lot""" - - client = Client(key, secret) - client.savings_change_position.when.called_with("USDT001", None).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, - "/sapi/v1/lending/positionChanged\\?projectId=USDT001&lot=1", - mock_item, - 200, -) -def test_change_fixed_activity_position_to_daily_position(): - """Tests the API endpoint to change Fixed/Activity Position to Daily Position""" - - client = Client(key, secret) - response = client.savings_change_position(projectId="USDT001", lot="1") - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_flexible_products.py b/tests/spot/savings/test_savings_flexible_products.py deleted file mode 100644 index b6eadb8d..00000000 --- a/tests/spot/savings/test_savings_flexible_products.py +++ /dev/null @@ -1,21 +0,0 @@ -import responses - -from tests.util import random_str -from tests.util import mock_http_response -from binance.spot import Spot as Client - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - - -@mock_http_response( - responses.GET, "/sapi/v1/lending/daily/product/list", mock_item, 200 -) -def test_savings_flexible_products(): - """Tests the API endpoint to get flexible product list""" - - client = Client(key, secret) - response = client.savings_flexible_products() - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_flexible_redeem.py b/tests/spot/savings/test_savings_flexible_redeem.py deleted file mode 100644 index fcb0d0a0..00000000 --- a/tests/spot/savings/test_savings_flexible_redeem.py +++ /dev/null @@ -1,52 +0,0 @@ -import responses - -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() - - -def test_savings_flexible_redeem_without_productId(): - """Tests the API endpoint to redeem flexible redemption without productId""" - - client = Client(key, secret) - client.savings_flexible_redeem.when.called_with("", 10, "NORMAL").should.throw( - ParameterRequiredError - ) - - -def test_savings_flexible_redeem_without_amount(): - """Tests the API endpoint to redeem flexible redemption without amount""" - - client = Client(key, secret) - client.savings_flexible_redeem.when.called_with("1", "", "NORMAL").should.throw( - ParameterRequiredError - ) - - -def test_savings_flexible_redeem_without_type(): - """Tests the API endpoint to redeem flexible redemption without type""" - - client = Client(key, secret) - client.savings_flexible_redeem.when.called_with("1", "10", "").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, - "/sapi/v1/lending/daily/redeem\\?productId=1&amount=2&type=NORMAL", - mock_item, - 200, -) -def test_savings_flexible_redeem(): - """Tests the API endpoint to get flexible redemption quota""" - - client = Client(key, secret) - response = client.savings_flexible_redeem(productId="1", amount=2, type="NORMAL") - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_flexible_user_left_quota.py b/tests/spot/savings/test_savings_flexible_user_left_quota.py deleted file mode 100644 index c047a46b..00000000 --- a/tests/spot/savings/test_savings_flexible_user_left_quota.py +++ /dev/null @@ -1,31 +0,0 @@ -import responses - -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() - - -def test_savings_flexible_user_left_quota_without_productId(): - """Tests the API endpoint to get left daily purchase quota of flexible product without productId""" - - client = Client(key, secret) - client.savings_flexible_user_left_quota.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, "/sapi/v1/lending/daily/userLeftQuota\\?productId=1", mock_item, 200 -) -def test_savings_flexible_user_left_quota(): - """Tests the API endpoint to get left daily purchase quota of flexible product""" - - client = Client(key, secret) - response = client.savings_flexible_user_left_quota(productId=1) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_flexible_user_redemption_quota.py b/tests/spot/savings/test_savings_flexible_user_redemption_quota.py deleted file mode 100644 index 6bc2d933..00000000 --- a/tests/spot/savings/test_savings_flexible_user_redemption_quota.py +++ /dev/null @@ -1,43 +0,0 @@ -import responses - -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() - - -def test_savings_flexible_user_redemption_quota_without_productId(): - """Tests the API endpoint to get left daily redemption quota of flexible Product without productId""" - - client = Client(key, secret) - client.savings_flexible_user_redemption_quota.when.called_with("", 10).should.throw( - ParameterRequiredError - ) - - -def test_savings_flexible_user_redemption_quota_without_type(): - """Tests the API endpoint to get left daily redemption quota of flexible Product without type""" - - client = Client(key, secret) - client.savings_flexible_user_redemption_quota.when.called_with( - "1", None - ).should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.GET, - "/sapi/v1/lending/daily/userRedemptionQuota\\?productId=1&type=2", - mock_item, - 200, -) -def test_savings_flexible_user_redemption_quota(): - """Tests the API endpoint to get left daily redemption quota of flexible Product""" - - client = Client(key, secret) - response = client.savings_flexible_user_redemption_quota(productId=1, type=2) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_interest_history.py b/tests/spot/savings/test_savings_interest_history.py deleted file mode 100644 index c36fae42..00000000 --- a/tests/spot/savings/test_savings_interest_history.py +++ /dev/null @@ -1,34 +0,0 @@ -import responses - -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() - - -def test_savings_interest_history_without_lendingType(): - """Tests the API endpoint to get interest history without lendingType""" - - client = Client(key, secret) - client.savings_interest_history.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/lending/union/interestHistory\\?lendingType=1", - mock_item, - 200, -) -def test_savings_interest_history(): - """Tests the API endpoint to get interest history""" - - client = Client(key, secret) - response = client.savings_interest_history(lendingType=1) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_project_list.py b/tests/spot/savings/test_savings_project_list.py deleted file mode 100644 index ca8ede20..00000000 --- a/tests/spot/savings/test_savings_project_list.py +++ /dev/null @@ -1,31 +0,0 @@ -import responses - -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() - - -def test_savings_project_list_without_type(): - """Tests the API endpoint to get Fixed and Activity Project without type""" - - client = Client(key, secret) - client.savings_project_list.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, "/sapi/v1/lending/project/list\\?type=1", mock_item, 200 -) -def test_savings_project_list(): - """Tests the API endpoint to get Fixed and Activity Project""" - - client = Client(key, secret) - response = client.savings_project_list(type=1) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_project_position.py b/tests/spot/savings/test_savings_project_position.py deleted file mode 100644 index 1e16c209..00000000 --- a/tests/spot/savings/test_savings_project_position.py +++ /dev/null @@ -1,21 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str - -mock_item = {"key_1": "value_1", "key_2": "value_2"} - -key = random_str() -secret = random_str() - - -@mock_http_response( - responses.GET, "/sapi/v1/lending/project/position/list", mock_item, 200 -) -def test_savings_fixed_activity_project(): - """Tests the API endpoint to purchase Fixed/Activity project position""" - - client = Client(key, secret) - response = client.savings_project_position() - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_purchase_flexible_product.py b/tests/spot/savings/test_savings_purchase_flexible_product.py deleted file mode 100644 index 5aaf12e0..00000000 --- a/tests/spot/savings/test_savings_purchase_flexible_product.py +++ /dev/null @@ -1,43 +0,0 @@ -import responses - -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() - - -def test_savings_purchase_flexible_product_without_productId(): - """Tests the API endpoint to purchase flexible product without productId""" - - client = Client(key, secret) - client.savings_purchase_flexible_product.when.called_with("", 10).should.throw( - ParameterRequiredError - ) - - -def test_savings_purchase_flexible_product_without_amount(): - """Tests the API endpoint to purchase flexible product without amount""" - - client = Client(key, secret) - client.savings_purchase_flexible_product.when.called_with("1", "").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, - "/sapi/v1/lending/daily/purchase\\?productId=1&amount=10", - mock_item, - 200, -) -def test_savings_purchase_flexible_product(): - """Tests the API endpoint to purchase flexible product list""" - - client = Client(key, secret) - response = client.savings_purchase_flexible_product(productId=1, amount=10) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_purchase_project.py b/tests/spot/savings/test_savings_purchase_project.py deleted file mode 100644 index a4c1e5ce..00000000 --- a/tests/spot/savings/test_savings_purchase_project.py +++ /dev/null @@ -1,43 +0,0 @@ -import responses - -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() - - -def test_savings_purchase_fixed_activity_project_without_projectId(): - """Tests the API endpoint to purchase Fixed/Activity Project without projectId""" - - client = Client(key, secret) - client.savings_purchase_project.when.called_with("", 1).should.throw( - ParameterRequiredError - ) - - -def test_savings_purchase_fixed_activity_project_without_lot(): - """Tests the API endpoint to purchase Fixed/Activity Project without without lot""" - - client = Client(key, secret) - client.savings_purchase_project.when.called_with( - "CUSDT14DAYSS001", None - ).should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.POST, - "/sapi/v1/lending/customizedFixed/purchase\\?projectId=CUSDT14DAYSS001&lot=1", - mock_item, - 200, -) -def test_savings_purchase_fixed_activity_project(): - """Tests the API endpoint to purchase Fixed/Activity Project""" - - client = Client(key, secret) - response = client.savings_purchase_project(projectId="CUSDT14DAYSS001", lot=1) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_purchase_record.py b/tests/spot/savings/test_savings_purchase_record.py deleted file mode 100644 index 23a0749d..00000000 --- a/tests/spot/savings/test_savings_purchase_record.py +++ /dev/null @@ -1,34 +0,0 @@ -import responses - -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() - - -def test_savings_purchase_record_without_lendingType(): - """Tests the API endpoint to get purchase record without lendingType""" - - client = Client(key, secret) - client.savings_purchase_record.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/lending/union/purchaseRecord\\?lendingType=1", - mock_item, - 200, -) -def test_savings_purchase_record(): - """Tests the API endpoint to get purchase record""" - - client = Client(key, secret) - response = client.savings_purchase_record(lendingType=1) - response.should.equal(mock_item) diff --git a/tests/spot/savings/test_savings_redemption_record.py b/tests/spot/savings/test_savings_redemption_record.py deleted file mode 100644 index 0555605e..00000000 --- a/tests/spot/savings/test_savings_redemption_record.py +++ /dev/null @@ -1,34 +0,0 @@ -import responses - -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() - - -def test_savings_redemption_record_without_lendingType(): - """Tests the API endpoint to get redemption record without lendingType""" - - client = Client(key, secret) - client.savings_redemption_record.when.called_with("").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/lending/union/redemptionRecord\\?lendingType=1", - mock_item, - 200, -) -def test_savings_redemption_record(): - """Tests the API endpoint to get redemption record""" - - client = Client(key, secret) - response = client.savings_redemption_record(lendingType=1) - response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_collateral_record.py b/tests/spot/simple_earn/test_get_collateral_record.py new file mode 100644 index 00000000..501db6b2 --- /dev/null +++ b/tests/spot/simple_earn/test_get_collateral_record.py @@ -0,0 +1,31 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/history/collateralRecord\\?" + + urlencode(expected_params), + mock_item, + 200, +) +def test_get_collateral_record(): + """Tests the API endpoint to get collateral record""" + + client = Client(key, secret) + response = client.get_collateral_record(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_flexible_personal_left_quota.py b/tests/spot/simple_earn/test_get_flexible_personal_left_quota.py new file mode 100644 index 00000000..fa35b9e1 --- /dev/null +++ b/tests/spot/simple_earn/test_get_flexible_personal_left_quota.py @@ -0,0 +1,30 @@ +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 = {"productId": "product_001", "recvWindow": 5000} +expected_params = {"productId": "product_001", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/personalLeftQuota\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_flexible_personal_left_quota(): + """Tests the API endpoint to get flexible personal left quota""" + + client = Client(key, secret) + response = client.get_flexible_personal_left_quota(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_flexible_product_position.py b/tests/spot/simple_earn/test_get_flexible_product_position.py new file mode 100644 index 00000000..30df0966 --- /dev/null +++ b/tests/spot/simple_earn/test_get_flexible_product_position.py @@ -0,0 +1,30 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/position\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_flexible_product_position(): + """Tests the API endpoint to get flexible product position""" + + client = Client(key, secret) + response = client.get_flexible_product_position(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_flexible_redemption_record.py b/tests/spot/simple_earn/test_get_flexible_redemption_record.py new file mode 100644 index 00000000..9ecdf21b --- /dev/null +++ b/tests/spot/simple_earn/test_get_flexible_redemption_record.py @@ -0,0 +1,31 @@ +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 = {"current": 1, "size": 100} +expected_params = {"current": 1, "size": 100} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/history/redemptionRecord\\?" + + urlencode(expected_params), + mock_item, + 200, +) +def test_get_flexible_redemption_record(): + """Tests the API endpoint to get flexible redemption record""" + + client = Client(key, secret) + response = client.get_flexible_redemption_record(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_flexible_rewards_history.py b/tests/spot/simple_earn/test_get_flexible_rewards_history.py new file mode 100644 index 00000000..d42b4b44 --- /dev/null +++ b/tests/spot/simple_earn/test_get_flexible_rewards_history.py @@ -0,0 +1,29 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +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 = {"type": "REWARDS"} +expected_params = {"type": "REWARDS"} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/history/rewardsRecord", + mock_item, + 200, +) +def test_get_flexible_rewards_history(): + """Tests the API endpoint to get flexible rewards history""" + + client = Client(key, secret) + response = client.get_flexible_rewards_history("REWARDS") + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_flexible_subscription_preview.py b/tests/spot/simple_earn/test_get_flexible_subscription_preview.py new file mode 100644 index 00000000..ce60a148 --- /dev/null +++ b/tests/spot/simple_earn/test_get_flexible_subscription_preview.py @@ -0,0 +1,30 @@ +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 = {"productId": "product_001", "amount": 100, "recvWindow": 5000} +expected_params = {"productId": "product_001", "amount": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/subscriptionPreview\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_flexible_subscription_preview(): + """Tests the API endpoint to get flexible subscription preview""" + + client = Client(key, secret) + response = client.get_flexible_subscription_preview(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_flexible_subscription_record.py b/tests/spot/simple_earn/test_get_flexible_subscription_record.py new file mode 100644 index 00000000..1059fb40 --- /dev/null +++ b/tests/spot/simple_earn/test_get_flexible_subscription_record.py @@ -0,0 +1,31 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/history/subscriptionRecord\\?" + + urlencode(expected_params), + mock_item, + 200, +) +def test_get_flexible_subscription_record(): + """Tests the API endpoint to get flexible subscription record""" + + client = Client(key, secret) + response = client.get_flexible_subscription_record(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_locked_personal_left_quota.py b/tests/spot/simple_earn/test_get_locked_personal_left_quota.py new file mode 100644 index 00000000..1567640b --- /dev/null +++ b/tests/spot/simple_earn/test_get_locked_personal_left_quota.py @@ -0,0 +1,30 @@ +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 = {"projectId": "project_001", "recvWindow": 5000} +expected_params = {"projectId": "project_001", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/personalLeftQuota\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_locked_personal_left_quota(): + """Tests the API endpoint to get locked personal left quota""" + + client = Client(key, secret) + response = client.get_locked_personal_left_quota(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_locked_product_position.py b/tests/spot/simple_earn/test_get_locked_product_position.py new file mode 100644 index 00000000..dfad1805 --- /dev/null +++ b/tests/spot/simple_earn/test_get_locked_product_position.py @@ -0,0 +1,30 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/position\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_locked_product_position(): + """Tests the API endpoint to get locked product position""" + + client = Client(key, secret) + response = client.get_locked_product_position(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_locked_redemption_record.py b/tests/spot/simple_earn/test_get_locked_redemption_record.py new file mode 100644 index 00000000..b942fee9 --- /dev/null +++ b/tests/spot/simple_earn/test_get_locked_redemption_record.py @@ -0,0 +1,31 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/history/redemptionRecord\\?" + + urlencode(expected_params), + mock_item, + 200, +) +def test_get_locked_redemption_record(): + """Tests the API endpoint to get locked redemption record""" + + client = Client(key, secret) + response = client.get_locked_redemption_record(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_locked_rewards_history.py b/tests/spot/simple_earn/test_get_locked_rewards_history.py new file mode 100644 index 00000000..a68fc979 --- /dev/null +++ b/tests/spot/simple_earn/test_get_locked_rewards_history.py @@ -0,0 +1,30 @@ +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 = {"size": 100, "recvWindow": 5000} +expected_params = {"size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/history/rewardsRecord\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_locked_rewards_history(): + """Tests the API endpoint to get locked rewards history""" + + client = Client(key, secret) + response = client.get_locked_rewards_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_locked_subscription_preview.py b/tests/spot/simple_earn/test_get_locked_subscription_preview.py new file mode 100644 index 00000000..af4f0c69 --- /dev/null +++ b/tests/spot/simple_earn/test_get_locked_subscription_preview.py @@ -0,0 +1,30 @@ +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 = {"projectId": "project_001", "amount": 100, "recvWindow": 5000} +expected_params = {"projectId": "project_001", "amount": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/subscriptionPreview\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_locked_subscription_preview(): + """Tests the API endpoint to get locked subscription preview""" + + client = Client(key, secret) + response = client.get_locked_subscription_preview(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_locked_subscription_record.py b/tests/spot/simple_earn/test_get_locked_subscription_record.py new file mode 100644 index 00000000..8ca2fb65 --- /dev/null +++ b/tests/spot/simple_earn/test_get_locked_subscription_record.py @@ -0,0 +1,31 @@ +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 = {"current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/history/subscriptionRecord\\?" + + urlencode(expected_params), + mock_item, + 200, +) +def test_get_locked_subscription_record(): + """Tests the API endpoint to get locked subscription record""" + + client = Client(key, secret) + response = client.get_locked_subscription_record(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_rate_history.py b/tests/spot/simple_earn/test_get_rate_history.py new file mode 100644 index 00000000..9b3cd801 --- /dev/null +++ b/tests/spot/simple_earn/test_get_rate_history.py @@ -0,0 +1,40 @@ +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 = { + "productId": "product_001", + "current": 1, + "size": 100, + "recvWindow": 5000, +} +expected_params = { + "productId": "product_001", + "current": 1, + "size": 100, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/history/rateHistory\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_rate_history(): + """Tests the API endpoint to get rate history""" + + client = Client(key, secret) + response = client.get_rate_history(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_simple_earn_flexible_product_list.py b/tests/spot/simple_earn/test_get_simple_earn_flexible_product_list.py new file mode 100644 index 00000000..ef61c611 --- /dev/null +++ b/tests/spot/simple_earn/test_get_simple_earn_flexible_product_list.py @@ -0,0 +1,30 @@ +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", "current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"asset": "BTC", "current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/flexible/list\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_simple_earn_flexible_product_list(): + """Tests the API endpoint to get simple earn flexible product list""" + + client = Client(key, secret) + response = client.get_simple_earn_flexible_product_list(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_get_simple_earn_locked_product_list.py b/tests/spot/simple_earn/test_get_simple_earn_locked_product_list.py new file mode 100644 index 00000000..023cb5b6 --- /dev/null +++ b/tests/spot/simple_earn/test_get_simple_earn_locked_product_list.py @@ -0,0 +1,30 @@ +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": "BNB", "current": 1, "size": 100, "recvWindow": 5000} +expected_params = {"asset": "BNB", "current": 1, "size": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/simple-earn/locked/list\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_get_simple_earn_locked_product_list(): + """Tests the API endpoint to get simple earn locked product list""" + + client = Client(key, secret) + response = client.get_simple_earn_locked_product_list(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_redeem_flexible_product.py b/tests/spot/simple_earn/test_redeem_flexible_product.py new file mode 100644 index 00000000..7ad8212f --- /dev/null +++ b/tests/spot/simple_earn/test_redeem_flexible_product.py @@ -0,0 +1,30 @@ +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 = {"productId": "product_001", "recvWindow": 5000} +expected_params = {"productId": "product_001", "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/simple-earn/flexible/redeem\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_redeem_flexible_product(): + """Tests the API endpoint to redeem flexible product""" + + client = Client(key, secret) + response = client.redeem_flexible_product(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_redeem_locked_product.py b/tests/spot/simple_earn/test_redeem_locked_product.py new file mode 100644 index 00000000..c37528dc --- /dev/null +++ b/tests/spot/simple_earn/test_redeem_locked_product.py @@ -0,0 +1,30 @@ +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 = {"positionId": "position_1", "recvWindow": 5000} +expected_params = {"positionId": "position_1", "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/simple-earn/locked/redeem\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_redeem_locked_product(): + """Tests the API endpoint to redeem locked product""" + + client = Client(key, secret) + response = client.redeem_locked_product(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_set_flexible_auto_subscribe.py b/tests/spot/simple_earn/test_set_flexible_auto_subscribe.py new file mode 100644 index 00000000..74b582a7 --- /dev/null +++ b/tests/spot/simple_earn/test_set_flexible_auto_subscribe.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 + + +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 = {"productId": "product_001", "autoSubscribe": True, "recvWindow": 5000} +expected_params = { + "productId": "product_001", + "autoSubscribe": True, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/simple-earn/flexible/setAutoSubscribe\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_set_flexible_auto_subscribe(): + """Tests the API endpoint to set flexible auto subscribe""" + + client = Client(key, secret) + response = client.set_flexible_auto_subscribe(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_set_locked_auto_subscribe.py b/tests/spot/simple_earn/test_set_locked_auto_subscribe.py new file mode 100644 index 00000000..577a28c5 --- /dev/null +++ b/tests/spot/simple_earn/test_set_locked_auto_subscribe.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 + + +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 = {"positionId": "position_001", "autoSubscribe": True, "recvWindow": 5000} +expected_params = { + "positionId": "position_001", + "autoSubscribe": True, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.POST, + "/sapi/v1/simple-earn/locked/setAutoSubscribe\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_set_locked_auto_subscribe(): + """Tests the API endpoint to set locked auto subscribe""" + + client = Client(key, secret) + response = client.set_locked_auto_subscribe(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_simple_account.py b/tests/spot/simple_earn/test_simple_account.py new file mode 100644 index 00000000..3c7317f2 --- /dev/null +++ b/tests/spot/simple_earn/test_simple_account.py @@ -0,0 +1,30 @@ +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/simple-earn/account\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_simple_account(): + """Tests the API endpoint to simple account""" + + client = Client(key, secret) + response = client.simple_account(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_subscribe_flexible_product.py b/tests/spot/simple_earn/test_subscribe_flexible_product.py new file mode 100644 index 00000000..f6d27a8b --- /dev/null +++ b/tests/spot/simple_earn/test_subscribe_flexible_product.py @@ -0,0 +1,30 @@ +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 = {"productId": "product_id", "amount": 100, "recvWindow": 5000} +expected_params = {"productId": "product_id", "amount": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/simple-earn/flexible/subscribe\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_subscribe_flexible_product(): + """Tests the API endpoint to subscribe flexible product""" + + client = Client(key, secret) + response = client.subscribe_flexible_product(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/simple_earn/test_subscribe_locked_product.py b/tests/spot/simple_earn/test_subscribe_locked_product.py new file mode 100644 index 00000000..cf25d564 --- /dev/null +++ b/tests/spot/simple_earn/test_subscribe_locked_product.py @@ -0,0 +1,30 @@ +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 = {"projectId": "project_id", "amount": 100, "recvWindow": 5000} +expected_params = {"projectId": "project_id", "amount": 100, "recvWindow": 5000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/simple-earn/locked/subscribe\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_subscribe_locked_product(): + """Tests the API endpoint to subscribe locked product""" + + client = Client(key, secret) + response = client.subscribe_locked_product(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_detail_on_sub_account_s_futures_account.py b/tests/spot/sub_account/test_detail_on_sub_account_s_futures_account.py new file mode 100644 index 00000000..b76647e0 --- /dev/null +++ b/tests/spot/sub_account/test_detail_on_sub_account_s_futures_account.py @@ -0,0 +1,30 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 1000} +expected_params = {"email": "alice@test.com", "recvWindow": 1000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/sub-account/futures/account\\?" + encoded_string(expected_params), + mock_item, + 200, +) +def test_detail_on_sub_account_s_futures_account(): + """Tests the API endpoint to detail on sub-account's futures account""" + + client = Client(key, secret) + response = client.detail_on_sub_account_s_futures_account(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_enable_options_for_sub_account.py b/tests/spot/sub_account/test_enable_options_for_sub_account.py new file mode 100644 index 00000000..3eb1f0cc --- /dev/null +++ b/tests/spot/sub_account/test_enable_options_for_sub_account.py @@ -0,0 +1,29 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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() + +param = {"email": "alice@test.com", "recvWindow": 1000} + + +@mock_http_response( + responses.POST, + "/sapi/v1/sub-account/eoptions/enable\\?" + encoded_string(param), + mock_item, + 200, +) +def test_enable_options_for_sub_account(): + """Tests the API endpoint to enable options for sub-account""" + + client = Client(key, secret) + response = client.enable_options_for_sub_account(**param) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_futures_position_risk_of_sub_account.py b/tests/spot/sub_account/test_futures_position_risk_of_sub_account.py new file mode 100644 index 00000000..c05d3351 --- /dev/null +++ b/tests/spot/sub_account/test_futures_position_risk_of_sub_account.py @@ -0,0 +1,29 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 1000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/sub-account/futures/positionRisk\\?" + encoded_string(params), + mock_item, + 200, +) +def test_futures_position_risk_of_sub_account(): + """Tests the API endpoint to futures position-risk of sub-account""" + + client = Client(key, secret) + response = client.futures_position_risk_of_sub_account(**params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_query_managed_sub_account_futures_asset_details.py b/tests/spot/sub_account/test_query_managed_sub_account_futures_asset_details.py new file mode 100644 index 00000000..80accf47 --- /dev/null +++ b/tests/spot/sub_account/test_query_managed_sub_account_futures_asset_details.py @@ -0,0 +1,31 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 5000} +expected_params = {"email": "alice@test.com", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/managed-subaccount/fetch-future-asset\\?" + + encoded_string(expected_params), + mock_item, + 200, +) +def test_query_managed_sub_account_futures_asset_details(): + """Tests the API endpoint to query managed sub-account futures asset details""" + + client = Client(key, secret) + response = client.query_managed_sub_account_futures_asset_details(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_query_managed_sub_account_list.py b/tests/spot/sub_account/test_query_managed_sub_account_list.py new file mode 100644 index 00000000..8537e580 --- /dev/null +++ b/tests/spot/sub_account/test_query_managed_sub_account_list.py @@ -0,0 +1,30 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "page": 1, "limit": 5, "recvWindow": 5000} +expected_params = {"email": "alice@test.com", "page": 1, "limit": 5, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/managed-subaccount/info\\?" + encoded_string(expected_params), + mock_item, + 200, +) +def test_query_managed_sub_account_list(): + """Tests the API endpoint to query managed sub-account list""" + + client = Client(key, secret) + response = client.query_managed_sub_account_list(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_query_managed_sub_account_margin_asset_details.py b/tests/spot/sub_account/test_query_managed_sub_account_margin_asset_details.py new file mode 100644 index 00000000..8b7d65e8 --- /dev/null +++ b/tests/spot/sub_account/test_query_managed_sub_account_margin_asset_details.py @@ -0,0 +1,30 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 5000} +expected_params = {"email": "alice@test.com", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/managed-subaccount/marginAsset\\?" + encoded_string(expected_params), + mock_item, + 200, +) +def test_query_managed_sub_account_margin_asset_details(): + """Tests the API endpoint to query managed sub-account margin asset details""" + + client = Client(key, secret) + response = client.query_managed_sub_account_margin_asset_details(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_query_managed_sub_account_transfer_log.py b/tests/spot/sub_account/test_query_managed_sub_account_transfer_log.py new file mode 100644 index 00000000..30730d25 --- /dev/null +++ b/tests/spot/sub_account/test_query_managed_sub_account_transfer_log.py @@ -0,0 +1,34 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = { + "startTime": 1679416673000, + "endTime": 1689416673000, + "page": 1, + "limit": 100, +} + + +@mock_http_response( + responses.GET, + "/sapi/v1/managed-subaccount/query-trans-log\\?" + encoded_string(send_params), + mock_item, + 200, +) +def test_query_managed_sub_account_transfer_log(): + """Tests the API endpoint to query Managed Sub Account Transfer Log""" + + client = Client(key, secret) + response = client.query_managed_sub_account_transfer_log(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_query_sub_account_assets.py b/tests/spot/sub_account/test_query_sub_account_assets.py new file mode 100644 index 00000000..1b22d5f1 --- /dev/null +++ b/tests/spot/sub_account/test_query_sub_account_assets.py @@ -0,0 +1,30 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 5000} +expected_params = {"email": "alice@test.com", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v4/sub-account/assets\\?" + encoded_string(expected_params), + mock_item, + 200, +) +def test_query_sub_account_assets(): + """Tests the API endpoint to query sub-account assets""" + + client = Client(key, secret) + response = client.query_sub_account_assets(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_query_sub_account_transaction_statistics.py b/tests/spot/sub_account/test_query_sub_account_transaction_statistics.py new file mode 100644 index 00000000..739d3f49 --- /dev/null +++ b/tests/spot/sub_account/test_query_sub_account_transaction_statistics.py @@ -0,0 +1,30 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 5000} +expected_params = {"email": "alice@test.com", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/sub-account/transaction-statistics\\?" + encoded_string(expected_params), + mock_item, + 200, +) +def test_query_sub_account_transaction_statistics(): + """Tests the API endpoint to query sub-account transaction statistics""" + + client = Client(key, secret) + response = client.query_sub_account_transaction_statistics(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_sub_account_assets.py b/tests/spot/sub_account/test_sub_account_assets.py new file mode 100644 index 00000000..cf0bf652 --- /dev/null +++ b/tests/spot/sub_account/test_sub_account_assets.py @@ -0,0 +1,30 @@ +import responses + +from binance.spot import Spot as Client +from tests.util import random_str +from binance.lib.utils import encoded_string +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 = {"email": "alice@test.com", "recvWindow": 5000} +expected_params = {"email": "alice@test.com", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v3/sub-account/assets\\?" + encoded_string(expected_params), + mock_item, + 200, +) +def test_sub_account_assets(): + """Tests the API endpoint to sub-account assets""" + + client = Client(key, secret) + response = client.sub_account_assets(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/sub_account/test_summary_of_sub_account_s_futures_account.py b/tests/spot/sub_account/test_summary_of_sub_account_s_futures_account.py new file mode 100644 index 00000000..fdf7e864 --- /dev/null +++ b/tests/spot/sub_account/test_summary_of_sub_account_s_futures_account.py @@ -0,0 +1,30 @@ +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 = {"futuresType": 1, "recvWindow": 5000} +expected_params = {"futuresType": 1, "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v2/sub-account/futures/accountSummary\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_summary_of_sub_account_s_futures_account(): + """Tests the API endpoint to summary of sub-account's futures account""" + + client = Client(key, secret) + response = client.summary_of_sub_account_s_futures_account(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/trade/test_query_prevented_matches.py b/tests/spot/trade/test_query_prevented_matches.py new file mode 100644 index 00000000..82f11623 --- /dev/null +++ b/tests/spot/trade/test_query_prevented_matches.py @@ -0,0 +1,42 @@ +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 = { + "symbol": "BNBUSDT", + "preventedMatchId": 1, + "fromPreventedMatchId": 1, + "limit": 5, + "recvWindow": 5000, +} +expected_params = { + "symbol": "BNBUSDT", + "preventedMatchId": 1, + "fromPreventedMatchId": 1, + "limit": 5, + "recvWindow": 5000, +} + + +@mock_http_response( + responses.GET, + "/api/v3/myPreventedMatches\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_prevented_matches(): + """Tests the API endpoint to query prevented matches""" + + client = Client(key, secret) + response = client.query_prevented_matches(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/wallet/test_one_click_arrival_deposit_apply.py b/tests/spot/wallet/test_one_click_arrival_deposit_apply.py new file mode 100644 index 00000000..5382ecf2 --- /dev/null +++ b/tests/spot/wallet/test_one_click_arrival_deposit_apply.py @@ -0,0 +1,30 @@ +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.POST, + "/sapi/v1/capital/deposit/credit-apply\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_one_click_arrival_deposit_apply(): + """Tests the API endpoint to one click arrival deposit apply""" + + client = Client(key, secret) + response = client.one_click_arrival_deposit_apply(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/wallet/test_transfer_dust.py b/tests/spot/wallet/test_transfer_dust.py index 0a696d03..67f30e6f 100644 --- a/tests/spot/wallet/test_transfer_dust.py +++ b/tests/spot/wallet/test_transfer_dust.py @@ -19,7 +19,7 @@ def test_withdraw_without_coin(): @mock_http_response( - responses.POST, "/sapi/v1/asset/dust\\?asset=LTC&asset=EOS", mock_item, 200 + responses.POST, "/sapi/v1/asset/dust\\?asset=LTC%2CEOS", mock_item, 200 ) def test_withdraw(): """Tests the API endpoint to transfer dust"""