For many, the cryptocurrency universe is just a hobby, but for many others a way to invest their money.
In this article, we are going to show you how YepCode could help you to do dollar-cost averaging (DCA) investments with cryptocurrencies using the Kraken exchange.
Dollar-cost averaging is an investment strategy that aims to reduce the impact of volatility on large purchases of financial assets. And, for sure, those cryptocurrencies are volatile 💸.
The idea behind DCA is to spread purchases across predefined intervals, regardless of asset prices.
Think that you want to invest in Bitcoin and your budget is $500. You could make an order at today's price. But maybe you don't want to invest the whole budget taking the risk that tomorrow the price is lower. An alternative could be to invest that budget in a fixed period of 5 months, investing $100 a month or $25 a week or $3,33 a day.
If you want to do this with manual orders in your cryptocurrency exchange, it may be a hard task. The biggest problem may be that you forgot to do the orders. Or your sentiment about the price at that moment could make that you don't really create the orders, going against the strategy.
A much better approach would be to automate that order creation tasks, and YepCode is a perfect tool to do that.
The process accepts the following parameters for each execution:
If you want to see a more practical approach to this task, you can see this process in our Sandbox, as it's fully configured there with the name [Sample] Crypto DCA on Kraken. But if your purpose is to learn how a process can be created in YepCode from scratch, keep reading as we are showing the steps and linking to the related page in our docs.
The first step is to create a new process:
YepCode supports a README for each process. For our case, it could be interesting to add some guides about what changes we need in Kraken to allow the process to access your cryptocurrency account.
The README content is a markdown, and a proposal content could be:
Following this guide, and after having these two keys, we have to create two YepCode environment variables to store their values. The name of the variables should be KRAKEN_API_KEY and KRAKEN_API_SECRET.
It's time to configure the input params for the process, allowing the user to provide the cash and cryptocurrencies, to use. And also the amount of cash to spend.
The JSON to configure our input parameterss would be this one:
As a result, YepCode could build a form to be shown to the user on each new execution configuration:
We'll need all the code to interact with Kraken API. We could add all the implementation in this same process. But as it seems a quite reusable component, a better idea is to use the YepCode JS modules feature to create a new module with a Kraken API client implementation.
Let's create a new Library:
And fill the source code for the module, ensuring that we export the desired objects or functions:
We like to follow the clean code conventions. Another interesting module to be created could be one to use Kraken API common functions:
The full source code of this library would be:
The process sends a report using an email client. In this case, we are using the Nodemailer integration to deliver the email using a Gmail account. The integration configuration would be:
The last step is to provide the full source code that reads the input params. By using the created modules and the configured mail integration makes the full process. This source code would be:
Having all this setup created, we could start a new on demand execution of the process, providing the requested parameters:
And navigation to the process execution details, we could also see the log output and execution information:
The used code is generating an email report, and the result for this execution is this one:
After being sure that everything works ok, and having done some on-demand executions, it's time to create a scheduled execution configuration to take the most of DCA. Let's create a new periodic execution on Friday's morning:
With the purpose of buying 10€ of ETH:
And that's all!
With this post, we hope to have shown you all the power that YepCode has to solve your everyday programming problems.