mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-03-06 22:03:57 +00:00
test: simplify ccxt_order_parse test (but improve it at the same time)
This commit is contained in:
@@ -26,6 +26,7 @@ class TestExchangeOnlineSetup(TypedDict):
|
||||
trades_lookback_hours: int
|
||||
private_methods: list[str] | None
|
||||
sample_order: list[dict[str, Any]] | None
|
||||
sample_order_futures: list[dict[str, Any]] | None
|
||||
sample_my_trades: list[dict[str, Any]] | None
|
||||
skip_ws_tests: bool | None
|
||||
|
||||
@@ -77,11 +78,12 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "3551312894",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"side": "buy",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
@@ -107,11 +109,12 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "3551312894",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"side": "buy",
|
||||
"status": "closed",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
@@ -148,9 +151,9 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "3551312894",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"amount": 1.1,
|
||||
@@ -203,12 +206,12 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"amount": 1.1,
|
||||
"id": "63d6742d0adc5570001d2bbf7",
|
||||
"timestamp": None,
|
||||
"datetime": None,
|
||||
"price": None,
|
||||
"status": None,
|
||||
"amount": None,
|
||||
},
|
||||
}, # create order
|
||||
{
|
||||
@@ -247,11 +250,11 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "63d6742d0adc5570001d2bbf7",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"status": "closed",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
@@ -304,11 +307,12 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "276266139423",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"average": 15.5,
|
||||
"status": "closed",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
@@ -347,11 +351,11 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "276401180529",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"status": "canceled",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
@@ -420,10 +424,11 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "1274754916287346280",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"side": "buy",
|
||||
"status": "open",
|
||||
"amount": 1.1,
|
||||
},
|
||||
@@ -499,18 +504,19 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "1762393630149869568",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"average": 15.5,
|
||||
"status": "closed",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"exchange_response": {
|
||||
"symbol": "SOL-USDT",
|
||||
"orderId": "1762393630149869568",
|
||||
"orderId": "1762393630149869567",
|
||||
"transactTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"stopPrice": "0",
|
||||
@@ -525,11 +531,12 @@ EXCHANGES: dict[str, TestExchangeOnlineSetup] = {
|
||||
"pair": "SOL/USDT",
|
||||
"expected": {
|
||||
"symbol": "SOL/USDT",
|
||||
"orderId": "3551312894",
|
||||
"id": "1762393630149869567",
|
||||
"timestamp": 1674493798550,
|
||||
"datetime": "2023-03-25T15:49:58.550Z",
|
||||
"datetime": "2023-01-23T17:09:58.550Z",
|
||||
"price": 15.5,
|
||||
"status": "open",
|
||||
"average": 15.5,
|
||||
"status": "closed",
|
||||
"amount": 1.1,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -90,23 +90,14 @@ class TestCCXTExchange:
|
||||
expected = order["expected"]
|
||||
assert isinstance(po["id"], str)
|
||||
assert po["id"] is not None
|
||||
if len(exchange_response.keys()) < 5:
|
||||
# Kucoin case
|
||||
assert po["status"] is None
|
||||
continue
|
||||
assert po["timestamp"] == expected["timestamp"]
|
||||
assert isinstance(po["datetime"], str)
|
||||
assert isinstance(po["timestamp"], int)
|
||||
assert isinstance(po["price"], float)
|
||||
assert po["price"] == expected["price"]
|
||||
if po["status"] == "closed":
|
||||
# Filled orders should have average assigned.
|
||||
assert isinstance(po["average"], float)
|
||||
assert po["average"] == 15.5
|
||||
assert po["symbol"] == pair
|
||||
assert isinstance(po["amount"], float)
|
||||
assert po["amount"] == expected["amount"]
|
||||
assert isinstance(po["status"], str)
|
||||
|
||||
# Generic comparison which works for all fields
|
||||
for key, value in expected.items():
|
||||
assert key in po, f"Expected key {key} not found in parsed order"
|
||||
assert po[key] == value, f"Expected {key} to be {value}, got {po[key]}"
|
||||
assert isinstance(po[key], type(value)), (
|
||||
f"Expected {key} to be of type {type(value)}, got {type(po[key])}"
|
||||
)
|
||||
else:
|
||||
pytest.skip(f"No sample order available for exchange {exchangename}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user