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