A university project on Python: a stock exchange simulator, functioning as a telegram bot.
Using this bot you can collect virtual investment portfolio with virtual money to buy virtual stocks for real market prices.
You can test your investment strategy without spending real money!
A deployed telegram bot is available: @HSEDuckBot.
Bot is working on Heroku platform, with CD pipeline from GitHub repository (
branch master
): https://github.com/petrtsv/HSEDuck
Stock prices are updated every hour using yfinance
library.
/help
— prints help message
/stock_list
— prints all available stocks
/my_portfolios
— prints list of all your portfolios
/new_portfolio NAME
— creates a new portfolio with initial balance of $10'000
/buy PORTFOLIO_ID TICKER QUANTITY
— buys some stock for one of your portfolios
/sell PORTFOLIO_ID TICKER QUANTITY
— sells some stock from one of your portfolios
Create investment portfolio; buy 3 FB stocks and sell one of them:
/new_portfolio Foo
/my_portfolios
— find Foo portfolio and remember its ID/buy ID FB 3
/my_portfolios
— to see the result/sell ID FB 1
/my_portfolios
— to see the result again
The bot has an option for creating contests. After joining a contest, user receives a special portfolio, connected to it.
The total cost of this portfolio is your result: you can see a leaderboard, containing results of all users, joined the same contest.
When creating a contest, owner chooses name and duration: after given amount of hours it is forbidden to perform any operation on connected portfolios.
Here are the commands for the competitive mode:
/new_contest NAME HOURS
— creates a new contest with given name (note: name can only be one word), lasting for the
given amount of hours
/my_contests
— prints full information about all contests you have joined
/join CONTEST_ID
— join the contest with given id
/join global
— join an eternal global competition
NOTE: actual results will be displayed only after all short positions will be automatically covered (maximum 24 hours after the end of the contest).
This bot also supports short-selling. You can borrow some stocks from the virtual broker for 24 hours. Stocks are immediately sold and money is transferred to the portfolio. After deadline, stocks are automatically taken from the portfolio (and purchased, if the amount is not enough to cover the short position).
After deadline, you can get negative amount of money on your portfolio.
There's a limitation on short-selling: you cannot borrow stocks if total cost of not covered short position
exceeds $10'000
after the requested operation.
Command to open a short position works similar to buy/sell commands:
/short PORTFOLIO_ID TICKER QUANTITY
To deploy the application on your own you have to:
- Install dependencies:
pip install -r requirements.txt
- Set following environment variables
HSEDUCK_TG_TOKEN
— telegram bot tokenHSEDUCK_DEBUG
— if you want to use sqlite database stored in a file in the app folder; otherwise,DATABASE_URL
must be set to PostgreSQL connection string.
- Run
python entrypoint.py
Configuration is stored in config.py