Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/bot.py
5925 views
1
from twitchio.ext import commands
2
import twitch_creds
3
import client
4
5
bot = commands.Bot(
6
token=twitch_creds.TMI_TOKEN,
7
client_id=twitch_creds.CLIENT_ID,
8
nick=twitch_creds.BOT_NICK,
9
prefix=twitch_creds.BOT_PREFIX,
10
initial_channels=[twitch_creds.CHANNEL]
11
)
12
13
14
@bot.command(name='sell')
15
async def sell(ctx, ticker):
16
# send signal to sell
17
if client.get_figi(ticker) in client.get_current_stocks():
18
try:
19
client.sell(ticker)
20
await ctx.send(f'{ctx.author.name} {ticker.upper()} sold')
21
except:
22
await ctx.send(f'{ctx.author.name} *ошибка*')
23
else:
24
await ctx.send(f'{ctx.author.name} Чтобы продать {ticker.upper()} - нужно иметь его в портфеле')
25
26
27
@bot.command(name='buy')
28
async def buy(ctx, ticker):
29
# send signal to buy
30
try:
31
client.buy(ticker)
32
await ctx.send(f'{ctx.author.name} {ticker.upper()} bought')
33
except:
34
await ctx.send(f'{ctx.author.name} *ошибка*')
35
36
37
if __name__ == '__main__':
38
bot.run()
39
40