21 lines
1.1 KiB
Markdown
21 lines
1.1 KiB
Markdown
# Stock trading bot
|
|
During my senior year of high school, my economics class had a
|
|
competition where we traded stocks on a fake online exchange.
|
|
I wrote a Python shell script which could make purchasing decisions
|
|
for me, and submit them to the website. It uses Beautiful Soup to
|
|
log in to the virtual exchange with my details, and to collect
|
|
stock information from sources like Yahoo Finance. When given a
|
|
budget, it chooses a diverse selection of shares which most closely
|
|
approaches the budget without exceeding it.
|
|
|
|
## Challenges
|
|
Using web scraping to collect data online is difficult to do performantly
|
|
and robustly. Network errors and slow internet speeds caused the program to
|
|
run very slowly, and changes to page layouts could cause the scraper to
|
|
err. To solve these errors, a script can query several pages in parallel
|
|
and retry on network errors. Caching can also significantly speed things
|
|
up. I chose Yahoo Stocks because its page layout changes very little over
|
|
time, and I use BeautifulSoup, a very robust HTML parser and scraper to
|
|
reliably retrieve data.
|
|
|