mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-02-15 10:40:31 +00:00
tests: Improve sample_order online testing
This commit is contained in:
@@ -30,40 +30,64 @@ EXCHANGES = {
|
||||
"private_methods": ["fapiPrivateGetPositionSideDual", "fapiPrivateGetMultiAssetsMargin"],
|
||||
"sample_order": [
|
||||
{
|
||||
"symbol": "SOLUSDT",
|
||||
"orderId": 3551312894,
|
||||
"orderListId": -1,
|
||||
"clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba",
|
||||
"transactTime": 1674493798550,
|
||||
"price": "15.50000000",
|
||||
"origQty": "1.10000000",
|
||||
"executedQty": "0.00000000",
|
||||
"cummulativeQuoteQty": "0.00000000",
|
||||
"status": "NEW",
|
||||
"timeInForce": "GTC",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"workingTime": 1674493798550,
|
||||
"fills": [],
|
||||
"selfTradePreventionMode": "NONE",
|
||||
"exchange_response": {
|
||||
"symbol": "SOLUSDT",
|
||||
"orderId": 3551312894,
|
||||
"orderListId": -1,
|
||||
"clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba",
|
||||
"transactTime": 1674493798550,
|
||||
"price": "15.50000000",
|
||||
"origQty": "1.10000000",
|
||||
"executedQty": "0.00000000",
|
||||
"cummulativeQuoteQty": "0.00000000",
|
||||
"status": "NEW",
|
||||
"timeInForce": "GTC",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"workingTime": 1674493798550,
|
||||
"fills": [],
|
||||
"selfTradePreventionMode": "NONE",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
{
|
||||
"symbol": "SOLUSDT",
|
||||
"orderId": 3551312894,
|
||||
"orderListId": -1,
|
||||
"clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba",
|
||||
"transactTime": 1674493798550,
|
||||
"price": "15.50000000",
|
||||
"origQty": "1.10000000",
|
||||
"executedQty": "1.10000000",
|
||||
"cummulativeQuoteQty": "17.05",
|
||||
"status": "FILLED",
|
||||
"timeInForce": "GTC",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"workingTime": 1674493798550,
|
||||
"fills": [],
|
||||
"selfTradePreventionMode": "NONE",
|
||||
"exchange_response": {
|
||||
"symbol": "SOLUSDT",
|
||||
"orderId": 3551312894,
|
||||
"orderListId": -1,
|
||||
"clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba",
|
||||
"transactTime": 1674493798550,
|
||||
"price": "15.50000000",
|
||||
"origQty": "1.10000000",
|
||||
"executedQty": "1.10000000",
|
||||
"cummulativeQuoteQty": "17.05",
|
||||
"status": "FILLED",
|
||||
"timeInForce": "GTC",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"workingTime": 1674493798550,
|
||||
"fills": [],
|
||||
"selfTradePreventionMode": "NONE",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -76,22 +100,34 @@ EXCHANGES = {
|
||||
"skip_ws_tests": True,
|
||||
"sample_order": [
|
||||
{
|
||||
"symbol": "SOLUSDT",
|
||||
"orderId": 3551312894,
|
||||
"orderListId": -1,
|
||||
"clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba",
|
||||
"transactTime": 1674493798550,
|
||||
"price": "15.50000000",
|
||||
"origQty": "1.10000000",
|
||||
"executedQty": "0.00000000",
|
||||
"cummulativeQuoteQty": "0.00000000",
|
||||
"status": "NEW",
|
||||
"timeInForce": "GTC",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"workingTime": 1674493798550,
|
||||
"fills": [],
|
||||
"selfTradePreventionMode": "NONE",
|
||||
"exchange_response": {
|
||||
"symbol": "SOLUSDT",
|
||||
"orderId": 3551312894,
|
||||
"orderListId": -1,
|
||||
"clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba",
|
||||
"transactTime": 1674493798550,
|
||||
"price": "15.50000000",
|
||||
"origQty": "1.10000000",
|
||||
"executedQty": "0.00000000",
|
||||
"cummulativeQuoteQty": "0.00000000",
|
||||
"status": "NEW",
|
||||
"timeInForce": "GTC",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"workingTime": 1674493798550,
|
||||
"fills": [],
|
||||
"selfTradePreventionMode": "NONE",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -112,38 +148,62 @@ EXCHANGES = {
|
||||
"leverage_tiers_public": False,
|
||||
"leverage_in_spot_market": True,
|
||||
"sample_order": [
|
||||
{"id": "63d6742d0adc5570001d2bbf7"}, # create order
|
||||
{
|
||||
"id": "63d6742d0adc5570001d2bbf7",
|
||||
"symbol": "SOL-USDT",
|
||||
"opType": "DEAL",
|
||||
"type": "limit",
|
||||
"side": "buy",
|
||||
"price": "15.5",
|
||||
"size": "1.1",
|
||||
"funds": "0",
|
||||
"dealFunds": "17.05",
|
||||
"dealSize": "1.1",
|
||||
"fee": "0.000065252",
|
||||
"feeCurrency": "USDT",
|
||||
"stp": "",
|
||||
"stop": "",
|
||||
"stopTriggered": False,
|
||||
"stopPrice": "0",
|
||||
"timeInForce": "GTC",
|
||||
"postOnly": False,
|
||||
"hidden": False,
|
||||
"iceberg": False,
|
||||
"visibleSize": "0",
|
||||
"cancelAfter": 0,
|
||||
"channel": "API",
|
||||
"clientOid": "0a053870-11bf-41e5-be61-b272a4cb62e1",
|
||||
"remark": None,
|
||||
"tags": "partner:ccxt",
|
||||
"isActive": False,
|
||||
"cancelExist": False,
|
||||
"createdAt": 1674493798550,
|
||||
"tradeType": "TRADE",
|
||||
"exchange_response": {"id": "63d6742d0adc5570001d2bbf7"},
|
||||
"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,
|
||||
},
|
||||
}, # create order
|
||||
{
|
||||
"exchange_response": {
|
||||
"id": "63d6742d0adc5570001d2bbf7",
|
||||
"symbol": "SOL-USDT",
|
||||
"opType": "DEAL",
|
||||
"type": "limit",
|
||||
"side": "buy",
|
||||
"price": "15.5",
|
||||
"size": "1.1",
|
||||
"funds": "0",
|
||||
"dealFunds": "17.05",
|
||||
"dealSize": "1.1",
|
||||
"fee": "0.000065252",
|
||||
"feeCurrency": "USDT",
|
||||
"stp": "",
|
||||
"stop": "",
|
||||
"stopTriggered": False,
|
||||
"stopPrice": "0",
|
||||
"timeInForce": "GTC",
|
||||
"postOnly": False,
|
||||
"hidden": False,
|
||||
"iceberg": False,
|
||||
"visibleSize": "0",
|
||||
"cancelAfter": 0,
|
||||
"channel": "API",
|
||||
"clientOid": "0a053870-11bf-41e5-be61-b272a4cb62e1",
|
||||
"remark": None,
|
||||
"tags": "partner:ccxt",
|
||||
"isActive": False,
|
||||
"cancelExist": False,
|
||||
"createdAt": 1674493798550,
|
||||
"tradeType": "TRADE",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -159,65 +219,89 @@ EXCHANGES = {
|
||||
"leverage_in_spot_market": True,
|
||||
"sample_order": [
|
||||
{
|
||||
"id": "276266139423",
|
||||
"text": "apiv4",
|
||||
"create_time": "1674493798",
|
||||
"update_time": "1674493798",
|
||||
"create_time_ms": "1674493798550",
|
||||
"update_time_ms": "1674493798550",
|
||||
"status": "closed",
|
||||
"currency_pair": "SOL_USDT",
|
||||
"type": "limit",
|
||||
"account": "spot",
|
||||
"side": "buy",
|
||||
"amount": "1.1",
|
||||
"price": "15.5",
|
||||
"time_in_force": "gtc",
|
||||
"iceberg": "0",
|
||||
"left": "0",
|
||||
"fill_price": "17.05",
|
||||
"filled_total": "17.05",
|
||||
"avg_deal_price": "15.5",
|
||||
"fee": "0.0000018",
|
||||
"fee_currency": "SOL",
|
||||
"point_fee": "0",
|
||||
"gt_fee": "0",
|
||||
"gt_maker_fee": "0",
|
||||
"gt_taker_fee": "0.0015",
|
||||
"gt_discount": True,
|
||||
"rebated_fee": "0",
|
||||
"rebated_fee_currency": "USDT",
|
||||
"exchange_response": {
|
||||
"id": "276266139423",
|
||||
"text": "apiv4",
|
||||
"create_time": "1674493798",
|
||||
"update_time": "1674493798",
|
||||
"create_time_ms": "1674493798550",
|
||||
"update_time_ms": "1674493798550",
|
||||
"status": "closed",
|
||||
"currency_pair": "SOL_USDT",
|
||||
"type": "limit",
|
||||
"account": "spot",
|
||||
"side": "buy",
|
||||
"amount": "1.1",
|
||||
"price": "15.5",
|
||||
"time_in_force": "gtc",
|
||||
"iceberg": "0",
|
||||
"left": "0",
|
||||
"fill_price": "17.05",
|
||||
"filled_total": "17.05",
|
||||
"avg_deal_price": "15.5",
|
||||
"fee": "0.0000018",
|
||||
"fee_currency": "SOL",
|
||||
"point_fee": "0",
|
||||
"gt_fee": "0",
|
||||
"gt_maker_fee": "0",
|
||||
"gt_taker_fee": "0.0015",
|
||||
"gt_discount": True,
|
||||
"rebated_fee": "0",
|
||||
"rebated_fee_currency": "USDT",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
{
|
||||
# market order
|
||||
"id": "276401180529",
|
||||
"text": "apiv4",
|
||||
"create_time": "1674493798",
|
||||
"update_time": "1674493798",
|
||||
"create_time_ms": "1674493798550",
|
||||
"update_time_ms": "1674493798550",
|
||||
"status": "cancelled",
|
||||
"currency_pair": "SOL_USDT",
|
||||
"type": "market",
|
||||
"account": "spot",
|
||||
"side": "buy",
|
||||
"amount": "17.05",
|
||||
"price": "0",
|
||||
"time_in_force": "ioc",
|
||||
"iceberg": "0",
|
||||
"left": "0.0000000016228",
|
||||
"fill_price": "17.05",
|
||||
"filled_total": "17.05",
|
||||
"avg_deal_price": "15.5",
|
||||
"fee": "0",
|
||||
"fee_currency": "SOL",
|
||||
"point_fee": "0.0199999999967544",
|
||||
"gt_fee": "0",
|
||||
"gt_maker_fee": "0",
|
||||
"gt_taker_fee": "0",
|
||||
"gt_discount": False,
|
||||
"rebated_fee": "0",
|
||||
"rebated_fee_currency": "USDT",
|
||||
"exchange_response": {
|
||||
# market order
|
||||
"id": "276401180529",
|
||||
"text": "apiv4",
|
||||
"create_time": "1674493798",
|
||||
"update_time": "1674493798",
|
||||
"create_time_ms": "1674493798550",
|
||||
"update_time_ms": "1674493798550",
|
||||
"status": "cancelled",
|
||||
"currency_pair": "SOL_USDT",
|
||||
"type": "market",
|
||||
"account": "spot",
|
||||
"side": "buy",
|
||||
"amount": "17.05",
|
||||
"price": "0",
|
||||
"time_in_force": "ioc",
|
||||
"iceberg": "0",
|
||||
"left": "0.0000000016228",
|
||||
"fill_price": "17.05",
|
||||
"filled_total": "17.05",
|
||||
"avg_deal_price": "15.5",
|
||||
"fee": "0",
|
||||
"fee_currency": "SOL",
|
||||
"point_fee": "0.0199999999967544",
|
||||
"gt_fee": "0",
|
||||
"gt_maker_fee": "0",
|
||||
"gt_taker_fee": "0",
|
||||
"gt_discount": False,
|
||||
"rebated_fee": "0",
|
||||
"rebated_fee_currency": "USDT",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
],
|
||||
"sample_my_trades": [
|
||||
@@ -264,19 +348,31 @@ EXCHANGES = {
|
||||
"leverage_in_spot_market": True,
|
||||
"sample_order": [
|
||||
{
|
||||
"orderId": "1274754916287346280",
|
||||
"orderLinkId": "1666798627015730",
|
||||
"symbol": "SOLUSDT",
|
||||
"createdTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"qty": "1.1",
|
||||
"orderType": "Limit",
|
||||
"side": "Buy",
|
||||
"orderStatus": "New",
|
||||
"timeInForce": "GTC",
|
||||
"accountId": "5555555",
|
||||
"execQty": "0",
|
||||
"orderCategory": "0",
|
||||
"exchange_response": {
|
||||
"orderId": "1274754916287346280",
|
||||
"orderLinkId": "1666798627015730",
|
||||
"symbol": "SOLUSDT",
|
||||
"createdTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"qty": "1.1",
|
||||
"orderType": "Limit",
|
||||
"side": "Buy",
|
||||
"orderStatus": "New",
|
||||
"timeInForce": "GTC",
|
||||
"accountId": "5555555",
|
||||
"execQty": "0",
|
||||
"orderCategory": "0",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -310,32 +406,56 @@ EXCHANGES = {
|
||||
"futures": False,
|
||||
"sample_order": [
|
||||
{
|
||||
"symbol": "SOL-USDT",
|
||||
"orderId": "1762393630149869568",
|
||||
"transactTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"stopPrice": "0",
|
||||
"origQty": "1.1",
|
||||
"executedQty": "1.1",
|
||||
"cummulativeQuoteQty": "17.05",
|
||||
"status": "FILLED",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"clientOrderID": "",
|
||||
"exchange_response": {
|
||||
"symbol": "SOL-USDT",
|
||||
"orderId": "1762393630149869568",
|
||||
"transactTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"stopPrice": "0",
|
||||
"origQty": "1.1",
|
||||
"executedQty": "1.1",
|
||||
"cummulativeQuoteQty": "17.05",
|
||||
"status": "FILLED",
|
||||
"type": "LIMIT",
|
||||
"side": "BUY",
|
||||
"clientOrderID": "",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
{
|
||||
"symbol": "SOL-USDT",
|
||||
"orderId": "1762393630149869568",
|
||||
"transactTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"stopPrice": "0",
|
||||
"origQty": "1.1",
|
||||
"executedQty": "1.1",
|
||||
"cummulativeQuoteQty": "17.05",
|
||||
"status": "FILLED",
|
||||
"type": "MARKET",
|
||||
"side": "BUY",
|
||||
"clientOrderID": "",
|
||||
"exchange_response": {
|
||||
"symbol": "SOL-USDT",
|
||||
"orderId": "1762393630149869568",
|
||||
"transactTime": "1674493798550",
|
||||
"price": "15.5",
|
||||
"stopPrice": "0",
|
||||
"origQty": "1.1",
|
||||
"executedQty": "1.1",
|
||||
"cummulativeQuoteQty": "17.05",
|
||||
"status": "FILLED",
|
||||
"type": "MARKET",
|
||||
"side": "BUY",
|
||||
"clientOrderID": "",
|
||||
},
|
||||
"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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -61,28 +61,31 @@ class TestCCXTExchange:
|
||||
def test_ccxt_order_parse(self, exchange: EXCHANGE_FIXTURE_TYPE):
|
||||
exch, exchange_name = exchange
|
||||
if orders := EXCHANGES[exchange_name].get("sample_order"):
|
||||
pair = "SOL/USDT"
|
||||
for order in orders:
|
||||
pair = order["pair"]
|
||||
exchange_response: dict = order["exchange_response"]
|
||||
|
||||
market = exch._api.markets[pair]
|
||||
po = exch._api.parse_order(order, market)
|
||||
po = exch._api.parse_order(exchange_response, market)
|
||||
expected = order["expected"]
|
||||
assert isinstance(po["id"], str)
|
||||
assert po["id"] is not None
|
||||
if len(order.keys()) < 5:
|
||||
if len(exchange_response.keys()) < 5:
|
||||
# Kucoin case
|
||||
assert po["status"] is None
|
||||
continue
|
||||
assert po["timestamp"] == 1674493798550
|
||||
assert po["timestamp"] == expected["timestamp"]
|
||||
assert isinstance(po["datetime"], str)
|
||||
assert isinstance(po["timestamp"], int)
|
||||
assert isinstance(po["price"], float)
|
||||
assert po["price"] == 15.5
|
||||
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"] == 1.1
|
||||
assert po["amount"] == expected["amount"]
|
||||
assert isinstance(po["status"], str)
|
||||
else:
|
||||
pytest.skip(f"No sample order available for exchange {exchange_name}")
|
||||
|
||||
Reference in New Issue
Block a user