Coverage for tests/django_tests/db/bots/test_plugin.py: 100%

31 statements  

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

1from datetime import datetime 

2from typing import ClassVar 

3 

4from pytz import UTC 

5 

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

7from django_napse.simulations.models import SimulationQueue 

8 

9""" 

10python tests/test_app/manage.py test tests.django_tests.bots.test_plugin -v2 --keepdb --parallel 

11""" 

12 

13 

14class PluginDefaultTestCase: 

15 strategy_class = EmptyStrategy 

16 config_settings: ClassVar = {"empty": True} 

17 

18 def simple_create(self): 

19 return self.model.objects.create(strategy=self.strategy) 

20 

21 @property 

22 def config(self): 

23 return self.strategy_class.config_class().objects.create(space=self.space, settings=self.config_settings) 

24 

25 @property 

26 def architecture(self): 

27 return self.strategy_class.architecture_class().objects.create(constants=self.architecture_constants) 

28 

29 @property 

30 def strategy(self): 

31 return self.strategy_class.objects.create(config=self.config, architecture=self.architecture) 

32 

33 @property 

34 def architecture_constants(self): 

35 return { 

36 "controller": Controller.get( 

37 exchange_account=self.exchange_account, 

38 base="BTC", 

39 quote="USDT", 

40 interval="1m", 

41 ), 

42 } 

43 

44 def test_simulation(self): 

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

46 architecture = SinglePairArchitecture.objects.create( 

47 constants={ 

48 "controller": Controller.get( 

49 exchange_account=self.exchange_account, 

50 base="BTC", 

51 quote="USDT", 

52 interval="1d", 

53 ), 

54 }, 

55 ) 

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

57 self.model.objects.create(strategy=strategy) 

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

59 simulation_queue = SimulationQueue.objects.create( 

60 space=self.space, 

61 bot=bot, 

62 start_date=datetime(2020, 1, 1, tzinfo=UTC), 

63 end_date=datetime(2020, 1, 5, tzinfo=UTC), 

64 investments={"USDT": 10000}, 

65 ) 

66 

67 simulation_queue.run_quick_simulation(verbose=False)