78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
from datetime import datetime
|
|
import telegram
|
|
import asyncio
|
|
|
|
class TelegramBot:
|
|
enable = None
|
|
BOT_TOKEN = None
|
|
CHANNEL_ID = None
|
|
client = None
|
|
|
|
def __init__(self, enable=True):
|
|
"""
|
|
botname: coinbot
|
|
username for the bot: ncue_coin_bot
|
|
token to access the HTTP API: 6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM
|
|
|
|
botname: lottobot
|
|
username for the bot: ncue_lotto_bot
|
|
token to access the HTTP API:6791293398:AAFi1zrQTs6UmuHycAuNdsBgHDHaHcOJcYA
|
|
|
|
botname: stockbot
|
|
username for the bot: ncue_stock_bot
|
|
token to access the HTTP API: 6874078562:AAEHxGDavfc0ssAXPQIaW8JGYmTR7LNUJOw
|
|
"""
|
|
self.botname = "coinbot"
|
|
self.username = "ncue_coin_bot"
|
|
self.token = "6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM"
|
|
self.chat_id = '574661323'
|
|
self.client = telegram.Bot(token=self.token)
|
|
|
|
self.enable = enable
|
|
return
|
|
|
|
def alarm_live(self, stock_code, stock_name):
|
|
if self.enable:
|
|
this_time = datetime.now()
|
|
text = "ALIVE (" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ") " + stock_code + "(" + stock_name +")"
|
|
asyncio.run(
|
|
self.client.sendMessage(chat_id=self.chat_id, text=text)
|
|
)
|
|
print(text)
|
|
|
|
return
|
|
|
|
def post(self, stock_code, stock_name, type, price, count):
|
|
if self.enable:
|
|
this_time = datetime.now()
|
|
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "stock_code:" + stock_code + ", " + "stock_name:" + stock_name + ", " + "type:" + type + ", " + "price:" + str(price) + ", " + "count:" + str(count)
|
|
asyncio.run(
|
|
self.client.sendMessage(chat_id=self.chat_id, text=text)
|
|
)
|
|
print(text)
|
|
return
|
|
|
|
def sendMsg(self, msg):
|
|
if self.enable:
|
|
this_time = datetime.now()
|
|
text = "DATE TIME:" + this_time.strftime('%Y-%m-%d %H:%M:%S') + ", " + "msg:" + msg
|
|
asyncio.run(
|
|
self.client.sendMessage(chat_id=self.chat_id, text=text)
|
|
)
|
|
print(text)
|
|
|
|
return
|
|
|
|
if __name__ == "__main__":
|
|
this_time = datetime.now()
|
|
stock_code = "252670"
|
|
stock_name = "x2"
|
|
type = "BUY"
|
|
price = 2000
|
|
count = 2
|
|
|
|
telegramBot = TelegramBot(True)
|
|
telegramBot.post(stock_code, stock_name, type, price, count)
|
|
|
|
|