Strategies – Framework [full setup]

Building on the previous guide Strategies – Framework [basics], we will set up a fully functional multi strategies setup. If you haven’t already read this guide, it’s recommended to at least skim through it.

This guide is not meant to be advanced, but basic coding knowledge is assumed. Additionally, this setup is crossplatform, so you will be able to run this on any platform [Linux, Mac, Windows, etc…], and basic Linux Bash commands are used in these examples on the command line, but do things how you feel comfortable when creating files and folders on your platform.

Prerequisites

Note that, we don’t even need to have NodeJS nor MongoDB installed, as Docker takes care of this automatically.

Getting started

To get started we first have to “Fork” the TAAPI.IO Strategies repository into our own Github account. Forking a repository simply means to “make a copy of a project into your own account“, so click the “Fork” button in the upper right hand side. Name the repository “taapi-strategies“. If you don’t have a Github account, then make a free account and sign in.

Then we’ll need a folder to put our project in:

> mkdir taapi-strategies

> git init # Initialize a new Git project
> git clone https://github.com/my-username/taapi-strategies

Be sure to replace “my-username” with your own actual username!

You should now have a complete copy of TAAPI.IOs open source strategies repository, along with all the strategies we’ve created for public use.

Boot up your favorite code IDE and verify that you see something similar to the below directory / files structure.

> code .

Directory / files Structure

taapi-strategies/
|-- strategies/
|   |-- phobos
|   |   |-- README.md
|   |   |-- State_<your-state-name>.js
|   |   |-- State_start.js
|   |   |-- State.js
|   |   |-- strategy.yml
|   |-- <other strategies>
|
|-- strategy/
|   |-- node_modules
|   |-- src/
|   |   |-- index.js
|   |
|   |-- config.yml
|   |-- package-lock.json
|   |-- package.json
|
|-- .env
|-- .gitignore
|-- docker-compose.yml

The only file missing is the config.yml. Please fill that in, and be sure to paste in your TAAPI.IO Secret! If you don’t have one, then get one.

server:
    env: "dev"
    host: "localhost"
    port: 3002
    debugMode: true

api:
    corsOrigin: "*"
    user: "user"
    pass: "pass"

database:
    namePrefix: "taapi_strategies_"
    name: "${BOT_ID}" # Will be replaced with the actual bot id in the strategies.yml file at run time!
    host: "mongo"
    port: 27017
    user: ""
    pass: ""
    protocol: "mongodb"
    collectionPrefix: ""
    replSetName: null
    sslValidate: false
    sslCertFilename: null

exchange:
    id: "binancefutures"
    name: "Binance Futures"

logging:
    errors: true
    stateChanges: true
    ta: false

uptimerobot:
    heartbeatUrl: ""

taapi:
    secret: ""

notifications:
    slack:
        webhookUrl: null
        channel: "bot"
        username: "TAAPI.IO Strategies"
        icon: "information_source"

    telegram:
        bot_key: null

And this is it for the setup. We’re now ready to start running things.

How it works

Now, for beginners that haven’t worked much with Docker or Docker Compose, this might seem like a lot of magic. But unless you have an urge to spend a lot of hours of your life understanding how and why this works, don’t worry about it.

All we have to do now, is run one command:

> docker-compose up

If things are working how they should, you should see something like this

So what happens in the background, is that first, Docker will look at your system and check if all dependencies are installed. This means a virtual Linux Operating System, NodeJS, MongoDB, and all program packages needed to run the APP.

This might take a minute or two, but once it’s done, you should see something similar to the above output. Don’t worry, all of these commands are safe to run. No additional software will be installed on your system, everything is running in so-called “containers” which is basically a very tiny Virtual Machine running on your host system.

Runtime configuration

You’ll notice that in the directory structure, there’s a folder named “strategies”, which contains a number of strategies. The folder name is an exact match for the strategy id in the configuration files, so be sure to name those precisely.

To change the framework to run a different strategy, open up the .env file. This file tells Docker Compose a couple of things.

bot_port=3002
app_version="dev"
strategy_id="phobos"

To change strategy, simply change the strategy_id to some other strategy, save the file, hit ctrl-c, and docker-compose up again, and you’ll be running the new strategy.

Development

Now we’re up and running and we can now start focusing on what this is all about – the strategies.