Automatic Stock Trader

A bot that automatically buys wanted stock when a headline features "good news" about the subject company

Bot: A program that performs actions designed for a human, e.g buy stocks, interact with platforms such as Reddit.

This was certainly an interesting project, and it was made up of several distict modules:

1. Newspaper parser

The first important feature was for the program to fetch and read newspaper headlines, I accomplished this using the newspaper3k library for Python3, whilst mostly functional it is not actively maintained and had some issues that needed workarounds (in addition to poor documentation which made the whole process more complicated). However it still ended up being faster than a manual implementation (No other libraries existed) and removes some complexity from the project.

2. The control method

The client wanted to be able to interact with the program through a Telegram bot, fortunately Telegram have a brilliant API and excellent documentation, this made this section much easier to develop. It needed to listen to commands from the user, parse the arguments and perform the appropriate action (for example adding a company, keyword or newssite to the list or getting the current status of the bot).

3. The stock buying API

This was undoubtably the most challenging part of this project, there are no easy to use libraries to simply buy stocks, the libraries I found required a lot of knowledge of the stock market and stock market terms and up to 100 lines of code before you could actually do anything, in one case you had to have a big piece of software running in addition to your code.

Fortunately I came across a brand new service, Alpaca which simplified the whole process and saved a lot of time and effort on this project (which was already exceeding my initial time requirements). Alpaca made it ridiculously simple to trade in just a couple lines of code.


After bringing together the three parts of this project and cleaning up some bugs I'm proud of how it turned out, there are some things I'd improve in the backend that caused some complications however the end result met the clients expectations and has the potential to create a lot of profit given the investment.