When running multiple strategies distributed over multiple servers, it would be nice if we didn’t have to set up an endpoint for each bot.
But rather having a central entry point for all strategies accessible from a single URL, for instance strategies.my-domain.com
NPM Proxy
This is exactly what the NPM Package taapi-strategies-proxy does. In a nutshell, it simply reroutes requests to the configured bots using the bot-ids, to wherever they might be located in the cloud.
Installation
Simply create a new folder for this proxy, install the NPM package and configure the available bots.
> mkdir taapi-strategies-proxy
> npm init -f
> npm install --save taapi-strategies-proxy
Configuration
server:
env: "dev"
port: 3001
admin:
user: "user"
pass: "pass"
services:
uptimerobot:
heartbeatUrl: ""
telegram:
bot_key: ""
hosts: [
"phobos": "127.0.0.1:3002", # Server 1
"deimos": "127.0.0.1:3003", # Server 1 different port
"titan": "127.0.0.2:3002" # Server 2
]
If you noticed in the previous chapters, we reserved the first port number 3001
and configured our bots to run on port 3002
and up. This reservation is thus for this proxy. But it can run on any port you want.
As you can see, we simply tell this proxy, where the different bots a running, and requests to this proxy will simply be rerouted based on the bot-id. For instance:
curl https://strategies.my-domain.com/get-trades?strategyId=deimos
This request will be routed to server 1
running on port 3003
Run time
We’ll expand on this section a little later, and leave you with the overall idea. And this is to launch this proxy whichever way you’d like, and map a domain name to your servers IP, along with creating an SSL certificate.
Docker
We do have a public Docker image that’ll make things easier: https://hub.docker.com/r/taapi/strategies-proxy
Conclusion
We’re now have all the components ready to install our UI web interface.