• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

freqtrade / freqtrade / 6181253459

08 Sep 2023 06:04AM UTC coverage: 94.614% (+0.06%) from 94.556%
6181253459

push

github-actions

web-flow
Merge pull request #9159 from stash86/fix-adjust

remove old codes when we only can do partial entries

2 of 2 new or added lines in 1 file covered. (100.0%)

19114 of 20202 relevant lines covered (94.61%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.44
/freqtrade/rpc/discord.py
1
import logging
1✔
2

3
from freqtrade.constants import Config
1✔
4
from freqtrade.enums import RPCMessageType
1✔
5
from freqtrade.rpc import RPC
1✔
6
from freqtrade.rpc.webhook import Webhook
1✔
7

8

9
logger = logging.getLogger(__name__)
1✔
10

11

12
class Discord(Webhook):
1✔
13
    def __init__(self, rpc: 'RPC', config: Config):
1✔
14
        self._config = config
1✔
15
        self.rpc = rpc
1✔
16
        self.strategy = config.get('strategy', '')
1✔
17
        self.timeframe = config.get('timeframe', '')
1✔
18

19
        self._url = config['discord']['webhook_url']
1✔
20
        self._format = 'json'
1✔
21
        self._retries = 1
1✔
22
        self._retry_delay = 0.1
1✔
23
        self._timeout = self._config['discord'].get('timeout', 10)
1✔
24

25
    def cleanup(self) -> None:
1✔
26
        """
27
        Cleanup pending module resources.
28
        This will do nothing for webhooks, they will simply not be called anymore
29
        """
30
        pass
×
31

32
    def send_msg(self, msg) -> None:
1✔
33

34
        if msg['type'].value in self._config['discord']:
1✔
35
            logger.info(f"Sending discord message: {msg}")
1✔
36

37
            msg['strategy'] = self.strategy
1✔
38
            msg['timeframe'] = self.timeframe
1✔
39
            fields = self._config['discord'].get(msg['type'].value)
1✔
40
            color = 0x0000FF
1✔
41
            if msg['type'] in (RPCMessageType.EXIT, RPCMessageType.EXIT_FILL):
1✔
42
                profit_ratio = msg.get('profit_ratio')
1✔
43
                color = (0x00FF00 if profit_ratio > 0 else 0xFF0000)
1✔
44
            title = msg['type'].value
1✔
45
            if 'pair' in msg:
1✔
46
                title = f"Trade: {msg['pair']} {msg['type'].value}"
1✔
47
            embeds = [{
1✔
48
                'title': title,
49
                'color': color,
50
                'fields': [],
51

52
            }]
53
            for f in fields:
1✔
54
                for k, v in f.items():
1✔
55
                    v = v.format(**msg)
1✔
56
                    embeds[0]['fields'].append(
1✔
57
                        {'name': k, 'value': v, 'inline': True})
58

59
            # Send the message to discord channel
60
            payload = {'embeds': embeds}
1✔
61
            self._send_msg(payload)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc