CredoEx Exchanges Technology Tutorial

Tutorial: How to Implement Dollar-Cost Averaging for Credo using the CredoEx API

August 16, 2018


Tutorial: How to Implement Dollar-Cost Averaging for Credo using the CredoEx API

Yesterday our team announced the CredoEx API. Some traders may have read through our documentation, but not been sure how to get started. This tutorial illustrates how you could use the API to programmatically implement a simple trading strategy: dollar-cost averaging.

Step 1 – Sign up for CredoEx

If you don’t have an account already, go to and sign up.

Step 2 – Generate an API Key

Once you have an account, you can generate an API Key using your email, password, and a new passphrase that you come up with. You’ll probably find it easiest to give your API key full permissions for now.

Step 3 – Set your API key, secret, passphrase in environment variables

Once you’ve generated the API key, set environment variables for these values on your computer. You can do so by putting lines like the following in your .bash_rc or .profile file:

export XAPI_KEY=9a252941-b1dc-4888-934d-ac797d1c8e3f
export XAPI_SECRET=6d3aescb-41de-49bb-bf5d-2eeee1dc5731
export XAPI_PASSPHRASE=myPassphrase

Step 4 – Create a new project

For this tutorial, I’ll be using Elixir. You can generate a new mix project using the following command:

mix new dollar_cost_averaging

Step 5 – Load the API Key environment variables

Once you’ve created the project, you can load your API key credentials from environment variables into the application. You can typically do this in the config file and then load them again where you’re using them.

Step 6 – Implement a request for placing a Credo-TUSD market buy order

Once you’ve got the application, you can follow instructions for creating an order to place a market buy order for 1 TUSD (or whatever amount you’d like) worth of Credo. Here’s an example of how I implemented this request.

Step 7 – Set up the order to be created at regular intervals.

Once you have a function for placing an order, you just need to set up a mechanism so that it’s called periodically. For Elixir, I used the quantum library to specify the interval like so.

Step 8 – Run your application

All that’s left now is to run your application. Just type the following command and your dollar-cost averaging trading strategy will start to execute:

mix run 

If you’d like to see a full example of this, I’ve open sourced the version I wrote here. Please feel free to adapt it to suit your trading needs, whatever they may be!