Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Nov 17, 2024
1 parent 8a7cc3c commit 91d9b9f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 91d9b9f

Please sign in to comment.