From 91d9b9f2cc489210523821102b5bd1fbd5200734 Mon Sep 17 00:00:00 2001 From: carlosmiei <43336371+carlosmiei@users.noreply.github.com> Date: Sun, 17 Nov 2024 14:09:26 +0000 Subject: [PATCH] add tests --- tests/test_ids.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_ids.py b/tests/test_ids.py index 27ade3cc6..814c0c7e3 100644 --- a/tests/test_ids.py +++ b/tests/test_ids.py @@ -39,6 +39,15 @@ def test_spot_market_id(): assert url_dict["newClientOrderId"].startswith("x-HNA2TXFJ") +def test_spot_cancel_replace_id(): + with requests_mock.mock() as m: + m.post("https://api.binance.com/api/v3/order/cancelReplace", json={}, status_code=200) + client.cancel_replace_order( + cancelOrderId="orderId", symbol="LTCUSDT", side="BUY", type="MARKET", quantity=0.1 + ) + url_dict = dict(pair.split("=") for pair in m.last_request.text.split("&")) + assert url_dict["newClientOrderId"].startswith("x-HNA2TXFJ") + def test_swap_id(): with requests_mock.mock() as m: m.post("https://fapi.binance.com/fapi/v1/order", json={}, status_code=200) @@ -147,6 +156,28 @@ def handler(url, **kwargs): await clientAsync.close_connection() +@pytest.mark.asyncio() +async def test_spot_cancel_replace_id_async(): + clientAsync = AsyncClient( + api_key="api_key", api_secret="api_secret" + ) # reuse client later + with aioresponses() as m: + + def handler(url, **kwargs): + client_order_id = kwargs["data"][0][1] + assert client_order_id.startswith("x-HNA2TXFJ") + + m.post( + "https://api.binance.com/api/v3/order/cancelReplace", + payload={"id": 1}, + status=200, + callback=handler, + ) + await clientAsync.cancel_replace_order( + orderId="id", symbol="LTCUSDT", side="BUY", type="MARKET", quantity=0.1 + ) + await clientAsync.close_connection() + @pytest.mark.asyncio() async def test_swap_id_async(): clientAsync = AsyncClient(api_key="api_key", api_secret="api_secret")