From bfc74bf5cb5e681b5c17835d894d6c3ab07f5087 Mon Sep 17 00:00:00 2001 From: carlosmiei <43336371+carlosmiei@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:36:55 +0000 Subject: [PATCH] add tests --- binance/client.py | 4 ++++ tests/test_ids.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/binance/client.py b/binance/client.py index 9d2b856e..348e11a0 100755 --- a/binance/client.py +++ b/binance/client.py @@ -1924,6 +1924,8 @@ def create_oco_order(self, **params): :raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException """ + if "listClientOrderId" not in params: + params["listClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22() return self._post("orderList/oco", True, data=params) def order_oco_buy(self, **params): @@ -11143,6 +11145,8 @@ async def order_market_sell(self, **params): order_market_sell.__doc__ = Client.order_market_sell.__doc__ async def create_oco_order(self, **params): + if "listClientOrderId" not in params: + params["listClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22() return await self._post("orderList/oco", True, data=params) create_oco_order.__doc__ = Client.create_oco_order.__doc__ diff --git a/tests/test_ids.py b/tests/test_ids.py index 814c0c7e..6a32ff42 100644 --- a/tests/test_ids.py +++ b/tests/test_ids.py @@ -48,6 +48,15 @@ def test_spot_cancel_replace_id(): url_dict = dict(pair.split("=") for pair in m.last_request.text.split("&")) assert url_dict["newClientOrderId"].startswith("x-HNA2TXFJ") +def test_spot_oco_order_id(): + with requests_mock.mock() as m: + m.post("https://api.binance.com/api/v3/orderList/oco", json={}, status_code=200) + client.create_oco_order( + symbol="LTCUSDT", side="BUY", aboveType="MARKET", quantity=0.1 + ) + url_dict = dict(pair.split("=") for pair in m.last_request.text.split("&")) + assert url_dict["listClientOrderId"].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) @@ -262,6 +271,26 @@ def handler(url, **kwargs): await clientAsync.close_connection() +@pytest.mark.asyncio() +async def test_spot_oco_id(): + clientAsync = AsyncClient(api_key="api_key", api_secret="api_secret") + 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/orderList/oco", + payload={"id": 1}, + status=200, + callback=handler, + ) + await clientAsync.create_oco_order( + symbol="BTCUSDT", side="BUY", type="MARKET", quantity=0.1 + ) + await clientAsync.close_connection() + @pytest.mark.asyncio() async def test_swap_batch_id_async(): with aioresponses() as m: