I’ve open sourced some of my PHP trading robot’s code. You can find the repository at https://github.com/sectioaurea/crypto-php-api. I hope it is useful for anyone setting up a price monitor or trading robot in PHP. Originally, I used some of this code in a web monitor to watch certain markets.
What you’ll find currently: modules to help you get prices from BTC-e and Cryptsy, and the API connector glue which every bot uses. Although the API connector glue code was sourced from Pastebin and broker docs, the orderbook depth traversal code is entirely original and solved an important problem for me: slippage.
If you’ve programmed a trading robot, or done a lot of trading by hand, you know the top order in the book is not always large enough to fill a trade. I wrote a function to step down the list of orders until the desired size is met, then calculate the overall price of the trade per unit.
What is missing:
- My proprietary trading engine
- The main control loop, which still is hardcoded to call my trading engine.
What will be added:
- The main control loop, once it’s refactored to not call the proprietary trading engine.