bbstrader 0.2.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bbstrader might be problematic. Click here for more details.

@@ -0,0 +1,67 @@
1
+ import asyncio
2
+
3
+ from notifypy import Notify
4
+ from telegram import Bot
5
+ from telegram.error import TelegramError
6
+
7
+ __all__ = ["send_telegram_message", "send_notification", "send_message"]
8
+
9
+
10
+ async def send_telegram_message(token, chat_id, text=""):
11
+ """
12
+ Send a message to a telegram chat
13
+
14
+ Args:
15
+ token: str: Telegram bot token
16
+ chat_id: int or str or list: Chat id or list of chat ids
17
+ text: str: Message to send
18
+ """
19
+ try:
20
+ bot = Bot(token=token)
21
+ if isinstance(chat_id, (int, str)):
22
+ chat_id = [chat_id]
23
+ for id in chat_id:
24
+ await bot.send_message(chat_id=id, text=text)
25
+ except TelegramError as e:
26
+ print(f"Error sending message: {e}")
27
+
28
+
29
+ def send_notification(title, message=""):
30
+ """
31
+ Send a desktop notification
32
+
33
+ Args:
34
+ title: str: Title of the notification
35
+ message: str: Message of the notification
36
+ """
37
+ notification = Notify(default_notification_application_name="bbstrading")
38
+ notification.title = title
39
+ notification.message = message
40
+ notification.send()
41
+
42
+
43
+ def send_message(
44
+ title="SIGNAL",
45
+ message="New signal",
46
+ notify_me=False,
47
+ telegram=False,
48
+ token=None,
49
+ chat_id=None,
50
+ ):
51
+ """
52
+ Send a message to the user
53
+
54
+ Args:
55
+ title: str: Title of the message
56
+ message: str: Message of the message
57
+ notify_me: bool: Send a desktop notification
58
+ telegram: bool: Send a telegram message
59
+ token: str: Telegram bot token
60
+ chat_id: int or str or list: Chat id or list of chat ids
61
+ """
62
+ if notify_me:
63
+ send_notification(title, message=message)
64
+ if telegram:
65
+ if token is None or chat_id is None:
66
+ raise ValueError("Token and chat_id must be provided")
67
+ asyncio.run(send_telegram_message(token, chat_id, text=message))