Skip to content

Commit 2191d2f

Browse files
committed
fix: round trigger_price to 1 decimal to fix precision error on LTCUSDT
1 parent 0094c52 commit 2191d2f

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

tests/test_async_client_ws_futures_requests.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ async def test_ws_futures_get_order_book_ticker(futuresClientAsync):
5959
@pytest.mark.skipif(sys.version_info < (3, 8), reason="websockets_proxy Python 3.8+")
6060
@pytest.mark.asyncio()
6161
async def test_ws_futures_create_get_edit_cancel_order_with_orjson(futuresClientAsync):
62-
if 'orjson' not in sys.modules:
62+
if "orjson" not in sys.modules:
6363
raise ImportError("orjson is not available")
64-
64+
6565
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
6666
positions = await futuresClientAsync.ws_futures_v2_account_position(
6767
symbol="LTCUSDT"
@@ -92,11 +92,16 @@ async def test_ws_futures_create_get_edit_cancel_order_with_orjson(futuresClient
9292
orderid=order["orderId"], symbol=order["symbol"]
9393
)
9494

95+
9596
@pytest.mark.skipif(sys.version_info < (3, 8), reason="websockets_proxy Python 3.8+")
9697
@pytest.mark.asyncio()
97-
async def test_ws_futures_create_get_edit_cancel_order_without_orjson(futuresClientAsync):
98-
with patch.dict('sys.modules', {'orjson': None}):
99-
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
98+
async def test_ws_futures_create_get_edit_cancel_order_without_orjson(
99+
futuresClientAsync,
100+
):
101+
with patch.dict("sys.modules", {"orjson": None}):
102+
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(
103+
symbol="LTCUSDT"
104+
)
100105
positions = await futuresClientAsync.ws_futures_v2_account_position(
101106
symbol="LTCUSDT"
102107
)
@@ -170,7 +175,11 @@ async def test_ws_futures_fail_to_connect(futuresClientAsync):
170175
await futuresClientAsync.close_connection()
171176

172177
# Mock the WebSocket API's connect method to raise an exception
173-
with patch.object(futuresClientAsync.ws_future, 'connect', side_effect=ConnectionError("Simulated connection failure")):
178+
with patch.object(
179+
futuresClientAsync.ws_future,
180+
"connect",
181+
side_effect=ConnectionError("Simulated connection failure"),
182+
):
174183
with pytest.raises(BinanceWebsocketUnableToConnect):
175184
await futuresClientAsync.ws_futures_get_order_book(symbol="BTCUSDT")
176185

@@ -180,7 +189,9 @@ async def test_ws_futures_fail_to_connect(futuresClientAsync):
180189
async def test_ws_futures_create_cancel_algo_order(futuresClientAsync):
181190
"""Test creating and canceling an algo order via websocket async"""
182191
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
183-
positions = await futuresClientAsync.ws_futures_v2_account_position(symbol="LTCUSDT")
192+
positions = await futuresClientAsync.ws_futures_v2_account_position(
193+
symbol="LTCUSDT"
194+
)
184195

185196
# Create an algo order
186197
order = await futuresClientAsync.ws_futures_create_algo_order(
@@ -210,12 +221,14 @@ async def test_ws_futures_create_cancel_algo_order(futuresClientAsync):
210221
async def test_ws_futures_create_conditional_order_auto_routing(futuresClientAsync):
211222
"""Test that conditional order types are automatically routed to algo endpoint"""
212223
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
213-
positions = await futuresClientAsync.ws_futures_v2_account_position(symbol="LTCUSDT")
224+
positions = await futuresClientAsync.ws_futures_v2_account_position(
225+
symbol="LTCUSDT"
226+
)
214227

215228
# Create a STOP_MARKET order using ws_futures_create_order
216229
# It should automatically route to the algo endpoint
217230
# Use a price above current market price for BUY STOP
218-
trigger_price = float(ticker["askPrice"]) * 1.5
231+
trigger_price = round(float(ticker["askPrice"]) * 1.5, 1)
219232
order = await futuresClientAsync.ws_futures_create_order(
220233
symbol=ticker["symbol"],
221234
side="BUY",
@@ -241,11 +254,13 @@ async def test_ws_futures_create_conditional_order_auto_routing(futuresClientAsy
241254
async def test_ws_futures_conditional_order_with_stop_price(futuresClientAsync):
242255
"""Test that stopPrice is converted to triggerPrice for conditional orders"""
243256
ticker = await futuresClientAsync.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
244-
positions = await futuresClientAsync.ws_futures_v2_account_position(symbol="LTCUSDT")
257+
positions = await futuresClientAsync.ws_futures_v2_account_position(
258+
symbol="LTCUSDT"
259+
)
245260

246261
# Create a TAKE_PROFIT_MARKET order with stopPrice (should be converted to triggerPrice)
247262
# Use a price above current market price for SELL TAKE_PROFIT
248-
trigger_price = float(ticker["askPrice"]) * 1.5
263+
trigger_price = round(float(ticker["askPrice"]) * 1.5, 1)
249264
order = await futuresClientAsync.ws_futures_create_order(
250265
symbol=ticker["symbol"],
251266
side="SELL",

tests/test_client_ws_futures_requests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_ws_futures_create_conditional_order_auto_routing(futuresClient):
122122
ticker = futuresClient.ws_futures_get_order_book_ticker(symbol="LTCUSDT")
123123
positions = futuresClient.ws_futures_v2_account_position(symbol="LTCUSDT")
124124

125-
trigger_price = round(float(ticker["askPrice"]) * 1.5, 2)
125+
trigger_price = round(float(ticker["askPrice"]) * 1.5, 1)
126126
order = futuresClient.ws_futures_create_order(
127127
symbol=ticker["symbol"],
128128
side="BUY",
@@ -151,7 +151,7 @@ def test_ws_futures_conditional_order_with_stop_price(futuresClient):
151151

152152
# Create a TAKE_PROFIT_MARKET order with stopPrice (should be converted to triggerPrice)
153153
# Use a price above current market price for SELL TAKE_PROFIT
154-
trigger_price = round(float(ticker["askPrice"]) * 1.5, 2)
154+
trigger_price = round(float(ticker["askPrice"]) * 1.5, 1)
155155
order = futuresClient.ws_futures_create_order(
156156
symbol=ticker["symbol"],
157157
side="SELL",

0 commit comments

Comments
 (0)