2021-08-29 14:22:12 +02:00 | | | import os
|
| | | import sys
|
| | | import asyncio
|
| | | import requests
|
| | |
|
2021-09-04 18:19:04 +02:00 | | | from service.App import *
|
2021-09-04 21:28:45 +02:00 | | | from common.utils import *
|
2021-08-29 14:22:12 +02:00 | | |
|
| | |
|
| | | async def notify_telegram():
|
| | | status = App.status
|
| | | signal = App.signal
|
2021-10-23 21:51:55 +02:00 | | | notification_threshold = App.config["signaler"]["notification_threshold"]
|
| | | symbol = App.config["symbol"]
|
2021-10-31 14:09:21 +01:00 | | | base_asset = App.config["base_asset"]
|
| | | quote_asset = App.config["quote_asset"]
|
| | | close_price = signal.get('close_price')
|
2021-10-23 21:51:55 +02:00 | | |
|
2021-08-29 14:22:12 +02:00 | | | signal_side = signal.get("side")
|
| | | score = signal.get('score')
|
| | |
|
2021-10-31 14:09:21 +01:00 | | | # How many steps of the score
|
| | | score_step_length = 0.05
|
| | | score_steps = np.abs(score) // score_step_length
|
| | |
|
| | | if score_steps < notification_threshold:
|
2021-10-23 21:51:55 +02:00 | | | return
|
| | |
|
2021-10-31 14:09:21 +01:00 | | | if score > 0:
|
| | | sign = "📈" * int(score_steps - notification_threshold + 1) # 📈 >
|
| | | elif score < 0:
|
| | | sign = "📉" * int(score_steps - notification_threshold + 1) # 📉 <
|
| | | else:
|
2021-10-23 21:51:55 +02:00 | | | sign = ""
|
2021-10-31 14:09:21 +01:00 | | |
|
| | | # Crypto Currency Symbols: https://github.com/yonilevy/crypto-currency-symbols
|
| | | if base_asset == "BTC":
|
| | | symbol_sign = "₿"
|
| | | elif base_asset == "ETH":
|
| | | symbol_sign = "Ξ"
|
2021-10-23 21:51:55 +02:00 | | | else:
|
2021-10-31 14:09:21 +01:00 | | | symbol_sign = base_asset
|
2021-10-23 21:51:55 +02:00 | | |
|
2021-10-31 14:09:21 +01:00 | | | message = f"{symbol_sign} {int(close_price):,} {sign} Score: {score:+.2f}"
|
| | | message = message.replace("+", "%2B") # For Telegram to display plus sign
|
2021-10-23 21:51:55 +02:00 | | |
|
2021-10-31 14:09:21 +01:00 | | | #if signal_side in ["BUY", "SELL"]:
|
| | | # message = f"*{message}. SIGNAL: {signal_side}*"
|
2021-08-29 14:22:12 +02:00 | | |
|
| | | bot_token = App.config["telegram_bot_token"]
|
| | | chat_id = App.config["telegram_chat_id"]
|
| | |
|
| | | url = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + chat_id + '&parse_mode=markdown&text=' + message
|
| | |
|
2021-10-31 14:09:21 +01:00 | | | try:
|
| | | response = requests.get(url)
|
| | | #response_json = response.json()
|
| | | except Exception as e:
|
| | | print(f"Error sending notification: {e}")
|
| | |
|
| | |
|
| | | if __name__ == '__main__':
|
| | | pass
|