diff --git a/pdr_backend/ppss/lake_ss.py b/pdr_backend/ppss/lake_ss.py index e5b34d451..defa9a623 100644 --- a/pdr_backend/ppss/lake_ss.py +++ b/pdr_backend/ppss/lake_ss.py @@ -1,5 +1,6 @@ import logging import os +from typing import Optional import numpy as np from enforce_typing import enforce_types @@ -87,3 +88,21 @@ def __str__(self) -> str: s += f"parquet_dir={self.parquet_dir}\n" s += "-" * 10 + "\n" return s + + +# ========================================================================= +# utilities for testing + + +@enforce_types +def lake_ss_test_dict(parquet_dir: str, feeds: Optional[list] = None): + """Use this function's return dict 'd' to construct LakeSS(d)""" + feeds = feeds or ["binance BTC/USDT c 5m"] + d = { + "feeds": feeds, + "parquet_dir": parquet_dir, + "st_timestr": "2023-06-18", + "fin_timestr": "2023-06-30", + "timeframe": "5m", + } + return d diff --git a/pdr_backend/ppss/sim_ss.py b/pdr_backend/ppss/sim_ss.py index e1107bc36..fef1b4956 100644 --- a/pdr_backend/ppss/sim_ss.py +++ b/pdr_backend/ppss/sim_ss.py @@ -58,3 +58,24 @@ def tradetype(self) -> str: @property def allowed_tradetypes(self) -> List[str]: return ["livemock", "livereal", "histmock"] + + +# ========================================================================= +# utilities for testing + + +@enforce_types +def sim_ss_test_dict(log_dir: str) -> dict: + d = { + "do_plot": True, + "log_dir": log_dir, + "test_n": 10, + "exchange_only": { + "timeout": 30000, + "options": { + "createMarketBuyOrderRequiresPrice": False, + "defaultType": "spot", + }, + }, + } + return d diff --git a/pdr_backend/ppss/test/test_lake_ss.py b/pdr_backend/ppss/test/test_lake_ss.py index 829e613cd..649ac3929 100644 --- a/pdr_backend/ppss/test/test_lake_ss.py +++ b/pdr_backend/ppss/test/test_lake_ss.py @@ -6,7 +6,7 @@ from pdr_backend.cli.arg_feed import ArgFeed from pdr_backend.cli.arg_feeds import ArgFeeds -from pdr_backend.ppss.lake_ss import LakeSS +from pdr_backend.ppss.lake_ss import LakeSS, lake_ss_test_dict from pdr_backend.util.time_types import UnixTimeMs _D = { @@ -81,3 +81,34 @@ def test_parquet_dir(tmpdir): ss = LakeSS(d) target_parquet_dir = os.path.join(tmpdir, "parquet_data") assert ss.parquet_dir == target_parquet_dir + + +@enforce_types +def test_lake_ss_test_dict_1_default_feeds(tmpdir): + parquet_dir = os.path.join(tmpdir, "parquet_data") + + d = lake_ss_test_dict(parquet_dir) + + assert d["parquet_dir"] == parquet_dir + + f = d["feeds"][0] + assert "binance" in f or "kraken" in f + assert "BTC" in f or "ETH" in f + assert "5m" in f or "1h" in f + + assert "st_timestr" in d + assert "fin_timestr" in d + assert "timeframe" in d + + ss = LakeSS(d) + assert ss.parquet_dir == parquet_dir + assert ss.feeds + + +@enforce_types +def test_lake_ss_test_dict_2_specify_feeds(tmpdir): + parquet_dir = os.path.join(tmpdir, "parquet_data") + feeds = ["kraken DOT/USDT c 60m", "dydx DOT/USDT c 60m"] + d = lake_ss_test_dict(parquet_dir, feeds) + assert d["parquet_dir"] == parquet_dir + assert d["feeds"] == feeds diff --git a/pdr_backend/ppss/test/test_predictoor_ss.py b/pdr_backend/ppss/test/test_predictoor_ss.py index 26dcd796c..fe19a993e 100644 --- a/pdr_backend/ppss/test/test_predictoor_ss.py +++ b/pdr_backend/ppss/test/test_predictoor_ss.py @@ -45,7 +45,7 @@ def test_predictoor_ss(): @enforce_types def test_predictoor_ss_test_dict(): - # test - reasoonable defaults when nothing passed in + # test - reasonable defaults when nothing passed in d = predictoor_ss_test_dict() f = d["predict_feed"] assert "binance" in f or "kraken" in f @@ -64,16 +64,14 @@ def test_predictoor_ss_test_dict(): assert d["aimodel_ss"]["input_feeds"] == ["binance ETH/USDT c 1h"] # test s_start_payouts attribute set - predictoor_ss = PredictoorSS(d) + ss = PredictoorSS(d) - assert ( - predictoor_ss.s_start_payouts == 0 - ), "Must be unset in the test dict, so should return 0" + assert ss.s_start_payouts == 0, "Must be unset in the test dict, so should return 0" # let's set it here d["bot_only"]["s_start_payouts"] = 100 - predictoor_ss = PredictoorSS(d) - assert predictoor_ss.s_start_payouts == 100, "Must be set to 100" + ss = PredictoorSS(d) + assert ss.s_start_payouts == 100, "Must be set to 100" @enforce_types diff --git a/pdr_backend/ppss/test/test_sim_ss.py b/pdr_backend/ppss/test/test_sim_ss.py index 0497dc85e..f175fa004 100644 --- a/pdr_backend/ppss/test/test_sim_ss.py +++ b/pdr_backend/ppss/test/test_sim_ss.py @@ -4,7 +4,7 @@ from enforce_typing import enforce_types -from pdr_backend.ppss.sim_ss import SimSS +from pdr_backend.ppss.sim_ss import SimSS, sim_ss_test_dict _D = {"do_plot": False, "log_dir": "logs", "test_n": 2} @@ -52,3 +52,15 @@ def test_log_dir(tmpdir): ss = SimSS(d) target_log_dir = os.path.join(tmpdir, "logs") assert ss.log_dir == target_log_dir + + +@enforce_types +def test_sim_ss_test_dict(tmpdir): + log_dir = os.path.join(tmpdir, "logs") + d = sim_ss_test_dict(log_dir) + assert d["do_plot"] + assert d["log_dir"] == log_dir + + ss = SimSS(d) + assert ss.do_plot + assert ss.log_dir == log_dir diff --git a/pdr_backend/sim/test/test_sim_engine.py b/pdr_backend/sim/test/test_sim_engine.py index 60d5a88a4..a507e57e5 100644 --- a/pdr_backend/sim/test/test_sim_engine.py +++ b/pdr_backend/sim/test/test_sim_engine.py @@ -3,10 +3,10 @@ from enforce_typing import enforce_types -from pdr_backend.ppss.lake_ss import LakeSS +from pdr_backend.ppss.lake_ss import LakeSS, lake_ss_test_dict from pdr_backend.ppss.ppss import PPSS, fast_test_yaml_str from pdr_backend.ppss.predictoor_ss import PredictoorSS, predictoor_ss_test_dict -from pdr_backend.ppss.sim_ss import SimSS +from pdr_backend.ppss.sim_ss import SimSS, sim_ss_test_dict from pdr_backend.sim.sim_engine import SimEngine @@ -25,28 +25,13 @@ def test_sim_engine(tmpdir): ppss.predictoor_ss = PredictoorSS(d) # lake ss - d = { - "feeds": input_feeds, - "parquet_dir": os.path.join(tmpdir, "parquet_data"), - "st_timestr": "2023-06-18", - "fin_timestr": "2023-06-30", - "timeframe": "5m", - } + parquet_dir = os.path.join(tmpdir, "parquet_data") + d = lake_ss_test_dict(parquet_dir, input_feeds) ppss.lake_ss = LakeSS(d) # sim ss - d = { - "do_plot": True, - "log_dir": os.path.join(tmpdir, "logs"), - "test_n": 10, - "exchange_only": { - "timeout": 30000, - "options": { - "createMarketBuyOrderRequiresPrice": False, - "defaultType": "spot", - }, - }, - } + log_dir = os.path.join(tmpdir, "logs") + d = sim_ss_test_dict(log_dir) ppss.sim_ss = SimSS(d) # go