Skip to content

Commit 820000f

Browse files
xmatthiasCopilot
andcommitted
chore: update dry-run order-id generation to uuid
this is supposed to avoid insert errors in windows CI due to time imprecisions on windows ... Co-authored-by: Copilot <copilot@github.com>
1 parent 5710fe4 commit 820000f

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

freqtrade/exchange/exchange.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from math import floor, isnan
1414
from threading import Lock
1515
from typing import Any, Literal, TypeGuard, TypeVar
16+
from uuid import uuid4
1617

1718
import ccxt
1819
import ccxt.pro as ccxt_pro
@@ -1152,7 +1153,7 @@ def create_dry_run_order(
11521153
stop_price: float | None = None,
11531154
) -> CcxtOrder:
11541155
now = dt_now()
1155-
order_id = f"dry_run_{side}_{pair}_{now.timestamp()}"
1156+
order_id = f"dry_run_{side}_{pair}_{uuid4()}"
11561157
# Rounding here must respect to contract sizes
11571158
_amount = self._contracts_to_amount(
11581159
pair, self.amount_to_precision(pair, self._amount_to_contracts(pair, amount))

tests/exchange/test_exchange.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import logging
3+
import re
34
from copy import deepcopy
45
from datetime import UTC, datetime, timedelta
56
from random import randint
@@ -1077,6 +1078,24 @@ def test_create_dry_run_order(default_conf, mocker, side, exchange_name, leverag
10771078
assert order["cost"] == 1 * 200
10781079

10791080

1081+
def test_create_dry_run_order_id_unique_with_same_timestamp(default_conf, mocker, time_machine):
1082+
exchange = get_patched_exchange(mocker, default_conf)
1083+
1084+
time_machine.move_to("2026-04-27T04:49:57.438232Z", tick=False)
1085+
order1 = exchange.create_dry_run_order(
1086+
pair="ETH/USDT", ordertype="limit", side="sell", amount=1, rate=2.05, leverage=1.0
1087+
)
1088+
order2 = exchange.create_dry_run_order(
1089+
pair="ETH/USDT", ordertype="limit", side="sell", amount=1, rate=2.05, leverage=1.0
1090+
)
1091+
1092+
assert order1["id"] != order2["id"]
1093+
assert re.match(
1094+
r"^dry_run_sell_ETH/USDT_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$",
1095+
order1["id"],
1096+
)
1097+
1098+
10801099
@pytest.mark.parametrize(
10811100
"side,is_short,order_reason",
10821101
[

0 commit comments

Comments
 (0)