Algo-trading Cryptocurrency – Client/Ordes Execution
Now when we have backtested strategy, we want to connect it to the market and battle test it. But first we need client to do so. Coinbase have really nice library for it so it’s quite easy to create “Account” that will sit on top of the client and will execute the orders from the strategy runner. Here is the big picture of the architecture we are building:
Coinbase API
As I have mention earlier Coinbase have pretty good client for Node.JS so I have created simple service to plug it into the runner. There are tow types of API. The first one is sandbox API, the second one is production API. For tuning I’m always using the sandbox and only when deployed, the production environment is used. Below is image of the my coinbase service AKA interface which is same for the AccountMock.
For my strategy 2 types of orders are used. It’s Market order and Stop Loss (Limit Order). Below are basic types of orders you should know.
Market Order
size/funds | Desired amount in BTC |
side | sell or buy |
product_id | e.g.BTC-USD |
type | market (default is limit ) |
Limit Order
size | Desired amount in BTC |
side | sell or buy |
price | e.g. 7200 |
product_id | e.g.BTC-USD |
(type) | default is limit |
Stop Order (Limit Order)
size | Desired amount in BTC |
side | sell or buy |
stop_price | e.g. 7300 (this is the trigger price) |
stop | loss or enter |
price | e.g. 7200 (this is the price that will be placed in the Order Book) |
product_id | e.g.BTC-USD |
(type) | default is limit |
Automation
My trading strategy needs to be ran once in the end of the time frame. For me its one day so I’m not going to use the web sockets API and keep it running all day but I will use CRON job to run the runner once a day. For sake of simplicity I will use Heroku with the Advance Scheduler Add-on.
Reference the runner script in my package.json as seen below
Add the command as a trigger in Advanced Scheduler App
Download
You can download or fork the repo here.
Note
I didn’t have much time to test it yet so it may contain some bugs.