Fix discord message sending
This commit is contained in:
parent
df5ae66252
commit
9454fb8f7b
@ -11,13 +11,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class Discord(Webhook):
|
class Discord(Webhook):
|
||||||
def __init__(self, rpc: 'RPC', config: Config):
|
def __init__(self, rpc: 'RPC', config: Config):
|
||||||
# super().__init__(rpc, config)
|
self._config = config
|
||||||
self.rpc = rpc
|
self.rpc = rpc
|
||||||
self.config = config
|
|
||||||
self.strategy = config.get('strategy', '')
|
self.strategy = config.get('strategy', '')
|
||||||
self.timeframe = config.get('timeframe', '')
|
self.timeframe = config.get('timeframe', '')
|
||||||
|
|
||||||
self._url = self.config['discord']['webhook_url']
|
self._url = config['discord']['webhook_url']
|
||||||
self._format = 'json'
|
self._format = 'json'
|
||||||
self._retries = 1
|
self._retries = 1
|
||||||
self._retry_delay = 0.1
|
self._retry_delay = 0.1
|
||||||
@ -31,19 +30,21 @@ class Discord(Webhook):
|
|||||||
|
|
||||||
def send_msg(self, msg) -> None:
|
def send_msg(self, msg) -> None:
|
||||||
|
|
||||||
if msg['type'].value in self.config['discord']:
|
if msg['type'].value in self._config['discord']:
|
||||||
logger.info(f"Sending discord message: {msg}")
|
logger.info(f"Sending discord message: {msg}")
|
||||||
|
|
||||||
msg['strategy'] = self.strategy
|
msg['strategy'] = self.strategy
|
||||||
msg['timeframe'] = self.timeframe
|
msg['timeframe'] = self.timeframe
|
||||||
fields = self.config['discord'].get(msg['type'].value)
|
fields = self._config['discord'].get(msg['type'].value)
|
||||||
color = 0x0000FF
|
color = 0x0000FF
|
||||||
if msg['type'] in (RPCMessageType.EXIT, RPCMessageType.EXIT_FILL):
|
if msg['type'] in (RPCMessageType.EXIT, RPCMessageType.EXIT_FILL):
|
||||||
profit_ratio = msg.get('profit_ratio')
|
profit_ratio = msg.get('profit_ratio')
|
||||||
color = (0x00FF00 if profit_ratio > 0 else 0xFF0000)
|
color = (0x00FF00 if profit_ratio > 0 else 0xFF0000)
|
||||||
|
title = msg['type'].value
|
||||||
|
if 'pair' in msg:
|
||||||
|
title = f"Trade: {msg['pair']} {msg['type'].value}"
|
||||||
embeds = [{
|
embeds = [{
|
||||||
'title': f"Trade: {msg['pair']} {msg['type'].value}",
|
'title': title,
|
||||||
'color': color,
|
'color': color,
|
||||||
'fields': [],
|
'fields': [],
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user