Trading securities is a dangerous game. It can be difficult to develop a strategy and stick to it in the face of an emotional marketplace that stampedes from one extreme to the other. Sticking to a trading strategy takes time, discipline and serious balls far beyond the capacity of most human beings.

One way rise above the impediments is to encode your strategy into an algorithm and instruct a machine to execute that strategy for you. You can still freak out and pull the plug at any time, but until you do, machines can execute your strategy without hesitation or emotion. Just the exercise of encoding potential trading strategies into machine instructions is enough to spot problems and potential weaknesses. That’s why my highest priority when choosing a stock broker was API quality. Strangely, I only found one broker who’s trading API was even acceptable, OptionsHouse. The OptionsHouse API offers all the functionality you need to create simple trading algorithms, the documentation is acceptable and they offer paper trading accounts so you can easily test your algorithms without using any real money (an absolute requirement).

To get started learning how to use the API, I created a generic API client in Python. My aim was primarily to create something generic enough to be useful to anyone who wants to automate interaction with OptionsHouse, and secondarily to create something reliable with unit tests that guarantee certain functionality: