diff --git a/binance/async_client.py b/binance/async_client.py index 9a700dde..c93e2c09 100644 --- a/binance/async_client.py +++ b/binance/async_client.py @@ -1766,6 +1766,14 @@ async def futures_create_order(self, **params): params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22() return await self._request_futures_api("post", "order", True, data=params) + async def futures_modify_order(self, **params): + """Modify an existing order. Currently only LIMIT order modification is supported. + + https://binance-docs.github.io/apidocs/futures/en/#modify-order-trade + + """ + return await self._request_futures_api("put", "order", True, data=params) + async def futures_create_test_order(self, **params): return await self._request_futures_api("post", "order/test", True, data=params) diff --git a/binance/base_client.py b/binance/base_client.py index 9c6bd5c3..46ce618a 100644 --- a/binance/base_client.py +++ b/binance/base_client.py @@ -206,6 +206,7 @@ def __init__( def _get_headers(self) -> Dict: headers = { "Accept": "application/json", + "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", # noqa } if self.API_KEY: diff --git a/tests/conftest.py b/tests/conftest.py index e859b6e0..5973d17c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ proxies = {} proxy = os.getenv("PROXY") -proxy="http://51.83.140.52:16301" +proxy = "http://51.83.140.52:16301" if proxy: proxies = {"http": proxy, "https": proxy} # tmp: improve this in the future else: @@ -19,11 +19,11 @@ futures_api_key = os.getenv("TEST_FUTURES_API_KEY") futures_api_secret = os.getenv("TEST_FUTURES_API_SECRET") testnet = os.getenv("TEST_TESTNET", "true").lower() == "true" -api_key="u4L8MG2DbshTfTzkx2Xm7NfsHHigvafxeC29HrExEmah1P8JhxXkoOu6KntLICUc" -api_secret="hBZEqhZUUS6YZkk7AIckjJ3iLjrgEFr5CRtFPp5gjzkrHKKC9DAv4OH25PlT6yq5" +api_key = "u4L8MG2DbshTfTzkx2Xm7NfsHHigvafxeC29HrExEmah1P8JhxXkoOu6KntLICUc" +api_secret = "hBZEqhZUUS6YZkk7AIckjJ3iLjrgEFr5CRtFPp5gjzkrHKKC9DAv4OH25PlT6yq5" testnet = True -futures_api_key="227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401" -futures_api_secret="b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c" +futures_api_key = "227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401" +futures_api_secret = "b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c" # Configure logging for all tests @@ -47,6 +47,11 @@ def client(): return Client(api_key, api_secret, {"proxies": proxies}, testnet=testnet) +@pytest.fixture(scope="function") +def optionsClient(): + return Client(api_key, api_secret, {"proxies": proxies}, testnet=False) + + @pytest.fixture(scope="function") def futuresClient(): return Client( @@ -66,6 +71,11 @@ def futuresClientAsync(): ) +@pytest.fixture(scope="function") +def optionsClientAsync(): + return AsyncClient(api_key, api_secret, https_proxy=proxy, testnet=False) + + @pytest.fixture(autouse=True, scope="function") def event_loop(): """Create new event loop for each test""" @@ -78,5 +88,49 @@ def event_loop(): loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True)) loop.close() + def pytest_addoption(parser): - parser.addoption("--run-portfolio-tests", action="store_true", default=False, help="Run portfolio tests") \ No newline at end of file + parser.addoption( + "--run-spot", action="store_true", default=True, help="Run margin tests" + ) + parser.addoption( + "--run-futures", action="store_true", default=True, help="Run margin tests" + ) + parser.addoption( + "--run-margin", action="store_true", default=False, help="Run margin tests" + ) + parser.addoption( + "--run-portfolio", + action="store_true", + default=False, + help="Run portfolio tests", + ) + + +def pytest_configure(config): + config.addinivalue_line("markers", "spot: mark a test as part of the spot tests") + config.addinivalue_line( + "markers", "futures: mark a test as part of the futures tests" + ) + config.addinivalue_line( + "markers", "margin: mark a test as part of the margin tests" + ) + config.addinivalue_line( + "markers", "portfolio: mark a test as part of the portfolio tests" + ) + + +def pytest_collection_modifyitems(config, items): + skip_spot = pytest.mark.skip(reason="need --run-spot option to run") + skip_futures = pytest.mark.skip(reason="need --run-futures option to run") + skip_margin = pytest.mark.skip(reason="need --run-margin option to run") + skip_portfolio = pytest.mark.skip(reason="need --run-portfolio option to run") + for item in items: + if "spot" in item.keywords and not config.getoption("--run-spot"): + item.add_marker(skip_spot) + if "futures" in item.keywords and not config.getoption("--run-futures"): + item.add_marker(skip_futures) + if "margin" in item.keywords and not config.getoption("--run-margin"): + item.add_marker(skip_margin) + if "portfolio" in item.keywords and not config.getoption("--run-portfolio"): + item.add_marker(skip_portfolio) diff --git a/tests/test_async_client.py b/tests/test_async_client.py index 58c80732..c1c9fb00 100644 --- a/tests/test_async_client.py +++ b/tests/test_async_client.py @@ -1,2069 +1,165 @@ import pytest +pytestmark = [pytest.mark.asyncio] -def test_clientAsync_initialization(clientAsync): + +async def test_clientAsync_initialization(clientAsync): assert clientAsync.API_KEY is not None assert clientAsync.API_SECRET is not None -# TODO: whitelist in proxy to pass test -# @pytest.mark.asyncio() -# async def test_get_products(clientAsync): -# await clientAsync.get_products() +@pytest.mark.skip(reason="Endpoint not documented") +async def test_get_products(clientAsync): + await clientAsync.get_products() -@pytest.mark.asyncio() async def test_get_exchange_info(clientAsync): await clientAsync.get_exchange_info() -@pytest.mark.asyncio() async def test_get_symbol_info(clientAsync): await clientAsync.get_symbol_info("BTCUSDT") -@pytest.mark.asyncio() async def test_ping(clientAsync): await clientAsync.ping() -@pytest.mark.asyncio() async def test_get_server_time(clientAsync): await clientAsync.get_server_time() -@pytest.mark.asyncio() async def test_get_all_tickers(clientAsync): await clientAsync.get_all_tickers() -@pytest.mark.asyncio() async def test_get_orderbook_tickers(clientAsync): await clientAsync.get_orderbook_tickers() -@pytest.mark.asyncio() async def test_get_order_book(clientAsync): await clientAsync.get_order_book(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_recent_trades(clientAsync): await clientAsync.get_recent_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_historical_trades(clientAsync): await clientAsync.get_historical_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_aggregate_trades(clientAsync): await clientAsync.get_aggregate_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_klines(clientAsync): await clientAsync.get_klines(symbol="BTCUSDT", interval="1d") -@pytest.mark.asyncio() async def test_get_avg_price(clientAsync): await clientAsync.get_avg_price(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_ticker(clientAsync): await clientAsync.get_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_symbol_ticker(clientAsync): await clientAsync.get_symbol_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_orderbook_ticker(clientAsync): await clientAsync.get_orderbook_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_account(clientAsync): await clientAsync.get_account() -@pytest.mark.asyncio() async def test_get_asset_balance(clientAsync): await clientAsync.get_asset_balance(asset="BTC") -@pytest.mark.asyncio() async def test_get_my_trades(clientAsync): await clientAsync.get_my_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_get_system_status(clientAsync): await clientAsync.get_system_status() -@pytest.mark.asyncio() -async def test_get_account_status(clientAsync): - await clientAsync.get_account_status() - - -@pytest.mark.asyncio() -async def test_get_account_api_trading_status(clientAsync): - await clientAsync.get_account_api_trading_status() - - -@pytest.mark.asyncio() -async def test_get_account_api_permissions(clientAsync): - await clientAsync.get_account_api_permissions() - - -@pytest.mark.asyncio() -async def test_get_dust_assets(clientAsync): - await clientAsync.get_dust_assets() - - -@pytest.mark.asyncio() -async def test_get_dust_log(clientAsync): - await clientAsync.test_get_dust_log() - - -@pytest.mark.asyncio() -async def test_transfer_dust(clientAsync): - await clientAsync.transfer_dust() - - -@pytest.mark.asyncio() -async def test_get_asset_dividend_history(clientAsync): - await clientAsync.get_asset_dividend_history() - - -@pytest.mark.asyncio() -async def test_make_universal_transfer(clientAsync): - await clientAsync.make_universal_transfer() - - -@pytest.mark.asyncio() -async def test_query_universal_transfer_history(clientAsync): - await clientAsync.query_universal_transfer_history() - - -@pytest.mark.asyncio() -async def test_get_trade_fee(clientAsync): - await clientAsync.get_trade_fee() - - -@pytest.mark.asyncio() -async def test_get_asset_details(clientAsync): - await clientAsync.get_asset_details() - - -@pytest.mark.asyncio() -async def test_get_spot_delist_schedule(clientAsync): - await clientAsync.get_spot_delist_schedule() - - -# Withdraw Endpoints - - -@pytest.mark.asyncio() -async def test_withdraw(clientAsync): - await clientAsync.withdraw() - - -@pytest.mark.asyncio() -async def test_get_deposit_history(clientAsync): - await clientAsync.get_deposit_history() - - -@pytest.mark.asyncio() -async def test_get_withdraw_history(clientAsync): - await clientAsync.get_withdraw_history() - - -@pytest.mark.asyncio() -async def test_get_withdraw_history_id(clientAsync): - await clientAsync.get_withdraw_history_id() - - -@pytest.mark.asyncio() -async def test_get_deposit_address(clientAsync): - await clientAsync.get_deposit_address() - - # User Stream Endpoints -@pytest.mark.asyncio() -async def test_stream_get_listen_key(clientAsync): - await clientAsync.stream_get_listen_key() - - -@pytest.mark.asyncio() -async def test_stream_close(clientAsync): - await clientAsync.stream_close() - - -# Margin Trading Endpoints - - -@pytest.mark.asyncio() -async def test_get_margin_account(clientAsync): - await clientAsync.get_margin_account() - - -@pytest.mark.asyncio() -async def test_get_isolated_margin_account(clientAsync): - await clientAsync.get_isolated_margin_account() - - -@pytest.mark.asyncio() -async def test_enable_isolated_margin_account(clientAsync): - await clientAsync.enable_isolated_margin_account() - - -@pytest.mark.asyncio() -async def test_disable_isolated_margin_account(clientAsync): - await clientAsync.disable_isolated_margin_account() - - -@pytest.mark.asyncio() -async def test_get_enabled_isolated_margin_account_limit(clientAsync): - await clientAsync.get_enabled_isolated_margin_account_limit() - - -@pytest.mark.asyncio() -async def test_get_margin_dustlog(clientAsync): - await clientAsync.get_margin_dustlog() - - -@pytest.mark.asyncio() -async def test_get_margin_dust_assets(clientAsync): - await clientAsync.get_margin_dust_assets() - - -@pytest.mark.asyncio() -async def test_transfer_margin_dust(clientAsync): - await clientAsync.transfer_margin_dust() - - -@pytest.mark.asyncio() -async def test_get_cross_margin_collateral_ratio(clientAsync): - await clientAsync.get_cross_margin_collateral_ratio() - - -@pytest.mark.asyncio() -async def test_get_small_liability_exchange_assets(clientAsync): - await clientAsync.get_small_liability_exchange_assets() - - -@pytest.mark.asyncio() -async def test_exchange_small_liability_assets(clientAsync): - await clientAsync.exchange_small_liability_assets() - - -@pytest.mark.asyncio() -async def test_get_small_liability_exchange_history(clientAsync): - await clientAsync.get_small_liability_exchange_history() - - -@pytest.mark.asyncio() -async def test_get_future_hourly_interest_rate(clientAsync): - await clientAsync.get_future_hourly_interest_rate() - - -@pytest.mark.asyncio() -async def test_get_margin_capital_flow(clientAsync): - await clientAsync.get_margin_capital_flow() - - -@pytest.mark.asyncio() -async def test_get_margin_asset(clientAsync): - await clientAsync.get_margin_asset() - - -@pytest.mark.asyncio() -async def test_get_margin_symbol(clientAsync): - await clientAsync.get_margin_symbol() - - -@pytest.mark.asyncio() -async def test_get_margin_all_assets(clientAsync): - await clientAsync.get_margin_all_assets() - - -@pytest.mark.asyncio() -async def test_get_margin_all_pairs(clientAsync): - await clientAsync.get_margin_all_pairs() - - -@pytest.mark.asyncio() -async def test_create_isolated_margin_account(clientAsync): - await clientAsync.create_isolated_margin_account() - - -@pytest.mark.asyncio() -async def test_get_isolated_margin_symbol(clientAsync): - await clientAsync.get_isolated_margin_symbol() - - -@pytest.mark.asyncio() -async def test_get_all_isolated_margin_symbols(clientAsync): - await clientAsync.get_all_isolated_margin_symbols() - - -@pytest.mark.asyncio() -async def test_get_isolated_margin_fee_data(clientAsync): - await clientAsync.get_isolated_margin_fee_data() - - -@pytest.mark.asyncio() -async def test_get_isolated_margin_tier_data(clientAsync): - await clientAsync.get_isolated_margin_tier_data() - - -@pytest.mark.asyncio() -async def test_margin_manual_liquidation(clientAsync): - await clientAsync.margin_manual_liquidation() - - -@pytest.mark.asyncio() -async def test_toggle_bnb_burn_spot_margin(clientAsync): - await clientAsync.toggle_bnb_burn_spot_margin() - - -@pytest.mark.asyncio() -async def test_get_bnb_burn_spot_margin(clientAsync): - await clientAsync.get_bnb_burn_spot_margin() - - -@pytest.mark.asyncio() -async def test_get_margin_price_index(clientAsync): - await clientAsync.get_margin_price_index() - - -@pytest.mark.asyncio() -async def test_transfer_margin_to_spot(clientAsync): - await clientAsync.transfer_margin_to_spot() - - -@pytest.mark.asyncio() -async def test_transfer_spot_to_margin(clientAsync): - await clientAsync.transfer_spot_to_margin() - - -@pytest.mark.asyncio() -async def test_transfer_isolated_margin_to_spot(clientAsync): - await clientAsync.transfer_isolated_margin_to_spot() - - -@pytest.mark.asyncio() -async def test_transfer_spot_to_isolated_margin(clientAsync): - await clientAsync.transfer_spot_to_isolated_margin() - - -@pytest.mark.asyncio() -async def test_get_isolated_margin_tranfer_history(clientAsync): - await clientAsync.get_isolated_margin_tranfer_history() - - -@pytest.mark.asyncio() -async def test_create_margin_loan(clientAsync): - await clientAsync.create_margin_loan() - - -@pytest.mark.asyncio() -async def test_repay_margin_loan(clientAsync): - await clientAsync.repay_margin_loan() - - -@pytest.mark.asyncio() -async def create_margin_ordertest_(clientAsync): - await clientAsync.create_margin_order() - - -@pytest.mark.asyncio() -async def test_cancel_margin_order(clientAsync): - await clientAsync.cancel_margin_order() - - -@pytest.mark.asyncio() -async def test_set_margin_max_leverage(clientAsync): - await clientAsync.set_margin_max_leverage() - - -@pytest.mark.asyncio() -async def test_get_margin_transfer_history(clientAsync): - await clientAsync.get_margin_transfer_history() - - -@pytest.mark.asyncio() -async def test_get_margin_loan_details(clientAsync): - await clientAsync.get_margin_loan_details() - - -@pytest.mark.asyncio() -async def test_get_margin_repay_details(clientAsync): - await clientAsync.get_margin_repay_details() - - -@pytest.mark.asyncio() -async def test_get_cross_margin_data(clientAsync): - await clientAsync.get_cross_margin_data() - - -@pytest.mark.asyncio() -async def test_get_margin_interest_history(clientAsync): - await clientAsync.get_margin_interest_history() - - -@pytest.mark.asyncio() -async def test_get_margin_force_liquidation_rec(clientAsync): - await clientAsync.get_margin_force_liquidation_rec() - - -@pytest.mark.asyncio() -async def test_get_margin_order(clientAsync): - await clientAsync.get_margin_order() - - -@pytest.mark.asyncio() -async def test_get_open_margin_orders(clientAsync): - await clientAsync.get_open_margin_orders() - - -@pytest.mark.asyncio() -async def test_get_all_margin_orders(clientAsync): - await clientAsync.get_all_margin_orders() - - -@pytest.mark.asyncio() -async def test_get_margin_trades(clientAsync): - await clientAsync.get_margin_trades() - - -@pytest.mark.asyncio() -async def test_get_max_margin_loan(clientAsync): - await clientAsync.get_max_margin_loan() - - -@pytest.mark.asyncio() -async def test_get_max_margin_transfer(clientAsync): - await clientAsync.get_max_margin_transfer() - - -@pytest.mark.asyncio() -async def test_get_margin_delist_schedule(clientAsync): - await clientAsync.get_margin_delist_schedule() - - -# Margin OCO - - -@pytest.mark.asyncio() -async def test_create_margin_oco_order(clientAsync): - await clientAsync.create_margin_oco_order() - - -@pytest.mark.asyncio() -async def test_cancel_margin_oco_order(clientAsync): - await clientAsync.cancel_margin_oco_order() - - -@pytest.mark.asyncio() -async def test_get_margin_oco_order(clientAsync): - await clientAsync.get_margin_oco_order() - - -@pytest.mark.asyncio() -async def test_get_open_margin_oco_orders(clientAsync): - await clientAsync.get_open_margin_oco_orders() - - -# Cross-margin - - -@pytest.mark.asyncio() -async def test_margin_stream_get_listen_key(clientAsync): - await clientAsync.margin_stream_get_listen_key() - - -@pytest.mark.asyncio() -async def test_margin_stream_close(clientAsync): - await clientAsync.margin_stream_close() - - -# Isolated margin - - -@pytest.mark.asyncio() -async def test_isolated_margin_stream_get_listen_key(clientAsync): - await clientAsync.isolated_margin_stream_get_listen_key() - - -@pytest.mark.asyncio() -async def test_isolated_margin_stream_close(clientAsync): - await clientAsync.isolated_margin_stream_close() - - -# Simple Earn Endpoints - - -@pytest.mark.asyncio() -async def test_get_simple_earn_flexible_product_list(clientAsync): - await clientAsync.get_simple_earn_flexible_product_list() - - -@pytest.mark.asyncio() -async def test_get_simple_earn_locked_product_list(clientAsync): - await clientAsync.get_simple_earn_locked_product_list() - - -@pytest.mark.asyncio() -async def test_subscribe_simple_earn_flexible_product(clientAsync): - await clientAsync.subscribe_simple_earn_flexible_product() - - -@pytest.mark.asyncio() -async def test_subscribe_simple_earn_locked_product(clientAsync): - await clientAsync.subscribe_simple_earn_locked_product() - - -@pytest.mark.asyncio() -async def test_redeem_simple_earn_flexible_product(clientAsync): - await clientAsync.redeem_simple_earn_flexible_product() - - -@pytest.mark.asyncio() -async def test_redeem_simple_earn_locked_product(clientAsync): - await clientAsync.redeem_simple_earn_locked_product() - - -@pytest.mark.asyncio() -async def test_get_simple_earn_flexible_product_position(clientAsync): - await clientAsync.get_simple_earn_flexible_product_position() - - -@pytest.mark.asyncio() -async def test_get_simple_earn_locked_product_position(clientAsync): - await clientAsync.get_simple_earn_locked_product_position() - - -@pytest.mark.asyncio() -async def test_get_simple_earn_account(clientAsync): - await clientAsync.get_simple_earn_account() - - -# Lending Endpoints - - -@pytest.mark.asyncio() -async def test_get_fixed_activity_project_list(clientAsync): - await clientAsync.get_fixed_activity_project_list() - - -@pytest.mark.asyncio() -async def test_change_fixed_activity_to_daily_position(clientAsync): - await clientAsync.change_fixed_activity_to_daily_position() - - -# Staking Endpoints - - -@pytest.mark.asyncio() -async def test_get_staking_product_list(clientAsync): - await clientAsync.get_staking_product_list() - - -@pytest.mark.asyncio() -async def test_purchase_staking_product(clientAsync): - await clientAsync.purchase_staking_product() - - -@pytest.mark.asyncio() -async def test_redeem_staking_product(clientAsync): - await clientAsync.redeem_staking_product() - - -@pytest.mark.asyncio() -async def test_get_staking_position(clientAsync): - await clientAsync.get_staking_position() - - -@pytest.mark.asyncio() -async def test_get_staking_purchase_history(clientAsync): - await clientAsync.get_staking_purchase_history() - - -@pytest.mark.asyncio() -async def test_set_auto_staking(clientAsync): - await clientAsync.set_auto_staking() - - -@pytest.mark.asyncio() -async def test_get_personal_left_quota(clientAsync): - await clientAsync.get_personal_left_quota() - - -# US Staking Endpoints - - -@pytest.mark.asyncio() -async def test_get_staking_asset_us(clientAsync): - await clientAsync.get_staking_asset_us() - - -@pytest.mark.asyncio() -async def test_stake_asset_us(clientAsync): - await clientAsync.stake_asset_us() - - -@pytest.mark.asyncio() -async def test_unstake_asset_us(clientAsync): - await clientAsync.unstake_asset_us() - - -@pytest.mark.asyncio() -async def test_get_staking_balance_us(clientAsync): - await clientAsync.get_staking_balance_us() - - -@pytest.mark.asyncio() -async def test_get_staking_history_us(clientAsync): - await clientAsync.get_staking_history_us() - - -@pytest.mark.asyncio() -async def test_get_staking_rewards_history_us(clientAsync): - await clientAsync.get_staking_rewards_history_us() - - -# Sub Accounts - - -@pytest.mark.asyncio() -async def test_get_sub_account_list(clientAsync): - await clientAsync.get_sub_account_list() - - -@pytest.mark.asyncio() -async def test_get_sub_account_transfer_history(clientAsync): - await clientAsync.get_sub_account_transfer_history() - - -@pytest.mark.asyncio() -async def test_get_sub_account_futures_transfer_history(clientAsync): - await clientAsync.get_sub_account_futures_transfer_history() - - -@pytest.mark.asyncio() -async def test_create_sub_account_futures_transfer(clientAsync): - await clientAsync.create_sub_account_futures_transfer() - - -@pytest.mark.asyncio() -async def test_get_sub_account_assets(clientAsync): - await clientAsync.get_sub_account_assets() - - -@pytest.mark.asyncio() -async def test_query_subaccount_spot_summary(clientAsync): - await clientAsync.query_subaccount_spot_summary() - - -@pytest.mark.asyncio() -async def test_get_subaccount_deposit_address(clientAsync): - await clientAsync.get_subaccount_deposit_address() - - -@pytest.mark.asyncio() -async def test_get_subaccount_deposit_history(clientAsync): - await clientAsync.get_subaccount_deposit_history() - - -@pytest.mark.asyncio() -async def test_get_subaccount_futures_margin_status(clientAsync): - await clientAsync.get_subaccount_futures_margin_status() - - -@pytest.mark.asyncio() -async def test_enable_subaccount_margin(clientAsync): - await clientAsync.enable_subaccount_margin() - - -@pytest.mark.asyncio() -async def test_get_subaccount_margin_details(clientAsync): - await clientAsync.get_subaccount_margin_details() - - -@pytest.mark.asyncio() -async def test_get_subaccount_margin_summary(clientAsync): - await clientAsync.get_subaccount_margin_summary() - - -@pytest.mark.asyncio() -async def test_enable_subaccount_futures(clientAsync): - await clientAsync.enable_subaccount_futures() - - -@pytest.mark.asyncio() -async def test_get_subaccount_futures_details(clientAsync): - await clientAsync.get_subaccount_futures_details() - - -@pytest.mark.asyncio() -async def test_get_subaccount_futures_summary(clientAsync): - await clientAsync.get_subaccount_futures_summary() - - -@pytest.mark.asyncio() -async def test_get_subaccount_futures_positionrisk(clientAsync): - await clientAsync.get_subaccount_futures_positionrisk() - - -@pytest.mark.asyncio() -async def test_make_subaccount_futures_transfer(clientAsync): - await clientAsync.make_subaccount_futures_transfer() - - -@pytest.mark.asyncio() -async def test_make_subaccount_margin_transfer(clientAsync): - await clientAsync.make_subaccount_margin_transfer() - - -@pytest.mark.asyncio() -async def test_make_subaccount_to_subaccount_transfer(clientAsync): - await clientAsync.make_subaccount_to_subaccount_transfer() - - -@pytest.mark.asyncio() -async def test_make_subaccount_to_master_transfer(clientAsync): - await clientAsync.make_subaccount_to_master_transfer() - - -@pytest.mark.asyncio() -async def test_get_subaccount_transfer_history(clientAsync): - await clientAsync.get_subaccount_transfer_history() - - -@pytest.mark.asyncio() -async def test_make_subaccount_universal_transfer(clientAsync): - await clientAsync.make_subaccount_universal_transfer() - - -@pytest.mark.asyncio() -async def test_get_universal_transfer_history(clientAsync): - await clientAsync.get_universal_transfer_history() - - -# Futures API - - -@pytest.mark.asyncio() -async def test_futures_ping(clientAsync): - await clientAsync.futures_ping() - - -@pytest.mark.asyncio() -async def test_futures_time(clientAsync): - await clientAsync.futures_time() - - -@pytest.mark.asyncio() -async def test_futures_exchange_info(clientAsync): - await clientAsync.futures_exchange_info() - - -@pytest.mark.asyncio() -async def test_futures_order_book(clientAsync): - await clientAsync.futures_order_book() - - -@pytest.mark.asyncio() -async def test_futures_recent_trades(clientAsync): - await clientAsync.futures_recent_trades() - - -@pytest.mark.asyncio() -async def test_futures_historical_trades(clientAsync): - await clientAsync.futures_historical_trades() - - -@pytest.mark.asyncio() -async def test_futures_aggregate_trades(clientAsync): - await clientAsync.futures_aggregate_trades() - - -@pytest.mark.asyncio() -async def test_futures_klines(clientAsync): - await clientAsync.futures_klines() - - -@pytest.mark.asyncio() -async def test_futures_continous_klines(clientAsync): - await clientAsync.futures_continous_klines() - - -@pytest.mark.asyncio() -async def test_futures_historical_klines(clientAsync): - await clientAsync.futures_historical_klines() - - -@pytest.mark.asyncio() -async def test_futures_historical_klines_generator(clientAsync): - await clientAsync.futures_historical_klines_generator() - - -@pytest.mark.asyncio() -async def test_futures_mark_price(clientAsync): - await clientAsync.futures_mark_price() - - -@pytest.mark.asyncio() -async def test_futures_funding_rate(clientAsync): - await clientAsync.futures_funding_rate() - - -@pytest.mark.asyncio() -async def test_futures_top_longshort_account_ratio(clientAsync): - await clientAsync.futures_top_longshort_account_ratio() - - -@pytest.mark.asyncio() -async def test_futures_top_longshort_position_ratio(clientAsync): - await clientAsync.futures_top_longshort_position_ratio() - - -@pytest.mark.asyncio() -async def test_futures_global_longshort_ratio(clientAsync): - await clientAsync.futures_global_longshort_ratio() - - -@pytest.mark.asyncio() -async def test_futures_ticker(clientAsync): - await clientAsync.futures_ticker() - - -@pytest.mark.asyncio() -async def test_futures_symbol_ticker(clientAsync): - await clientAsync.futures_symbol_ticker() - - -@pytest.mark.asyncio() -async def test_futures_orderbook_ticker(clientAsync): - await clientAsync.futures_orderbook_ticker() - - -@pytest.mark.asyncio() -async def test_futures_liquidation_orders(clientAsync): - await clientAsync.futures_liquidation_orders() - - -@pytest.mark.asyncio() -async def test_futures_api_trading_status(clientAsync): - await clientAsync.futures_api_trading_status() - - -@pytest.mark.asyncio() -async def test_futures_commission_rate(clientAsync): - await clientAsync.futures_commission_rate() - - -@pytest.mark.asyncio() -async def test_futures_adl_quantile_estimate(clientAsync): - await clientAsync.futures_adl_quantile_estimate() - - -@pytest.mark.asyncio() -async def test_futures_open_interest(clientAsync): - await clientAsync.futures_open_interest() - - -@pytest.mark.asyncio() -async def test_futures_index_info(clientAsync): - await clientAsync.futures_index_info() - - -@pytest.mark.asyncio() -async def test_futures_open_interest_hist(clientAsync): - await clientAsync.futures_open_interest_hist() - - -@pytest.mark.asyncio() -async def test_futures_leverage_bracket(clientAsync): - await clientAsync.futures_leverage_bracket() - - -@pytest.mark.asyncio() -async def test_futures_account_transfer(clientAsync): - await clientAsync.futures_account_transfer() - - -@pytest.mark.asyncio() -async def test_transfer_history(clientAsync): - await clientAsync.transfer_history() - - -@pytest.mark.asyncio() -async def test_futures_loan_borrow_history(clientAsync): - await clientAsync.futures_loan_borrow_history() - - -@pytest.mark.asyncio() -async def test_futures_loan_repay_history(clientAsync): - await clientAsync.futures_loan_repay_history() - - -@pytest.mark.asyncio() -async def test_futures_loan_wallet(clientAsync): - await clientAsync.futures_loan_wallet() - - -@pytest.mark.asyncio() -async def test_futures_cross_collateral_adjust_history(clientAsync): - await clientAsync.futures_cross_collateral_adjust_history() - - -@pytest.mark.asyncio() -async def test_futures_cross_collateral_liquidation_history(clientAsync): - await clientAsync.futures_cross_collateral_liquidation_history() - - -@pytest.mark.asyncio() -async def test_futures_loan_interest_history(clientAsync): - await clientAsync.futures_loan_interest_history() - - -@pytest.mark.asyncio() -async def test_futures_create_order(clientAsync): - await clientAsync.futures_create_order() - - -@pytest.mark.asyncio() -async def test_futures_modify_order(clientAsync): - await clientAsync.futures_modify_order() - - -@pytest.mark.asyncio() -async def test_futures_create_test_order(clientAsync): - await clientAsync.futures_create_test_order() - - -@pytest.mark.asyncio() -async def test_futures_place_batch_order(clientAsync): - await clientAsync.futures_place_batch_order() - - -@pytest.mark.asyncio() -async def test_futures_get_order(clientAsync): - await clientAsync.futures_get_order() - - -@pytest.mark.asyncio() -async def test_futures_get_open_orders(clientAsync): - await clientAsync.futures_get_open_orders() - - -@pytest.mark.asyncio() -async def test_futures_get_all_orders(clientAsync): - await clientAsync.futures_get_all_orders() - - -@pytest.mark.asyncio() -async def test_futures_cancel_order(clientAsync): - await clientAsync.futures_cancel_order() - - -@pytest.mark.asyncio() -async def test_futures_cancel_all_open_orders(clientAsync): - await clientAsync.futures_cancel_all_open_orders() - - -@pytest.mark.asyncio() -async def test_futures_cancel_orders(clientAsync): - await clientAsync.futures_cancel_orders() - - -@pytest.mark.asyncio() -async def test_futures_countdown_cancel_all(clientAsync): - await clientAsync.futures_countdown_cancel_all() - - -@pytest.mark.asyncio() -async def test_futures_account_balance(clientAsync): - await clientAsync.futures_account_balance() - - -@pytest.mark.asyncio() -async def test_futures_account(clientAsync): - await clientAsync.futures_account() - - -@pytest.mark.asyncio() -async def test_futures_change_leverage(clientAsync): - await clientAsync.futures_change_leverage() - - -@pytest.mark.asyncio() -async def test_futures_change_margin_type(clientAsync): - await clientAsync.futures_change_margin_type() - - -@pytest.mark.asyncio() -async def test_futures_change_position_margin(clientAsync): - await clientAsync.futures_change_position_margin() - - -@pytest.mark.asyncio() -async def test_futures_position_margin_history(clientAsync): - await clientAsync.futures_position_margin_history() - - -@pytest.mark.asyncio() -async def test_futures_position_information(clientAsync): - await clientAsync.futures_position_information() - - -@pytest.mark.asyncio() -async def test_futures_account_trades(clientAsync): - await clientAsync.futures_account_trades() - - -@pytest.mark.asyncio() -async def test_futures_income_history(clientAsync): - await clientAsync.futures_income_history() - - -@pytest.mark.asyncio() -async def test_futures_change_position_mode(clientAsync): - await clientAsync.futures_change_position_mode() - - -@pytest.mark.asyncio() -async def test_futures_get_position_mode(clientAsync): - await clientAsync.futures_get_position_mode() - - -@pytest.mark.asyncio() -async def test_futures_change_multi_assets_mode(clientAsync): - await clientAsync.futures_change_multi_assets_mode() - - -@pytest.mark.asyncio() -async def test_futures_get_multi_assets_mode(clientAsync): - await clientAsync.futures_get_multi_assets_mode() - - -@pytest.mark.asyncio() -async def test_futures_stream_get_listen_key(clientAsync): - await clientAsync.futures_stream_get_listen_key() - - -@pytest.mark.asyncio() -async def test_futures_stream_close(clientAsync): - await clientAsync.futures_stream_close() - - -# new methods -@pytest.mark.asyncio() -async def test_futures_account_config(clientAsync): - await clientAsync.futures_account_config() - - -@pytest.mark.asyncio() -async def test_futures_symbol_config(clientAsync): - await clientAsync.futures_symbol_config() - - -# COIN Futures API -@pytest.mark.asyncio() -async def test_futures_coin_ping(clientAsync): - await clientAsync.futures_coin_ping() - - -@pytest.mark.asyncio() -async def test_futures_coin_time(clientAsync): - await clientAsync.futures_coin_time() - - -@pytest.mark.asyncio() -async def test_futures_coin_exchange_info(clientAsync): - await clientAsync.futures_coin_exchange_info() - - -@pytest.mark.asyncio() -async def test_futures_coin_order_book(clientAsync): - await clientAsync.futures_coin_order_book() - - -@pytest.mark.asyncio() -async def test_futures_coin_recent_trades(clientAsync): - await clientAsync.futures_coin_recent_trades() - - -@pytest.mark.asyncio() -async def test_futures_coin_historical_trades(clientAsync): - await clientAsync.futures_coin_historical_trades() - - -@pytest.mark.asyncio() -async def test_futures_coin_aggregate_trades(clientAsync): - await clientAsync.futures_coin_aggregate_trades() - - -@pytest.mark.asyncio() -async def test_futures_coin_klines(clientAsync): - await clientAsync.futures_coin_klines() - - -@pytest.mark.asyncio() -async def test_futures_coin_continous_klines(clientAsync): - await clientAsync.futures_coin_continous_klines() - - -@pytest.mark.asyncio() -async def test_futures_coin_index_price_klines(clientAsync): - await clientAsync.futures_coin_index_price_klines() - - -@pytest.mark.asyncio() -async def test_futures_coin_mark_price_klines(clientAsync): - await clientAsync.futures_coin_mark_price_klines() - - -@pytest.mark.asyncio() -async def test_futures_coin_mark_price(clientAsync): - await clientAsync.futures_coin_mark_price() - - -@pytest.mark.asyncio() -async def test_futures_coin_funding_rate(clientAsync): - await clientAsync.futures_coin_funding_rate() - - -@pytest.mark.asyncio() -async def test_futures_coin_ticker(clientAsync): - await clientAsync.futures_coin_ticker() - - -@pytest.mark.asyncio() -async def test_futures_coin_symbol_ticker(clientAsync): - await clientAsync.futures_coin_symbol_ticker() - - -@pytest.mark.asyncio() -async def test_futures_coin_orderbook_ticker(clientAsync): - await clientAsync.futures_coin_orderbook_ticker() - - -@pytest.mark.asyncio() -async def test_futures_coin_liquidation_orders(clientAsync): - await clientAsync.futures_coin_liquidation_orders() - - -@pytest.mark.asyncio() -async def test_futures_coin_open_interest(clientAsync): - await clientAsync.futures_coin_open_interest() - - -@pytest.mark.asyncio() -async def test_futures_coin_open_interest_hist(clientAsync): - await clientAsync.futures_coin_open_interest_hist() - - -@pytest.mark.asyncio() -async def test_futures_coin_leverage_bracket(clientAsync): - await clientAsync.futures_coin_leverage_bracket() - - -@pytest.mark.asyncio() -async def test_new_transfer_history(clientAsync): - await clientAsync.new_transfer_history() - - -@pytest.mark.asyncio() -async def test_funding_wallet(clientAsync): - await clientAsync.funding_wallet() - - -@pytest.mark.asyncio() -async def test_get_user_asset(clientAsync): - await clientAsync.get_user_asset() - - -@pytest.mark.asyncio() -async def test_universal_transfer(clientAsync): - await clientAsync.universal_transfer() - - -@pytest.mark.asyncio() -async def test_futures_coin_create_order(clientAsync): - await clientAsync.futures_coin_create_order() - - -@pytest.mark.asyncio() -async def test_futures_coin_place_batch_order(clientAsync): - await clientAsync.futures_coin_place_batch_order() - - -@pytest.mark.asyncio() -async def test_futures_coin_get_order(clientAsync): - await clientAsync.futures_coin_get_order() - - -@pytest.mark.asyncio() -async def test_futures_coin_get_open_orders(clientAsync): - await clientAsync.futures_coin_get_open_orders() - - -@pytest.mark.asyncio() -async def test_futures_coin_get_all_orders(clientAsync): - await clientAsync.futures_coin_get_all_orders() - - -@pytest.mark.asyncio() -async def test_futures_coin_cancel_order(clientAsync): - await clientAsync.futures_coin_cancel_order() - - -@pytest.mark.asyncio() -async def test_futures_coin_cancel_all_open_orders(clientAsync): - await clientAsync.futures_coin_cancel_all_open_orders() - - -@pytest.mark.asyncio() -async def test_futures_coin_cancel_orders(clientAsync): - await clientAsync.futures_coin_cancel_orders() - - -@pytest.mark.asyncio() -async def test_futures_coin_account_balance(clientAsync): - await clientAsync.futures_coin_account_balance() - - -@pytest.mark.asyncio() -async def test_futures_coin_account(clientAsync): - await clientAsync.futures_coin_account() - - -@pytest.mark.asyncio() -async def test_futures_coin_change_leverage(clientAsync): - await clientAsync.futures_coin_change_leverage() - - -@pytest.mark.asyncio() -async def test_futures_coin_change_margin_type(clientAsync): - await clientAsync.futures_coin_change_margin_type() - - -@pytest.mark.asyncio() -async def test_futures_coin_change_position_margin(clientAsync): - await clientAsync.futures_coin_change_position_margin() - - -@pytest.mark.asyncio() -async def test_futures_coin_position_margin_history(clientAsync): - await clientAsync.futures_coin_position_margin_history() - - -@pytest.mark.asyncio() -async def test_futures_coin_position_information(clientAsync): - await clientAsync.futures_coin_position_information() - - -@pytest.mark.asyncio() -async def test_futures_coin_account_trades(clientAsync): - await clientAsync.futures_coin_account_trades() - - -@pytest.mark.asyncio() -async def test_futures_coin_income_history(clientAsync): - await clientAsync.futures_coin_income_history() - - -@pytest.mark.asyncio() -async def test_futures_coin_change_position_mode(clientAsync): - await clientAsync.futures_coin_change_position_mode() - - -@pytest.mark.asyncio() -async def test_futures_coin_get_position_mode(clientAsync): - await clientAsync.futures_coin_get_position_mode() - - -@pytest.mark.asyncio() -async def test_futures_coin_stream_get_listen_key(clientAsync): - await clientAsync.futures_coin_stream_get_listen_key() - - -@pytest.mark.asyncio() -async def test_futures_coin_stream_close(clientAsync): - await clientAsync.futures_coin_stream_close() - - -@pytest.mark.asyncio() -async def test_get_all_coins_info(clientAsync): - await clientAsync.get_all_coins_info() - - -@pytest.mark.asyncio() -async def test_get_account_snapshot(clientAsync): - await clientAsync.get_account_snapshot() - - -@pytest.mark.asyncio() -async def test_disable_fast_withdraw_switch(clientAsync): - await clientAsync.disable_fast_withdraw_switch() - - -@pytest.mark.asyncio() -async def test_enable_fast_withdraw_switch(clientAsync): - await clientAsync.enable_fast_withdraw_switch() +async def test_stream_get_listen_key_and_close(clientAsync): + listen_key = await clientAsync.stream_get_listen_key() + await clientAsync.stream_close(listen_key) # Quoting interface endpoints -@pytest.mark.asyncio() -async def test_options_ping(clientAsync): - await clientAsync.options_ping() - - -@pytest.mark.asyncio() -async def test_options_time(clientAsync): - await clientAsync.options_time() - - -@pytest.mark.asyncio() -async def test_options_info(clientAsync): - await clientAsync.options_info() - - -@pytest.mark.asyncio() -async def test_options_exchange_info(clientAsync): - await clientAsync.options_exchange_info() - - -@pytest.mark.asyncio() -async def test_options_index_price(clientAsync): - await clientAsync.options_index_price() - - -@pytest.mark.asyncio() -async def test_options_price(clientAsync): - await clientAsync.options_price() - - -@pytest.mark.asyncio() -async def test_options_mark_price(clientAsync): - await clientAsync.options_mark_price() - - -@pytest.mark.asyncio() -async def test_options_order_book(clientAsync): - await clientAsync.options_order_book() - - -@pytest.mark.asyncio() -async def test_options_klines(clientAsync): - await clientAsync.options_klines() - - -@pytest.mark.asyncio() -async def test_options_recent_trades(clientAsync): - await clientAsync.options_recent_trades() - - -@pytest.mark.asyncio() -async def test_options_historical_trades(clientAsync): - await clientAsync.options_historical_trades() - - -# Account and trading interface endpoints - - -@pytest.mark.asyncio() -async def test_options_account_info(clientAsync): - await clientAsync.options_account_info() - - -@pytest.mark.asyncio() -async def test_options_funds_transfer(clientAsync): - await clientAsync.options_funds_transfer() - - -@pytest.mark.asyncio() -async def test_options_positions(clientAsync): - await clientAsync.options_positions() - - -@pytest.mark.asyncio() -async def test_options_bill(clientAsync): - await clientAsync.options_bill() - - -@pytest.mark.asyncio() -async def test_options_place_order(clientAsync): - await clientAsync.options_place_order() - - -@pytest.mark.asyncio() -async def test_test_options_place_batch_order(clientAsync): - await clientAsync.test_options_place_batch_order() - - -@pytest.mark.asyncio() -async def test_options_cancel_order(clientAsync): - await clientAsync.options_cancel_order() - - -@pytest.mark.asyncio() -async def test_options_cancel_batch_order(clientAsync): - await clientAsync.options_cancel_batch_order() - - -@pytest.mark.asyncio() -async def test_options_cancel_all_orders(clientAsync): - await clientAsync.options_cancel_all_orders() - - -@pytest.mark.asyncio() -async def test_options_query_order(clientAsync): - await clientAsync.options_query_order() - - -@pytest.mark.asyncio() -async def test_options_query_pending_orders(clientAsync): - await clientAsync.options_query_pending_orders() - - -@pytest.mark.asyncio() -async def test_options_query_order_history(clientAsync): - await clientAsync.options_query_order_history() - - -@pytest.mark.asyncio() -async def test_options_user_trades(clientAsync): - await clientAsync.options_user_trades() - - -# Fiat Endpoints - - -@pytest.mark.asyncio() -async def test_get_fiat_deposit_withdraw_history(clientAsync): - await clientAsync.get_fiat_deposit_withdraw_history() - - -@pytest.mark.asyncio() -async def test_get_fiat_payments_history(clientAsync): - await clientAsync.get_fiat_payments_history() - - -# C2C Endpoints - - -@pytest.mark.asyncio() -async def test_get_c2c_trade_history(clientAsync): - await clientAsync.get_c2c_trade_history() - - -# Pay Endpoints - - -@pytest.mark.asyncio() -async def test_get_pay_trade_history(clientAsync): - await clientAsync.get_pay_trade_history() - - -# Convert Endpoints - - -@pytest.mark.asyncio() -async def test_get_convert_trade_history(clientAsync): - await clientAsync.get_convert_trade_history() - - -@pytest.mark.asyncio() -async def test_convert_request_quote(clientAsync): - await clientAsync.convert_request_quote() - - -@pytest.mark.asyncio() -async def test_convert_accept_quote(clientAsync): - await clientAsync.convert_accept_quote() - - -@pytest.mark.asyncio() -async def test_papi_get_balance(clientAsync): - await clientAsync.papi_get_balance() - - -@pytest.mark.asyncio() -async def test_papi_get_account(clientAsync): - await clientAsync.papi_get_account() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_max_borrowable(clientAsync): - await clientAsync.papi_get_margin_max_borrowable() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_max_withdraw(clientAsync): - await clientAsync.papi_get_margin_max_withdraw() - - -@pytest.mark.asyncio() -async def test_papi_get_um_position_risk(clientAsync): - await clientAsync.papi_get_um_position_risk() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_position_risk(clientAsync): - await clientAsync.papi_get_cm_position_risk() - - -@pytest.mark.asyncio() -async def test_papi_set_um_leverage(clientAsync): - await clientAsync.papi_set_um_leverage() - - -@pytest.mark.asyncio() -async def test_papi_set_cm_leverage(clientAsync): - await clientAsync.papi_set_cm_leverage() - - -@pytest.mark.asyncio() -async def test_papi_change_um_position_side_dual(clientAsync): - await clientAsync.papi_change_um_position_side_dual() - - -@pytest.mark.asyncio() -async def test_papi_get_um_position_side_dual(clientAsync): - await clientAsync.papi_get_um_position_side_dual() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_position_side_dual(clientAsync): - await clientAsync.papi_get_cm_position_side_dual() - - -@pytest.mark.asyncio() -async def test_papi_get_um_leverage_bracket(clientAsync): - await clientAsync.papi_get_um_leverage_bracket() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_leverage_bracket(clientAsync): - await clientAsync.papi_get_cm_leverage_bracket() - - -@pytest.mark.asyncio() -async def test_papi_get_um_api_trading_status(clientAsync): - await clientAsync.papi_get_um_api_trading_status() - - -@pytest.mark.asyncio() -async def test_papi_get_um_comission_rate(clientAsync): - await clientAsync.papi_get_um_comission_rate() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_comission_rate(clientAsync): - await clientAsync.papi_get_cm_comission_rate() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_margin_loan(clientAsync): - await clientAsync.papi_get_margin_margin_loan() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_repay_loan(clientAsync): - await clientAsync.papi_get_margin_repay_loan() - - -@pytest.mark.asyncio() -async def test_papi_get_repay_futures_switch(clientAsync): - await clientAsync.papi_get_repay_futures_switch() - - -@pytest.mark.asyncio() -async def test_papi_repay_futures_switch(clientAsync): - await clientAsync.papi_repay_futures_switch() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_interest_history(clientAsync): - await clientAsync.papi_get_margin_interest_history() - - -@pytest.mark.asyncio() -async def test_papi_repay_futures_negative_balance(clientAsync): - await clientAsync.papi_repay_futures_negative_balance() - - -@pytest.mark.asyncio() -async def test_papi_get_portfolio_interest_history(clientAsync): - await clientAsync.papi_get_portfolio_interest_history() - - -@pytest.mark.asyncio() -async def test_papi_fund_auto_collection(clientAsync): - await clientAsync.papi_fund_auto_collection() - - -@pytest.mark.asyncio() -async def test_papi_fund_asset_collection(clientAsync): - await clientAsync.papi_fund_asset_collection() - - -@pytest.mark.asyncio() -async def test_papi_bnb_transfer(clientAsync): - await clientAsync.papi_bnb_transfer() - - -@pytest.mark.asyncio() -async def test_papi_get_um_income_history(clientAsync): - await clientAsync.papi_get_um_income_history() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_income_history(clientAsync): - await clientAsync.papi_get_cm_income_history() - - -@pytest.mark.asyncio() -async def test_papi_get_um_account(clientAsync): - await clientAsync.papi_get_um_account() - - -@pytest.mark.asyncio() -async def test_papi_get_um_account_v2(clientAsync): - await clientAsync.papi_get_um_account_v2() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_account(clientAsync): - await clientAsync.papi_get_cm_account() - - -@pytest.mark.asyncio() -async def test_papi_get_um_account_config(clientAsync): - await clientAsync.papi_get_um_account_config() - - -@pytest.mark.asyncio() -async def test_papi_get_um_symbol_config(clientAsync): - await clientAsync.papi_get_um_symbol_config() - - -@pytest.mark.asyncio() -async def test_papi_get_um_trade_asyn(clientAsync): - await clientAsync.papi_get_um_trade_asyn() - - -@pytest.mark.asyncio() -async def test_papi_get_um_trade_asyn_id(clientAsync): - await clientAsync.papi_get_um_trade_asyn_id() - - -@pytest.mark.asyncio() -async def test_papi_get_um_order_asyn(clientAsync): - await clientAsync.papi_get_um_order_asyn() - - -@pytest.mark.asyncio() -async def test_papi_get_um_order_asyn_id(clientAsync): - await clientAsync.papi_get_um_order_asyn_id() - - -@pytest.mark.asyncio() -async def test_papi_get_um_income_asyn(clientAsync): - await clientAsync.papi_get_um_income_asyn() - - -@pytest.mark.asyncio() -async def test_papi_get_um_income_asyn_id(clientAsync): - await clientAsync.papi_get_um_income_asyn_id() - - -# Public papi endpoints - - -@pytest.mark.asyncio() -async def test_papi_ping(clientAsync): - await clientAsync.papi_ping() - - -# Trade papi endpoints - - -@pytest.mark.asyncio() -async def test_papi_create_um_order(clientAsync): - await clientAsync.papi_create_um_order() - - -@pytest.mark.asyncio() -async def test_papi_create_um_conditional_order(clientAsync): - await clientAsync.papi_create_um_conditional_order() - - -@pytest.mark.asyncio() -async def test_papi_create_cm_order(clientAsync): - await clientAsync.papi_create_cm_order() - - -@pytest.mark.asyncio() -async def test_papi_create_cm_conditional_order(clientAsync): - await clientAsync.papi_create_cm_conditional_order() - - -@pytest.mark.asyncio() -async def test_papi_create_margin_order(clientAsync): - await clientAsync.papi_create_margin_order() - - -@pytest.mark.asyncio() -async def test_papi_margin_loan(clientAsync): - await clientAsync.papi_margin_loan() - - -@pytest.mark.asyncio() -async def test_papi_repay_loan(clientAsync): - await clientAsync.papi_repay_loan() - - -@pytest.mark.asyncio() -async def test_papi_margin_order_oco(clientAsync): - await clientAsync.papi_margin_order_oco() - - -@pytest.mark.asyncio() -async def test_papi_cancel_um_order(clientAsync): - await clientAsync.papi_cancel_um_order() - - -@pytest.mark.asyncio() -async def test_papi_cancel_um_all_open_orders(clientAsync): - await clientAsync.papi_cancel_um_all_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_cancel_um_conditional_order(clientAsync): - await clientAsync.papi_cancel_um_conditional_order() - - -@pytest.mark.asyncio() -async def test_papi_cancel_um_conditional_all_open_orders(clientAsync): - await clientAsync.papi_cancel_um_conditional_all_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_cancel_cm_order(clientAsync): - await clientAsync.papi_cancel_cm_order() - - -@pytest.mark.asyncio() -async def test_papi_cancel_cm_all_open_orders(clientAsync): - await clientAsync.papi_cancel_cm_all_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_cancel_cm_conditional_order(clientAsync): - await clientAsync.papi_cancel_cm_conditional_order() - - -@pytest.mark.asyncio() -async def test_papi_cancel_cm_conditional_all_open_orders(clientAsync): - await clientAsync.papi_cancel_cm_conditional_all_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_cancel_margin_order(clientAsync): - await clientAsync.papi_cancel_margin_order() - - -@pytest.mark.asyncio() -async def test_papi_cancel_margin_order_list(clientAsync): - await clientAsync.papi_cancel_margin_order_list() - - -@pytest.mark.asyncio() -async def test_papi_cancel_margin_all_open_orders(clientAsync): - await clientAsync.papi_cancel_margin_all_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_modify_um_order(clientAsync): - await clientAsync.papi_modify_um_order() - - -@pytest.mark.asyncio() -async def test_papi_modify_cm_order(clientAsync): - await clientAsync.papi_modify_cm_order() - - -@pytest.mark.asyncio() -async def test_papi_get_um_order(clientAsync): - await clientAsync.papi_get_um_order() - - -@pytest.mark.asyncio() -async def test_papi_get_um_all_orders(clientAsync): - await clientAsync.papi_get_um_all_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_um_open_order(clientAsync): - await clientAsync.papi_get_um_open_order() - - -@pytest.mark.asyncio() -async def test_papi_get_um_open_orders(clientAsync): - await clientAsync.papi_get_um_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_um_conditional_all_orders(clientAsync): - await clientAsync.papi_get_um_conditional_all_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_um_conditional_open_orders(clientAsync): - await clientAsync.papi_get_um_conditional_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_um_conditional_open_order(clientAsync): - await clientAsync.papi_get_um_conditional_open_order() - - -@pytest.mark.asyncio() -async def test_papi_get_um_conditional_order_history(clientAsync): - await clientAsync.papi_get_um_conditional_order_history() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_order(clientAsync): - await clientAsync.papi_get_cm_order() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_all_orders(clientAsync): - await clientAsync.papi_get_cm_all_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_open_order(clientAsync): - await clientAsync.papi_get_cm_open_order() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_open_orders(clientAsync): - await clientAsync.papi_get_cm_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_conditional_all_orders(clientAsync): - await clientAsync.papi_get_cm_conditional_all_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_conditional_open_orders(clientAsync): - await clientAsync.papi_get_cm_conditional_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_conditional_open_order(clientAsync): - await clientAsync.papi_get_cm_conditional_open_order() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_conditional_order_history(clientAsync): - await clientAsync.papi_get_cm_conditional_order_history() - - -@pytest.mark.asyncio() -async def test_papi_get_um_force_orders(clientAsync): - await clientAsync.papi_get_um_force_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_force_orders(clientAsync): - await clientAsync.papi_get_cm_force_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_um_order_amendment(clientAsync): - await clientAsync.papi_get_um_order_amendment() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_order_amendment(clientAsync): - await clientAsync.papi_get_cm_order_amendment() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_force_orders(clientAsync): - await clientAsync.papi_get_margin_force_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_um_user_trades(clientAsync): - await clientAsync.papi_get_um_user_trades() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_user_trades(clientAsync): - await clientAsync.papi_get_cm_user_trades() - - -@pytest.mark.asyncio() -async def test_papi_get_um_adl_quantile(clientAsync): - await clientAsync.papi_get_um_adl_quantile() - - -@pytest.mark.asyncio() -async def test_papi_get_cm_adl_quantile(clientAsync): - await clientAsync.papi_get_cm_adl_quantile() - - -@pytest.mark.asyncio() -async def test_papi_set_um_fee_burn(clientAsync): - await clientAsync.papi_set_um_fee_burn() - - -@pytest.mark.asyncio() -async def test_papi_get_um_fee_burn(clientAsync): - await clientAsync.papi_get_um_fee_burn() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_order(clientAsync): - await clientAsync.papi_get_margin_order() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_open_orders(clientAsync): - await clientAsync.papi_get_margin_open_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_all_orders(clientAsync): - await clientAsync.papi_get_margin_all_orders() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_order_list(clientAsync): - await clientAsync.papi_get_margin_order_list() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_all_order_list(clientAsync): - await clientAsync.papi_get_margin_all_order_list() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_open_order_list(clientAsync): - await clientAsync.papi_get_margin_open_order_list() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_my_trades(clientAsync): - await clientAsync.papi_get_margin_my_trades() - - -@pytest.mark.asyncio() -async def test_papi_get_margin_repay_debt(clientAsync): - await clientAsync.papi_get_margin_repay_debt() - - -@pytest.mark.asyncio() -async def test_close_connection(clientAsync): - await clientAsync.close_connection() - - ######################### # Websocket API Requests # ######################### -@pytest.mark.asyncio() async def test_ws_get_order_book(clientAsync): await clientAsync.ws_get_order_book(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_recent_trades(clientAsync): await clientAsync.ws_get_recent_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_historical_trades(clientAsync): await clientAsync.ws_get_historical_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_aggregate_trades(clientAsync): await clientAsync.ws_get_aggregate_trades(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_klines(clientAsync): await clientAsync.ws_get_klines(symbol="BTCUSDT", interval="1m") -@pytest.mark.asyncio() async def test_ws_get_uiKlines(clientAsync): await clientAsync.ws_get_uiKlines(symbol="BTCUSDT", interval="1m") -@pytest.mark.asyncio() async def test_ws_get_avg_price(clientAsync): await clientAsync.ws_get_avg_price(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_ticker(clientAsync): ticker = await clientAsync.ws_get_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_trading_day_ticker(clientAsync): await clientAsync.ws_get_trading_day_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_symbol_ticker_window(clientAsync): await clientAsync.ws_get_symbol_ticker_window(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_symbol_ticker(clientAsync): await clientAsync.ws_get_symbol_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_get_orderbook_ticker(clientAsync): await clientAsync.ws_get_orderbook_ticker(symbol="BTCUSDT") -@pytest.mark.asyncio() async def test_ws_ping(clientAsync): await clientAsync.ws_ping() -@pytest.mark.asyncio() async def test_ws_get_time(clientAsync): await clientAsync.ws_get_time() -@pytest.mark.asyncio() async def test_ws_get_exchange_info(clientAsync): await clientAsync.ws_get_exchange_info(symbol="BTCUSDT") diff --git a/tests/test_async_client_futures.py b/tests/test_async_client_futures.py new file mode 100644 index 00000000..88a000dd --- /dev/null +++ b/tests/test_async_client_futures.py @@ -0,0 +1,559 @@ +from datetime import datetime + +import pytest +from .test_order import assert_contract_order +from .test_get_order_book import assert_ob + +pytestmark = [pytest.mark.futures, pytest.mark.asyncio] + + +async def test_futures_ping(futuresClientAsync): + await futuresClientAsync.futures_ping() + + +async def test_futures_time(futuresClientAsync): + await futuresClientAsync.futures_time() + + +async def test_futures_exchange_info(futuresClientAsync): + await futuresClientAsync.futures_exchange_info() + + +async def test_futures_order_book(futuresClientAsync): + order_book = await futuresClientAsync.futures_order_book(symbol="BTCUSDT") + assert_ob(order_book) + + +async def test_futures_recent_trades(futuresClientAsync): + await futuresClientAsync.futures_recent_trades(symbol="BTCUSDT") + + +async def test_futures_historical_trades(futuresClientAsync): + await futuresClientAsync.futures_historical_trades(symbol="BTCUSDT") + + +async def test_futures_aggregate_trades(futuresClientAsync): + await futuresClientAsync.futures_aggregate_trades(symbol="BTCUSDT") + + +async def test_futures_klines(futuresClientAsync): + await futuresClientAsync.futures_klines(symbol="BTCUSDT", interval="1h") + + +async def test_futures_continous_klines(futuresClientAsync): + await futuresClientAsync.futures_continous_klines( + pair="BTCUSDT", contractType="PERPETUAL", interval="1h" + ) + + +async def test_futures_historical_klines(futuresClientAsync): + await futuresClientAsync.futures_historical_klines( + symbol="BTCUSDT", interval="1h", start_str=datetime.now().strftime("%Y-%m-%d") + ) + + +async def test_futures_historical_klines_generator(futuresClientAsync): + await futuresClientAsync.futures_historical_klines_generator( + symbol="BTCUSDT", interval="1h", start_str=datetime.now().strftime("%Y-%m-%d") + ) + + +async def test_futures_mark_price(futuresClientAsync): + await futuresClientAsync.futures_mark_price() + + +async def test_futures_funding_rate(futuresClientAsync): + await futuresClientAsync.futures_funding_rate() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_top_longshort_account_ratio(futuresClientAsync): + await futuresClientAsync.futures_top_longshort_account_ratio() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_top_longshort_position_ratio(futuresClientAsync): + await futuresClientAsync.futures_top_longshort_position_ratio() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_global_longshort_ratio(futuresClientAsync): + await futuresClientAsync.futures_global_longshort_ratio() + + +async def test_futures_ticker(futuresClientAsync): + await futuresClientAsync.futures_ticker() + + +async def test_futures_symbol_ticker(futuresClientAsync): + await futuresClientAsync.futures_symbol_ticker() + + +async def test_futures_orderbook_ticker(futuresClientAsync): + await futuresClientAsync.futures_orderbook_ticker() + + +async def test_futures_liquidation_orders(futuresClientAsync): + await futuresClientAsync.futures_liquidation_orders() + + +async def test_futures_api_trading_status(futuresClientAsync): + await futuresClientAsync.futures_api_trading_status() + + +async def test_futures_commission_rate(futuresClientAsync): + await futuresClientAsync.futures_commission_rate(symbol="BTCUSDT") + + +async def test_futures_adl_quantile_estimate(futuresClientAsync): + await futuresClientAsync.futures_adl_quantile_estimate() + + +async def test_futures_open_interest(futuresClientAsync): + await futuresClientAsync.futures_open_interest(symbol="BTCUSDT") + + +async def test_futures_index_info(futuresClientAsync): + await futuresClientAsync.futures_index_info() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_open_interest_hist(futuresClientAsync): + await futuresClientAsync.futures_open_interest_hist(symbol="BTCUSDT") + + +async def test_futures_leverage_bracket(futuresClientAsync): + await futuresClientAsync.futures_leverage_bracket() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_account_transfer(futuresClientAsync): + await futuresClientAsync.futures_account_transfer() + + +@pytest.mark.skip(reason="Not implemented") +async def test_transfer_history(client): + client.transfer_history() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_loan_borrow_history(futuresClientAsync): + await futuresClientAsync.futures_loan_borrow_history() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_loan_repay_history(futuresClientAsync): + await futuresClientAsync.futures_loan_repay_history() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_loan_wallet(futuresClientAsync): + await futuresClientAsync.futures_loan_wallet() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_cross_collateral_adjust_history(futuresClientAsync): + await futuresClientAsync.futures_cross_collateral_adjust_history() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_cross_collateral_liquidation_history(futuresClientAsync): + await futuresClientAsync.futures_cross_collateral_liquidation_history() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_loan_interest_history(futuresClientAsync): + await futuresClientAsync.futures_loan_interest_history() + + +async def test_futures_create_get_edit_cancel_order(futuresClientAsync): + ticker = await futuresClientAsync.futures_ticker(symbol="LTCUSDT") + positions = await futuresClientAsync.futures_position_information(symbol="LTCUSDT") + order = await futuresClientAsync.futures_create_order( + symbol=ticker["symbol"], + side="BUY", + positionSide=positions[0]["positionSide"], + type="LIMIT", + timeInForce="GTC", + quantity=0.1, + price=str(round(float(ticker["lastPrice"]) - 1)), + ) + assert_contract_order(futuresClientAsync, order) + order = await futuresClientAsync.futures_modify_order( + orderid=order["orderId"], + symbol=order["symbol"], + quantity=0.11, + side=order["side"], + price=order["price"], + ) + assert_contract_order(futuresClientAsync, order) + order = await futuresClientAsync.futures_get_order( + symbol=order["symbol"], orderid=order["orderId"] + ) + assert_contract_order(futuresClientAsync, order) + order = await futuresClientAsync.futures_cancel_order( + orderid=order["orderId"], symbol=order["symbol"] + ) + + +async def test_futures_create_test_order(futuresClientAsync): + ticker = await futuresClientAsync.futures_ticker(symbol="LTCUSDT") + positions = await futuresClientAsync.futures_position_information(symbol="LTCUSDT") + await futuresClientAsync.futures_create_test_order( + symbol=ticker["symbol"], + side="BUY", + positionSide=positions[0]["positionSide"], + type="LIMIT", + timeInForce="GTC", + quantity=0.1, + price=str(round(float(ticker["lastPrice"]) - 1, 0)), + ) + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_place_batch_order_and_cancel(futuresClientAsync): + ticker = await futuresClientAsync.futures_ticker(symbol="LTCUSDT") + positions = await futuresClientAsync.futures_position_information(symbol="LTCUSDT") + orders = await futuresClientAsync.futures_place_batch_order( + batchOrders=[ + { + "symbol": ticker["symbol"], + "side": "BUY", + "positionSide": positions[0]["positionSide"], + "type": "LIMIT", + "timeInForce": "GTC", + "quantity": "0.1", + "price": str(round(float(ticker["lastPrice"]) - 1, 0)), + } + ] + ) + for order in orders: + assert_contract_order(futuresClientAsync, order) + + order_ids = [order["orderId"] for order in orders] + # orders = await futuresClientAsync.futures_cancel_orders(symbol=orders[0]["symbol"], orderidList=order_ids) + # for order in orders: + # assert_contract_order(futuresClientAsync, order) + + +async def test_futures_get_open_orders(futuresClientAsync): + await futuresClientAsync.futures_get_open_orders() + + +async def test_futures_get_all_orders(futuresClientAsync): + orders = futuresClientAsync.futures_get_all_orders() + print(orders) + + +async def test_futures_cancel_all_open_orders(futuresClientAsync): + await futuresClientAsync.futures_cancel_all_open_orders(symbol="LTCUSDT") + + +async def test_futures_countdown_cancel_all(futuresClientAsync): + await futuresClientAsync.futures_countdown_cancel_all( + symbol="LTCUSDT", countdownTime=10 + ) + + +async def test_futures_account_balance(futuresClientAsync): + await futuresClientAsync.futures_account_balance() + + +async def test_futures_account(futuresClientAsync): + await futuresClientAsync.futures_account() + + +async def test_futures_change_leverage(futuresClientAsync): + await futuresClientAsync.futures_change_leverage(symbol="LTCUSDT", leverage=10) + + +async def test_futures_change_margin_type(futuresClientAsync): + try: + await futuresClientAsync.futures_change_margin_type( + symbol="XRPUSDT", marginType="CROSSED" + ) + except Exception as e: + await futuresClientAsync.futures_change_margin_type( + symbol="XRPUSDT", marginType="ISOLATED" + ) + + +async def test_futures_position_margin_history(futuresClientAsync): + position = await futuresClientAsync.futures_position_margin_history( + symbol="LTCUSDT" + ) + print(position) + + +async def test_futures_position_information(futuresClientAsync): + await futuresClientAsync.futures_position_information() + + +async def test_futures_account_trades(futuresClientAsync): + await futuresClientAsync.futures_account_trades() + + +async def test_futures_income_history(futuresClientAsync): + await futuresClientAsync.futures_income_history() + + +async def close_all_futures_positions(futuresClientAsync): + # Get all open positions + positions = await futuresClientAsync.futures_position_information(symbol="LTCUSDT") + + for position in positions: + # Check if there is an open position + if float(position["positionAmt"]) != 0: + symbol = position["symbol"] + position_amt = float(position["positionAmt"]) + side = "SELL" if position_amt > 0 else "BUY" + + # Place a market order to close the position + try: + print(f"Closing position for {symbol}: {position_amt} units") + await futuresClientAsync.futures_create_order( + symbol=symbol, side=side, type="market", quantity=abs(position_amt) + ) + print(f"Position for {symbol} closed successfully.") + except Exception as e: + print(f"Failed to close position for {symbol}: {e}") + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_get_and_change_position_mode(futuresClientAsync): + mode = await futuresClientAsync.futures_get_position_mode() + await futuresClientAsync.futures_change_position_mode( + dualSidePosition=not mode["dualSidePosition"] + ) + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_change_multi_assets_mode(futuresClientAsync): + await futuresClientAsync.futures_change_multi_assets_mode() + + +async def test_futures_get_multi_assets_mode(futuresClientAsync): + await futuresClientAsync.futures_get_multi_assets_mode() + + +async def test_futures_stream_get_listen_key(futuresClientAsync): + await futuresClientAsync.futures_stream_get_listen_key() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_stream_close(futuresClientAsync): + await futuresClientAsync.futures_stream_close() + + +# new methods +async def test_futures_account_config(futuresClientAsync): + await futuresClientAsync.futures_account_config() + + +async def test_futures_symbol_config(futuresClientAsync): + await futuresClientAsync.futures_symbol_config() + + +# COIN Futures API +async def test_futures_coin_ping(futuresClientAsync): + await futuresClientAsync.futures_coin_ping() + + +async def test_futures_coin_time(futuresClientAsync): + await futuresClientAsync.futures_coin_time() + + +async def test_futures_coin_exchange_info(futuresClientAsync): + await futuresClientAsync.futures_coin_exchange_info() + + +async def test_futures_coin_order_book(futuresClientAsync): + order_book = await futuresClientAsync.futures_coin_order_book(symbol="BTCUSD_PERP") + assert_ob(order_book) + + +async def test_futures_coin_recent_trades(futuresClientAsync): + await futuresClientAsync.futures_coin_recent_trades(symbol="BTCUSD_PERP") + + +async def test_futures_coin_historical_trades(futuresClientAsync): + await futuresClientAsync.futures_coin_historical_trades(symbol="BTCUSD_PERP") + + +async def test_futures_coin_aggregate_trades(futuresClientAsync): + await futuresClientAsync.futures_coin_aggregate_trades(symbol="BTCUSD_PERP") + + +async def test_futures_coin_klines(futuresClientAsync): + await futuresClientAsync.futures_coin_klines(symbol="BTCUSD_PERP", interval="1h") + + +async def test_futures_coin_continous_klines(futuresClientAsync): + await futuresClientAsync.futures_coin_continous_klines( + pair="BTCUSD", contractType="PERPETUAL", interval="1h" + ) + + +async def test_futures_coin_index_price_klines(futuresClientAsync): + await futuresClientAsync.futures_coin_index_price_klines( + pair="BTCUSD", interval="1h" + ) + + +async def test_futures_coin_mark_price_klines(futuresClientAsync): + await futuresClientAsync.futures_coin_mark_price_klines( + symbol="BTCUSD_PERP", interval="1h" + ) + + +async def test_futures_coin_mark_price(futuresClientAsync): + await futuresClientAsync.futures_coin_mark_price() + + +async def test_futures_coin_funding_rate(futuresClientAsync): + await futuresClientAsync.futures_coin_funding_rate(symbol="BTCUSD_PERP") + + +async def test_futures_coin_ticker(futuresClientAsync): + await futuresClientAsync.futures_coin_ticker() + + +async def test_futures_coin_symbol_ticker(futuresClientAsync): + await futuresClientAsync.futures_coin_symbol_ticker() + + +async def test_futures_coin_orderbook_ticker(futuresClientAsync): + await futuresClientAsync.futures_coin_orderbook_ticker() + + +async def test_futures_coin_liquidation_orders(futuresClientAsync): + await futuresClientAsync.futures_coin_liquidation_orders() + + +async def test_futures_coin_open_interest(futuresClientAsync): + await futuresClientAsync.futures_coin_open_interest(symbol="BTCUSD_PERP") + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_open_interest_hist(futuresClientAsync): + await futuresClientAsync.futures_coin_open_interest_hist(symbol="BTCUSD_PERP") + + +async def test_futures_coin_leverage_bracket(futuresClientAsync): + await futuresClientAsync.futures_coin_leverage_bracket() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_create_order(futuresClientAsync): + positions = await futuresClientAsync.futures_coin_position_information() + ticker = await futuresClientAsync.futures_coin_ticker(symbol=positions[0]["symbol"]) + order = await futuresClientAsync.futures_coin_create_order( + symbol=positions[0]["symbol"], + side="BUY", + type="LIMIT", + timeInForce="GTC", + quantity=1, + price=str(round(float(ticker[0]["lastPrice"]) - 1, 0)), + ) + assert_contract_order(futuresClientAsync, order) + order = await futuresClientAsync.futures_modify_order( + orderid=order["orderId"], + symbol=order["symbol"], + quantity=0.11, + side=order["side"], + price=order["price"], + ) + assert_contract_order(futuresClientAsync, order) + order = await futuresClientAsync.futures_get_order( + symbol=order["symbol"], orderid=order["orderId"] + ) + assert_contract_order(futuresClientAsync, order) + order = await futuresClientAsync.futures_cancel_order( + orderid=order["orderId"], symbol=order["symbol"] + ) + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_place_batch_order(futuresClientAsync): + await futuresClientAsync.futures_coin_place_batch_order() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_get_order(futuresClientAsync): + await futuresClientAsync.futures_coin_get_order() + + +async def test_futures_coin_get_open_orders(futuresClientAsync): + await futuresClientAsync.futures_coin_get_open_orders() + + +async def test_futures_coin_get_all_orders(futuresClientAsync): + await futuresClientAsync.futures_coin_get_all_orders() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_cancel_order(futuresClientAsync): + await futuresClientAsync.futures_coin_cancel_order() + + +async def test_futures_coin_cancel_all_open_orders(futuresClientAsync): + await futuresClientAsync.futures_coin_cancel_all_open_orders(symbol="BTCUSD_PERP") + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_cancel_orders(futuresClientAsync): + await futuresClientAsync.futures_coin_cancel_orders() + + +async def test_futures_coin_account_balance(futuresClientAsync): + await futuresClientAsync.futures_coin_account_balance() + + +async def test_futures_coin_account(futuresClientAsync): + await futuresClientAsync.futures_coin_account() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_change_leverage(futuresClientAsync): + await futuresClientAsync.futures_coin_change_leverage(symbol="XRPUSDT", leverage=10) + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_change_margin_type(futuresClientAsync): + await futuresClientAsync.futures_coin_change_margin_type() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_change_position_margin(futuresClientAsync): + await futuresClientAsync.futures_coin_change_position_margin() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_position_margin_history(futuresClientAsync): + await futuresClientAsync.futures_coin_position_margin_history() + + +async def test_futures_coin_position_information(futuresClientAsync): + await futuresClientAsync.futures_coin_position_information() + + +async def test_futures_coin_account_trades(futuresClientAsync): + await futuresClientAsync.futures_coin_account_trades() + + +async def test_futures_coin_income_history(futuresClientAsync): + await futuresClientAsync.futures_coin_income_history() + + +@pytest.mark.skip(reason="Not implemented") +async def test_futures_coin_change_position_mode(futuresClientAsync): + await futuresClientAsync.futures_coin_change_position_mode() + + +async def test_futures_coin_get_position_mode(futuresClientAsync): + await futuresClientAsync.futures_coin_get_position_mode() + + +async def test_futures_coin_stream_close(futuresClientAsync): + listen_key = await futuresClientAsync.futures_coin_stream_get_listen_key() + await futuresClientAsync.futures_coin_stream_close(listenKey=listen_key) diff --git a/tests/test_async_client_margin.py b/tests/test_async_client_margin.py new file mode 100644 index 00000000..38019bc4 --- /dev/null +++ b/tests/test_async_client_margin.py @@ -0,0 +1,562 @@ +import pytest + + +pytestmark = [pytest.mark.margin, pytest.mark.asyncio] + + +async def test_margin__get_account_status(asyncClient): + await asyncClient.get_account_status() + + +async def test_margin_get_account_api_trading_status(asyncClient): + await asyncClient.get_account_api_trading_status() + + +async def test_margin_get_account_api_permissions(asyncClient): + await asyncClient.get_account_api_permissions() + + +async def test_margin_get_dust_assets(asyncClient): + await asyncClient.get_dust_assets() + + +async def test_margin_get_dust_log(asyncClient): + await asyncClient.test_get_dust_log() + + +async def test_margin_transfer_dust(asyncClient): + await asyncClient.transfer_dust() + + +async def test_margin_get_asset_dividend_history(asyncClient): + await asyncClient.get_asset_dividend_history() + + +async def test_margin_make_universal_transfer(asyncClient): + await asyncClient.make_universal_transfer() + + +async def test_margin_query_universal_transfer_history(asyncClient): + await asyncClient.query_universal_transfer_history() + + +async def test_margin_get_trade_fee(asyncClient): + await asyncClient.get_trade_fee() + + +async def test_margin_get_asset_details(asyncClient): + await asyncClient.get_asset_details() + + +async def test_margin_get_spot_delist_schedule(asyncClient): + await asyncClient.get_spot_delist_schedule() + + +# Withdraw Endpoints + + +async def test_margin_withdraw(asyncClient): + await asyncClient.withdraw() + + +async def test_margin_get_deposit_history(asyncClient): + await asyncClient.get_deposit_history() + + +async def test_margin_get_withdraw_history(asyncClient): + await asyncClient.get_withdraw_history() + + +async def test_margin_get_withdraw_history_id(asyncClient): + await asyncClient.get_withdraw_history_id() + + +async def test_margin_get_deposit_address(asyncClient): + await asyncClient.get_deposit_address() + + +# Margin Trading Endpoints + + +async def test_margin_get_margin_account(asyncClient): + await asyncClient.get_margin_account() + + +async def test_margin_get_isolated_margin_account(asyncClient): + await asyncClient.get_isolated_margin_account() + + +async def test_margin_enable_isolated_margin_account(asyncClient): + await asyncClient.enable_isolated_margin_account() + + +async def test_margin_disable_isolated_margin_account(asyncClient): + await asyncClient.disable_isolated_margin_account() + + +async def test_margin_get_enabled_isolated_margin_account_limit(asyncClient): + await asyncClient.get_enabled_isolated_margin_account_limit() + + +async def test_margin_get_margin_dustlog(asyncClient): + await asyncClient.get_margin_dustlog() + + +async def test_margin_get_margin_dust_assets(asyncClient): + await asyncClient.get_margin_dust_assets() + + +async def test_margin_transfer_margin_dust(asyncClient): + await asyncClient.transfer_margin_dust() + + +async def test_margin_get_cross_margin_collateral_ratio(asyncClient): + await asyncClient.get_cross_margin_collateral_ratio() + + +async def test_margin_get_small_liability_exchange_assets(asyncClient): + await asyncClient.get_small_liability_exchange_assets() + + +async def test_margin_exchange_small_liability_assets(asyncClient): + await asyncClient.exchange_small_liability_assets() + + +async def test_margin_get_small_liability_exchange_history(asyncClient): + await asyncClient.get_small_liability_exchange_history() + + +async def test_margin_get_future_hourly_interest_rate(asyncClient): + await asyncClient.get_future_hourly_interest_rate() + + +async def test_margin_get_margin_capital_flow(asyncClient): + await asyncClient.get_margin_capital_flow() + + +async def test_margin_get_margin_asset(asyncClient): + await asyncClient.get_margin_asset() + + +async def test_margin_get_margin_symbol(asyncClient): + await asyncClient.get_margin_symbol() + + +async def test_margin_get_margin_all_assets(asyncClient): + await asyncClient.get_margin_all_assets() + + +async def test_margin_get_margin_all_pairs(asyncClient): + await asyncClient.get_margin_all_pairs() + + +async def test_margin_create_isolated_margin_account(asyncClient): + await asyncClient.create_isolated_margin_account() + + +async def test_margin_get_isolated_margin_symbol(asyncClient): + await asyncClient.get_isolated_margin_symbol() + + +async def test_margin_get_all_isolated_margin_symbols(asyncClient): + await asyncClient.get_all_isolated_margin_symbols() + + +async def test_margin_get_isolated_margin_fee_data(asyncClient): + await asyncClient.get_isolated_margin_fee_data() + + +async def test_margin_get_isolated_margin_tier_data(asyncClient): + await asyncClient.get_isolated_margin_tier_data() + + +async def test_margin_margin_manual_liquidation(asyncClient): + await asyncClient.margin_manual_liquidation() + + +async def test_margin_toggle_bnb_burn_spot_margin(asyncClient): + await asyncClient.toggle_bnb_burn_spot_margin() + + +async def test_margin_get_bnb_burn_spot_margin(asyncClient): + await asyncClient.get_bnb_burn_spot_margin() + + +async def test_margin_get_margin_price_index(asyncClient): + await asyncClient.get_margin_price_index() + + +async def test_margin_transfer_margin_to_spot(asyncClient): + await asyncClient.transfer_margin_to_spot() + + +async def test_margin_transfer_spot_to_margin(asyncClient): + await asyncClient.transfer_spot_to_margin() + + +async def test_margin_transfer_isolated_margin_to_spot(asyncClient): + await asyncClient.transfer_isolated_margin_to_spot() + + +async def test_margin_transfer_spot_to_isolated_margin(asyncClient): + await asyncClient.transfer_spot_to_isolated_margin() + + +async def test_margin_get_isolated_margin_tranfer_history(asyncClient): + await asyncClient.get_isolated_margin_tranfer_history() + + +async def test_margin_create_margin_loan(asyncClient): + await asyncClient.create_margin_loan() + + +async def test_margin_repay_margin_loan(asyncClient): + await asyncClient.repay_margin_loan() + + +async def create_margin_ordertest_(asyncClient): + await asyncClient.create_margin_order() + + +async def test_margin_cancel_margin_order(asyncClient): + await asyncClient.cancel_margin_order() + + +async def test_margin_set_margin_max_leverage(asyncClient): + await asyncClient.set_margin_max_leverage() + + +async def test_margin_get_margin_transfer_history(asyncClient): + await asyncClient.get_margin_transfer_history() + + +async def test_margin_get_margin_loan_details(asyncClient): + await asyncClient.get_margin_loan_details() + + +async def test_margin_get_margin_repay_details(asyncClient): + await asyncClient.get_margin_repay_details() + + +async def test_margin_get_cross_margin_data(asyncClient): + await asyncClient.get_cross_margin_data() + + +async def test_margin_get_margin_interest_history(asyncClient): + await asyncClient.get_margin_interest_history() + + +async def test_margin_get_margin_force_liquidation_rec(asyncClient): + await asyncClient.get_margin_force_liquidation_rec() + + +async def test_margin_get_margin_order(asyncClient): + await asyncClient.get_margin_order() + + +async def test_margin_get_open_margin_orders(asyncClient): + await asyncClient.get_open_margin_orders() + + +async def test_margin_get_all_margin_orders(asyncClient): + await asyncClient.get_all_margin_orders() + + +async def test_margin_get_margin_trades(asyncClient): + await asyncClient.get_margin_trades() + + +async def test_margin_get_max_margin_loan(asyncClient): + await asyncClient.get_max_margin_loan() + + +async def test_margin_get_max_margin_transfer(asyncClient): + await asyncClient.get_max_margin_transfer() + + +async def test_margin_get_margin_delist_schedule(asyncClient): + await asyncClient.get_margin_delist_schedule() + + +# Margin OCO + + +async def test_margin_create_margin_oco_order(asyncClient): + await asyncClient.create_margin_oco_order() + + +async def test_margin_cancel_margin_oco_order(asyncClient): + await asyncClient.cancel_margin_oco_order() + + +async def test_margin_get_margin_oco_order(asyncClient): + await asyncClient.get_margin_oco_order() + + +async def test_margin_get_open_margin_oco_orders(asyncClient): + await asyncClient.get_open_margin_oco_orders() + + +# Cross-margin + + +async def test_margin_margin_stream_get_listen_key(asyncClient): + await asyncClient.margin_stream_get_listen_key() + + +async def test_margin_margin_stream_close(asyncClient): + await asyncClient.margin_stream_close() + + +# Isolated margin + + +async def test_margin_isolated_margin_stream_get_listen_key(asyncClient): + await asyncClient.isolated_margin_stream_get_listen_key() + + +async def test_margin_isolated_margin_stream_close(asyncClient): + await asyncClient.isolated_margin_stream_close() + + +# Simple Earn Endpoints + + +async def test_margin_get_simple_earn_flexible_product_list(asyncClient): + await asyncClient.get_simple_earn_flexible_product_list() + + +async def test_margin_get_simple_earn_locked_product_list(asyncClient): + await asyncClient.get_simple_earn_locked_product_list() + + +async def test_margin_subscribe_simple_earn_flexible_product(asyncClient): + await asyncClient.subscribe_simple_earn_flexible_product() + + +async def test_margin_subscribe_simple_earn_locked_product(asyncClient): + await asyncClient.subscribe_simple_earn_locked_product() + + +async def test_margin_redeem_simple_earn_flexible_product(asyncClient): + await asyncClient.redeem_simple_earn_flexible_product() + + +async def test_margin_redeem_simple_earn_locked_product(asyncClient): + await asyncClient.redeem_simple_earn_locked_product() + + +async def test_margin_get_simple_earn_flexible_product_position(asyncClient): + await asyncClient.get_simple_earn_flexible_product_position() + + +async def test_margin_get_simple_earn_locked_product_position(asyncClient): + await asyncClient.get_simple_earn_locked_product_position() + + +async def test_margin_get_simple_earn_account(asyncClient): + await asyncClient.get_simple_earn_account() + + +# Lending Endpoints + + +async def test_margin_get_fixed_activity_project_list(asyncClient): + await asyncClient.get_fixed_activity_project_list() + + +async def test_margin_change_fixed_activity_to_daily_position(asyncClient): + await asyncClient.change_fixed_activity_to_daily_position() + + +# Staking Endpoints + + +async def test_margin_get_staking_product_list(asyncClient): + await asyncClient.get_staking_product_list() + + +async def test_margin_purchase_staking_product(asyncClient): + await asyncClient.purchase_staking_product() + + +async def test_margin_redeem_staking_product(asyncClient): + await asyncClient.redeem_staking_product() + + +async def test_margin_get_staking_position(asyncClient): + await asyncClient.get_staking_position() + + +async def test_margin_get_staking_purchase_history(asyncClient): + await asyncClient.get_staking_purchase_history() + + +async def test_margin_set_auto_staking(asyncClient): + await asyncClient.set_auto_staking() + + +async def test_margin_get_personal_left_quota(asyncClient): + await asyncClient.get_personal_left_quota() + + +# US Staking Endpoints + + +async def test_margin_get_staking_asset_us(asyncClient): + await asyncClient.get_staking_asset_us() + + +async def test_margin_stake_asset_us(asyncClient): + await asyncClient.stake_asset_us() + + +async def test_margin_unstake_asset_us(asyncClient): + await asyncClient.unstake_asset_us() + + +async def test_margin_get_staking_balance_us(asyncClient): + await asyncClient.get_staking_balance_us() + + +async def test_margin_get_staking_history_us(asyncClient): + await asyncClient.get_staking_history_us() + + +async def test_margin_get_staking_rewards_history_us(asyncClient): + await asyncClient.get_staking_rewards_history_us() + + +# Sub Accounts + + +async def test_margin_get_sub_account_list(asyncClient): + await asyncClient.get_sub_account_list() + + +async def test_margin_get_sub_account_transfer_history(asyncClient): + await asyncClient.get_sub_account_transfer_history() + + +async def test_margin_get_sub_account_futures_transfer_history(asyncClient): + await asyncClient.get_sub_account_futures_transfer_history() + + +async def test_margin_create_sub_account_futures_transfer(asyncClient): + await asyncClient.create_sub_account_futures_transfer() + + +async def test_margin_get_sub_account_assets(asyncClient): + await asyncClient.get_sub_account_assets() + + +async def test_margin_query_subaccount_spot_summary(asyncClient): + await asyncClient.query_subaccount_spot_summary() + + +async def test_margin_get_subaccount_deposit_address(asyncClient): + await asyncClient.get_subaccount_deposit_address() + + +async def test_margin_get_subaccount_deposit_history(asyncClient): + await asyncClient.get_subaccount_deposit_history() + + +async def test_margin_get_subaccount_futures_margin_status(asyncClient): + await asyncClient.get_subaccount_futures_margin_status() + + +async def test_margin_enable_subaccount_margin(asyncClient): + await asyncClient.enable_subaccount_margin() + + +async def test_margin_get_subaccount_margin_details(asyncClient): + await asyncClient.get_subaccount_margin_details() + + +async def test_margin_get_subaccount_margin_summary(asyncClient): + await asyncClient.get_subaccount_margin_summary() + + +async def test_margin_enable_subaccount_futures(asyncClient): + await asyncClient.enable_subaccount_futures() + + +async def test_margin_get_subaccount_futures_details(asyncClient): + await asyncClient.get_subaccount_futures_details() + + +async def test_margin_get_subaccount_futures_summary(asyncClient): + await asyncClient.get_subaccount_futures_summary() + + +async def test_margin_get_subaccount_futures_positionrisk(asyncClient): + await asyncClient.get_subaccount_futures_positionrisk() + + +async def test_margin_make_subaccount_futures_transfer(asyncClient): + await asyncClient.make_subaccount_futures_transfer() + + +async def test_margin_make_subaccount_margin_transfer(asyncClient): + await asyncClient.make_subaccount_margin_transfer() + + +async def test_margin_make_subaccount_to_subaccount_transfer(asyncClient): + await asyncClient.make_subaccount_to_subaccount_transfer() + + +async def test_margin_make_subaccount_to_master_transfer(asyncClient): + await asyncClient.make_subaccount_to_master_transfer() + + +async def test_margin_get_subaccount_transfer_history(asyncClient): + await asyncClient.get_subaccount_transfer_history() + + +async def test_margin_make_subaccount_universal_transfer(asyncClient): + await asyncClient.make_subaccount_universal_transfer() + + +async def test_margin_get_universal_transfer_history(asyncClient): + await asyncClient.get_universal_transfer_history() + + +# Fiat Endpoints + + +async def test_margin_get_fiat_deposit_withdraw_history(asyncClient): + await asyncClient.get_fiat_deposit_withdraw_history() + + +async def test_margin_get_fiat_payments_history(asyncClient): + await asyncClient.get_fiat_payments_history() + + +# C2C Endpoints + + +async def test_margin_get_c2c_trade_history(asyncClient): + await asyncClient.get_c2c_trade_history() + + +# Pay Endpoints + + +async def test_margin_get_pay_trade_history(asyncClient): + await asyncClient.get_pay_trade_history() + + +# Convert Endpoints + + +async def test_margin_get_convert_trade_history(asyncClient): + await asyncClient.get_convert_trade_history() + + +async def test_margin_convert_request_quote(asyncClient): + await asyncClient.convert_request_quote() + + +async def test_margin_convert_accept_quote(asyncClient): + await asyncClient.convert_accept_quote() diff --git a/tests/test_async_client_options.py b/tests/test_async_client_options.py new file mode 100644 index 00000000..7e3ce25c --- /dev/null +++ b/tests/test_async_client_options.py @@ -0,0 +1,123 @@ +import pytest + + +pytestmark = [pytest.mark.options, pytest.mark.asyncio] + + +@pytest.fixture +def options_symbol(optionsClient): + prices = optionsClient.options_price() + return prices[0]["symbol"] + + +async def test_options_ping(optionsClientAsync): + await optionsClientAsync.options_ping() + + +async def test_options_time(optionsClientAsync): + await optionsClientAsync.options_time() + + +@pytest.mark.skip(reason="Not implemented") +async def test_options_info(optionsClientAsync): + await optionsClientAsync.options_info() + + +async def test_options_exchange_info(optionsClientAsync): + await optionsClientAsync.options_exchange_info() + + +async def test_options_index_price(optionsClientAsync): + await optionsClientAsync.options_index_price(underlying="BTCUSDT") + + +async def test_options_price(optionsClientAsync): + prices = await optionsClientAsync.options_price() + + +async def test_options_mark_price(optionsClientAsync): + await optionsClientAsync.options_mark_price() + + +async def test_options_order_book(optionsClientAsync, options_symbol): + await optionsClientAsync.options_order_book(symbol=options_symbol) + + +async def test_options_klines(optionsClientAsync, options_symbol): + await optionsClientAsync.options_klines(symbol=options_symbol, interval="1m") + + +async def test_options_recent_trades(optionsClientAsync, options_symbol): + await optionsClientAsync.options_recent_trades(symbol=options_symbol) + + +async def test_options_historical_trades(optionsClientAsync, options_symbol): + await optionsClientAsync.options_historical_trades(symbol=options_symbol) + + +# Account and trading interface endpoints + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_account_info(optionsClientAsync): + await optionsClientAsync.options_account_info() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_funds_transfer(optionsClientAsync): + await optionsClientAsync.options_funds_transfer() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_positions(optionsClientAsync): + await optionsClientAsync.options_positions() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_bill(optionsClientAsync): + await optionsClientAsync.options_bill() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_place_order(optionsClientAsync): + await optionsClientAsync.options_place_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_test_options_place_batch_order(optionsClientAsync): + await optionsClientAsync.test_options_place_batch_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_cancel_order(optionsClientAsync): + await optionsClientAsync.options_cancel_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_cancel_batch_order(optionsClientAsync): + await optionsClientAsync.options_cancel_batch_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_cancel_all_orders(optionsClientAsync): + await optionsClientAsync.options_cancel_all_orders() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_query_order(optionsClientAsync): + await optionsClientAsync.options_query_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_query_pending_orders(optionsClientAsync): + await optionsClientAsync.options_query_pending_orders() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_query_order_history(optionsClientAsync): + await optionsClientAsync.options_query_order_history() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +async def test_options_user_trades(optionsClientAsync): + await optionsClientAsync.options_user_trades() diff --git a/tests/test_async_client_portfolio.py b/tests/test_async_client_portfolio.py new file mode 100644 index 00000000..824db17a --- /dev/null +++ b/tests/test_async_client_portfolio.py @@ -0,0 +1,398 @@ +import pytest + +# Apply the 'portfolio' mark to all tests in this file +pytestmark = [pytest.mark.portfolio, pytest.mark.asyncio] + + +async def test_papi_get_balance(client): + await client.papi_get_balance() + + +async def test_papi_get_account(client): + await client.papi_get_account() + + +async def test_papi_get_margin_max_borrowable(client): + await client.papi_get_margin_max_borrowable() + + +async def test_papi_get_margin_max_withdraw(client): + await client.papi_get_margin_max_withdraw() + + +async def test_papi_get_um_position_risk(client): + await client.papi_get_um_position_risk() + + +async def test_papi_get_cm_position_risk(client): + await client.papi_get_cm_position_risk() + + +async def test_papi_set_um_leverage(client): + await client.papi_set_um_leverage() + + +async def test_papi_set_cm_leverage(client): + await client.papi_set_cm_leverage() + + +async def test_papi_change_um_position_side_dual(client): + await client.papi_change_um_position_side_dual() + + +async def test_papi_get_um_position_side_dual(client): + await client.papi_get_um_position_side_dual() + + +async def test_papi_get_cm_position_side_dual(client): + await client.papi_get_cm_position_side_dual() + + +async def test_papi_get_um_leverage_bracket(client): + await client.papi_get_um_leverage_bracket() + + +async def test_papi_get_cm_leverage_bracket(client): + await client.papi_get_cm_leverage_bracket() + + +async def test_papi_get_um_api_trading_status(client): + await client.papi_get_um_api_trading_status() + + +async def test_papi_get_um_comission_rate(client): + await client.papi_get_um_comission_rate() + + +async def test_papi_get_cm_comission_rate(client): + await client.papi_get_cm_comission_rate() + + +async def test_papi_get_margin_margin_loan(client): + await client.papi_get_margin_margin_loan() + + +async def test_papi_get_margin_repay_loan(client): + await client.papi_get_margin_repay_loan() + + +async def test_papi_get_repay_futures_switch(client): + await client.papi_get_repay_futures_switch() + + +async def test_papi_repay_futures_switch(client): + await client.papi_repay_futures_switch() + + +async def test_papi_get_margin_interest_history(client): + await client.papi_get_margin_interest_history() + + +async def test_papi_repay_futures_negative_balance(client): + await client.papi_repay_futures_negative_balance() + + +async def test_papi_get_portfolio_interest_history(client): + await client.papi_get_portfolio_interest_history() + + +async def test_papi_fund_auto_collection(client): + await client.papi_fund_auto_collection() + + +async def test_papi_fund_asset_collection(client): + await client.papi_fund_asset_collection() + + +async def test_papi_bnb_transfer(client): + await client.papi_bnb_transfer() + + +async def test_papi_get_um_income_history(client): + await client.papi_get_um_income_history() + + +async def test_papi_get_cm_income_history(client): + await client.papi_get_cm_income_history() + + +async def test_papi_get_um_account(client): + await client.papi_get_um_account() + + +async def test_papi_get_um_account_v2(client): + await client.papi_get_um_account_v2() + + +async def test_papi_get_cm_account(client): + await client.papi_get_cm_account() + + +async def test_papi_get_um_account_config(client): + await client.papi_get_um_account_config() + + +async def test_papi_get_um_symbol_config(client): + await client.papi_get_um_symbol_config() + + +async def test_papi_get_um_trade_asyn(client): + await client.papi_get_um_trade_asyn() + + +async def test_papi_get_um_trade_asyn_id(client): + await client.papi_get_um_trade_asyn_id() + + +async def test_papi_get_um_order_asyn(client): + await client.papi_get_um_order_asyn() + + +async def test_papi_get_um_order_asyn_id(client): + await client.papi_get_um_order_asyn_id() + + +async def test_papi_get_um_income_asyn(client): + await client.papi_get_um_income_asyn() + + +async def test_papi_get_um_income_asyn_id(client): + await client.papi_get_um_income_asyn_id() + + +# Public papi endpoints + + +async def test_papi_ping(client): + await client.papi_ping() + + +# Trade papi endpoints + + +async def test_papi_create_um_order(client): + await client.papi_create_um_order() + + +async def test_papi_create_um_conditional_order(client): + await client.papi_create_um_conditional_order() + + +async def test_papi_create_cm_order(client): + await client.papi_create_cm_order() + + +async def test_papi_create_cm_conditional_order(client): + await client.papi_create_cm_conditional_order() + + +async def test_papi_create_margin_order(client): + await client.papi_create_margin_order() + + +async def test_papi_margin_loan(client): + await client.papi_margin_loan() + + +async def test_papi_repay_loan(client): + await client.papi_repay_loan() + + +async def test_papi_margin_order_oco(client): + await client.papi_margin_order_oco() + + +async def test_papi_cancel_um_order(client): + await client.papi_cancel_um_order() + + +async def test_papi_cancel_um_all_open_orders(client): + await client.papi_cancel_um_all_open_orders() + + +async def test_papi_cancel_um_conditional_order(client): + await client.papi_cancel_um_conditional_order() + + +async def test_papi_cancel_um_conditional_all_open_orders(client): + await client.papi_cancel_um_conditional_all_open_orders() + + +async def test_papi_cancel_cm_order(client): + await client.papi_cancel_cm_order() + + +async def test_papi_cancel_cm_all_open_orders(client): + await client.papi_cancel_cm_all_open_orders() + + +async def test_papi_cancel_cm_conditional_order(client): + await client.papi_cancel_cm_conditional_order() + + +async def test_papi_cancel_cm_conditional_all_open_orders(client): + await client.papi_cancel_cm_conditional_all_open_orders() + + +async def test_papi_cancel_margin_order(client): + await client.papi_cancel_margin_order() + + +async def test_papi_cancel_margin_order_list(client): + await client.papi_cancel_margin_order_list() + + +async def test_papi_cancel_margin_all_open_orders(client): + await client.papi_cancel_margin_all_open_orders() + + +async def test_papi_modify_um_order(client): + await client.papi_modify_um_order() + + +async def test_papi_modify_cm_order(client): + await client.papi_modify_cm_order() + + +async def test_papi_get_um_order(client): + await client.papi_get_um_order() + + +async def test_papi_get_um_all_orders(client): + await client.papi_get_um_all_orders() + + +async def test_papi_get_um_open_order(client): + await client.papi_get_um_open_order() + + +async def test_papi_get_um_open_orders(client): + await client.papi_get_um_open_orders() + + +async def test_papi_get_um_conditional_all_orders(client): + await client.papi_get_um_conditional_all_orders() + + +async def test_papi_get_um_conditional_open_orders(client): + await client.papi_get_um_conditional_open_orders() + + +async def test_papi_get_um_conditional_open_order(client): + await client.papi_get_um_conditional_open_order() + + +async def test_papi_get_um_conditional_order_history(client): + await client.papi_get_um_conditional_order_history() + + +async def test_papi_get_cm_order(client): + await client.papi_get_cm_order() + + +async def test_papi_get_cm_all_orders(client): + await client.papi_get_cm_all_orders() + + +async def test_papi_get_cm_open_order(client): + await client.papi_get_cm_open_order() + + +async def test_papi_get_cm_open_orders(client): + await client.papi_get_cm_open_orders() + + +async def test_papi_get_cm_conditional_all_orders(client): + await client.papi_get_cm_conditional_all_orders() + + +async def test_papi_get_cm_conditional_open_orders(client): + await client.papi_get_cm_conditional_open_orders() + + +async def test_papi_get_cm_conditional_open_order(client): + await client.papi_get_cm_conditional_open_order() + + +async def test_papi_get_cm_conditional_order_history(client): + await client.papi_get_cm_conditional_order_history() + + +async def test_papi_get_um_force_orders(client): + await client.papi_get_um_force_orders() + + +async def test_papi_get_cm_force_orders(client): + await client.papi_get_cm_force_orders() + + +async def test_papi_get_um_order_amendment(client): + await client.papi_get_um_order_amendment() + + +async def test_papi_get_cm_order_amendment(client): + await client.papi_get_cm_order_amendment() + + +async def test_papi_get_margin_force_orders(client): + await client.papi_get_margin_force_orders() + + +async def test_papi_get_um_user_trades(client): + await client.papi_get_um_user_trades() + + +async def test_papi_get_cm_user_trades(client): + await client.papi_get_cm_user_trades() + + +async def test_papi_get_um_adl_quantile(client): + await client.papi_get_um_adl_quantile() + + +async def test_papi_get_cm_adl_quantile(client): + await client.papi_get_cm_adl_quantile() + + +async def test_papi_set_um_fee_burn(client): + await client.papi_set_um_fee_burn() + + +async def test_papi_get_um_fee_burn(client): + await client.papi_get_um_fee_burn() + + +async def test_papi_get_margin_order(client): + await client.papi_get_margin_order() + + +async def test_papi_get_margin_open_orders(client): + await client.papi_get_margin_open_orders() + + +async def test_papi_get_margin_all_orders(client): + await client.papi_get_margin_all_orders() + + +async def test_papi_get_margin_order_list(client): + await client.papi_get_margin_order_list() + + +async def test_papi_get_margin_all_order_list(client): + await client.papi_get_margin_all_order_list() + + +async def test_papi_get_margin_open_order_list(client): + await client.papi_get_margin_open_order_list() + + +async def test_papi_get_margin_my_trades(client): + await client.papi_get_margin_my_trades() + + +async def test_papi_get_margin_repay_debt(client): + await client.papi_get_margin_repay_debt() + + +async def test_close_connection(client): + await client.close_connection() diff --git a/tests/test_client.py b/tests/test_client.py index af76c6ac..e3552835 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,11 +1,14 @@ +import pytest + + def test_client_initialization(client): assert client.API_KEY is not None assert client.API_SECRET is not None -# TODO: whitelist in proxy to pass test -# def test_get_products(client): -# client.get_products() +@pytest.mark.skip(reason="Endpoint not documented") +def test_get_products(client): + client.get_products() def test_get_exchange_info(client): @@ -84,685 +87,17 @@ def test_get_system_status(client): client.get_system_status() -# TODO: Tests not working on testnet -# def test_get_account_status(client): -# client.get_account_status() - - -def test_get_account_api_trading_status(client): - client.get_account_api_trading_status() - - -def test_get_account_api_permissions(client): - client.get_account_api_permissions() - - -def test_get_dust_assets(client): - client.get_dust_assets() - - -def test_get_dust_log(client): - client.test_get_dust_log() - - -def test_transfer_dust(client): - client.transfer_dust() - - -def test_get_asset_dividend_history(client): - client.get_asset_dividend_history() - - -def test_make_universal_transfer(client): - client.make_universal_transfer() - - -def test_query_universal_transfer_history(client): - client.query_universal_transfer_history() - - -def test_get_trade_fee(client): - client.get_trade_fee() - - -def test_get_asset_details(client): - client.get_asset_details() - - -def test_get_spot_delist_schedule(client): - client.get_spot_delist_schedule() - - -# Withdraw Endpoints - - -def test_withdraw(client): - client.withdraw() - - -def test_get_deposit_history(client): - client.get_deposit_history() - - -def test_get_withdraw_history(client): - client.get_withdraw_history() - - -def test_get_withdraw_history_id(client): - client.get_withdraw_history_id() - - -def test_get_deposit_address(client): - client.get_deposit_address() - - # User Stream Endpoints -def test_stream_get_listen_key(client): - client.stream_get_listen_key() - - -def test_stream_close(client): - client.stream_close() - - -# Margin Trading Endpoints - - -def test_get_margin_account(client): - client.get_margin_account() - - -def test_get_isolated_margin_account(client): - client.get_isolated_margin_account() - - -def test_enable_isolated_margin_account(client): - client.enable_isolated_margin_account() - - -def test_disable_isolated_margin_account(client): - client.disable_isolated_margin_account() - - -def test_get_enabled_isolated_margin_account_limit(client): - client.get_enabled_isolated_margin_account_limit() - - -def test_get_margin_dustlog(client): - client.get_margin_dustlog() - - -def test_get_margin_dust_assets(client): - client.get_margin_dust_assets() - - -def test_transfer_margin_dust(client): - client.transfer_margin_dust() - - -def test_get_cross_margin_collateral_ratio(client): - client.get_cross_margin_collateral_ratio() - - -def test_get_small_liability_exchange_assets(client): - client.get_small_liability_exchange_assets() - - -def test_exchange_small_liability_assets(client): - client.exchange_small_liability_assets() - - -def test_get_small_liability_exchange_history(client): - client.get_small_liability_exchange_history() - - -def test_get_future_hourly_interest_rate(client): - client.get_future_hourly_interest_rate() - - -def test_get_margin_capital_flow(client): - client.get_margin_capital_flow() - - -def test_get_margin_asset(client): - client.get_margin_asset() - - -def test_get_margin_symbol(client): - client.get_margin_symbol() - - -def test_get_margin_all_assets(client): - client.get_margin_all_assets() - - -def test_get_margin_all_pairs(client): - client.get_margin_all_pairs() - - -def test_create_isolated_margin_account(client): - client.create_isolated_margin_account() - - -def test_get_isolated_margin_symbol(client): - client.get_isolated_margin_symbol() - - -def test_get_all_isolated_margin_symbols(client): - client.get_all_isolated_margin_symbols() - - -def test_get_isolated_margin_fee_data(client): - client.get_isolated_margin_fee_data() - - -def test_get_isolated_margin_tier_data(client): - client.get_isolated_margin_tier_data() - - -def test_margin_manual_liquidation(client): - client.margin_manual_liquidation() - - -def test_toggle_bnb_burn_spot_margin(client): - client.toggle_bnb_burn_spot_margin() - - -def test_get_bnb_burn_spot_margin(client): - client.get_bnb_burn_spot_margin() - - -def test_get_margin_price_index(client): - client.get_margin_price_index() - - -def test_transfer_margin_to_spot(client): - client.transfer_margin_to_spot() - - -def test_transfer_spot_to_margin(client): - client.transfer_spot_to_margin() - - -def test_transfer_isolated_margin_to_spot(client): - client.transfer_isolated_margin_to_spot() - - -def test_transfer_spot_to_isolated_margin(client): - client.transfer_spot_to_isolated_margin() - - -def test_get_isolated_margin_tranfer_history(client): - client.get_isolated_margin_tranfer_history() - - -def test_create_margin_loan(client): - client.create_margin_loan() - - -def test_repay_margin_loan(client): - client.repay_margin_loan() - - -def create_margin_ordertest_(client): - client.create_margin_order() - - -def test_cancel_margin_order(client): - client.cancel_margin_order() - - -def test_set_margin_max_leverage(client): - client.set_margin_max_leverage() - - -def test_get_margin_transfer_history(client): - client.get_margin_transfer_history() - - -def test_get_margin_loan_details(client): - client.get_margin_loan_details() - - -def test_get_margin_repay_details(client): - client.get_margin_repay_details() - - -def test_get_cross_margin_data(client): - client.get_cross_margin_data() - - -def test_get_margin_interest_history(client): - client.get_margin_interest_history() - - -def test_get_margin_force_liquidation_rec(client): - client.get_margin_force_liquidation_rec() - - -def test_get_margin_order(client): - client.get_margin_order() - - -def test_get_open_margin_orders(client): - client.get_open_margin_orders() - - -def test_get_all_margin_orders(client): - client.get_all_margin_orders() - - -def test_get_margin_trades(client): - client.get_margin_trades() - - -def test_get_max_margin_loan(client): - client.get_max_margin_loan() - - -def test_get_max_margin_transfer(client): - client.get_max_margin_transfer() - - -def test_get_margin_delist_schedule(client): - client.get_margin_delist_schedule() - - -# Margin OCO - - -def test_create_margin_oco_order(client): - client.create_margin_oco_order() - - -def test_cancel_margin_oco_order(client): - client.cancel_margin_oco_order() - - -def test_get_margin_oco_order(client): - client.get_margin_oco_order() - - -def test_get_open_margin_oco_orders(client): - client.get_open_margin_oco_orders() - - -# Cross-margin - - -def test_margin_stream_get_listen_key(client): - client.margin_stream_get_listen_key() - - -def test_margin_stream_close(client): - client.margin_stream_close() - - -# Isolated margin - - -def test_isolated_margin_stream_get_listen_key(client): - client.isolated_margin_stream_get_listen_key() - - -def test_isolated_margin_stream_close(client): - client.isolated_margin_stream_close() - - -# Simple Earn Endpoints - - -def test_get_simple_earn_flexible_product_list(client): - client.get_simple_earn_flexible_product_list() - - -def test_get_simple_earn_locked_product_list(client): - client.get_simple_earn_locked_product_list() - - -def test_subscribe_simple_earn_flexible_product(client): - client.subscribe_simple_earn_flexible_product() - - -def test_subscribe_simple_earn_locked_product(client): - client.subscribe_simple_earn_locked_product() - - -def test_redeem_simple_earn_flexible_product(client): - client.redeem_simple_earn_flexible_product() - - -def test_redeem_simple_earn_locked_product(client): - client.redeem_simple_earn_locked_product() - - -def test_get_simple_earn_flexible_product_position(client): - client.get_simple_earn_flexible_product_position() - - -def test_get_simple_earn_locked_product_position(client): - client.get_simple_earn_locked_product_position() - - -def test_get_simple_earn_account(client): - client.get_simple_earn_account() - - -# Lending Endpoints - - -def test_get_fixed_activity_project_list(client): - client.get_fixed_activity_project_list() - - -def test_change_fixed_activity_to_daily_position(client): - client.change_fixed_activity_to_daily_position() - - -# Staking Endpoints - - -def test_get_staking_product_list(client): - client.get_staking_product_list() - - -def test_purchase_staking_product(client): - client.purchase_staking_product() - - -def test_redeem_staking_product(client): - client.redeem_staking_product() - - -def test_get_staking_position(client): - client.get_staking_position() - - -def test_get_staking_purchase_history(client): - client.get_staking_purchase_history() - - -def test_set_auto_staking(client): - client.set_auto_staking() - - -def test_get_personal_left_quota(client): - client.get_personal_left_quota() - - -# US Staking Endpoints - - -def test_get_staking_asset_us(client): - client.get_staking_asset_us() - - -def test_stake_asset_us(client): - client.stake_asset_us() - - -def test_unstake_asset_us(client): - client.unstake_asset_us() - - -def test_get_staking_balance_us(client): - client.get_staking_balance_us() - - -def test_get_staking_history_us(client): - client.get_staking_history_us() - - -def test_get_staking_rewards_history_us(client): - client.get_staking_rewards_history_us() - - -# Sub Accounts - - -def test_get_sub_account_list(client): - client.get_sub_account_list() - - -def test_get_sub_account_transfer_history(client): - client.get_sub_account_transfer_history() - - -def test_get_sub_account_futures_transfer_history(client): - client.get_sub_account_futures_transfer_history() - - -def test_create_sub_account_futures_transfer(client): - client.create_sub_account_futures_transfer() - - -def test_get_sub_account_assets(client): - client.get_sub_account_assets() - - -def test_query_subaccount_spot_summary(client): - client.query_subaccount_spot_summary() - - -def test_get_subaccount_deposit_address(client): - client.get_subaccount_deposit_address() - - -def test_get_subaccount_deposit_history(client): - client.get_subaccount_deposit_history() - - -def test_get_subaccount_futures_margin_status(client): - client.get_subaccount_futures_margin_status() - - -def test_enable_subaccount_margin(client): - client.enable_subaccount_margin() - - -def test_get_subaccount_margin_details(client): - client.get_subaccount_margin_details() - - -def test_get_subaccount_margin_summary(client): - client.get_subaccount_margin_summary() - - -def test_enable_subaccount_futures(client): - client.enable_subaccount_futures() - - -def test_get_subaccount_futures_details(client): - client.get_subaccount_futures_details() - - -def test_get_subaccount_futures_summary(client): - client.get_subaccount_futures_summary() - - -def test_get_subaccount_futures_positionrisk(client): - client.get_subaccount_futures_positionrisk() - - -def test_make_subaccount_futures_transfer(client): - client.make_subaccount_futures_transfer() - - -def test_make_subaccount_margin_transfer(client): - client.make_subaccount_margin_transfer() - - -def test_make_subaccount_to_subaccount_transfer(client): - client.make_subaccount_to_subaccount_transfer() - - -def test_make_subaccount_to_master_transfer(client): - client.make_subaccount_to_master_transfer() - - -def test_get_subaccount_transfer_history(client): - client.get_subaccount_transfer_history() - - -def test_make_subaccount_universal_transfer(client): - client.make_subaccount_universal_transfer() - - -def test_get_universal_transfer_history(client): - client.get_universal_transfer_history() - - -# Futures API - - +def test_stream_get_listen_key_and_close(client): + listen_key = client.stream_get_listen_key() + client.stream_close(listen_key) # Quoting interface endpoints -def test_options_ping(client): - client.options_ping() - - -def test_options_time(client): - client.options_time() - - -def test_options_info(client): - client.options_info() - - -def test_options_exchange_info(client): - client.options_exchange_info() - - -def test_options_index_price(client): - client.options_index_price() - - -def test_options_price(client): - client.options_price() - - -def test_options_mark_price(client): - client.options_mark_price() - - -def test_options_order_book(client): - client.options_order_book() - - -def test_options_klines(client): - client.options_klines() - - -def test_options_recent_trades(client): - client.options_recent_trades() - - -def test_options_historical_trades(client): - client.options_historical_trades() - - -# Account and trading interface endpoints - - -def test_options_account_info(client): - client.options_account_info() - - -def test_options_funds_transfer(client): - client.options_funds_transfer() - - -def test_options_positions(client): - client.options_positions() - - -def test_options_bill(client): - client.options_bill() - - -def test_options_place_order(client): - client.options_place_order() - - -def test_test_options_place_batch_order(client): - client.test_options_place_batch_order() - - -def test_options_cancel_order(client): - client.options_cancel_order() - - -def test_options_cancel_batch_order(client): - client.options_cancel_batch_order() - - -def test_options_cancel_all_orders(client): - client.options_cancel_all_orders() - - -def test_options_query_order(client): - client.options_query_order() - - -def test_options_query_pending_orders(client): - client.options_query_pending_orders() - - -def test_options_query_order_history(client): - client.options_query_order_history() - - -def test_options_user_trades(client): - client.options_user_trades() - - -# Fiat Endpoints - - -def test_get_fiat_deposit_withdraw_history(client): - client.get_fiat_deposit_withdraw_history() - - -def test_get_fiat_payments_history(client): - client.get_fiat_payments_history() - - -# C2C Endpoints - - -def test_get_c2c_trade_history(client): - client.get_c2c_trade_history() - - -# Pay Endpoints - - -def test_get_pay_trade_history(client): - client.get_pay_trade_history() - - -# Convert Endpoints - - -def test_get_convert_trade_history(client): - client.get_convert_trade_history() - - -def test_convert_request_quote(client): - client.convert_request_quote() - - -def test_convert_accept_quote(client): - client.convert_accept_quote() - - - - ######################### # Websocket API Requests # ######################### diff --git a/tests/test_client_futures.py b/tests/test_client_futures.py index 98383ed7..5f2c5dcc 100644 --- a/tests/test_client_futures.py +++ b/tests/test_client_futures.py @@ -2,6 +2,8 @@ import pytest from .test_order import assert_contract_order +from .test_get_order_book import assert_ob + def test_futures_ping(futuresClient): futuresClient.futures_ping() @@ -16,7 +18,8 @@ def test_futures_exchange_info(futuresClient): def test_futures_order_book(futuresClient): - futuresClient.futures_order_book(symbol="BTCUSDT") + order_book = futuresClient.futures_order_book(symbol="BTCUSDT") + assert_ob(order_book) def test_futures_recent_trades(futuresClient): @@ -36,15 +39,21 @@ def test_futures_klines(futuresClient): def test_futures_continous_klines(futuresClient): - futuresClient.futures_continous_klines(pair="BTCUSDT", contractType="PERPETUAL", interval="1h") + futuresClient.futures_continous_klines( + pair="BTCUSDT", contractType="PERPETUAL", interval="1h" + ) def test_futures_historical_klines(futuresClient): - futuresClient.futures_historical_klines(symbol="BTCUSDT", interval="1h", start_str=datetime.now().strftime("%Y-%m-%d")) + futuresClient.futures_historical_klines( + symbol="BTCUSDT", interval="1h", start_str=datetime.now().strftime("%Y-%m-%d") + ) def test_futures_historical_klines_generator(futuresClient): - futuresClient.futures_historical_klines_generator(symbol="BTCUSDT", interval="1h", start_str=datetime.now().strftime("%Y-%m-%d")) + futuresClient.futures_historical_klines_generator( + symbol="BTCUSDT", interval="1h", start_str=datetime.now().strftime("%Y-%m-%d") + ) def test_futures_mark_price(futuresClient): @@ -119,10 +128,12 @@ def test_futures_leverage_bracket(futuresClient): def test_futures_account_transfer(futuresClient): futuresClient.futures_account_transfer() + @pytest.mark.skip(reason="Not implemented") def test_transfer_history(client): client.transfer_history() + @pytest.mark.skip(reason="Not implemented") def test_futures_loan_borrow_history(futuresClient): futuresClient.futures_loan_borrow_history() @@ -132,6 +143,7 @@ def test_futures_loan_borrow_history(futuresClient): def test_futures_loan_repay_history(futuresClient): futuresClient.futures_loan_repay_history() + @pytest.mark.skip(reason="Not implemented") def test_futures_loan_wallet(futuresClient): futuresClient.futures_loan_wallet() @@ -192,23 +204,25 @@ def test_futures_create_test_order(futuresClient): type="LIMIT", timeInForce="GTC", quantity=0.1, - price=str(round(float(ticker["lastPrice"]) - 1)), + price=str(round(float(ticker["lastPrice"]) - 1, 0)), ) def test_futures_place_batch_order_and_cancel(futuresClient): ticker = futuresClient.futures_ticker(symbol="LTCUSDT") positions = futuresClient.futures_position_information(symbol="LTCUSDT") - orders =futuresClient.futures_place_batch_order( - batchOrders=[{ - "symbol": ticker["symbol"], - "side": "BUY", - "positionSide": positions[0]["positionSide"], - "type": "LIMIT", - "timeInForce": "GTC", - "quantity": '0.1', - "price": str(round(float(ticker["lastPrice"]) - 1)), - }] + orders = futuresClient.futures_place_batch_order( + batchOrders=[ + { + "symbol": ticker["symbol"], + "side": "BUY", + "positionSide": positions[0]["positionSide"], + "type": "LIMIT", + "timeInForce": "GTC", + "quantity": "0.1", + "price": str(round(float(ticker["lastPrice"]) - 1, 0)), + } + ] ) for order in orders: assert_contract_order(futuresClient, order) @@ -224,7 +238,7 @@ def test_futures_get_open_orders(futuresClient): def test_futures_get_all_orders(futuresClient): - orders=futuresClient.futures_get_all_orders() + orders = futuresClient.futures_get_all_orders() print(orders) @@ -232,8 +246,6 @@ def test_futures_cancel_all_open_orders(futuresClient): futuresClient.futures_cancel_all_open_orders(symbol="LTCUSDT") - - def test_futures_countdown_cancel_all(futuresClient): futuresClient.futures_countdown_cancel_all(symbol="LTCUSDT", countdownTime=10) @@ -254,13 +266,16 @@ def test_futures_change_margin_type(futuresClient): try: futuresClient.futures_change_margin_type(symbol="XRPUSDT", marginType="CROSSED") except Exception as e: - futuresClient.futures_change_margin_type(symbol="XRPUSDT", marginType="ISOLATED") + futuresClient.futures_change_margin_type( + symbol="XRPUSDT", marginType="ISOLATED" + ) def test_futures_position_margin_history(futuresClient): position = futuresClient.futures_position_margin_history(symbol="LTCUSDT") print(position) + def test_futures_position_information(futuresClient): futuresClient.futures_position_information() @@ -279,28 +294,29 @@ def close_all_futures_positions(futuresClient): for position in positions: # Check if there is an open position - if float(position['positionAmt']) != 0: - symbol = position['symbol'] - position_amt = float(position['positionAmt']) + if float(position["positionAmt"]) != 0: + symbol = position["symbol"] + position_amt = float(position["positionAmt"]) side = "SELL" if position_amt > 0 else "BUY" # Place a market order to close the position try: print(f"Closing position for {symbol}: {position_amt} units") futuresClient.futures_create_order( - symbol=symbol, - side=side, - type="market", - quantity=abs(position_amt) + symbol=symbol, side=side, type="market", quantity=abs(position_amt) ) print(f"Position for {symbol} closed successfully.") except Exception as e: - print(f"Failed") + print(f"Failed to close position for {symbol}: {e}") +@pytest.mark.skip(reason="Not implemented") def test_futures_get_and_change_position_mode(futuresClient): mode = futuresClient.futures_get_position_mode() - futuresClient.futures_change_position_mode(dualSidePosition=not mode['dualSidePosition']) + futuresClient.futures_change_position_mode( + dualSidePosition=not mode["dualSidePosition"] + ) + @pytest.mark.skip(reason="Not implemented") def test_futures_change_multi_assets_mode(futuresClient): @@ -342,53 +358,47 @@ def test_futures_coin_exchange_info(futuresClient): futuresClient.futures_coin_exchange_info() -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_order_book(futuresClient): - futuresClient.futures_coin_order_book() + order_book = futuresClient.futures_coin_order_book(symbol="BTCUSD_PERP") + assert_ob(order_book) -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_recent_trades(futuresClient): - futuresClient.futures_coin_recent_trades() + futuresClient.futures_coin_recent_trades(symbol="BTCUSD_PERP") -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_historical_trades(futuresClient): - futuresClient.futures_coin_historical_trades() + futuresClient.futures_coin_historical_trades(symbol="BTCUSD_PERP") -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_aggregate_trades(futuresClient): - futuresClient.futures_coin_aggregate_trades() + futuresClient.futures_coin_aggregate_trades(symbol="BTCUSD_PERP") -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_klines(futuresClient): - futuresClient.futures_coin_klines() + futuresClient.futures_coin_klines(symbol="BTCUSD_PERP", interval="1h") -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_continous_klines(futuresClient): - futuresClient.futures_coin_continous_klines() + futuresClient.futures_coin_continous_klines( + pair="BTCUSD", contractType="PERPETUAL", interval="1h" + ) -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_index_price_klines(futuresClient): - futuresClient.futures_coin_index_price_klines() + futuresClient.futures_coin_index_price_klines(pair="BTCUSD", interval="1h") -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_mark_price_klines(futuresClient): - futuresClient.futures_coin_mark_price_klines() + futuresClient.futures_coin_mark_price_klines(symbol="BTCUSD_PERP", interval="1h") def test_futures_coin_mark_price(futuresClient): futuresClient.futures_coin_mark_price() -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_funding_rate(futuresClient): - futuresClient.futures_coin_funding_rate() + futuresClient.futures_coin_funding_rate(symbol="BTCUSD_PERP") def test_futures_coin_ticker(futuresClient): @@ -407,43 +417,47 @@ def test_futures_coin_liquidation_orders(futuresClient): futuresClient.futures_coin_liquidation_orders() -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_open_interest(futuresClient): - futuresClient.futures_coin_open_interest() + futuresClient.futures_coin_open_interest(symbol="BTCUSD_PERP") @pytest.mark.skip(reason="Not implemented") def test_futures_coin_open_interest_hist(futuresClient): - futuresClient.futures_coin_open_interest_hist() + futuresClient.futures_coin_open_interest_hist(symbol="BTCUSD_PERP") def test_futures_coin_leverage_bracket(futuresClient): futuresClient.futures_coin_leverage_bracket() -@pytest.mark.skip(reason="Not implemented") -def test_new_transfer_history(futuresClient): - futuresClient.new_transfer_history() - - -@pytest.mark.skip(reason="Not implemented") -def test_funding_wallet(futuresClient): - futuresClient.funding_wallet() - - -@pytest.mark.skip(reason="Not implemented") -def test_get_user_asset(futuresClient): - futuresClient.get_user_asset() - - -@pytest.mark.skip(reason="Not implemented") -def test_universal_transfer(futuresClient): - futuresClient.universal_transfer() - - @pytest.mark.skip(reason="Not implemented") def test_futures_coin_create_order(futuresClient): - futuresClient.futures_coin_create_order() + positions = futuresClient.futures_coin_position_information() + ticker = futuresClient.futures_coin_ticker(symbol=positions[0]["symbol"]) + order = futuresClient.futures_coin_create_order( + symbol=positions[0]["symbol"], + side="BUY", + type="LIMIT", + timeInForce="GTC", + quantity=1, + price=str(round(float(ticker[0]["lastPrice"]) - 1, 0)), + ) + assert_contract_order(futuresClient, order) + order = futuresClient.futures_modify_order( + orderid=order["orderId"], + symbol=order["symbol"], + quantity=0.11, + side=order["side"], + price=order["price"], + ) + assert_contract_order(futuresClient, order) + order = futuresClient.futures_get_order( + symbol=order["symbol"], orderid=order["orderId"] + ) + assert_contract_order(futuresClient, order) + order = futuresClient.futures_cancel_order( + orderid=order["orderId"], symbol=order["symbol"] + ) @pytest.mark.skip(reason="Not implemented") @@ -460,7 +474,6 @@ def test_futures_coin_get_open_orders(futuresClient): futuresClient.futures_coin_get_open_orders() -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_get_all_orders(futuresClient): futuresClient.futures_coin_get_all_orders() @@ -470,9 +483,8 @@ def test_futures_coin_cancel_order(futuresClient): futuresClient.futures_coin_cancel_order() -@pytest.mark.skip(reason="Not implemented") def test_futures_coin_cancel_all_open_orders(futuresClient): - futuresClient.futures_coin_cancel_all_open_orders() + futuresClient.futures_coin_cancel_all_open_orders(symbol="BTCUSD_PERP") @pytest.mark.skip(reason="Not implemented") @@ -503,6 +515,7 @@ def test_futures_coin_change_position_margin(futuresClient): futuresClient.futures_coin_change_position_margin() +@pytest.mark.skip(reason="Not implemented") def test_futures_coin_position_margin_history(futuresClient): futuresClient.futures_coin_position_margin_history() @@ -531,23 +544,3 @@ def test_futures_coin_get_position_mode(futuresClient): def test_futures_coin_stream_close(futuresClient): listen_key = futuresClient.futures_coin_stream_get_listen_key() futuresClient.futures_coin_stream_close(listenKey=listen_key) - - -@pytest.mark.skip(reason="Not implemented") -def test_get_all_coins_info(futuresClient): - futuresClient.get_all_coins_info() - - -@pytest.mark.skip(reason="Not implemented") -def test_get_account_snapshot(futuresClient): - futuresClient.get_account_snapshot() - - -@pytest.mark.skip(reason="Not implemented") -def test_disable_fast_withdraw_switch(futuresClient): - futuresClient.disable_fast_withdraw_switch() - - -@pytest.mark.skip(reason="Not supported in testnet") -def test_enable_fast_withdraw_switch(futuresClient): - futuresClient.enable_fast_withdraw_switch() \ No newline at end of file diff --git a/tests/test_client_margin.py b/tests/test_client_margin.py new file mode 100644 index 00000000..5e6add03 --- /dev/null +++ b/tests/test_client_margin.py @@ -0,0 +1,594 @@ +import pytest + + +pytestmark = pytest.mark.margin + + +def test_margin__get_account_status(client): + client.get_account_status() + + +def test_margin_get_account_api_trading_status(client): + client.get_account_api_trading_status() + + +def test_margin_get_account_api_permissions(client): + client.get_account_api_permissions() + + +def test_margin_get_dust_assets(client): + client.get_dust_assets() + + +def test_margin_get_dust_log(client): + client.test_get_dust_log() + + +def test_margin_transfer_dust(client): + client.transfer_dust() + + +def test_margin_get_asset_dividend_history(client): + client.get_asset_dividend_history() + + +def test_margin_make_universal_transfer(client): + client.make_universal_transfer() + + +def test_margin_query_universal_transfer_history(client): + client.query_universal_transfer_history() + + +def test_margin_get_trade_fee(client): + client.get_trade_fee() + + +def test_margin_get_asset_details(client): + client.get_asset_details() + + +def test_margin_get_spot_delist_schedule(client): + client.get_spot_delist_schedule() + + +# Withdraw Endpoints + + +def test_margin_withdraw(client): + client.withdraw() + + +def test_margin_get_deposit_history(client): + client.get_deposit_history() + + +def test_margin_get_withdraw_history(client): + client.get_withdraw_history() + + +def test_margin_get_withdraw_history_id(client): + client.get_withdraw_history_id() + + +def test_margin_get_deposit_address(client): + client.get_deposit_address() + + +# Margin Trading Endpoints + + +def test_margin_get_margin_account(client): + client.get_margin_account() + + +def test_margin_get_isolated_margin_account(client): + client.get_isolated_margin_account() + + +def test_margin_enable_isolated_margin_account(client): + client.enable_isolated_margin_account() + + +def test_margin_disable_isolated_margin_account(client): + client.disable_isolated_margin_account() + + +def test_margin_get_enabled_isolated_margin_account_limit(client): + client.get_enabled_isolated_margin_account_limit() + + +def test_margin_get_margin_dustlog(client): + client.get_margin_dustlog() + + +def test_margin_get_margin_dust_assets(client): + client.get_margin_dust_assets() + + +def test_margin_transfer_margin_dust(client): + client.transfer_margin_dust() + + +def test_margin_get_cross_margin_collateral_ratio(client): + client.get_cross_margin_collateral_ratio() + + +def test_margin_get_small_liability_exchange_assets(client): + client.get_small_liability_exchange_assets() + + +def test_margin_exchange_small_liability_assets(client): + client.exchange_small_liability_assets() + + +def test_margin_get_small_liability_exchange_history(client): + client.get_small_liability_exchange_history() + + +def test_margin_get_future_hourly_interest_rate(client): + client.get_future_hourly_interest_rate() + + +def test_margin_get_margin_capital_flow(client): + client.get_margin_capital_flow() + + +def test_margin_get_margin_asset(client): + client.get_margin_asset() + + +def test_margin_get_margin_symbol(client): + client.get_margin_symbol() + + +def test_margin_get_margin_all_assets(client): + client.get_margin_all_assets() + + +def test_margin_get_margin_all_pairs(client): + client.get_margin_all_pairs() + + +def test_margin_create_isolated_margin_account(client): + client.create_isolated_margin_account() + + +def test_margin_get_isolated_margin_symbol(client): + client.get_isolated_margin_symbol() + + +def test_margin_get_all_isolated_margin_symbols(client): + client.get_all_isolated_margin_symbols() + + +def test_margin_get_isolated_margin_fee_data(client): + client.get_isolated_margin_fee_data() + + +def test_margin_get_isolated_margin_tier_data(client): + client.get_isolated_margin_tier_data() + + +def test_margin_margin_manual_liquidation(client): + client.margin_manual_liquidation() + + +def test_margin_toggle_bnb_burn_spot_margin(client): + client.toggle_bnb_burn_spot_margin() + + +def test_margin_get_bnb_burn_spot_margin(client): + client.get_bnb_burn_spot_margin() + + +def test_margin_get_margin_price_index(client): + client.get_margin_price_index() + + +def test_margin_transfer_margin_to_spot(client): + client.transfer_margin_to_spot() + + +def test_margin_transfer_spot_to_margin(client): + client.transfer_spot_to_margin() + + +def test_margin_transfer_isolated_margin_to_spot(client): + client.transfer_isolated_margin_to_spot() + + +def test_margin_transfer_spot_to_isolated_margin(client): + client.transfer_spot_to_isolated_margin() + + +def test_margin_get_isolated_margin_tranfer_history(client): + client.get_isolated_margin_tranfer_history() + + +def test_margin_create_margin_loan(client): + client.create_margin_loan() + + +def test_margin_repay_margin_loan(client): + client.repay_margin_loan() + + +def create_margin_ordertest_(client): + client.create_margin_order() + + +def test_margin_cancel_margin_order(client): + client.cancel_margin_order() + + +def test_margin_set_margin_max_leverage(client): + client.set_margin_max_leverage() + + +def test_margin_get_margin_transfer_history(client): + client.get_margin_transfer_history() + + +def test_margin_get_margin_loan_details(client): + client.get_margin_loan_details() + + +def test_margin_get_margin_repay_details(client): + client.get_margin_repay_details() + + +def test_margin_get_cross_margin_data(client): + client.get_cross_margin_data() + + +def test_margin_get_margin_interest_history(client): + client.get_margin_interest_history() + + +def test_margin_get_margin_force_liquidation_rec(client): + client.get_margin_force_liquidation_rec() + + +def test_margin_get_margin_order(client): + client.get_margin_order() + + +def test_margin_get_open_margin_orders(client): + client.get_open_margin_orders() + + +def test_margin_get_all_margin_orders(client): + client.get_all_margin_orders() + + +def test_margin_get_margin_trades(client): + client.get_margin_trades() + + +def test_margin_get_max_margin_loan(client): + client.get_max_margin_loan() + + +def test_margin_get_max_margin_transfer(client): + client.get_max_margin_transfer() + + +def test_margin_get_margin_delist_schedule(client): + client.get_margin_delist_schedule() + + +# Margin OCO + + +def test_margin_create_margin_oco_order(client): + client.create_margin_oco_order() + + +def test_margin_cancel_margin_oco_order(client): + client.cancel_margin_oco_order() + + +def test_margin_get_margin_oco_order(client): + client.get_margin_oco_order() + + +def test_margin_get_open_margin_oco_orders(client): + client.get_open_margin_oco_orders() + + +# Cross-margin + + +def test_margin_margin_stream_get_listen_key(client): + client.margin_stream_get_listen_key() + + +def test_margin_margin_stream_close(client): + client.margin_stream_close() + + +# Isolated margin + + +def test_margin_isolated_margin_stream_get_listen_key(client): + client.isolated_margin_stream_get_listen_key() + + +def test_margin_isolated_margin_stream_close(client): + client.isolated_margin_stream_close() + + +# Simple Earn Endpoints + + +def test_margin_get_simple_earn_flexible_product_list(client): + client.get_simple_earn_flexible_product_list() + + +def test_margin_get_simple_earn_locked_product_list(client): + client.get_simple_earn_locked_product_list() + + +def test_margin_subscribe_simple_earn_flexible_product(client): + client.subscribe_simple_earn_flexible_product() + + +def test_margin_subscribe_simple_earn_locked_product(client): + client.subscribe_simple_earn_locked_product() + + +def test_margin_redeem_simple_earn_flexible_product(client): + client.redeem_simple_earn_flexible_product() + + +def test_margin_redeem_simple_earn_locked_product(client): + client.redeem_simple_earn_locked_product() + + +def test_margin_get_simple_earn_flexible_product_position(client): + client.get_simple_earn_flexible_product_position() + + +def test_margin_get_simple_earn_locked_product_position(client): + client.get_simple_earn_locked_product_position() + + +def test_margin_get_simple_earn_account(client): + client.get_simple_earn_account() + + +# Lending Endpoints + + +def test_margin_get_fixed_activity_project_list(client): + client.get_fixed_activity_project_list() + + +def test_margin_change_fixed_activity_to_daily_position(client): + client.change_fixed_activity_to_daily_position() + + +# Staking Endpoints + + +def test_margin_get_staking_product_list(client): + client.get_staking_product_list() + + +def test_margin_purchase_staking_product(client): + client.purchase_staking_product() + + +def test_margin_redeem_staking_product(client): + client.redeem_staking_product() + + +def test_margin_get_staking_position(client): + client.get_staking_position() + + +def test_margin_get_staking_purchase_history(client): + client.get_staking_purchase_history() + + +def test_margin_set_auto_staking(client): + client.set_auto_staking() + + +def test_margin_get_personal_left_quota(client): + client.get_personal_left_quota() + + +# US Staking Endpoints + + +def test_margin_get_staking_asset_us(client): + client.get_staking_asset_us() + + +def test_margin_stake_asset_us(client): + client.stake_asset_us() + + +def test_margin_unstake_asset_us(client): + client.unstake_asset_us() + + +def test_margin_get_staking_balance_us(client): + client.get_staking_balance_us() + + +def test_margin_get_staking_history_us(client): + client.get_staking_history_us() + + +def test_margin_get_staking_rewards_history_us(client): + client.get_staking_rewards_history_us() + + +# Sub Accounts + + +def test_margin_get_sub_account_list(client): + client.get_sub_account_list() + + +def test_margin_get_sub_account_transfer_history(client): + client.get_sub_account_transfer_history() + + +def test_margin_get_sub_account_futures_transfer_history(client): + client.get_sub_account_futures_transfer_history() + + +def test_margin_create_sub_account_futures_transfer(client): + client.create_sub_account_futures_transfer() + + +def test_margin_get_sub_account_assets(client): + client.get_sub_account_assets() + + +def test_margin_query_subaccount_spot_summary(client): + client.query_subaccount_spot_summary() + + +def test_margin_get_subaccount_deposit_address(client): + client.get_subaccount_deposit_address() + + +def test_margin_get_subaccount_deposit_history(client): + client.get_subaccount_deposit_history() + + +def test_margin_get_subaccount_futures_margin_status(client): + client.get_subaccount_futures_margin_status() + + +def test_margin_enable_subaccount_margin(client): + client.enable_subaccount_margin() + + +def test_margin_get_subaccount_margin_details(client): + client.get_subaccount_margin_details() + + +def test_margin_get_subaccount_margin_summary(client): + client.get_subaccount_margin_summary() + + +def test_margin_enable_subaccount_futures(client): + client.enable_subaccount_futures() + + +def test_margin_get_subaccount_futures_details(client): + client.get_subaccount_futures_details() + + +def test_margin_get_subaccount_futures_summary(client): + client.get_subaccount_futures_summary() + + +def test_margin_get_subaccount_futures_positionrisk(client): + client.get_subaccount_futures_positionrisk() + + +def test_margin_make_subaccount_futures_transfer(client): + client.make_subaccount_futures_transfer() + + +def test_margin_make_subaccount_margin_transfer(client): + client.make_subaccount_margin_transfer() + + +def test_margin_make_subaccount_to_subaccount_transfer(client): + client.make_subaccount_to_subaccount_transfer() + + +def test_margin_make_subaccount_to_master_transfer(client): + client.make_subaccount_to_master_transfer() + + +def test_margin_get_subaccount_transfer_history(client): + client.get_subaccount_transfer_history() + + +def test_margin_make_subaccount_universal_transfer(client): + client.make_subaccount_universal_transfer() + + +def test_margin_get_universal_transfer_history(client): + client.get_universal_transfer_history() + + +# Fiat Endpoints + + +def test_margin_get_fiat_deposit_withdraw_history(client): + client.get_fiat_deposit_withdraw_history() + + +def test_margin_get_fiat_payments_history(client): + client.get_fiat_payments_history() + + +# C2C Endpoints + + +def test_margin_get_c2c_trade_history(client): + client.get_c2c_trade_history() + + +# Pay Endpoints + + +def test_margin_get_pay_trade_history(client): + client.get_pay_trade_history() + + +# Convert Endpoints + + +def test_margin_get_convert_trade_history(client): + client.get_convert_trade_history() + + +def test_margin_convert_request_quote(client): + client.convert_request_quote() + + +def test_margin_convert_accept_quote(client): + client.convert_accept_quote() + + +def test_margin_new_transfer_history(futuresClient): + futuresClient.new_transfer_history() + + +def test_margin_funding_wallet(futuresClient): + futuresClient.funding_wallet() + + +def test_margin_get_user_asset(futuresClient): + futuresClient.get_user_asset() + + +def test_margin_universal_transfer(futuresClient): + futuresClient.universal_transfer() + + +def test_margin_get_all_coins_info(client): + client.get_all_coins_info() + + +def test_margin_get_account_snapshot(client): + client.get_account_snapshot() + + +def test_margin_disable_fast_withdraw_switch(client): + client.disable_fast_withdraw_switch() + + +def test_margin_enable_fast_withdraw_switch(client): + client.enable_fast_withdraw_switch() diff --git a/tests/test_client_options.py b/tests/test_client_options.py new file mode 100644 index 00000000..efcf6d5e --- /dev/null +++ b/tests/test_client_options.py @@ -0,0 +1,123 @@ +import pytest + + +pytestmark = pytest.mark.options + + +@pytest.fixture +def options_symbol(optionsClient): + prices = optionsClient.options_price() + return prices[0]["symbol"] + + +def test_options_ping(optionsClient): + optionsClient.options_ping() + + +def test_options_time(optionsClient): + optionsClient.options_time() + + +@pytest.mark.skip(reason="Not implemented") +def test_options_info(optionsClient): + optionsClient.options_info() + + +def test_options_exchange_info(optionsClient): + optionsClient.options_exchange_info() + + +def test_options_index_price(optionsClient): + optionsClient.options_index_price(underlying="BTCUSDT") + + +def test_options_price(optionsClient): + optionsClient.options_price() + + +def test_options_mark_price(optionsClient): + optionsClient.options_mark_price() + + +def test_options_order_book(optionsClient, options_symbol): + optionsClient.options_order_book(symbol=options_symbol) + + +def test_options_klines(optionsClient, options_symbol): + optionsClient.options_klines(symbol=options_symbol, interval="1m") + + +def test_options_recent_trades(optionsClient, options_symbol): + optionsClient.options_recent_trades(symbol=options_symbol) + + +def test_options_historical_trades(optionsClient, options_symbol): + optionsClient.options_historical_trades(symbol=options_symbol) + + +# Account and trading interface endpoints + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_account_info(optionsClient): + optionsClient.options_account_info() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_funds_transfer(optionsClient): + optionsClient.options_funds_transfer() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_positions(optionsClient): + optionsClient.options_positions() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_bill(optionsClient): + optionsClient.options_bill() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_place_order(optionsClient): + optionsClient.options_place_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_test_options_place_batch_order(optionsClient): + optionsClient.test_options_place_batch_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_cancel_order(optionsClient): + optionsClient.options_cancel_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_cancel_batch_order(optionsClient): + optionsClient.options_cancel_batch_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_cancel_all_orders(optionsClient): + optionsClient.options_cancel_all_orders() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_query_order(optionsClient): + optionsClient.options_query_order() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_query_pending_orders(optionsClient): + optionsClient.options_query_pending_orders() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_query_order_history(optionsClient): + optionsClient.options_query_order_history() + + +@pytest.mark.skip(reason="No sandbox to environmnet to test") +def test_options_user_trades(optionsClient): + optionsClient.options_user_trades() diff --git a/tests/test_client_portfolio.py b/tests/test_client_portfolio.py index 0f709189..d8f657e7 100644 --- a/tests/test_client_portfolio.py +++ b/tests/test_client_portfolio.py @@ -1,3 +1,8 @@ +import pytest + +# Apply the 'portfolio' mark to all tests in this file +pytestmark = pytest.mark.portfolio + def test_papi_get_balance(client): client.papi_get_balance() @@ -390,4 +395,4 @@ def test_papi_get_margin_repay_debt(client): def test_close_connection(client): - client.close_connection() \ No newline at end of file + client.close_connection()