Coverage for django_napse/core/models/bots/plugins/sbv.py: 100%

16 statements  

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

1from django_napse.core.models.bots.plugin import Plugin 

2from django_napse.core.models.connections.connection import ConnectionSpecificArgs 

3from django_napse.utils.constants import PLUGIN_CATEGORIES, SIDES 

4 

5 

6class SBVPlugin(Plugin): 

7 @classmethod 

8 def plugin_category(cls): 

9 return PLUGIN_CATEGORIES.POST_ORDER 

10 

11 def _apply(self, data: dict) -> dict: 

12 order = data["order"] 

13 current_base_amout = data["connection_data"][data["connection"]]["wallet"]["currencies"].get(order["controller"].base, {"amount": 0})[ 

14 "amount" 

15 ] 

16 current_quote_amout = data["connection_data"][data["connection"]]["wallet"]["currencies"].get(order["controller"].quote, {"amount": 0})[ 

17 "amount" 

18 ] 

19 if data["connection_data"][data["connection"]]["connection_specific_args"]["sbv"].get_value() is None or order["side"] == SIDES.SELL: 

20 order["ConnectionModifications"] += [ 

21 { 

22 "key": "sbv", 

23 "value": current_quote_amout + current_base_amout * order["price"], 

24 "target_type": "float", 

25 "ignore_failed_order": False, 

26 "connection_specific_arg": data["connection_data"][data["connection"]]["connection_specific_args"]["sbv"], 

27 }, 

28 ] 

29 return data 

30 

31 def _connect(self, connection): 

32 ConnectionSpecificArgs.objects.create(connection=connection, key="sbv", value="None", target_type="float")