diff --git a/CHANGELOG.md b/CHANGELOG.md index 0468154d..a93f3c4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,74 @@ # Changelog +## 3.7.0 - 2024-05-03 +### Added +- Convert + - `POST /sapi/v1/convert/limit/placeOrder` + - `POST /sapi/v1/convert/limit/cancelOrder` + - `GET /sapi/v1/convert/limit/queryOpenOrders` + +- Margin + - `GET /sapi/v1/margin/available-inventory` + - `POST /sapi/v1/margin/manual-liquidation` + - `GET /sapi/v1/margin/leverageBracket` + +- Market + - `GET /api/v3/ticker/tradingDay` + +- Trade + - `GET /api/v3/myAllocations` + - `GET /api/v3/account/commission` + +- Wallet + - `GET /sapi/v1/capital/deposit/address/list` + - `GET /sapi/v1/spot/delist-schedule` + +### Updated +- `POST /sapi/v1/asset/dust-btc` add parameter `accountType` +- `POST /sapi/v1/asset/dust` add parameter `accountType` +- `GET /sapi/v1/asset/dribblet` add parameter `accountType` +- `POST /sapi/v1/margin/order/oco`: New enumerate value `AUTO_BORROW_REPAY` for the field of `sideEffectType` +- `POST /sapi/v1/margin/order`: New enumerate value `AUTO_BORROW_REPAY` for the field of `sideEffectType` +- Update documentation +- Add new handle exception in websocket read_data + +### Removed +- Bswap + - `GET /sapi/v1/bswap/pools` + - `GET /sapi/v1/bswap/liquidity` + - `POST /sapi/v1/bswap/liquidityAdd` + - `POST /sapi/v1/bswap/liquidityRemove` + - `GET /sapi/v1/bswap/liquidityOps` + - `GET /sapi/v1/bswap/quote` + - `POST /sapi/v1/bswap/swap` + - `GET /sapi/v1/bswap/swap` + - `GET /sapi/v1/bswap/poolConfigure` + - `GET /sapi/v1/bswap/addLiquidityPreview` + - `GET /sapi/v1/bswap/removeLiquidityPreview` + - `GET /sapi/v1/bswap/unclaimedRewards` + - `POST /sapi/v1/bswap/claimRewards` + - `GET /sapi/v1/bswap/claimedHistory` + +- Loan + - `POST /sapi/v1/loan/flexible/borrow` + - `GET /sapi/v1/loan/flexible/ongoing/orders` + - `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` + +- Staking + - `GET /sapi/v1/staking/productList` + - `POST /sapi/v1/staking/purchase` + - `POST /sapi/v1/staking/redeem` + - `GET /sapi/v1/staking/position` + - `GET /sapi/v1/staking/stakingRecord` + - `POST /sapi/v1/staking/setAutoStaking` + - `GET /sapi/v1/staking/personalLeftQuota` + ## 3.6.0 - 2024-03-07 ### Removed - `POST /sapi/v1/margin/transfer` diff --git a/binance/__version__.py b/binance/__version__.py index 85197cb4..46f67e7f 100644 --- a/binance/__version__.py +++ b/binance/__version__.py @@ -1 +1 @@ -__version__ = "3.6.0" +__version__ = "3.7.0" diff --git a/binance/spot/__init__.py b/binance/spot/__init__.py index e70930ab..d2f37914 100644 --- a/binance/spot/__init__.py +++ b/binance/spot/__init__.py @@ -19,6 +19,7 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._market import ui_klines from binance.spot._market import avg_price from binance.spot._market import ticker_24hr + from binance.spot._market import trading_day_ticker from binance.spot._market import ticker_price from binance.spot._market import book_ticker from binance.spot._market import rolling_window_ticker @@ -41,6 +42,8 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._trade import my_trades from binance.spot._trade import get_order_rate_limit from binance.spot._trade import query_prevented_matches + from binance.spot._trade import query_allocations + from binance.spot._trade import query_commission_rates # STREAMS from binance.spot._data_stream import new_listen_key @@ -95,15 +98,9 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): 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 adjust_cross_margin_max_leverage - - # Staking - from binance.spot._staking import staking_product_list - from binance.spot._staking import staking_purchase_product - from binance.spot._staking import staking_redeem_product - from binance.spot._staking import staking_product_position - from binance.spot._staking import staking_history - from binance.spot._staking import staking_set_auto_staking - from binance.spot._staking import staking_product_quota + from binance.spot._margin import margin_available_inventory + from binance.spot._margin import margin_manual_liquidation + from binance.spot._margin import liability_coin_leverage_bracket # WALLET from binance.spot._wallet import system_status @@ -130,11 +127,13 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._wallet import bnb_convertible_assets from binance.spot._wallet import convertible_coins from binance.spot._wallet import toggle_auto_convertion + from binance.spot._wallet import list_deposit_address 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 from binance.spot._wallet import balance + from binance.spot._wallet import delist_schedule_symbols # MINING from binance.spot._mining import mining_algo_list @@ -212,22 +211,6 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): from binance.spot._blvt import redemption_record from binance.spot._blvt import user_limit_info - # BSwap - from binance.spot._bswap import bswap_pools - from binance.spot._bswap import bswap_liquidity - from binance.spot._bswap import bswap_liquidity_add - from binance.spot._bswap import bswap_liquidity_remove - from binance.spot._bswap import bswap_liquidity_operation_record - from binance.spot._bswap import bswap_request_quote - from binance.spot._bswap import bswap_swap - from binance.spot._bswap import bswap_swap_history - from binance.spot._bswap import bswap_pool_configure - from binance.spot._bswap import bswap_add_liquidity_preview - from binance.spot._bswap import bswap_remove_liquidity_preview - from binance.spot._bswap import bswap_unclaimed_rewards - from binance.spot._bswap import bswap_claim_rewards - from binance.spot._bswap import bswap_claimed_rewards - # FIAT from binance.spot._fiat import fiat_order_history from binance.spot._fiat import fiat_payment_history @@ -252,15 +235,6 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): 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 @@ -271,6 +245,9 @@ def __init__(self, api_key=None, api_secret=None, **kwargs): 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 place_limit_order + from binance.spot._convert import cancel_limit_order + from binance.spot._convert import query_limit_open_order from binance.spot._convert import get_convert_trade_history # REBATE diff --git a/binance/spot/_bswap.py b/binance/spot/_bswap.py deleted file mode 100644 index fa5eeef6..00000000 --- a/binance/spot/_bswap.py +++ /dev/null @@ -1,333 +0,0 @@ -from binance.lib.utils import check_required_parameters - - -def bswap_pools(self): - """List All Swap Pools (MARKET_DATA) - Get metadata about all swap pools. - - GET /sapi/v1/bswap/pools - - https://binance-docs.github.io/apidocs/spot/en/#list-all-swap-pools-market_data - - """ - - return self.limit_request("GET", "/sapi/v1/bswap/pools", {}) - - -def bswap_liquidity(self, **kwargs): - """Get liquidity information of a pool (USER_DATA) - Get liquidity information and user share of a pool - - GET /sapi/v1/bswap/liquidity - - https://binance-docs.github.io/apidocs/spot/en/#get-liquidity-information-of-a-pool-user_data - - Keyword Args: - poolId (int, optional) - recvWindow (int, optional): The value cannot be greater than 60000 - - """ - return self.sign_request("GET", "/sapi/v1/bswap/liquidity", kwargs) - - -def bswap_liquidity_add(self, poolId: int, asset: str, quantity: float, **kwargs): - """Add Liquidity (TRADE) - Add liquidity to a pool. - - POST /sapi/v1/bswap/liquidityAdd - - https://binance-docs.github.io/apidocs/spot/en/#add-liquidity-trade - - Args: - poolId (int) - asset (str) - quantity (float) - Keyword Args: - type (str, optional): "Single" to add a single token; "Combination" to add dual tokens. Default "Single" - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [[poolId, "poolId"], [asset, "asset"], [quantity, "quantity"]] - ) - payload = {"poolId": poolId, "asset": asset, "quantity": quantity, **kwargs} - - return self.sign_request("POST", "/sapi/v1/bswap/liquidityAdd", payload) - - -def bswap_liquidity_remove( - self, poolId: str, type: str, asset: list, shareAmount, **kwargs -): - """Remove Liquidity (TRADE) - Remove liquidity from a pool, type include SINGLE and COMBINATION, asset is mandatory for single asset removal - - POST /sapi/v1/bswap/liquidityRemove - - https://binance-docs.github.io/apidocs/spot/en/#remove-liquidity-trade - - Args: - poolId (int) - type (str): SINGLE for single asset removal, COMBINATION for combination of all coins removal - asset (str) - shareAmount (float): Mandatory for liquidity removal - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [ - [poolId, "poolId"], - [type, "type"], - [asset, "asset"], - [shareAmount, "shareAmount"], - ] - ) - payload = { - "poolId": poolId, - "type": type, - "asset": ",".join(asset), - "shareAmount": shareAmount, - **kwargs, - } - - return self.sign_request("POST", "/sapi/v1/bswap/liquidityRemove", payload) - - -def bswap_liquidity_operation_record(self, **kwargs): - """Get Liquidity Operation Record (USER_DATA) - Get liquidity operation (add/remove) records. - - GET /sapi/v1/bswap/liquidityOps - - https://binance-docs.github.io/apidocs/spot/en/#get-liquidity-operation-record-user_data - - Keyword Args: - operationId (int, optional) - poolId (int, optional) - operation (str, optional): ADD or REMOVE - startTime (int, optional) - endTime (int, optional) - limit (int, optional): default 3, max 100 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - return self.sign_request("GET", "/sapi/v1/bswap/liquidityOps", kwargs) - - -def bswap_request_quote( - self, quoteAsset: str, baseAsset: str, quoteQty: float, **kwargs -): - """Request Quote (USER_DATA) - Request a quote for swap quote asset (selling asset) for base asset (buying asset), essentially price/exchange rates. - quoteQty is quantity of quote asset (to sell). - - Please be noted the quote is for reference only, the actual price will change as the liquidity changes, - it's recommended to swap immediate after request a quote for slippage prevention. - - GET /sapi/v1/bswap/quote - - https://binance-docs.github.io/apidocs/spot/en/#request-quote-user_data - - Args: - quoteAsset (str) - baseAsset (str) - quoteQty (float) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - check_required_parameters( - [[quoteAsset, "quoteAsset"], [baseAsset, "baseAsset"], [quoteQty, "quoteQty"]] - ) - payload = { - "quoteAsset": quoteAsset, - "baseAsset": baseAsset, - "quoteQty": quoteQty, - **kwargs, - } - - return self.sign_request("GET", "/sapi/v1/bswap/quote", payload) - - -def bswap_swap(self, quoteAsset: str, baseAsset: str, quoteQty: float, **kwargs): - """Swap (TRADE) - Swap quoteAsset for baseAsset. - - POST /sapi/v1/bswap/swap - - https://binance-docs.github.io/apidocs/spot/en/#swap-trade - - Args: - baseAsset (str) - quoteAsset (str) - quoteQty (float) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [[quoteAsset, "quoteAsset"], [baseAsset, "baseAsset"], [quoteQty, "quoteQty"]] - ) - payload = { - "quoteAsset": quoteAsset, - "baseAsset": baseAsset, - "quoteQty": quoteQty, - **kwargs, - } - return self.sign_request("POST", "/sapi/v1/bswap/swap", payload) - - -def bswap_swap_history(self, **kwargs): - """Get Swap History (USER_DATA) - Get swap history. - - GET /sapi/v1/bswap/swap - - https://binance-docs.github.io/apidocs/spot/en/#get-swap-history-user_data - - Keyword Args: - swapId (int, optional) - startTime (int, optional) - endTime (int, optional) - status (int, optional) - baseAsset (str, optional) - quoteAsset (str, optional) - limit (int, optional) - recvWindow (int, optional): The value cannot be greater than 60000 - """ - return self.sign_request("GET", "/sapi/v1/bswap/swap", kwargs) - - -def bswap_pool_configure(self, **kwargs): - """Get Pool Configure (USER_DATA) - - GET /sapi/v1/bswap/poolConfigure - - https://binance-docs.github.io/apidocs/spot/en/#get-pool-configure-user_data - - Keyword Args: - poolId (int, optional) - recvWindow (int, optional): The value cannot be greater than 60000 - """ - return self.sign_request("GET", "/sapi/v1/bswap/poolConfigure", kwargs) - - -def bswap_add_liquidity_preview( - self, poolId: int, type: str, quoteAsset: str, quoteQty: float, **kwargs -): - """Add Liquidity Preview (USER_DATA) - Calculate expected share amount for adding liquidity in single or dual token. - - GET /sapi/v1/bswap/addLiquidityPreview - - https://binance-docs.github.io/apidocs/spot/en/#add-liquidity-preview-user_data - - Args: - poolId (int) - type (str): "SINGLE" for adding a single token;"COMBINATION" for adding dual tokens - quoteAsset (str) - quoteQty (float) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [ - [poolId, "poolId"], - [type, "type"], - [quoteAsset, "quoteAsset"], - [quoteQty, "quoteQty"], - ] - ) - payload = { - "poolId": poolId, - "type": type, - "quoteAsset": quoteAsset, - "quoteQty": quoteQty, - **kwargs, - } - return self.sign_request("GET", "/sapi/v1/bswap/addLiquidityPreview", payload) - - -def bswap_remove_liquidity_preview( - self, poolId: int, type: str, quoteAsset: str, shareAmount: float, **kwargs -): - """Remove Liquidity Preview (USER_DATA) - Calculate the expected asset amount of single token redemption or dual token redemption. - - GET /sapi/v1/bswap/removeLiquidityPreview - - https://binance-docs.github.io/apidocs/spot/en/#remove-liquidity-preview-user_data - - Args: - poolId (int) - type (str): Type is "SINGLE", remove and obtain a single token;Type is "COMBINATION", remove and obtain dual token - quoteAsset (str) - shareAmount (float) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [ - [poolId, "poolId"], - [type, "type"], - [quoteAsset, "quoteAsset"], - [shareAmount, "shareAmount"], - ] - ) - payload = { - "poolId": poolId, - "type": type, - "quoteAsset": quoteAsset, - "shareAmount": shareAmount, - **kwargs, - } - return self.sign_request("GET", "/sapi/v1/bswap/removeLiquidityPreview", payload) - - -def bswap_unclaimed_rewards(self, **kwargs): - """Get Unclaimed Rewards Record (USER_DATA) - Get unclaimed rewards record. - - GET /sapi/v1/bswap/unclaimedRewards - - https://binance-docs.github.io/apidocs/spot/en/#get-unclaimed-rewards-record-user_data - - Keyword Args: - type (int, optional): 0: Swap rewards,1:Liquidity rewards, default to 0 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/bswap/unclaimedRewards", kwargs) - - -def bswap_claim_rewards(self, **kwargs): - """Claim rewards (TRADE) - Claim swap rewards or liquidity rewards - - POST /sapi/v1/bswap/claimRewards - - https://binance-docs.github.io/apidocs/spot/en/#claim-rewards-trade - - Keyword Args: - type (int, optional): 0: Swap rewards,1:Liquidity rewards, default to 0 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("POST", "/sapi/v1/bswap/claimRewards", kwargs) - - -def bswap_claimed_rewards(self, **kwargs): - """Get Claimed History (USER_DATA) - Get history of claimed rewards. - - GET /sapi/v1/bswap/claimedHistory - - https://binance-docs.github.io/apidocs/spot/en/#get-claimed-history-user_data - - Keyword Args: - poolId (int, optional) - assetRewards (str, optional) - type (int, optional): 0: Swap rewards,1:Liquidity rewards, default to 0 - startTime (int, optional) - endTime (int, optional) - limit (int, optional): default 3, max 100 - recvWindow (int, optional): The value cannot be greater than 60000 - """ - - return self.sign_request("GET", "/sapi/v1/bswap/claimedHistory", kwargs) diff --git a/binance/spot/_convert.py b/binance/spot/_convert.py index 6be48255..f006874e 100644 --- a/binance/spot/_convert.py +++ b/binance/spot/_convert.py @@ -115,6 +115,88 @@ def order_status(self, **kwargs): return self.sign_request("GET", url_path, {**kwargs}) +def place_limit_order( + self, + baseAsset: str, + quoteAsset: str, + limitPrice: float, + side: str, + expiredType: str, + **kwargs +): + """Place limit order (USER_DATA) + + POST /sapi/v1/convert/limit/placeOrder + + https://binance-docs.github.io/apidocs/spot/en/#place-limit-order-user_data + + Args: + baseAsset (str): base asset (use the response fromIsBase from GET /sapi/v1/convert/exchangeInfo api to check which one is baseAsset) + quoteAsset (str): quote asset + limitPrice (float): Symbol limit price (from baseAsset to quoteAsset) + side (str): BUY or SELL + expiredType (str): 1_D, 3_D, 7_D, 30_D (D means day) + Keyword Args: + baseAmount (float, optional): Base asset amount. (One of baseAmount or quoteAmount is required) + quotrAmount (float, optional): Quote asset amount. (One of baseAmount or quoteAmount is required) + walletType (str, optional): SPOT or FUNDING or SPOT_FUNDING. It is to use which type of assets. Default is SPOT. + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters( + [ + [baseAsset, "baseAsset"], + [quoteAsset, "quoteAsset"], + [limitPrice, "limitPrice"], + [side, "side"], + [expiredType, "expiredType"], + ] + ) + + params = { + "baseAsset": baseAsset, + "quoteAsset": quoteAsset, + "limitPrice": limitPrice, + "side": side, + "expiredType": expiredType, + **kwargs, + } + url_path = "/sapi/v1/convert/limit/placeOrder" + return self.sign_request("POST", url_path, params) + + +def cancel_limit_order(self, orderId: str, **kwargs): + """Cancel limit order (USER_DATA) + + POST /sapi/v1/convert/limit/cancelOrder + + https://binance-docs.github.io/apidocs/spot/en/#cancel-limit-order-user_data + + Args: + orderId (str): The orderId from placeOrder api + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(orderId, "orderId") + + params = {"orderId": orderId, **kwargs} + url_path = "/sapi/v1/convert/limit/cancelOrder" + return self.sign_request("POST", url_path, params) + + +def query_limit_open_order(self, **kwargs): + """Query limit open orders (USER_DATA) + + GET /sapi/v1/convert/limit/queryOpenOrders + + https://binance-docs.github.io/apidocs/spot/en/#query-limit-open-orders-user_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + url_path = "/sapi/v1/convert/limit/queryOpenOrders" + 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) diff --git a/binance/spot/_crypto_loan.py b/binance/spot/_crypto_loan.py index 0185adbf..dc329337 100644 --- a/binance/spot/_crypto_loan.py +++ b/binance/spot/_crypto_loan.py @@ -348,249 +348,3 @@ 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/_margin.py b/binance/spot/_margin.py index da6aa946..538081b6 100644 --- a/binance/spot/_margin.py +++ b/binance/spot/_margin.py @@ -112,9 +112,9 @@ def new_margin_order(self, symbol: str, side: str, type: str, **kwargs): icebergQty (float, optional): Used with LIMIT, STOP_LOSS_LIMIT and TAKE_PROFIT_LIMIT to create an iceberg order. newOrderRespType (str, optional): Set the response JSON. ACK, RESULT or FULL; MARKET and LIMIT order types default to FULL, all other orders default to ACK. - sideEffectType (str, optional): NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT. + sideEffectType (str, optional): NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY,AUTO_BORROW_REPAY; default NO_SIDE_EFFECT. timeInForce (str, optional): GTC,IOC,FOK - isIsolated (str, optional): for isolated margin or not,"TRUE", "FALSE",default "FALSE". + isIsolated (str, optional): for isolated margin or not,"TRUE", "FALSE" default "FALSE". recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -512,7 +512,7 @@ def new_margin_oco_order( stopIcebergQty (float, optional) stopLimitTimeInForce (str, optional): Valid values are GTC/FOK/IOC newOrderRespType (str, optional): Set the response JSON - sideEffectType (str, optional): NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT + sideEffectType (str, optional): NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY,AUTO_BORROW_REPAY; default NO_SIDE_EFFECT recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -630,7 +630,7 @@ def get_margin_open_oco_orders(self, **kwargs): https://binance-docs.github.io/apidocs/spot/en/#query-margin-account-39-s-open-oco-user_data Keyword Args: - isIsolated (str, optional): For isolated margin or not "TRUE", "FALSE",default "FALSE" + isIsolated (str, optional): For isolated margin or not "TRUE", "FALSE" default "FALSE" symbol (str, optional): Mandatory for isolated margin, not supported for cross margin recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -881,3 +881,51 @@ def adjust_cross_margin_max_leverage(self, maxLeverage: int, **kwargs): params = {"maxLeverage": maxLeverage, **kwargs} url_path = "/sapi/v1/margin/max-leverage" return self.sign_request("POST", url_path, params) + + +def margin_available_inventory(self, type: str, **kwargs): + """Query Margin Available Inventory (USER_DATA) + + GET /sapi/v1/margin/available-inventory + + https://binance-docs.github.io/apidocs/spot/en/#query-margin-available-inventory-user_data + + Args: + type (str): "MARGIN", "ISOLATED" + Keyword Args: + 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/margin/available-inventory", payload) + + +def margin_manual_liquidation(self, type: str, **kwargs): + """Margin manual liquidation(MARGIN) + + POST /sapi/v1/margin/manual-liquidation + + https://binance-docs.github.io/apidocs/spot/en/#margin-manual-liquidation-margin + + Args: + type (str): "MARGIN", "ISOLATED" + Keyword Args: + symbol (str, optional): When type selects ISOLATED, symbol must be filled in + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameters([[type, "type"]]) + payload = {"type": type, **kwargs} + return self.sign_request("POST", "/sapi/v1/margin/manual-liquidation", payload) + + +def liability_coin_leverage_bracket(self, **kwargs): + """Query Liability Coin Leverage Bracket in Cross Margin Pro Mode(MARKET_DATA) + + GET /sapi/v1/margin/leverageBracket + + https://binance-docs.github.io/apidocs/spot/en/#query-liability-coin-leverage-bracket-in-cross-margin-pro-mode-market_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + return self.sign_request("GET", "/sapi/v1/margin/leverageBracket", kwargs) diff --git a/binance/spot/_market.py b/binance/spot/_market.py index 8cdd6c4b..e51413be 100644 --- a/binance/spot/_market.py +++ b/binance/spot/_market.py @@ -228,6 +228,28 @@ def ticker_24hr(self, symbol: str = None, symbols: list = None, **kwargs): return self.query("/api/v3/ticker/24hr", params) +def trading_day_ticker(self, symbol: str = None, symbols: list = None): + """Trading Day Ticker + + GET /api/v3/ticker/tradingDay + + https://binance-docs.github.io/apidocs/spot/en/#trading-day-ticker + + Args: + symbol (str, optional): Either symbol or symbols must be provided + symbols (list, optional): list of trading pairs + Keyword Args: + timeZone (str, optional): Default: 0 (UTC) + type (str, optional): Supported values: FULL or MINI. If none provided, the default is FULL. + """ + if symbol and symbols: + raise ParameterArgumentError("symbol and symbols cannot be sent together.") + + check_type_parameter(symbols, "symbols", list) + params = {"symbol": symbol, "symbols": convert_list_to_json_array(symbols)} + return self.query("/api/v3/ticker/tradingDay", params) + + def ticker_price(self, symbol: str = None, symbols: list = None): """Symbol Price Ticker diff --git a/binance/spot/_staking.py b/binance/spot/_staking.py deleted file mode 100644 index 284b07de..00000000 --- a/binance/spot/_staking.py +++ /dev/null @@ -1,192 +0,0 @@ -from binance.lib.utils import ( - check_required_parameter, -) -from binance.lib.utils import check_required_parameters - - -def staking_product_list(self, product: str, **kwargs): - """Get Staking Product List (USER_DATA) - - Get available Staking product list. - - Weight(IP): 1 - - GET /sapi/v1/staking/productList - - https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-list-user_data - - Args: - product (str) - Keyword Args: - asset (str, 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(product, "product") - - params = {"product": product, **kwargs} - url_path = "/sapi/v1/staking/productList" - return self.sign_request("GET", url_path, params) - - -def staking_purchase_product( - self, product: str, productId: str, amount: float, **kwargs -): - """Purchase Staking Product (USER_DATA) - - Weight(IP): 1 - - POST /sapi/v1/staking/purchase - - https://binance-docs.github.io/apidocs/spot/en/#purchase-staking-product-user_data - - Args: - product (str) - productId (str) - amount (float) - Keyword Args: - renewable (str, optional): true or false, default false. Active if product is `STAKING` or `L_DEFI` - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [[product, "product"], [productId, "productId"], [amount, "amount"]] - ) - - params = {"product": product, "productId": productId, "amount": amount, **kwargs} - url_path = "/sapi/v1/staking/purchase" - return self.sign_request("POST", url_path, params) - - -def staking_redeem_product(self, product: str, productId: str, **kwargs): - """Redeem Staking Product (USER_DATA) - - Redeem Staking product. Locked staking and Locked DeFI staking belong to early redemption, redeeming in advance will result in loss of interest that you have earned. - - Weight(IP): 1 - - POST /sapi/v1/staking/redeem - - https://binance-docs.github.io/apidocs/spot/en/#redeem-staking-product-user_data - - Args: - product (str) - productId (str) - Keyword Args: - positionId (str, optional): Mandatory if product is `STAKING` or `L_DEFI` - amount (float, optional): Mandatory if product is `F_DEFI` - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters([[product, "product"], [productId, "productId"]]) - - params = {"product": product, "productId": productId, **kwargs} - url_path = "/sapi/v1/staking/redeem" - return self.sign_request("POST", url_path, params) - - -def staking_product_position(self, product: str, **kwargs): - """Get Staking Product Position (USER_DATA) - - Weight(IP): 1 - - GET /sapi/v1/staking/position - - https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-position-user_data - - Args: - product (str) - Keyword Args: - productId (str, optional) - asset (str, optional) - 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 - """ - check_required_parameter(product, "product") - - params = {"product": product, **kwargs} - url_path = "/sapi/v1/staking/position" - return self.sign_request("GET", url_path, params) - - -def staking_history(self, product: str, txnType: str, **kwargs): - """Get Staking History (USER_DATA) - - Weight(IP): 1 - - GET /sapi/v1/staking/stakingRecord - - https://binance-docs.github.io/apidocs/spot/en/#get-staking-history-user_data - - Args: - product (str) - txnType (str) - Keyword Args: - asset (str, optional) - startTime (int, optional) - endTime (int, optional) - 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 - """ - check_required_parameters([[product, "product"], [txnType, "txnType"]]) - - params = {"product": product, "txnType": txnType, **kwargs} - url_path = "/sapi/v1/staking/stakingRecord" - return self.sign_request("GET", url_path, params) - - -def staking_set_auto_staking( - self, product: str, positionId: str, renewable: str, **kwargs -): - """Set Auto Staking (USER_DATA) - - Set auto staking on Locked Staking or Locked DeFi Staking - - Weight(IP): 1 - - POST /sapi/v1/staking/setAutoStaking - - https://binance-docs.github.io/apidocs/spot/en/#set-auto-staking-user_data - - Args: - product (str) - positionId (str) - renewable (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters( - [[product, "product"], [positionId, "positionId"], [renewable, "renewable"]] - ) - - params = { - "product": product, - "positionId": positionId, - "renewable": renewable, - **kwargs, - } - url_path = "/sapi/v1/staking/setAutoStaking" - return self.sign_request("POST", url_path, params) - - -def staking_product_quota(self, product: str, productId: str, **kwargs): - """Get Personal Left Quota of Staking Product (USER_DATA) - - Weight(IP): 1 - - GET /sapi/v1/staking/personalLeftQuota - - https://binance-docs.github.io/apidocs/spot/en/#get-personal-left-quota-of-staking-product-user_data - - Args: - product (str) - productId (str) - Keyword Args: - recvWindow (int, optional): The value cannot be greater than 60000 - """ - check_required_parameters([[product, "product"], [productId, "productId"]]) - - params = {"product": product, "productId": productId, **kwargs} - url_path = "/sapi/v1/staking/personalLeftQuota" - return self.sign_request("GET", url_path, params) diff --git a/binance/spot/_trade.py b/binance/spot/_trade.py index 398f06f4..ae62a0b6 100644 --- a/binance/spot/_trade.py +++ b/binance/spot/_trade.py @@ -442,7 +442,7 @@ def get_order_rate_limit(self, **kwargs): def query_prevented_matches(self, symbol: str, **kwargs): - """Query Prevented Matches + """Query Prevented Matches (USER_DATA) Displays the list of orders that were expired because of STP. @@ -480,3 +480,46 @@ def query_prevented_matches(self, symbol: str, **kwargs): params = {"symbol": symbol, **kwargs} url_path = "/api/v3/myPreventedMatches" return self.sign_request("GET", url_path, params) + + +def query_allocations(self, symbol: str, **kwargs): + """Query Cross-Collateral Information (USER_DATA) + + GET /api/v3/myAllocations + + https://binance-docs.github.io/apidocs/spot/en/#query-allocations-user_data + + Args: + symbol (str) + Keyword Args: + startTime (int, optional) + endTime (int, optional) + fromAllocationId (int, optional) + limit (int, optional): Default Value: 500; Max Value: 1000 + orderId (int, optional) + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(symbol, "symbol") + + params = {"symbol": symbol, **kwargs} + url_path = "/api/v3/myAllocations" + return self.sign_request("GET", url_path, params) + + +def query_commission_rates(self, symbol: str, **kwargs): + """Query Commission Rates (USER_DATA) + + GET /api/v3/account/commission + + https://binance-docs.github.io/apidocs/spot/en/#query-commission-rates-user_data + + Args: + symbol (str) + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + check_required_parameter(symbol, "symbol") + + params = {"symbol": symbol, **kwargs} + url_path = "/api/v3/account/commission" + return self.sign_request("GET", url_path, params) diff --git a/binance/spot/_wallet.py b/binance/spot/_wallet.py index 1a4601c4..bf60335f 100644 --- a/binance/spot/_wallet.py +++ b/binance/spot/_wallet.py @@ -218,6 +218,9 @@ def dust_log(self, **kwargs): https://binance-docs.github.io/apidocs/spot/en/#dustlog-sapi-user_data Keyword Args: + accountType (str, optional): SPOT or MARGIN, default SPOT + startTime (int, optional) + endTime (int, optional) recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -281,6 +284,7 @@ def transfer_dust(self, asset: list, **kwargs): Args: asset (str) Keyword Args: + accountType (str, optional): SPOT or MARGIN, default SPOT recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -400,6 +404,7 @@ def bnb_convertible_assets(self, **kwargs): https://binance-docs.github.io/apidocs/spot/en/#get-assets-that-can-be-converted-into-bnb-user_data Keyword Args: + accountType (str, optional): SPOT or MARGIN, default SPOT recvWindow (int, optional): The value cannot be greater than 60000 """ @@ -435,6 +440,23 @@ def toggle_auto_convertion(self, coin: str, enable: bool, **kwargs): ) +def list_deposit_address(self, coin: str, **kwargs): + """Fetch deposit address list with network(USER_DATA) + + GET /sapi/v1/capital/deposit/address/list + + https://binance-docs.github.io/apidocs/spot/en/#fetch-deposit-address-list-with-network-user_data + + Args: + coin (str): coin refers to the parent network address format that the address is using + Keyword Args: + network (str, optional) + """ + check_required_parameter(coin, "coin") + payload = {"coin": coin, **kwargs} + return self.sign_request("GET", "/sapi/v1/capital/deposit/address/list", payload) + + def cloud_mining_trans_history(self, startTime: int, endTime: int, **kwargs): """Get Cloud-Mining payment and refund history (USER_DATA) @@ -560,8 +582,23 @@ def balance(self, **kwargs): https://binance-docs.github.io/apidocs/spot/en/#query-user-wallet-balance-user_data Keyword Args: - recvWindow (LONG, optional) + recvWindow (int, optional): The value cannot be greater than 60000 """ url_path = "/sapi/v1/asset/wallet/balance" return self.sign_request("GET", url_path, {**kwargs}) + + +def delist_schedule_symbols(self, **kwargs): + """Get symbols delist schedule for spot (MARKET_DATA) + + GET /sapi/v1/spot/delist-schedule + + https://binance-docs.github.io/apidocs/spot/en/#get-symbols-delist-schedule-for-spot-market_data + + Keyword Args: + recvWindow (int, optional): The value cannot be greater than 60000 + """ + + url_path = "/sapi/v1/spot/delist-schedule" + return self.sign_request("GET", url_path, {**kwargs}) diff --git a/binance/websocket/binance_socket_manager.py b/binance/websocket/binance_socket_manager.py index 1cfe0dfd..c2c280cc 100644 --- a/binance/websocket/binance_socket_manager.py +++ b/binance/websocket/binance_socket_manager.py @@ -78,10 +78,12 @@ def read_data(self): self.logger.error("Websocket connection timeout") else: self.logger.error("Websocket exception: {}".format(e)) - raise e + self._handle_exception(e) + break except Exception as e: self.logger.error("Exception in read_data: {}".format(e)) - raise e + self._handle_exception(e) + break self._handle_data(op_code, frame, data) self._handle_heartbeat(op_code, frame) @@ -112,7 +114,6 @@ def close(self): self.logger.warning("Websocket already closed") else: self.ws.send_close() - return def _callback(self, callback, *args): if callback: @@ -120,5 +121,10 @@ def _callback(self, callback, *args): callback(self, *args) except Exception as e: self.logger.error("Error from callback {}: {}".format(callback, e)) - if self.on_error: - self.on_error(self, e) + self._handle_exception(e) + + def _handle_exception(self, e): + if self.on_error: + self.on_error(self, e) + else: + raise e diff --git a/binance/websocket/spot/websocket_api/_market.py b/binance/websocket/spot/websocket_api/_market.py index a3b05c23..c810579a 100644 --- a/binance/websocket/spot/websocket_api/_market.py +++ b/binance/websocket/spot/websocket_api/_market.py @@ -223,7 +223,11 @@ def exchange_info(self, **kwargs): "Only one of symbol, symbols or permissions is required." ) - payload = {"id": parameters.pop("id", get_uuid()), "method": "exchangeInfo"} + payload = { + "id": parameters.pop("id", get_uuid()), + "method": "exchangeInfo", + "params": parameters, + } self.send(payload) diff --git a/docs/source/CHANGELOG.rst b/docs/source/CHANGELOG.rst index 47c2ee30..a04284ea 100644 --- a/docs/source/CHANGELOG.rst +++ b/docs/source/CHANGELOG.rst @@ -2,6 +2,91 @@ Changelog ========= +3.7.0 - 2024-05-03 +------------------ + +Added +^^^^^ + +* Convert + + * ``POST /sapi/v1/convert/limit/placeOrder`` + * ``POST /sapi/v1/convert/limit/cancelOrder`` + * ``GET /sapi/v1/convert/limit/queryOpenOrders`` + +* Margin + + * ``GET /sapi/v1/margin/available-inventory`` + * ``POST /sapi/v1/margin/manual-liquidation`` + * ``GET /sapi/v1/margin/leverageBracket`` + +* Market + + * ``GET /api/v3/ticker/tradingDay`` + +* Trade + + * ``GET /api/v3/myAllocations`` + * ``GET /api/v3/account/commission`` + +* Wallet + + * ``GET /sapi/v1/capital/deposit/address/list`` + * ``GET /sapi/v1/spot/delist-schedule`` + +Updated +^^^^^^^ + +* ``POST /sapi/v1/asset/dust-btc`` add parameter ``accountType`` +* ``POST /sapi/v1/asset/dust`` add parameter ``accountType`` +* ``GET /sapi/v1/asset/dribblet`` add parameter ``accountType`` +* ``POST /sapi/v1/margin/order/oco``: New enumerate value ``AUTO_BORROW_REPAY`` for the field of ``sideEffectType`` +* ``POST /sapi/v1/margin/order``: New enumerate value ``AUTO_BORROW_REPAY`` for the field of ``sideEffectType`` +* Update documentation +* Add new handle exception in websocket read_data + +Removed +^^^^^^^ + +* Bswap + + * ``GET /sapi/v1/bswap/pools`` + * ``GET /sapi/v1/bswap/liquidity`` + * ``POST /sapi/v1/bswap/liquidityAdd`` + * ``POST /sapi/v1/bswap/liquidityRemove`` + * ``GET /sapi/v1/bswap/liquidityOps`` + * ``GET /sapi/v1/bswap/quote`` + * ``POST /sapi/v1/bswap/swap`` + * ``GET /sapi/v1/bswap/swap`` + * ``GET /sapi/v1/bswap/poolConfigure`` + * ``GET /sapi/v1/bswap/addLiquidityPreview`` + * ``GET /sapi/v1/bswap/removeLiquidityPreview`` + * ``GET /sapi/v1/bswap/unclaimedRewards`` + * ``POST /sapi/v1/bswap/claimRewards`` + * ``GET /sapi/v1/bswap/claimedHistory`` + +* Loan + + * ``POST /sapi/v1/loan/flexible/borrow`` + * ``GET /sapi/v1/loan/flexible/ongoing/orders`` + * ``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`` + +* Staking + + * ``GET /sapi/v1/staking/productList`` + * ``POST /sapi/v1/staking/purchase`` + * ``POST /sapi/v1/staking/redeem`` + * ``GET /sapi/v1/staking/position`` + * ``GET /sapi/v1/staking/stakingRecord`` + * ``POST /sapi/v1/staking/setAutoStaking`` + * ``GET /sapi/v1/staking/personalLeftQuota`` + 3.6.0 - 2024-03-07 ------------------ diff --git a/docs/source/binance.spot.bswap.rst b/docs/source/binance.spot.bswap.rst deleted file mode 100644 index 62a53640..00000000 --- a/docs/source/binance.spot.bswap.rst +++ /dev/null @@ -1,58 +0,0 @@ -Bswap Endpoints -=============== - -List All Swap Pools (MARKET_DATA) ---------------------------------- -.. autofunction:: binance.spot.Spot.bswap_pools - -Get liquidity information of a pool (USER_DATA) ------------------------------------------------ -.. autofunction:: binance.spot.Spot.bswap_liquidity - -Add Liquidity (TRADE) ---------------------- -.. autofunction:: binance.spot.Spot.bswap_liquidity_add - -Remove Liquidity (TRADE) ------------------------- -.. autofunction:: binance.spot.Spot.bswap_liquidity_remove - -Get Liquidity Operation Record (USER_DATA) ------------------------------------------- -.. autofunction:: binance.spot.Spot.bswap_liquidity_operation_record - -Request Quote (USER_DATA) -------------------------- -.. autofunction:: binance.spot.Spot.bswap_request_quote - -Swap (TRADE) ------------- -.. autofunction:: binance.spot.Spot.bswap_swap - -Get Swap History (USER_DATA) ----------------------------- -.. autofunction:: binance.spot.Spot.bswap_swap_history - -Get Pool Configure (USER_DATA) ------------------------------- -.. autofunction:: binance.spot.Spot.bswap_pool_configure - -Add Liquidity Preview (USER_DATA) ---------------------------------- -.. autofunction:: binance.spot.Spot.bswap_add_liquidity_preview - -Remove Liquidity Preview (USER_DATA) ------------------------------------- -.. autofunction:: binance.spot.Spot.bswap_remove_liquidity_preview - -Get Unclaimed Rewards Record (USER_DATA) ----------------------------------------- -.. autofunction:: binance.spot.Spot.bswap_unclaimed_rewards - -Claim rewards (TRADE) ---------------------- -.. autofunction:: binance.spot.Spot.bswap_claim_rewards - -Get Claimed History (USER_DATA) -------------------------------- -.. autofunction:: binance.spot.Spot.bswap_claimed_rewards diff --git a/docs/source/binance.spot.market.rst b/docs/source/binance.spot.market.rst index 4ff7a180..e214be53 100644 --- a/docs/source/binance.spot.market.rst +++ b/docs/source/binance.spot.market.rst @@ -45,6 +45,10 @@ Current Average Price ----------------------------------- .. autofunction:: binance.spot.Spot.ticker_24hr +Trading Day Ticker +------------------ +.. autofunction:: binance.spot.Spot.trading_day_ticker + Symbol Price Ticker ------------------- .. autofunction:: binance.spot.Spot.ticker_price diff --git a/docs/source/binance.spot.rst b/docs/source/binance.spot.rst index 6fe8b6c3..8974e223 100644 --- a/docs/source/binance.spot.rst +++ b/docs/source/binance.spot.rst @@ -5,7 +5,6 @@ Spot APIs :maxdepth: 2 binance.spot.blvt - binance.spot.bswap binance.spot.c2c binance.spot.convert binance.spot.data_stream @@ -20,7 +19,6 @@ Spot APIs binance.spot.pay binance.spot.portfolio_margin binance.spot.rebate - binance.spot.staking binance.spot.sub_account binance.spot.trade binance.spot.wallet diff --git a/docs/source/binance.spot.staking.rst b/docs/source/binance.spot.staking.rst deleted file mode 100644 index 18910b9f..00000000 --- a/docs/source/binance.spot.staking.rst +++ /dev/null @@ -1,30 +0,0 @@ -Staking Endpoints -================= - -Get Staking Product List (USER_DATA) ------------------------------------- -.. autofunction:: binance.spot.Spot.staking_product_list - -Purchase Staking Product (USER_DATA) ------------------------------------- -.. autofunction:: binance.spot.Spot.staking_purchase_product - -Redeem Staking Product (USER_DATA) ----------------------------------- -.. autofunction:: binance.spot.Spot.staking_redeem_product - -Get Staking Product Position (USER_DATA) ----------------------------------------- -.. autofunction:: binance.spot.Spot.staking_product_position - -Get Staking History (USER_DATA) -------------------------------- -.. autofunction:: binance.spot.Spot.staking_history - -Set Auto Staking (USER_DATA) ----------------------------- -.. autofunction:: binance.spot.Spot.staking_set_auto_staking - -Get Personal Left Quota of Staking Product (USER_DATA) ------------------------------------------------------- -.. autofunction:: binance.spot.Spot.staking_product_quota diff --git a/docs/source/binance.spot.trade.rst b/docs/source/binance.spot.trade.rst index df9bf6cc..8541bd7c 100644 --- a/docs/source/binance.spot.trade.rst +++ b/docs/source/binance.spot.trade.rst @@ -66,6 +66,14 @@ Query Current Order Count Usage (TRADE) --------------------------------------- .. autofunction:: binance.spot.Spot.get_order_rate_limit -Query Prevented Matches ------------------------ +Query Prevented Matches (USER_DATA) +----------------------------------- .. autofunction:: binance.spot.Spot.query_prevented_matches + +Query Cross-Collateral Information (USER_DATA) +---------------------------------------------- +.. autofunction:: binance.spot.Spot.query_allocations + +Query Commission Rates (USER_DATA) +---------------------------------- +.. autofunction:: binance.spot.Spot.query_commission_rates diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index f2ee07f3..fd123514 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -115,24 +115,24 @@ Usage example: .. code-block:: python - from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient + import logging + from binance.websocket.spot.websocket_api import SpotWebsocketAPIClient def message_handler(message): print(message) - ws_client = WebsocketClient() - ws_client.start() + ws_client = SpotWebsocketAPIClient(on_message=message_handler, on_close=on_close) - ws_client.mini_ticker( + ws_client.ticker( symbol='bnbusdt', - id=1, - callback=message_handler, + type="FULL", ) # Combine selected streams - ws_client.instant_subscribe( - stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'], - callback=message_handler, + ws_client.ticker( + symbols=["BNBBUSD", "BTCUSDT"], + type="MINI", + windowSize="2h", ) ws_client.stop() @@ -173,9 +173,9 @@ WebSocket .. code-block:: python - from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient + from binance.websocket.spot.websocket_api import SpotWebsocketAPIClient - ws_client = WebsocketClient(stream_url='wss://testnet.binance.vision') + ws_client = SpotWebsocketAPIClient(stream_url='wss://testnet.binance.vision') Errors ------ diff --git a/docs/source/intro.rst b/docs/source/intro.rst index cb9cde37..cd4cb34f 100644 --- a/docs/source/intro.rst +++ b/docs/source/intro.rst @@ -89,15 +89,19 @@ RESTful APIs .. code-block:: python + import logging from binance.spot import Spot + from binance.lib.utils import config_logging + + config_logging(logging, logging.DEBUG) client = Spot() - print(client.time()) + logging.info(client.time()) client = Spot(api_key='', api_secret='') # Get account information - print(client.account()) + logging.info(client.account()) # Post a new order params = { @@ -110,7 +114,7 @@ RESTful APIs } response = client.new_order(**params) - print(response) + logging.info(response) Please find `examples `_ folder to check for more endpoints. @@ -120,24 +124,27 @@ Websocket .. code-block:: python - from binance.websocket.spot.websocket_client import SpotWebsocketClient as WebsocketClient + import logging + from binance.websocket.spot.websocket_api import SpotWebsocketAPIClient + + def on_close(_): + logging.info("Do custom stuff when connection is closed") def message_handler(message): print(message) - ws_client = WebsocketClient() - ws_client.start() + ws_client = SpotWebsocketAPIClient(on_message=message_handler, on_close=on_close) - ws_client.mini_ticker( + ws_client.ticker( symbol='bnbusdt', - id=1, - callback=message_handler, + type="FULL", ) # Combine selected streams - ws_client.instant_subscribe( - stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'], - callback=message_handler, + ws_client.ticker( + symbols=["BNBBUSD", "BTCUSDT"], + type="MINI", + windowSize="2h", ) ws_client.stop() diff --git a/examples/spot/bswap/bswap_add_liquidity_preview.py b/examples/spot/bswap/bswap_add_liquidity_preview.py deleted file mode 100644 index a3fb23b3..00000000 --- a/examples/spot/bswap/bswap_add_liquidity_preview.py +++ /dev/null @@ -1,17 +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.bswap_add_liquidity_preview( - poolId=2, type="SINGLE", quoteAsset="USDT", quoteQty=0.01 - ) -) diff --git a/examples/spot/bswap/bswap_claim_rewards.py b/examples/spot/bswap/bswap_claim_rewards.py deleted file mode 100644 index b3a157b6..00000000 --- a/examples/spot/bswap/bswap_claim_rewards.py +++ /dev/null @@ -1,14 +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.bswap_claim_rewards(type=0)) diff --git a/examples/spot/bswap/bswap_claimed_rewards.py b/examples/spot/bswap/bswap_claimed_rewards.py deleted file mode 100644 index 1f823d8e..00000000 --- a/examples/spot/bswap/bswap_claimed_rewards.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.bswap_claimed_rewards(type=0, assetRewards="BNB")) diff --git a/examples/spot/bswap/bswap_liquidity.py b/examples/spot/bswap/bswap_liquidity.py deleted file mode 100644 index 24feefba..00000000 --- a/examples/spot/bswap/bswap_liquidity.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.bswap_liquidity()) diff --git a/examples/spot/bswap/bswap_liquidity_add.py b/examples/spot/bswap/bswap_liquidity_add.py deleted file mode 100644 index 8edc65c7..00000000 --- a/examples/spot/bswap/bswap_liquidity_add.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.bswap_liquidity_add("2", "BUSD", "1")) diff --git a/examples/spot/bswap/bswap_liquidity_operation_record.py b/examples/spot/bswap/bswap_liquidity_operation_record.py deleted file mode 100644 index fa95adeb..00000000 --- a/examples/spot/bswap/bswap_liquidity_operation_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.bswap_liquidity_operation_record()) diff --git a/examples/spot/bswap/bswap_pool_configure.py b/examples/spot/bswap/bswap_pool_configure.py deleted file mode 100644 index c3e2301d..00000000 --- a/examples/spot/bswap/bswap_pool_configure.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.bswap_pool_configure(poolId=2)) diff --git a/examples/spot/bswap/bswap_pools.py b/examples/spot/bswap/bswap_pools.py deleted file mode 100644 index 30b214b2..00000000 --- a/examples/spot/bswap/bswap_pools.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.bswap_pools()) diff --git a/examples/spot/bswap/bswap_remove_liquidity.py b/examples/spot/bswap/bswap_remove_liquidity.py deleted file mode 100644 index 95a0ffcb..00000000 --- a/examples/spot/bswap/bswap_remove_liquidity.py +++ /dev/null @@ -1,17 +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.bswap_liquidity_remove("2", "SINGLE", ["BUSD"], "12415")) -logging.info( - client.bswap_liquidity_remove("2", "COMBINATION", ["BUSD", "USDT"], "12415") -) diff --git a/examples/spot/bswap/bswap_remove_liquidity_preview.py b/examples/spot/bswap/bswap_remove_liquidity_preview.py deleted file mode 100644 index 67d8160c..00000000 --- a/examples/spot/bswap/bswap_remove_liquidity_preview.py +++ /dev/null @@ -1,17 +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.bswap_remove_liquidity_preview( - poolId=2, type="SINGLE", quoteAsset="USDT", shareAmount=0.01 - ) -) diff --git a/examples/spot/bswap/bswap_request_quote.py b/examples/spot/bswap/bswap_request_quote.py deleted file mode 100644 index 8dc1c9f4..00000000 --- a/examples/spot/bswap/bswap_request_quote.py +++ /dev/null @@ -1,14 +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.bswap_request_quote("USDT", "BUSD", "30000")) diff --git a/examples/spot/bswap/bswap_swap.py b/examples/spot/bswap/bswap_swap.py deleted file mode 100644 index 9455de9f..00000000 --- a/examples/spot/bswap/bswap_swap.py +++ /dev/null @@ -1,14 +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.bswap_swap("USDT", "BUSD", "30000")) diff --git a/examples/spot/bswap/bswap_swap_history.py b/examples/spot/bswap/bswap_swap_history.py deleted file mode 100644 index 720e67a8..00000000 --- a/examples/spot/bswap/bswap_swap_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.bswap_swap_history()) diff --git a/examples/spot/bswap/bswap_unclaimed_rewards.py b/examples/spot/bswap/bswap_unclaimed_rewards.py deleted file mode 100644 index 203c63a3..00000000 --- a/examples/spot/bswap/bswap_unclaimed_rewards.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.bswap_unclaimed_rewards(type=0)) diff --git a/examples/spot/loan/flexible_loan_repay.py b/examples/spot/convert/cancel_limit_order.py similarity index 88% rename from examples/spot/loan/flexible_loan_repay.py rename to examples/spot/convert/cancel_limit_order.py index 9c9e8f38..802c7c80 100644 --- a/examples/spot/loan/flexible_loan_repay.py +++ b/examples/spot/convert/cancel_limit_order.py @@ -15,7 +15,7 @@ client = Client(api_key, api_secret) try: - response = client.flexible_loan_repay("BTC", "USDT", 1.01, recvWindow=5000) + response = client.cancel_limit_order(orderId=1) logger.info(response) except ClientError as error: logger.error( diff --git a/examples/spot/loan/flexible_loan_borrow.py b/examples/spot/convert/place_limit_order.py similarity index 75% rename from examples/spot/loan/flexible_loan_borrow.py rename to examples/spot/convert/place_limit_order.py index 78ddea90..85465340 100644 --- a/examples/spot/loan/flexible_loan_borrow.py +++ b/examples/spot/convert/place_limit_order.py @@ -15,11 +15,13 @@ client = Client(api_key, api_secret) try: - response = client.flexible_loan_borrow( - loanCoin="BUSD", - loanAmount=100.1, - collateralCoin="BNB", - recvWindow=5000, + response = client.place_limit_order( + baseAsset="BNB", + quoteAsset="USDT", + limitPrice=0.0001, + side="BUY", + expiredType="1_D", + baseAmount=0.0001, ) logger.info(response) except ClientError as error: diff --git a/examples/spot/loan/flexible_loan_assets_data.py b/examples/spot/convert/query_limit_open_order.py similarity index 88% rename from examples/spot/loan/flexible_loan_assets_data.py rename to examples/spot/convert/query_limit_open_order.py index 96c4a77f..edc21990 100644 --- a/examples/spot/loan/flexible_loan_assets_data.py +++ b/examples/spot/convert/query_limit_open_order.py @@ -15,7 +15,7 @@ client = Client(api_key, api_secret) try: - response = client.flexible_loan_assets_data(loanCoin="BUSD", recvWindow=5000) + response = client.query_limit_open_order() logger.info(response) except ClientError as error: logger.error( diff --git a/examples/spot/loan/flexible_loan_borrow_history.py b/examples/spot/loan/flexible_loan_borrow_history.py deleted file mode 100644 index c5a704c0..00000000 --- a/examples/spot/loan/flexible_loan_borrow_history.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError - -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) -logger = logging.getLogger(__name__) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.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_ltv_adjustment_history.py b/examples/spot/loan/flexible_loan_ltv_adjustment_history.py deleted file mode 100644 index 27f17d52..00000000 --- a/examples/spot/loan/flexible_loan_ltv_adjustment_history.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError - -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) -logger = logging.getLogger(__name__) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.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 deleted file mode 100644 index 91ce2654..00000000 --- a/examples/spot/loan/flexible_loan_ongoing_orders.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError - -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) -logger = logging.getLogger(__name__) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.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_repayment_history.py b/examples/spot/loan/flexible_loan_repayment_history.py deleted file mode 100644 index a1fda393..00000000 --- a/examples/spot/loan/flexible_loan_repayment_history.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError - -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) -logger = logging.getLogger(__name__) - -api_key, api_secret = get_api_key() - -client = Client(api_key, api_secret) - -try: - response = client.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/loan/flexible_loan_collateral_assets_data.py b/examples/spot/margin/liability_coin_leverage_bracket.py similarity index 84% rename from examples/spot/loan/flexible_loan_collateral_assets_data.py rename to examples/spot/margin/liability_coin_leverage_bracket.py index e8f1d8f1..d433611d 100644 --- a/examples/spot/loan/flexible_loan_collateral_assets_data.py +++ b/examples/spot/margin/liability_coin_leverage_bracket.py @@ -15,9 +15,7 @@ client = Client(api_key, api_secret) try: - response = client.flexible_loan_collateral_assets_data( - collateralCoin="BNB", recvWindow=5000 - ) + response = client.liability_coin_leverage_bracket() logger.info(response) except ClientError as error: logger.error( diff --git a/examples/spot/loan/flexible_loan_adjust_ltv.py b/examples/spot/margin/margin_available_inventory.py similarity index 84% rename from examples/spot/loan/flexible_loan_adjust_ltv.py rename to examples/spot/margin/margin_available_inventory.py index a4a01ec6..de39be57 100644 --- a/examples/spot/loan/flexible_loan_adjust_ltv.py +++ b/examples/spot/margin/margin_available_inventory.py @@ -15,9 +15,7 @@ client = Client(api_key, api_secret) try: - response = client.flexible_loan_adjust_ltv( - "BTC", "USDT", 1.01, "ADDITIONAL", recvWindow=5000 - ) + response = client.margin_available_inventory(type="MARGIN") logger.info(response) except ClientError as error: logger.error( diff --git a/examples/spot/margin/margin_manual_liquidation.py b/examples/spot/margin/margin_manual_liquidation.py new file mode 100644 index 00000000..72ad4cde --- /dev/null +++ b/examples/spot/margin/margin_manual_liquidation.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.margin_manual_liquidation(type="MARGIN") + 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/market/trading_day_ticker.py b/examples/spot/market/trading_day_ticker.py new file mode 100644 index 00000000..0d38ea1f --- /dev/null +++ b/examples/spot/market/trading_day_ticker.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.trading_day_ticker(symbol="BNBUSDT") + 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/staking/staking_history.py b/examples/spot/staking/staking_history.py deleted file mode 100644 index 8fb6a6d7..00000000 --- a/examples/spot/staking/staking_history.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING", "txnType": "SUBSCRIPTION"} - -client = Client(api_key, api_secret) - -try: - response = client.staking_history(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/staking/staking_product_list.py b/examples/spot/staking/staking_product_list.py deleted file mode 100644 index 715e5186..00000000 --- a/examples/spot/staking/staking_product_list.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING"} - -client = Client(api_key, api_secret) - -try: - response = client.staking_product_list(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/staking/staking_product_position.py b/examples/spot/staking/staking_product_position.py deleted file mode 100644 index 5a4750df..00000000 --- a/examples/spot/staking/staking_product_position.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING"} - -client = Client(api_key, api_secret) - -try: - response = client.staking_product_position(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/staking/staking_product_quota.py b/examples/spot/staking/staking_product_quota.py deleted file mode 100644 index 3199b6b1..00000000 --- a/examples/spot/staking/staking_product_quota.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING", "productId": "Axs*90"} - -client = Client(api_key, api_secret) - -try: - response = client.staking_product_quota(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/staking/staking_purchase_product.py b/examples/spot/staking/staking_purchase_product.py deleted file mode 100644 index 248136a9..00000000 --- a/examples/spot/staking/staking_purchase_product.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING", "productId": "Axs*90", "amount": 10.1} - -client = Client(api_key, api_secret) - -try: - response = client.staking_purchase_product(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/staking/staking_redeem_product.py b/examples/spot/staking/staking_redeem_product.py deleted file mode 100644 index fbaf2d24..00000000 --- a/examples/spot/staking/staking_redeem_product.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING", "productId": "Axs*90"} - -client = Client(api_key, api_secret) - -try: - response = client.staking_redeem_product(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/staking/staking_set_auto_staking.py b/examples/spot/staking/staking_set_auto_staking.py deleted file mode 100644 index f0f80fb1..00000000 --- a/examples/spot/staking/staking_set_auto_staking.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -import logging -from binance.spot import Spot as Client -from binance.lib.utils import config_logging -from binance.error import ClientError -from examples.utils.prepare_env import get_api_key - -config_logging(logging, logging.DEBUG) - -api_key, api_secret = get_api_key() - -params = {"product": "STAKING", "positionId": "1234", "renewable": "true"} - -client = Client(api_key, api_secret) - -try: - response = client.staking_set_auto_staking(**params) - logging.info(response) -except ClientError as error: - logging.error( - "Found error. status: {}, error code: {}, error message: {}".format( - error.status_code, error.error_code, error.error_message - ) - ) diff --git a/examples/spot/trade/query_allocations.py b/examples/spot/trade/query_allocations.py new file mode 100644 index 00000000..1d1f3b1c --- /dev/null +++ b/examples/spot/trade/query_allocations.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_allocations(symbol="BNBUSDT") + 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_commission_rates.py b/examples/spot/trade/query_commission_rates.py new file mode 100644 index 00000000..372ed313 --- /dev/null +++ b/examples/spot/trade/query_commission_rates.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_commission_rates(symbol="BNBUSDT") + 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/delist_schedule_symbols.py b/examples/spot/wallet/delist_schedule_symbols.py new file mode 100644 index 00000000..b4339b01 --- /dev/null +++ b/examples/spot/wallet/delist_schedule_symbols.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.delist_schedule_symbols() + 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/list_deposit_address.py b/examples/spot/wallet/list_deposit_address.py new file mode 100644 index 00000000..813852cb --- /dev/null +++ b/examples/spot/wallet/list_deposit_address.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.list_deposit_address(coin="BNB") + 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/tests/spot/bswap/test_bswap_add_liquidity_preview.py b/tests/spot/bswap/test_bswap_add_liquidity_preview.py deleted file mode 100644 index 6cf251e8..00000000 --- a/tests/spot/bswap/test_bswap_add_liquidity_preview.py +++ /dev/null @@ -1,52 +0,0 @@ -import responses -import pytest - -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str -from binance.error import ParameterRequiredError -from binance.lib.utils import encoded_string - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -key = random_str() -secret = random_str() - -complete_params = { - "poolId": 2, - "type": "SINGLE", - "quoteAsset": "USDT", - "quoteQty": 0.01, -} - -parameterized_test_params = [ - ({"poolId": None, "type": None, "quoteAsset": None, "quoteQty": None}), - ({"poolId": "", "type": "SINGLE", "quoteAsset": "USDT", "quoteQty": 0.01}), - ({"poolId": 2, "type": "", "quoteAsset": "USDT", "quoteQty": 0.01}), - ({"poolId": 2, "type": "SINGLE", "quoteAsset": "", "quoteQty": 0.01}), - ({"poolId": 2, "type": "SINGLE", "quoteAsset": "USDT", "quoteQty": ""}), -] - -client = Client(key, secret) - - -@pytest.mark.parametrize("params", parameterized_test_params) -def test_bswap_add_liquidity_preview_with_missing_param(params): - """Tests the API endpoint to get add liquidity preview with missing param""" - - client.bswap_add_liquidity_preview.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/bswap/addLiquidityPreview\\?" + encoded_string(complete_params), - mock_item, - 200, -) -def test_bswap_add_liquidity_preview(): - """Tests the API endpoint to get add liquidity preview""" - - response = client.bswap_add_liquidity_preview(**complete_params) - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_claim_rewards.py b/tests/spot/bswap/test_bswap_claim_rewards.py deleted file mode 100644 index c4157f2d..00000000 --- a/tests/spot/bswap/test_bswap_claim_rewards.py +++ /dev/null @@ -1,17 +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() -client = Client(key, secret) - - -@mock_http_response(responses.POST, "/sapi/v1/bswap/claimRewards", mock_item, 200) -def test_bswap_claim_rewards(): - """Tests the API endpoint to get liquidity information and user share of a pool""" - - response = client.bswap_claim_rewards() - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_claimed_rewards.py b/tests/spot/bswap/test_bswap_claimed_rewards.py deleted file mode 100644 index b0bdf904..00000000 --- a/tests/spot/bswap/test_bswap_claimed_rewards.py +++ /dev/null @@ -1,17 +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/bswap/claimedHistory", mock_item, 200) -def test_bswap_claimed_rewards(): - """Tests the API endpoint to get history of claimed rewards""" - - client = Client(key, secret) - response = client.bswap_claimed_rewards() - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_liquidity.py b/tests/spot/bswap/test_bswap_liquidity.py deleted file mode 100644 index 7dbdb72b..00000000 --- a/tests/spot/bswap/test_bswap_liquidity.py +++ /dev/null @@ -1,17 +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/bswap/liquidity", mock_item, 200) -def test_bswap_liquidity(): - """Tests the API endpoint to get liquidity information and user share of a pool""" - - client = Client(key, secret) - response = client.bswap_liquidity() - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_liquidity_add.py b/tests/spot/bswap/test_bswap_liquidity_add.py deleted file mode 100644 index 55bab0be..00000000 --- a/tests/spot/bswap/test_bswap_liquidity_add.py +++ /dev/null @@ -1,50 +0,0 @@ -import responses -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str -from binance.error import ParameterRequiredError - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -key = random_str() -secret = random_str() - - -def test_bswap_liquidity_add_without_poolId(): - """Tests the API endpoint to add liquidity to a pool without poolId.""" - - client = Client(key, secret) - client.bswap_liquidity_add.when.called_with("", "BUSD", "1").should.throw( - ParameterRequiredError - ) - - -def test_bswap_liquidity_add_without_asset(): - """Tests the API endpoint to add liquidity to a pool without asset.""" - - client = Client(key, secret) - client.bswap_liquidity_add.when.called_with("2", "", "1").should.throw( - ParameterRequiredError - ) - - -def test_bswap_liquidity_add_without_quantity(): - """Tests the API endpoint to add liquidity to a pool without quantity.""" - - client = Client(key, secret) - client.bswap_liquidity_add.when.called_with("2", "BUSD", "").should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, - "/sapi/v1/bswap/liquidityAdd\\?poolId=2&asset=BUSD&quantity=1", - mock_item, - 200, -) -def test_subscribe_blvt(): - """Tests the API endpoint to add liquidity to a pool.""" - - client = Client(key, secret) - response = client.bswap_liquidity_add("2", "BUSD", "1") - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_liquidity_operation_record.py b/tests/spot/bswap/test_bswap_liquidity_operation_record.py deleted file mode 100644 index 7c1793a5..00000000 --- a/tests/spot/bswap/test_bswap_liquidity_operation_record.py +++ /dev/null @@ -1,17 +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/bswap/liquidityOps", mock_item, 200) -def test_bswap_liquidity(): - """Tests the API endpoint to get liquidity operation (add/remove) records.""" - - client = Client(key, secret) - response = client.bswap_liquidity_operation_record() - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_pool_configure.py b/tests/spot/bswap/test_bswap_pool_configure.py deleted file mode 100644 index a8be0bdf..00000000 --- a/tests/spot/bswap/test_bswap_pool_configure.py +++ /dev/null @@ -1,28 +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/bswap/poolConfigure", mock_item, 200) -def test_bswap_pool_configure(): - """Tests the API endpoint to get pool configure""" - - client = Client(key, secret) - response = client.bswap_pool_configure() - response.should.equal(mock_item) - - -@mock_http_response( - responses.GET, "sapi/v1/bswap/poolConfigure\\?poolId=2", mock_item, 200 -) -def test_bswap_pool_configure_with_poolId(): - """Tests the API endpoint to get pool configure with poolId""" - - client = Client(key, secret) - response = client.bswap_pool_configure(poolId=2) - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_pools.py b/tests/spot/bswap/test_bswap_pools.py deleted file mode 100644 index 4efa294e..00000000 --- a/tests/spot/bswap/test_bswap_pools.py +++ /dev/null @@ -1,17 +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/bswap/pools", mock_item, 200) -def test_bswap_pools(): - """Tests the API endpoint to list All Swap Pools""" - - client = Client(key, secret) - response = client.bswap_pools() - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_remove_liquidity.py b/tests/spot/bswap/test_bswap_remove_liquidity.py deleted file mode 100644 index d8ac6de7..00000000 --- a/tests/spot/bswap/test_bswap_remove_liquidity.py +++ /dev/null @@ -1,60 +0,0 @@ -import responses -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str -from binance.error import ParameterRequiredError - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -key = random_str() -secret = random_str() - - -def test_bswap_liquidity_remove_without_poolId(): - """Tests the API endpoint to remove liquidity from a pool without poolId.""" - - client = Client(key, secret) - client.bswap_liquidity_remove.when.called_with( - "", "SINGLE", ["BUSD"], "12415" - ).should.throw(ParameterRequiredError) - - -def test_bswap_liquidity_remove_without_type(): - """Tests the API endpoint to remove liquidity from a pool without type.""" - - client = Client(key, secret) - client.bswap_liquidity_remove.when.called_with( - "2", "", ["BUSD"], "12415" - ).should.throw(ParameterRequiredError) - - -def test_bswap_liquidity_remove_without_asset(): - """Tests the API endpoint to remove liquidity from a pool without asset .""" - - client = Client(key, secret) - client.bswap_liquidity_remove.when.called_with( - "2", "SINGLE", None, "12415" - ).should.throw(ParameterRequiredError) - - -def test_bswap_liquidity_remove_without_shareAmount(): - """Tests the API endpoint to remove liquidity from a pool without shareAmount.""" - - client = Client(key, secret) - client.bswap_liquidity_remove.when.called_with( - "2", "SINGLE", ["BUSD"], "" - ).should.throw(ParameterRequiredError) - - -@mock_http_response( - responses.POST, - "/sapi/v1/bswap/liquidityRemove\\?poolId=2&type=SINGLE&asset=BUSD&shareAmount=12415", - mock_item, - 200, -) -def test_bswap_liquidity_remove(): - """Tests the API endpoint to remove liquidity from a pool""" - - client = Client(key, secret) - response = client.bswap_liquidity_remove("2", "SINGLE", ["BUSD"], "12415") - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_remove_liquidity_preview.py b/tests/spot/bswap/test_bswap_remove_liquidity_preview.py deleted file mode 100644 index 0c78ae0d..00000000 --- a/tests/spot/bswap/test_bswap_remove_liquidity_preview.py +++ /dev/null @@ -1,52 +0,0 @@ -import responses -import pytest - -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str -from binance.error import ParameterRequiredError -from binance.lib.utils import encoded_string - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -key = random_str() -secret = random_str() - -complete_params = { - "poolId": 2, - "type": "SINGLE", - "quoteAsset": "USDT", - "shareAmount": 0.01, -} - -parameterized_test_params = [ - ({"poolId": None, "type": None, "quoteAsset": None, "shareAmount": None}), - ({"poolId": "", "type": "SINGLE", "quoteAsset": "USDT", "shareAmount": 0.01}), - ({"poolId": 2, "type": "", "quoteAsset": "USDT", "shareAmount": 0.01}), - ({"poolId": 2, "type": "SINGLE", "quoteAsset": "", "shareAmount": 0.01}), - ({"poolId": 2, "type": "SINGLE", "quoteAsset": "USDT", "shareAmount": ""}), -] - -client = Client(key, secret) - - -@pytest.mark.parametrize("params", parameterized_test_params) -def test_bswap_remove_liquidity_preview_with_missing_param(params): - """Tests the API endpoint to get remove liquidity preview with missing param""" - - client.bswap_remove_liquidity_preview.when.called_with(**params).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/bswap/removeLiquidityPreview\\?" + encoded_string(complete_params), - mock_item, - 200, -) -def test_bswap_remove_liquidity_preview(): - """Tests the API endpoint to get remove liquidity preview""" - - response = client.bswap_remove_liquidity_preview(**complete_params) - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_request_quote.py b/tests/spot/bswap/test_bswap_request_quote.py deleted file mode 100644 index 215db4eb..00000000 --- a/tests/spot/bswap/test_bswap_request_quote.py +++ /dev/null @@ -1,55 +0,0 @@ -import responses -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str -from binance.error import ParameterRequiredError - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -key = random_str() -secret = random_str() - - -def test_bswap_request_quote_without_quoteAsset(): - """Tests the API endpoint to Request a quote for swap quote asset (selling asset) for base asset (buying asset), - essentially price/exchange rates without quoteAsset""" - - client = Client(key, secret) - client.bswap_request_quote.when.called_with("", "BUSD", "30000").should.throw( - ParameterRequiredError - ) - - -def test_bswap_request_quote_without_baseAsset(): - """Tests the API endpoint to Request a quote for swap quote asset (selling asset) for base asset (buying asset), - essentially price/exchange rates without baseAsset""" - - client = Client(key, secret) - client.bswap_request_quote.when.called_with("USDT", "", "30000").should.throw( - ParameterRequiredError - ) - - -def test_bswap_request_quote_without_quoteQty(): - """Tests the API endpoint to Request a quote for swap quote asset (selling asset) for base asset (buying asset), - essentially price/exchange rates without quoteQty""" - - client = Client(key, secret) - client.bswap_request_quote.when.called_with("USDT", "BUSD", None).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.GET, - "/sapi/v1/bswap/quote\\?quoteAsset=USDT&baseAsset=BUSD"eQty=30000", - mock_item, - 200, -) -def test_bswap_liquidity_remove(): - """Tests the API endpoint to Request a quote for swap quote asset (selling asset) for base asset (buying asset), - essentially price/exchange rates""" - - client = Client(key, secret) - response = client.bswap_request_quote("USDT", "BUSD", "30000") - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_swap.py b/tests/spot/bswap/test_bswap_swap.py deleted file mode 100644 index 24a4b142..00000000 --- a/tests/spot/bswap/test_bswap_swap.py +++ /dev/null @@ -1,51 +0,0 @@ -import responses -from binance.spot import Spot as Client -from tests.util import mock_http_response -from tests.util import random_str -from binance.error import ParameterRequiredError - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -key = random_str() -secret = random_str() - - -def test_bswap_swap_without_quoteAsset(): - """Swap quoteAsset for baseAsset without quoteAsset""" - - client = Client(key, secret) - client.bswap_swap.when.called_with("", "BUSD", "30000").should.throw( - ParameterRequiredError - ) - - -def test_bswap_swap_without_baseAsset(): - """Swap quoteAsset for baseAsset without baseAsset""" - - client = Client(key, secret) - client.bswap_swap.when.called_with("USDT", "", "30000").should.throw( - ParameterRequiredError - ) - - -def test_bswap_swap_without_quoteQty(): - """Swap quoteAsset for baseAsset without quoteQty""" - - client = Client(key, secret) - client.bswap_swap.when.called_with("USDT", "BUSD", None).should.throw( - ParameterRequiredError - ) - - -@mock_http_response( - responses.POST, - "/sapi/v1/bswap/swap\\?quoteAsset=USDT&baseAsset=BUSD"eQty=30000", - mock_item, - 200, -) -def test_bswap_swap(): - """Swap quoteAsset for baseAsset.""" - - client = Client(key, secret) - response = client.bswap_swap("USDT", "BUSD", "30000") - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_swap_history.py b/tests/spot/bswap/test_bswap_swap_history.py deleted file mode 100644 index 27793e6e..00000000 --- a/tests/spot/bswap/test_bswap_swap_history.py +++ /dev/null @@ -1,17 +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/bswap/swap", mock_item, 200) -def test_bswap_swap_history(): - """Tests the API endpoint to get swap history.""" - - client = Client(key, secret) - response = client.bswap_swap_history() - response.should.equal(mock_item) diff --git a/tests/spot/bswap/test_bswap_unclaimed_rewards.py b/tests/spot/bswap/test_bswap_unclaimed_rewards.py deleted file mode 100644 index 48db74c1..00000000 --- a/tests/spot/bswap/test_bswap_unclaimed_rewards.py +++ /dev/null @@ -1,17 +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() -client = Client(key, secret) - - -@mock_http_response(responses.GET, "/sapi/v1/bswap/unclaimedRewards", mock_item, 200) -def test_bswap_unclaimed_rewards(): - """Tests the API endpoint to get unclaimed rewards record.""" - - response = client.bswap_unclaimed_rewards() - response.should.equal(mock_item) diff --git a/tests/spot/staking/test_staking_redeem_product.py b/tests/spot/convert/test_cancel_limit_order.py similarity index 56% rename from tests/spot/staking/test_staking_redeem_product.py rename to tests/spot/convert/test_cancel_limit_order.py index eed19a5b..731b5530 100644 --- a/tests/spot/staking/test_staking_redeem_product.py +++ b/tests/spot/convert/test_cancel_limit_order.py @@ -5,28 +5,26 @@ 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 = { - "product": "STAKING", - "productId": "Axs*90", - "recvWindow": 5000, -} +send_params = {"orderId": 1603680255057330400, "recvWindow": 5000} +expected_params = {"orderId": 1603680255057330400, "recvWindow": 5000} @mock_http_response( responses.POST, - "/sapi/v1/staking/redeem\\?" + urlencode(params), + "/sapi/v1/convert/limit/cancelOrder\\?" + urlencode(expected_params), mock_item, 200, ) -def test_staking_redeem_product(): - """Tests the API endpoint to staking redeem product""" +def test_cancel_limit_order(): + """Tests the API endpoint to cancel a limit order""" client = Client(key, secret) - response = client.staking_redeem_product(**params) + response = client.cancel_limit_order(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_borrow.py b/tests/spot/convert/test_place_limit_order.py similarity index 52% rename from tests/spot/loan/test_flexible_loan_borrow.py rename to tests/spot/convert/test_place_limit_order.py index 37cad1ef..ac91b36b 100644 --- a/tests/spot/loan/test_flexible_loan_borrow.py +++ b/tests/spot/convert/test_place_limit_order.py @@ -13,28 +13,30 @@ secret = random_str() send_params = { - "loanCoin": "BUSD", - "collateralCoin": "BNB", - "loanAmount": 100.1, - "recvWindow": 5000, + "baseAsset": "BNB", + "quoteAsset": "BTC", + "limitPrice": 1.0, + "side": "BUY", + "expiredType": "1_D", } expected_params = { - "loanCoin": "BUSD", - "collateralCoin": "BNB", - "loanAmount": 100.1, - "recvWindow": 5000, + "baseAsset": "BNB", + "quoteAsset": "BTC", + "limitPrice": 1.0, + "side": "BUY", + "expiredType": "1_D", } @mock_http_response( responses.POST, - "/sapi/v1/loan/flexible/borrow\\?" + urlencode(expected_params), + "/sapi/v1/convert/limit/placeOrder\\?" + urlencode(expected_params), mock_item, 200, ) -def test_flexible_loan_borrow(): - """Tests the API endpoint to borrow - flexible loan borrow""" +def test_place_limit_order(): + """Tests the API endpoint to place a limit order""" client = Client(key, secret) - response = client.flexible_loan_borrow(**send_params) + response = client.place_limit_order(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/staking/test_staking_product_quota.py b/tests/spot/convert/test_query_limit_open_order.py similarity index 60% rename from tests/spot/staking/test_staking_product_quota.py rename to tests/spot/convert/test_query_limit_open_order.py index 05b6a797..d31b721f 100644 --- a/tests/spot/staking/test_staking_product_quota.py +++ b/tests/spot/convert/test_query_limit_open_order.py @@ -5,27 +5,26 @@ 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 = { - "product": "STAKING", - "productId": "Axs*90", -} +send_params = {"recvWindow": 5000} +expected_params = {"recvWindow": 5000} @mock_http_response( responses.GET, - "/sapi/v1/staking/personalLeftQuota\\?" + urlencode(params), + "/sapi/v1/convert/limit/queryOpenOrders\\?" + urlencode(expected_params), mock_item, 200, ) -def test_staking_product_quota(): - """Tests the API endpoint to staking product quota""" +def test_query_limit_open_order(): + """Tests the API endpoint to get limit open order""" client = Client(key, secret) - response = client.staking_product_quota(**params) + response = client.query_limit_open_order(**send_params) 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 deleted file mode 100644 index 2c2a92d3..00000000 --- a/tests/spot/loan/test_flexible_loan_adjust_ltv.py +++ /dev/null @@ -1,35 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = { - "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 deleted file mode 100644 index 67d9b2bc..00000000 --- a/tests/spot/loan/test_flexible_loan_assets_data.py +++ /dev/null @@ -1,30 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = {"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_history.py b/tests/spot/loan/test_flexible_loan_borrow_history.py deleted file mode 100644 index e6222457..00000000 --- a/tests/spot/loan/test_flexible_loan_borrow_history.py +++ /dev/null @@ -1,42 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = { - "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 deleted file mode 100644 index 955eb309..00000000 --- a/tests/spot/loan/test_flexible_loan_collateral_assets_data.py +++ /dev/null @@ -1,30 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = {"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 deleted file mode 100644 index 8eaab7a4..00000000 --- a/tests/spot/loan/test_flexible_loan_ltv_adjustment_history.py +++ /dev/null @@ -1,42 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = { - "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_repayment_history.py b/tests/spot/loan/test_flexible_loan_repayment_history.py deleted file mode 100644 index 2eeb9797..00000000 --- a/tests/spot/loan/test_flexible_loan_repayment_history.py +++ /dev/null @@ -1,42 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -send_params = { - "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/staking/test_staking_product_list.py b/tests/spot/margin/test_liability_coin_leverage_bracket.py similarity index 57% rename from tests/spot/staking/test_staking_product_list.py rename to tests/spot/margin/test_liability_coin_leverage_bracket.py index b5a4c59a..f7085816 100644 --- a/tests/spot/staking/test_staking_product_list.py +++ b/tests/spot/margin/test_liability_coin_leverage_bracket.py @@ -5,27 +5,26 @@ 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 = { - "product": "STAKING", - "recvWindow": 5000, -} +send_params = {"recvWindow": 5000} +expected_params = {"recvWindow": 5000} @mock_http_response( responses.GET, - "/sapi/v1/staking/productList\\?" + urlencode(params), + "/sapi/v1/margin/leverageBracket\\?" + urlencode(expected_params), mock_item, 200, ) -def test_staking_product_list(): - """Tests the API endpoint to staking product list""" +def test_liability_coin_leverage_bracket(): + """Tests the API endpoint to retrieve liability coin leverage bracket""" client = Client(key, secret) - response = client.staking_product_list(**params) + response = client.liability_coin_leverage_bracket(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/margin/test_margin_available_inventory.py b/tests/spot/margin/test_margin_available_inventory.py new file mode 100644 index 00000000..5db19016 --- /dev/null +++ b/tests/spot/margin/test_margin_available_inventory.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 = {"type": "MARGIN", "recvWindow": 5000} +expected_params = {"type": "MARGIN", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/sapi/v1/margin/available-inventory\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_margin_available_inventory(): + """Tests the API endpoint to margin available inventory""" + + client = Client(key, secret) + response = client.margin_available_inventory(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_repay.py b/tests/spot/margin/test_margin_manual_liquidation.py similarity index 57% rename from tests/spot/loan/test_flexible_loan_repay.py rename to tests/spot/margin/test_margin_manual_liquidation.py index 8c6ba0cd..9b45ab24 100644 --- a/tests/spot/loan/test_flexible_loan_repay.py +++ b/tests/spot/margin/test_margin_manual_liquidation.py @@ -12,18 +12,19 @@ key = random_str() secret = random_str() -send_params = {"repayAmount": 100, "collateralCoin": "USDT", "loanCoin": "BTC"} +send_params = {"type": "MARGIN", "recvWindow": 5000} +expected_params = {"type": "MARGIN", "recvWindow": 5000} @mock_http_response( responses.POST, - "/sapi/v1/loan/flexible/repay\\?" + urlencode(send_params), + "/sapi/v1/margin/manual-liquidation\\?" + urlencode(expected_params), mock_item, 200, ) -def test_flexible_loan_repay(): - """Tests the API endpoint to repay - flexible loan repay""" +def test_margin_manual_liquidation(): + """Tests the API endpoint to margin manual liquidation""" client = Client(key, secret) - response = client.flexible_loan_repay(**send_params) + response = client.margin_manual_liquidation(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/market/test_trading_day_ticker.py b/tests/spot/market/test_trading_day_ticker.py new file mode 100644 index 00000000..87fc5e15 --- /dev/null +++ b/tests/spot/market/test_trading_day_ticker.py @@ -0,0 +1,62 @@ +from binance.spot import Spot as Client +from binance.error import ParameterTypeError, ParameterArgumentError +import responses +from urllib.parse import urlencode + +from tests.util import mock_http_response + +mock_item = {"key_1": "value_1", "key_2": "value_2"} +params = {"symbols": '["BTCUSDT", "BNBUSDT"]'} + + +@mock_http_response(responses.GET, "/api/v3/ticker/tradingDay", mock_item, 200) +def test_trading_day_ticker_without_pair(): + """Tests the API endpoint to get price ticker from all pairs""" + + api = Client() + response = api.trading_day_ticker() + response.should.equal(mock_item) + + +@mock_http_response( + responses.GET, "/api/v3/ticker/tradingDay\\?symbol=BTCUSDT", mock_item, 200 +) +def test_trading_day_ticker_single_symbol(): + """Tests the API endpoint to get price ticker of one pair""" + + api = Client() + response = api.trading_day_ticker(symbol="BTCUSDT") + response.should.equal(mock_item) + + +@mock_http_response( + responses.GET, "/api/v3/ticker/tradingDay\\?" + urlencode(params), mock_item, 200 +) +def test_trading_day_ticker_multiple_symbols(): + """Tests the API endpoint to get price tickers of multiple pairs""" + + api = Client() + symbols = ["BTCUSDT", "BNBUSDT"] + response = api.trading_day_ticker(symbols=symbols) + response.should.equal(mock_item) + + +def test_trading_day_ticker_invalid_type_symbols(): + """Tests the API endpoint with invalid symbols data type""" + + api = Client() + symbols = {"BTCUSDT", "BNBUSDT"} + api.trading_day_ticker.when.called_with(symbols=symbols).should.throw( + ParameterTypeError + ) + + +def test_trading_day_ticker_with_double_parameter(): + """Tests the API endpoint with double parameter""" + + api = Client() + symbol = "ETHUSDT" + symbols = ["BTCUSDT", "BNBUSDT"] + api.trading_day_ticker.when.called_with( + symbol=symbol, symbols=symbols + ).should.throw(ParameterArgumentError) diff --git a/tests/spot/staking/test_staking_purchase_product.py b/tests/spot/staking/test_staking_purchase_product.py deleted file mode 100644 index c15b89ba..00000000 --- a/tests/spot/staking/test_staking_purchase_product.py +++ /dev/null @@ -1,33 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -params = { - "product": "STAKING", - "productId": "Axs*90", - "amount": 10.1, - "recvWindow": 5000, -} - - -@mock_http_response( - responses.POST, - "/sapi/v1/staking/purchase\\?" + urlencode(params), - mock_item, - 200, -) -def test_staking_purchase_product(): - """Tests the API endpoint to staking purchase product""" - - client = Client(key, secret) - response = client.staking_purchase_product(**params) - response.should.equal(mock_item) diff --git a/tests/spot/staking/test_staking_set_auto_staking.py b/tests/spot/staking/test_staking_set_auto_staking.py deleted file mode 100644 index 4acde754..00000000 --- a/tests/spot/staking/test_staking_set_auto_staking.py +++ /dev/null @@ -1,33 +0,0 @@ -import responses - -from binance.spot import Spot as Client -from tests.util import random_str -from urllib.parse import urlencode -from tests.util import mock_http_response - -mock_item = {"key_1": "value_1", "key_2": "value_2"} -mock_exception = {"code": -1, "msg": "error message"} - -key = random_str() -secret = random_str() - -params = { - "product": "STAKING", - "positionId": "1234", - "renewable": "true", - "recvWindow": 5000, -} - - -@mock_http_response( - responses.POST, - "/sapi/v1/staking/setAutoStaking\\?" + urlencode(params), - mock_item, - 200, -) -def test_staking_set_auto_staking(): - """Tests the API endpoint to staking set auto staking""" - - client = Client(key, secret) - response = client.staking_set_auto_staking(**params) - response.should.equal(mock_item) diff --git a/tests/spot/loan/test_flexible_loan_ongoing_orders.py b/tests/spot/trade/test_query_allocations.py similarity index 53% rename from tests/spot/loan/test_flexible_loan_ongoing_orders.py rename to tests/spot/trade/test_query_allocations.py index 4587358a..5f2fca9f 100644 --- a/tests/spot/loan/test_flexible_loan_ongoing_orders.py +++ b/tests/spot/trade/test_query_allocations.py @@ -3,6 +3,7 @@ from binance.spot import Spot as Client from tests.util import random_str from urllib.parse import urlencode +from tests.util import current_timestamp from tests.util import mock_http_response @@ -13,30 +14,28 @@ secret = random_str() send_params = { - "loanCoin": "BUSD", - "collateralCoin": "BNB", - "current": 1, - "limit": 5, + "symbol": "BTCUSDT", + "startTime": current_timestamp(), + "endTime": current_timestamp(), "recvWindow": 5000, } expected_params = { - "loanCoin": "BUSD", - "collateralCoin": "BNB", - "current": 1, - "limit": 5, + "symbol": "BTCUSDT", + "startTime": current_timestamp(), + "endTime": current_timestamp(), "recvWindow": 5000, } @mock_http_response( responses.GET, - "/sapi/v1/loan/flexible/ongoing/orders\\?" + urlencode(expected_params), + "/api/v3/myAllocations\\?" + urlencode(expected_params), mock_item, 200, ) -def test_flexible_loan_ongoing_orders(): - """Tests the API endpoint to borrow - get flexible loan ongoing orders""" +def test_query_allocations(): + """Tests the API endpoint to get allocations resulting from SOR order placement""" client = Client(key, secret) - response = client.flexible_loan_ongoing_orders(**send_params) + response = client.query_allocations(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/trade/test_query_commission_rates.py b/tests/spot/trade/test_query_commission_rates.py new file mode 100644 index 00000000..6d1e92a1 --- /dev/null +++ b/tests/spot/trade/test_query_commission_rates.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 = {"symbol": "BTCUSDT", "recvWindow": 5000} +expected_params = {"symbol": "BTCUSDT", "recvWindow": 5000} + + +@mock_http_response( + responses.GET, + "/api/v3/account/commission\\?" + urlencode(expected_params), + mock_item, + 200, +) +def test_query_commission_rates(): + """Tests the API endpoint to get current account commission rates""" + + client = Client(key, secret) + response = client.query_commission_rates(**send_params) + response.should.equal(mock_item) diff --git a/tests/spot/staking/test_staking_history.py b/tests/spot/wallet/test_delist_schedule_symbols.py similarity index 59% rename from tests/spot/staking/test_staking_history.py rename to tests/spot/wallet/test_delist_schedule_symbols.py index 18484eee..14be8891 100644 --- a/tests/spot/staking/test_staking_history.py +++ b/tests/spot/wallet/test_delist_schedule_symbols.py @@ -5,28 +5,26 @@ 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 = { - "product": "STAKING", - "txnType": "SUBSCRIPTION", - "recvWindow": 5000, -} +send_params = {"recvWindow": 5000} +expected_params = {"recvWindow": 5000} @mock_http_response( responses.GET, - "/sapi/v1/staking/stakingRecord\\?" + urlencode(params), + "/sapi/v1/spot/delist-schedule\\?" + urlencode(expected_params), mock_item, 200, ) -def test_staking_history(): - """Tests the API endpoint to staking history""" +def test_delist_schedule_symbols(): + """Tests the API endpoint to get symbols delist schedule for spot""" client = Client(key, secret) - response = client.staking_history(**params) + response = client.delist_schedule_symbols(**send_params) response.should.equal(mock_item) diff --git a/tests/spot/staking/test_staking_product_position.py b/tests/spot/wallet/test_list_deposit_address.py similarity index 57% rename from tests/spot/staking/test_staking_product_position.py rename to tests/spot/wallet/test_list_deposit_address.py index c1bea849..81f7f6b5 100644 --- a/tests/spot/staking/test_staking_product_position.py +++ b/tests/spot/wallet/test_list_deposit_address.py @@ -5,27 +5,26 @@ 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 = { - "product": "STAKING", - "recvWindow": 5000, -} +send_params = {"coin": "BNB", "network": "BSC"} +expected_params = {"coin": "BNB", "network": "BSC"} @mock_http_response( responses.GET, - "/sapi/v1/staking/position\\?" + urlencode(params), + "/sapi/v1/capital/deposit/address/list\\?" + urlencode(expected_params), mock_item, 200, ) -def test_staking_product_position(): - """Tests the API endpoint to staking product position""" +def test_list_deposit_address(): + """Tests the API endpoint to fetch deposit address list with network""" client = Client(key, secret) - response = client.staking_product_position(**params) + response = client.list_deposit_address(**send_params) response.should.equal(mock_item)