How I made the robot read the trading and investment channels for me

Hello everyone! I want to share one of my crafts, maybe it will be useful to someone else. I decided to rewrite my article for Habr, adding code examples from which you can build such a robot for yourself. Who cares, welcome to cat.





Background

About six months ago, I began to understand the topic of investments, because deposit rates have broken through another bottom, this time having dropped below the inflation rate, which is of course very sad. Nevertheless, thanks to this event, I plunged into the topic of investments and learned a lot of new and interesting things. Now I can distinguish stocks from bonds.





My acquaintance with this topic took place in several directions.





First, I bought some stocks and started looking at how their quotes react to certain news. Suddenly it turned out that after an excellent report, the price may fall (because on good news, large players often try to fix profits, which makes quotes collapse).





Secondly, every day I began to disassemble exchange terms, phenomena and relationships, and write notes for myself in the cart. There were 500 such posts in six months.





Thirdly, I started reading news on RBK, Finam and just in the channels in the cart. At the same time, as I noticed on my own, my attention gradually completely shifted to telegrams, because when I want to see the relationship between the movement of quotes and events, the time factor becomes important.





At first I read everything and it was just interesting, then I began to notice inconsistencies between different channels in assessing certain events, I realized that you need to look at the information critically, since people (including experts) are constantly mistaken in their forecasts. Already on the stock exchange it is just in the order of things. Nevertheless, constant analysis in this format gives a good immersion in the topic and already forms its own opinion on this or that issue.





The problem of the endless flow of information

, , , , "" , - , , , , , . , , "", , , , "" , .





, 150 , , , , , , , .





, -, , , . .





, -, , , -, — , , «Yandex», «», «YNDX». , , . , ? .





telethon





from telethon import TelegramClient, events, sync
from telethon.tl.functions.channels import JoinChannelRequest
import re
      
      



, API https://my.telegram.org/, , "API development tools", 2 , Platform Desktop.





App api_id, App api_hash . PHONE_NUMBER , .





API_ID = 1234567 #   api_id
API_HASH = 'your_hash'
PHONE_NUMBER = '+7xxxxxxxxxx'  
      
      



,





 CHANNELS = (
             'channel1_name',  #     
             'channel2_name',  #  https://t.me, @   -  
   					 'channel3_name    
             )  
      
      



, , . , , .





# 
names = {
    'channel1_to_post': ['interesting_text1', 
                         'interesting_text2'],
    'channel2_to_post': ['other_channel_interesting_text1', 
                         'other_channel_interesting_text2', 
                         'other_channel_interesting_text3'],
}
# ""     +    
d = {}
for name in names.keys():
    for t in names[name]:
        d[t.lower()] = name.lower()
print(d)
      
      



- , :





client = TelegramClient('session', API_ID, API_HASH)
client.start()

for channel in CHANNELS:
    client(JoinChannelRequest(channel))
      
      



, ,





#     
@client.on(events.NewMessage(CHANNELS))
async def handler(event):
    print(f'received text: {event.message.message}')
    
    for tmp in d.keys():
      await client.forward_messages(d[tmp], event.message)

client.run_until_disconnected()
      
      



( , 150 )





t.me/tesla_twits - Tesla

t.me/apple_twits - Apple

t.me/amazon_twits - Amazon

t.me/moderna_twits - Moderna

t.me/pfizer_twits - Pfizer

t.me/google_twits - Google

t.me/facebook_twits - Facebook

t.me/microsoft_twits - Microsoft

t.me/yandex_twits -

t.me/mailru_twits - Mail.ru

t.me/mts_twits -

t.me/aeroflot_twits -

t.me/rosneft_twits -

t.me/sber_twits -

t.me/gazprom_twits -

t.me/afk_twits -

t.me/nornickel_twits  - Norilsk Nickel

t.me/vtb_twits  - VTB

t.me/rusal_twits  - Rusal

t.me/lukoil_twits  - Lukoil





I would be glad if someone else besides me would appreciate it. Therefore, if you own shares of these companies and periodically do not understand why they are sagging, or you just want to "pick" them up on time and at a low price, subscribe. Unfortunately, Telegram allows you to make a limited number of open channels, so I will delete those channels in which there will be the least number of subscribers.





All good!








All Articles