TermlessDocs

Guides

Reaching Termless from elsewhere

termlessd listens on its own machine only. The four ways to reach it from somewhere else, from an SSH tunnel to a public HTTPS address, and how a bot on another server calls it.

termlessd listens on 127.0.0.1:8780, so only programs on the same machine can reach it. That is on purpose: anyone who reaches the API with a trade key can place orders. Open it up only as far as you need.

WayBest forWho can reach it
Same machinebots and scripts running on the Termless boxthat machine only
SSH tunnelyou, from your own computer, now and thenwhoever holds the SSH key
Private networkyour own apps on other serversthe machines on your Tailscale or WireGuard network
Public HTTPS addresspeople and services outside your networkanyone with the password or a key

Streams (SSE and WebSocket) work through all four. The server writes a heartbeat every 15 seconds, so proxies and Cloudflare do not close a quiet stream.

Same machine#

Nothing to set up. Call http://127.0.0.1:8780 with a key:

Shell
curl -s "http://127.0.0.1:8780/api/v1/accounts/pepperstone-12345678/quotes?symbols=XAUUSD" \
  -H "Authorization: Bearer $TERMLESS_KEY"

SSH tunnel#

From your computer, forward a local port to the box and keep the terminal open:

Shell
ssh -N -L 8780:127.0.0.1:8780 you@your-box

Then open http://127.0.0.1:8780 for the dashboard, or point a script at the same address. Nothing on the box changes and nothing is public. A tunnel ends when the laptop sleeps, so it suits people, not bots; a bot on another server is better on a private network.

Private network#

With Tailscale (or WireGuard) on both machines, termlessd can listen on the box's private address. Traffic between the machines is encrypted by the network itself, and nothing outside it can connect.

Find the other machine's Tailscale address with tailscale ip -4 on it (for example 100.101.102.104). Then let termlessd listen on every address of the box, but accept connections only from that machine and the box itself, with sudo systemctl edit termlessd:

override.conf
[Service]
Environment=TERMLESS_LISTEN=0.0.0.0:8780
Environment=TERMLESS_ALLOW_FROM=127.0.0.0/8,100.101.102.104

Then sudo systemctl restart termlessd. --allow-from (TERMLESS_ALLOW_FROM) takes addresses and CIDR ranges separated by commas; a connection from anywhere else is closed before termlessd reads a byte of it, and logged once an hour per address. Listening on 0.0.0.0 means termlessd starts even when Tailscale is not up yet at boot, and programs on the box keep calling 127.0.0.1:8780. From the other machine, curl http://<the box's Tailscale address>:8780/api/v1/health should answer. termlessd doctor warns about any listen address beyond loopback that has no --allow-from.

Keep the box's firewall closed to port 8780 from the internet as well: the allowlist is a second wall, not the only one. On a private network every caller may share a few addresses, which is fine: the lockouts count wrong passwords and unknown keys per address, and a valid key always works, whatever its address (0.6.3).

Public HTTPS address#

To open Termless at an address such as https://termless.example.com, put Caddy, nginx or a Cloudflare Tunnel in front of it and keep its own port on localhost, so the proxy is the only way in. Your own domain walks through each one step by step: the DNS record, the proxy's configuration, the two settings termlessd needs behind it (TERMLESS_TRUST_PROXY and the header holding the visitor's address), an optional sign-in in front with Cloudflare Access, and how to check it worked. In Docker, the same ways come as ready-made compose files (Running in Docker).

A bot on another server#

The same code works over any of the four ways; only the address changes. This one keeps a live price stream open and reconnects by itself:

prices.py
import json, os, time
import requests

BASE = os.environ["TERMLESS_URL"]          # e.g. http://100.101.102.103:8780
KEY = os.environ["TERMLESS_KEY"]           # a read key is enough for prices
URL = f"{BASE}/api/v1/accounts/pepperstone-12345678/stream?symbols=XAUUSD,EURUSD"

while True:
    try:
        with requests.get(URL, headers={"Authorization": f"Bearer {KEY}"}, stream=True, timeout=(5, 30)) as r:
            r.raise_for_status()
            event = None
            for line in r.iter_lines(chunk_size=None, decode_unicode=True):
                if line.startswith("event:"):
                    event = line[6:].strip()
                elif line.startswith("data:") and event == "tick":
                    tick = json.loads(line[5:])
                    print(tick["symbol"], tick["bid"], tick["ask"])
    except requests.RequestException as e:
        print("stream dropped:", e)
    time.sleep(1)

The 30-second read timeout is safe because the server writes at least a heartbeat every 15 seconds. Streaming prices has the event shapes, the WebSocket version and the trade and account events.