Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions binance/ws/reconnecting_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def __init__(
self._https_proxy = https_proxy
self._ws_kwargs = kwargs

def json_dumps(self, msg):
def json_dumps(self, msg) -> str:
if orjson:
return orjson.dumps(msg)
return orjson.dumps(msg).decode("utf-8")
return json.dumps(msg)

def json_loads(self, msg):
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tox
setuptools
aioresponses
pre-commit
orjson
39 changes: 38 additions & 1 deletion tests/test_async_client_ws_futures_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import pytest
import sys

from binance.exceptions import BinanceAPIException, BinanceWebsocketUnableToConnect
from .test_get_order_book import assert_ob
Expand Down Expand Up @@ -52,7 +53,10 @@ async def test_ws_futures_get_order_book_ticker(futuresClientAsync):


@pytest.mark.asyncio()
async def test_ws_futures_create_get_edit_cancel_order(futuresClientAsync):
async def test_ws_futures_create_get_edit_cancel_order_with_orjson(futuresClientAsync):
if 'orjson' not in sys.modules:
raise ImportError("orjson is not available")

ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
positions = await futuresClientAsync.ws_futures_v2_account_position(
symbol="LTCUSDT"
Expand Down Expand Up @@ -83,6 +87,39 @@ async def test_ws_futures_create_get_edit_cancel_order(futuresClientAsync):
orderid=order["orderId"], symbol=order["symbol"]
)

@pytest.mark.asyncio()
async def test_ws_futures_create_get_edit_cancel_order_without_orjson(futuresClientAsync):
with patch.dict('sys.modules', {'orjson': None}):
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
positions = await futuresClientAsync.ws_futures_v2_account_position(
symbol="LTCUSDT"
)
order = await futuresClientAsync.ws_futures_create_order(
symbol=ticker["symbol"],
side="BUY",
positionSide=positions[0]["positionSide"],
type="LIMIT",
timeInForce="GTC",
quantity=0.1,
price=str(float(ticker["bidPrice"]) - 2),
)
assert_contract_order(futuresClientAsync, order)
order = await futuresClientAsync.ws_futures_edit_order(
orderid=order["orderId"],
symbol=order["symbol"],
quantity=0.11,
side=order["side"],
price=order["price"],
)
assert_contract_order(futuresClientAsync, order)
order = await futuresClientAsync.ws_futures_get_order(
symbol="LTCUSDT", orderid=order["orderId"]
)
assert_contract_order(futuresClientAsync, order)
order = await futuresClientAsync.ws_futures_cancel_order(
orderid=order["orderId"], symbol=order["symbol"]
)


@pytest.mark.asyncio()
async def test_ws_futures_v2_account_position(futuresClientAsync):
Expand Down
Loading