Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Nov 19, 2024
1 parent ccd0a3a commit bfc74bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions binance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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__
Expand Down
29 changes: 29 additions & 0 deletions tests/test_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bfc74bf

Please sign in to comment.