Coverage for django_napse/core/models/bots/architectures/single_pair.py: 97%

30 statements  

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

1from datetime import datetime, timedelta 

2 

3from binance.helpers import interval_to_milliseconds 

4from django.db import models 

5from pytz import UTC 

6 

7from django_napse.core.models.bots.architecture import Architecture 

8 

9 

10class SinglePairArchitecture(Architecture): 

11 controller = models.ForeignKey("Controller", on_delete=models.CASCADE, related_name="single_pair_architectures") 

12 variable_last_candle_date = models.DateTimeField(default=datetime(1970, 1, 1, 0, 0, 0, 0, tzinfo=UTC)) 

13 

14 def __str__(self) -> str: 

15 return f"SINGLE PAIR ARCHITECHTURE {self.pk}" 

16 

17 def info(self, verbose=True, beacon=""): 

18 string = "" 

19 string += f"{beacon}Single Pair Architecture {self.pk}:\n" 

20 new_beacon = beacon + "\t" 

21 string += f"{beacon}Controller:\n{beacon}{self.controller.info(beacon=new_beacon, verbose=False)}\n" 

22 

23 if verbose: # pragma: no cover 

24 print(string) 

25 return string 

26 

27 def copy(self): 

28 return SinglePairArchitecture.objects.create(constants={"controller": self.controller}, variables={}) 

29 

30 def controllers_dict(self): 

31 return {"main": self.controller} 

32 

33 def skip(self, data: dict) -> bool: 

34 if data["candles"][data["controllers"]["main"]]["current"]["open_time"] < self.variable_last_candle_date + timedelta( 

35 milliseconds=interval_to_milliseconds(data["controllers"]["main"].interval), 

36 ): 

37 return True 

38 return False 

39 

40 def architecture_modifications(self, order: dict, data: dict): 

41 return [ 

42 { 

43 "key": "last_candle_date", 

44 "value": str(data["candles"][data["controllers"]["main"]]["current"]["open_time"]), 

45 "target_type": "datetime", 

46 "ignore_failed_order": True, 

47 }, 

48 ] 

49 

50 def accepted_tickers(self): 

51 return [self.controller.base, self.controller.quote] 

52 

53 def accepted_investment_tickers(self): 

54 return [self.controller.quote]