Crypto DCA with ruby in Binance and Kraken

In this post I'll describe a basic way of doing crypto Dollar Cost Average on Binance and Kraken. I am doing this strategy using a toy ruby on rails application in heroku. In this application I have implemented some other interesting things but for now we will focus on DCA.
I am using heroku scheduler addon and run everyday a specific task which executes an order. I will show some code and give a description, but I won't give the complete application. It's pretty basic so I urge you to try and build it. But if you still can't and be interested, I'll help you to create it and learn... or I'll extract it for you if you absolutely need it and can't build it by yourself. :)

Basic settings

I am using a Setting model with EAV pattern. It's a pretty common rails model with two fields, one with the name "key" and the other with name "value" which is in jsonb type. I am storing the necessary settings per case. Here is the migration:

Binance

For connecting to binance you will need a valid Binance account. Then you need to get an API key (go to account->API Management as photo). You have to check the Spot & Margin trading during the creation.
Now for the ruby part, you need to add gem "binance-connector-ruby" and add it to an initializer for using it everywhere inside your app. The code which is pretty straightforward is the following: As you can see I am storing into settings the actual amount of money to invest each day, the euro price which left and the total volume of BTC. If there are less than 5 times the amount in euro, then it alarms me to deposit more money on binance. Another thing that we can add is the reminder for the re-generation of the API key as it gets expired after some months.
Kraken API is similar. I have used gem 'kraken_ruby_client', initialize a KrakenClient into initialize script and then the command for using the buy order is: KrakenClient.add_order(volume: quantity, type: "buy", pair: 'BTCEUR', ordertype: 'market')

Conclusion

I have described and show some ideas and code of how you can use a basic automation for DCA using kraken and binance. In my app I have also added a form for changing the price or displaying the variables. I am currently using Binance for this as it has better fees than Kraken, not something significant but still. On the other hand, Kraken is simpler and it's API is easier, so depending on what your preference, it may be a better choice.
Max one mail per week.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.