2022-01-27 19:12:15 +00:00
|
|
|
# Twisted/Klein imports
|
|
|
|
from twisted.logger import Logger
|
|
|
|
|
|
|
|
# Other library imports
|
|
|
|
import requests
|
|
|
|
|
|
|
|
# Project imports
|
|
|
|
from settings import settings
|
|
|
|
|
|
|
|
|
|
|
|
class Notify(object):
|
|
|
|
"""
|
|
|
|
Class to handle more robust notifications.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.log = Logger("notify")
|
|
|
|
|
|
|
|
def sendmsg(self, msg, title=None, priority=None, tags=None):
|
|
|
|
headers = {"Title": "Bot"}
|
|
|
|
if title:
|
|
|
|
headers["Title"] = title
|
|
|
|
if priority:
|
|
|
|
headers["Priority"] = priority
|
|
|
|
if tags:
|
|
|
|
headers["Tags"] = tags
|
|
|
|
requests.post(
|
|
|
|
f"{settings.Notify.Host}/{settings.Notify.Topic}",
|
|
|
|
data=msg,
|
|
|
|
headers=headers,
|
|
|
|
)
|
|
|
|
|
|
|
|
def notify_new_trade(self, amount, currency):
|
|
|
|
amount_usd = self.agora.to_usd(amount, currency)
|
2022-02-14 20:35:48 +00:00
|
|
|
self.sendmsg(f"Total: {amount_usd}", title="New trade", tags="trades", priority=2)
|
2022-01-27 19:12:15 +00:00
|
|
|
|
|
|
|
def notify_complete_trade(self, amount, currency):
|
|
|
|
amount_usd = self.agora.to_usd(amount, currency)
|
2022-02-14 20:35:48 +00:00
|
|
|
self.sendmsg(f"Total: {amount_usd}", title="Trade complete", tags="trades,profit", priority=3)
|
2022-01-27 19:12:15 +00:00
|
|
|
|
|
|
|
def notify_withdrawal(self, amount_usd):
|
2022-02-14 20:35:48 +00:00
|
|
|
self.sendmsg(f"Total: {amount_usd}", title="Withdrawal", tags="profit", priority=4)
|
2022-01-28 17:16:47 +00:00
|
|
|
|
|
|
|
def notify_need_topup(self, amount_usd_xmr, amount_usd_btc):
|
2022-02-14 20:35:48 +00:00
|
|
|
self.sendmsg(f"XMR: {amount_usd_xmr} | BTC: {amount_usd_btc}", title="Topup needed", tags="admin", priority=5)
|