This commit is contained in:
dsyoon
2023-12-12 00:15:38 +09:00
parent 6b22132b43
commit fbfab6d236
7 changed files with 550 additions and 359 deletions

View File

@@ -1,6 +1,7 @@
from datetime import datetime
import telegram
import asyncio
import platform
from multiprocessing import Pool
class TelegramBot:
@@ -23,9 +24,9 @@ class TelegramBot:
username for the bot: ncue_stock_bot
token to access the HTTP API: 6874078562:AAEHxGDavfc0ssAXPQIaW8JGYmTR7LNUJOw
"""
self.botname = "stockbot"
self.username = "ncue_stock_bot"
self.token = "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)
@@ -36,25 +37,29 @@ class TelegramBot:
@staticmethod
def send(text):
client = telegram.Bot(token="6874078562:AAEHxGDavfc0ssAXPQIaW8JGYmTR7LNUJOw")
#client.sendMessage(chat_id='574661323', text=text)
client = telegram.Bot(token="6435061393:AAHOh9wB5yGNGUdb3SfCYJrrWTBe7wgConM")
if platform.system().lower() == 'windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(client.send_message(chat_id='574661323', text=text))
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 +")"
text = "[ALIVE] {} {} ({})".format(this_time.strftime('%H:%M'), stock_code, stock_name)
pool = Pool(12)
pool.map(self.send, [text])
print(text)
return
def post(self, stock_code, stock_name, type, price, count):
def post(self, stock_code, stock_name, type, price, amount, rsi, balance=0):
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)
if 0 < balance:
text = "{}, {}, code: {}, name: {}, price: {}, amount: {}, (balance: {:2f}), (rsi: {:2f})".format(type, this_time.strftime('%H:%M'), stock_code, stock_name, price, amount, balance, rsi)
else:
text = "{}, {}, code: {}, name: {}, price: {}, amount: {}, (rsi: {:2f})".format(type, this_time.strftime('%H:%M'), stock_code, stock_name, price, amount, rsi)
pool = Pool(12)
pool.map(self.send, [text])
print(text)
@@ -63,7 +68,7 @@ class TelegramBot:
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
text = "{}: {}".format(this_time.strftime('%H:%M'), msg)
pool = Pool(12)
pool.map(self.send, [text])
print(text)
@@ -76,10 +81,9 @@ if __name__ == "__main__":
stock_name = "x2"
type = "BUY"
price = 2000
count = 2
telegramBot = TelegramBot()
telegramBot.alarm_live(stock_code, stock_name)
telegramBot.post(stock_code, stock_name, type, price, count)
telegramBot.post(stock_code, stock_name, type, price)