diff --git a/requirements.txt b/requirements.txt index 1441bcb..71b141e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,5 @@ ipywidgets==7.0.0 torchvision transformers scikit-learn -pybithumb \ No newline at end of file +pybithumb +slack_sdk \ No newline at end of file diff --git a/stock/util/SlackBot.py b/stock/util/SlackBot.py new file mode 100644 index 0000000..1418f4b --- /dev/null +++ b/stock/util/SlackBot.py @@ -0,0 +1,44 @@ +from slack_sdk import WebClient +from slack_sdk.errors import SlackApiError +from datetime import datetime + + +class SlackBot: + BOT_TOKEN = None + CHANNEL_ID = None + client = None + + def __init__(self): + self.BOT_TOKEN = "xoxb-1214605084611-4694289701799-1lCW10baLrihe60DvW1oZ32V" + self.CHANNEL_ID = "C021KN0GG94" + self.client = WebClient(token=self.BOT_TOKEN) + + return + + def post_to_slack(self, this_time, stock_code, stock_name, type, price, count): + try: + 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) + result = self.client.chat_postMessage( + channel=self.CHANNEL_ID, + text=text + ) + print(text) + + except SlackApiError as e: + print(f"Error posting message: {e}") + + return + + +if __name__ == "__main__": + this_time = datetime.now() + stock_code = "252670" + stock_name = "x2" + type = "BUY" + price = 2000 + count = 2 + + slackBot = SlackBot() + slackBot.post_to_slack(this_time, stock_code, stock_name, type, price, count)