Move to a new server
Move Trade with its combos, trade records and accounts to a new server: how to package, restore, and what to do afterward.
Moving servers means taking Trade and its data from the old server to a new one. Combos, trade records, exchange accounts, and the administrator’s username and password all come with it. Trading stops for a while during the move; your positions stay on the exchanges. You can also move without connecting to ZML’s services; see step 5.
Only one server may run at a time. Two servers running the same combos with the same API keys would place duplicate orders, so stop the old server before you start the new one.
1. Install on the new server
Run the install command on the new server. This gives it Docker and the program:
curl -fsSL https:// api.zmarketlab.com/ install.sh | sudo bashThe new server’s version must not be older than the old server’s. Run this on both servers and compare version:
curl -sk https:// 127.0.0.1/ api/ healthIf the new server’s version is older, don’t move yet. Wait until it is at least as new as the old server.
2. Stop and package the old server
cd /opt/zml-trade
sudo docker compose stop
cd /var/lib/docker/volumes
sudo tar -czf /root/zml-trade-volumes.tgz zml-trade_pg-data zml-trade_zml-trade-data zml-trade_agent-state zml-trade_local-control zml-trade_caddy-data zml-trade_backups
sudo tar -C /opt -czf /root/zml-trade-project.tgz zml-tradeA socket ignored message while packaging is normal.
Trading has stopped from this point on. Don’t start the old server again. Together, these two files can restore your API keys and the administrator’s username and password, so treat them like passwords. Transfer them to /root on the new server, for example:
sudo scp / root/ zml-trade-volumes.tgz / root/ zml-trade-project.tgz root@NEW_SERVER_IP:/ root/3. Restore on the new server
These commands clear the empty data from the fresh install and replace it with the old server’s data:
cd /opt/zml-trade
sudo docker compose down --volumes
cd /
sudo rm -rf /opt/zml-trade
sudo tar -C /opt -xzf /root/zml-trade-project.tgz
cd /opt/zml-trade
sudo docker compose create
sudo tar -C /var/lib/docker/volumes -xzf /root/zml-trade-volumes.tgz
sudo docker compose up -d4. After the move
Open Trade at the new server’s address and sign in with your existing username and password. Allow inbound TCP 443 as in Install ZML Trade.
Running combos continue trading by their settings as soon as Trade starts. They don’t pick up earlier orders; any differences show up in reconciliation.
If your API keys use an IP allowlist, add the new server’s IP on the exchange. See The server’s egress IP changed or a new one was added.
If you use your own domain, point it at the new server.
If the old server used a certificate the browser trusts directly (requested for its public IP at install), Trade requests a new one for the new server’s IP within a few minutes of starting, and the browser opens it directly. If it can’t get one (for example, inbound TCP 443 isn’t allowed yet), it switches back to the self-signed certificate. If Trade still won’t open by IP after a few minutes, switch back to the self-signed certificate yourself:
bashsudo rm -f /opt/zml-trade/certs/public-ip/certificate.options /opt/zml-trade/certs/public-ip/certificate.site cd /opt/zml-trade sudo docker compose up -d --force-recreate caddyIf you use the self-signed certificate, Trade signs a new one for the new address and the browser warns once more that the certificate isn’t trusted. Run this on the new server and compare it character by character with the SHA-256 fingerprint in the browser’s certificate details; continue only if they match:
bashsudo openssl x509 -in /opt/ zml-trade/ certs/ local/ fallback.pem -noout -fingerprint -sha256 Once everything looks right, clear the old server with Uninstall Trade and delete the two package files in
/rooton both servers.
5. Move without connecting to ZML
Trade’s program (its Docker images) is already stored on the old server. Package it together with your data and load it on the new server.
This way you don’t run the install command on the new server, don’t connect to ZML’s services and don’t download the program again; the new server runs the same version as the old one, so there’s no version to compare. This section replaces steps 1 and 3.
Install Docker with the Compose plugin on the new server first, for example with Docker’s official install script:
curl -fsSL https:// get.docker.com | sudo shOn the old server, stop and package Trade as in step 2, then package the program:
sudo docker save -o /root/zml-trade-images.tar zml-trade-postgres:current zml-trade-app:current zml-trade-caddy:current zml-trade-agent:current
sudo gzip /root/zml-trade-images.tarTransfer the three files to /root on the new server:
sudo scp / root/ zml-trade-volumes.tgz / root/ zml-trade-project.tgz / root/ zml-trade-images.tar.gz root@NEW_SERVER_IP:/ root/On the new server, load the program, restore the data and start Trade:
sudo docker load -i /root/zml-trade-images.tar.gz
sudo tar -C /opt -xzf /root/zml-trade-project.tgz
cd /opt/zml-trade
sudo docker compose create
sudo tar -C /var/lib/docker/volumes -xzf /root/zml-trade-volumes.tgz
sudo docker compose up -dIf the new server has the ufw firewall enabled, also run this; otherwise the page returns 502:
sudo ufw allow in on 'br-+' to "$(ip -4 -o addr show docker0 | awk '{print $4}' | cut -d/ -f1)" port 8000 proto tcpThen finish with step 4, and delete zml-trade-images.tar.gz along with the other package files.