Skip to content

Commit 5e64416

Browse files
committed
test: add test for profit_all
1 parent 1118032 commit 5e64416

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/rpc/test_rpc_apiserver.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,44 @@ def test_api_profit(botclient, mocker, ticker, fee, markets, is_short, expected)
13431343
}
13441344

13451345

1346+
def test_api_profit_all(botclient, mocker, ticker, fee, markets):
1347+
ftbot, client = botclient
1348+
ftbot.config["tradable_balance_ratio"] = 1
1349+
ftbot.config["trading_mode"] = TradingMode.FUTURES
1350+
patch_get_signal(ftbot)
1351+
mocker.patch.multiple(
1352+
EXMS,
1353+
get_balances=MagicMock(return_value=ticker),
1354+
fetch_ticker=ticker,
1355+
get_fee=fee,
1356+
markets=PropertyMock(return_value=markets),
1357+
)
1358+
1359+
rc = client_get(client, f"{BASE_URI}/profit_all")
1360+
assert_response(rc, 200)
1361+
response = rc.json()
1362+
assert "all" in response
1363+
assert "long" in response
1364+
assert "short" in response
1365+
1366+
assert response["all"]["trade_count"] == 0
1367+
create_mock_trades_usdt(fee, is_short=None)
1368+
1369+
rc = client_get(client, f"{BASE_URI}/profit_all")
1370+
assert_response(rc, 200)
1371+
response = rc.json()
1372+
assert response["all"]["trade_count"] == 7
1373+
assert response["long"]["trade_count"] == 2
1374+
assert response["short"]["trade_count"] == 5
1375+
assert pytest.approx(response["all"]["profit_all_coin"]) == 22.58997755
1376+
assert pytest.approx(response["long"]["profit_all_coin"]) == -20.0498903
1377+
assert pytest.approx(response["short"]["profit_all_coin"]) == 42.639867
1378+
1379+
assert response["all"]["best_pair"] == "NEO/USDT"
1380+
assert response["long"]["best_pair"] == ""
1381+
assert response["short"]["best_pair"] == "NEO/USDT"
1382+
1383+
13461384
@pytest.mark.parametrize("is_short", [True, False])
13471385
def test_api_stats(botclient, mocker, ticker, fee, markets, is_short):
13481386
ftbot, client = botclient

0 commit comments

Comments
 (0)