Coverage for tests/django_tests/db/simulations/test_simulation.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-12 13:49 +0000

1import uuid 

2from datetime import datetime 

3 

4from pytz import UTC 

5 

6from django_napse.core.models import Bot, Controller, EmptyBotConfig, EmptyStrategy, SinglePairArchitecture 

7from django_napse.simulations.models import Simulation 

8from django_napse.utils.model_test_case import ModelTestCase 

9 

10""" 

11python tests/test_app/manage.py test tests.django_tests.db.simulations.test_simulation -v2 --keepdb --parallel 

12""" 

13 

14 

15class SimulationTestCase: 

16 model = Simulation 

17 

18 def simple_create(self): 

19 config = EmptyBotConfig.objects.create(space=self.space, settings={"empty": True}) 

20 architecture = SinglePairArchitecture.objects.create( 

21 constants={ 

22 "controller": Controller.get( 

23 exchange_account=self.exchange_account, 

24 base="BTC", 

25 quote="USDT", 

26 interval="1m", 

27 ), 

28 }, 

29 ) 

30 strategy = EmptyStrategy.objects.create(config=config, architecture=architecture) 

31 bot = Bot.objects.create(name="Test Bot", strategy=strategy) 

32 return Simulation.objects.create( 

33 space=self.space, 

34 bot=bot, 

35 start_date=datetime(2021, 1, 1, tzinfo=UTC), 

36 end_date=datetime(2021, 1, 3, tzinfo=UTC), 

37 simulation_reference=uuid.uuid4(), 

38 data={}, 

39 ) 

40 

41 def test_with_data(self): 

42 config = EmptyBotConfig.objects.create(space=self.space, settings={"empty": True}) 

43 architecture = SinglePairArchitecture.objects.create( 

44 constants={ 

45 "controller": Controller.get( 

46 exchange_account=self.exchange_account, 

47 base="BTC", 

48 quote="USDT", 

49 interval="1m", 

50 ), 

51 }, 

52 ) 

53 strategy = EmptyStrategy.objects.create(config=config, architecture=architecture) 

54 bot = Bot.objects.create(name="Test Bot", strategy=strategy) 

55 simulation = Simulation.objects.create( 

56 space=self.space, 

57 bot=bot, 

58 start_date=datetime(2021, 1, 1, tzinfo=UTC), 

59 end_date=datetime(2021, 1, 3, tzinfo=UTC), 

60 simulation_reference=uuid.uuid4(), 

61 data={ 

62 "dates": [datetime.now(tz=UTC)], 

63 "values": [1], 

64 "actions": ["BUY"], 

65 "amounts": [1], 

66 "tickers": ["USDT"], 

67 "mbp": [10], 

68 }, 

69 ) 

70 simulation.info(verbose=False) 

71 

72 def test_with_more_data(self): 

73 config = EmptyBotConfig.objects.create(space=self.space, settings={"empty": True}) 

74 architecture = SinglePairArchitecture.objects.create( 

75 constants={ 

76 "controller": Controller.get( 

77 exchange_account=self.exchange_account, 

78 base="BTC", 

79 quote="USDT", 

80 interval="1m", 

81 ), 

82 }, 

83 ) 

84 strategy = EmptyStrategy.objects.create(config=config, architecture=architecture) 

85 bot = Bot.objects.create(name="Test Bot", strategy=strategy) 

86 simulation = Simulation.objects.create( 

87 space=self.space, 

88 bot=bot, 

89 start_date=datetime(2021, 1, 1, tzinfo=UTC), 

90 end_date=datetime(2021, 1, 3, tzinfo=UTC), 

91 simulation_reference=uuid.uuid4(), 

92 data={ 

93 "dates": [ 

94 datetime(2021, 1, 1, tzinfo=UTC), 

95 datetime(2021, 1, 2, tzinfo=UTC), 

96 datetime(2021, 1, 3, tzinfo=UTC), 

97 datetime(2021, 1, 4, tzinfo=UTC), 

98 datetime(2021, 1, 5, tzinfo=UTC), 

99 datetime(2021, 1, 6, tzinfo=UTC), 

100 datetime(2021, 1, 7, tzinfo=UTC), 

101 datetime(2021, 1, 8, tzinfo=UTC), 

102 datetime(2021, 1, 9, tzinfo=UTC), 

103 datetime(2021, 1, 10, tzinfo=UTC), 

104 ], 

105 "values": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 

106 "actions": ["BUY", "SELL", "SELL", "BUY", "KEEP", "KEEP", "BUY", "SELL", "BUY", "SELL"], 

107 "amounts": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 

108 "tickers": ["USDT", "USDT", "USDT", "USDT", "USDT", "USDT", "USDT", "USDT", "USDT", "USDT"], 

109 "mbp": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10], 

110 }, 

111 ) 

112 simulation.info(verbose=False) 

113 

114 

115class SimulationBINANCETestCase(SimulationTestCase, ModelTestCase): 

116 exchange = "BINANCE"