pingwa
Recipe · freqtrade

Stop, check or exit your freqtrade bot from WhatsApp

Three buttons on your phone: Stop, Status and Exit all. A tap reaches a small listener on the machine that runs freqtrade, which calls freqtrade's own REST API and sends the answer back to the chat. That machine needs no public address and no port forwarding. Text join to get a key first.

§ 1

What you get

Write menu to the pingwa number and the three actions come back as buttons. Stop and Exit all ask “Run <button>?” first, so a stray tap does nothing. After the tap, the line the call printed is the answer:

pingwa · WhatsApp
Created exit orders for all open trades.
the answer to Exit all, from a dry-run bot
§ 2

Setup with the listener (no public address)

freqtrade usually runs at home or on a small server you do not want to open to the internet. So the machine asks pingwa for taps (a long poll out), instead of pingwa calling in. Five steps:

  1. Text join to pingwa on WhatsApp (the button below): your key comes straight back. It is a full-access key: use it for step 3 and keep it off the freqtrade machine.
  2. Make a key that can do nothing but run actions, for the listener. Its scope is actions:listen; the answer holds the key once:
A key for the listener only
curl -X POST https://pingwa.dev/v1/keys \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "freqtrade-listen", "scopes": ["actions:listen"]}'
  1. Create the three actions. They have no target_url, so a tap is delivered to the listener, not to an address. confirm makes pingwa ask Yes / Cancel first:
The three actions
curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Stop", "confirm": true}'

curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Status"}'

curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Exit all", "confirm": true}'
  1. Turn on freqtrade's API server (config.json) and keep it on the machine's own address. In docker use 0.0.0.0 inside and publish the port as 127.0.0.1:8080:8080. The JWT key needs 32 characters or more:
config.json, the api_server block
"api_server": {
    "enabled": true,
    "listen_ip_address": "127.0.0.1",
    "listen_port": 8080,
    "jwt_secret_key": "a-random-string-of-32-characters-or-more",
    "username": "freqtrader",
    "password": "a-long-password"
}

Save this as freqtrade.sh next to freqtrade and make it executable. It is the whole bridge: three calls to freqtrade's REST API with basic auth, and a one-line answer. The login comes from the environment, not from the file. Needs curl (7.76 or newer) and jq.

freqtrade.sh
#!/usr/bin/env bash
# Called by `pingwa listen`: freqtrade.sh stop | status | exit-all
# FT_USER and FT_PASS (freqtrade's api_server login) come from the environment.
set -euo pipefail
api="${FT_API:-http://127.0.0.1:8080/api/v1}"
call() { curl --fail-with-body -sS -m 8 -u "$FT_USER:$FT_PASS" "$@"; }
text='.status // .result // .detail // .error'

case "${1:-}" in
  stop)     call -X POST "$api/stop" | jq -r "$text" ;;
  status)   call "$api/status" | jq -r 'if type == "array" then
              (if length == 0 then "No open trades"
               else map("\(.pair) \(.profit_pct)%") | join(", ") end)
            else .detail // .error end' ;;
  exit-all) call -X POST "$api/forceexit" -H 'Content-Type: application/json' \
              -d '{"tradeid": "all"}' | jq -r "$text" ;;
  *) echo "usage: freqtrade.sh stop|status|exit-all" >&2; exit 2 ;;
esac
  1. Write the listener's config, then start it with the listener key and freqtrade's login in the environment. The listener runs each command without a shell, so a $VAR inside the config would stay literal: that is why the script reads them. It never hands PINGWA_KEY to a command.
listen.toml
[listen]
timeout = 10   # seconds a command may run; must stay below 15

[actions]
"Stop"     = "/home/me/pingwa/freqtrade.sh stop"
"Status"   = "/home/me/pingwa/freqtrade.sh status"
"Exit all" = "/home/me/pingwa/freqtrade.sh exit-all"
Start the listener
export PINGWA_KEY=pw_THE_LISTENER_KEY
export FT_USER=freqtrader FT_PASS=a-long-password
uvx pingwa listen --config listen.toml

Write menu on WhatsApp and tap Status: a few seconds later it answers with your open pairs and their profit, or “No open trades”. A command that exits with an error answers “Could not run <button>” with the first line it printed, for example freqtrade's “trader is not running”. The listener reconnects on its own after a network drop, so run it under systemd, docker or any supervisor.

§ 3

Setup with a webhook (you have a public address)

If you would rather have pingwa call your server, create the actions with a target_url (public HTTPS) instead of the listener. A tap is then one signed POST to that URL. freqtrade's API cannot check pingwa's X-Pingwa-Signature, so do not point the action at freqtrade itself, and do not put freqtrade's API on the internet: point it at a small handler of yours that verifies the signature and then calls the same three routes. The check, with code, is in the Actions section of llms.txt.

An action with a target_url
curl -X POST https://pingwa.dev/v1/actions \
  -H "Authorization: Bearer pw_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label": "Stop", "confirm": true, "target_url": "https://your-host.example/freqtrade/stop"}'

The answer carries the action's secret, once: it signs every POST of that action. The calls to make from the handler are the ones in freqtrade.sh.

§ 4

Good to know

§ 5

FAQ

freqtrade already has Telegram. Why this?

If Telegram works for you, keep it. This is for people who want the same three buttons in WhatsApp, with no bot token to create and no chat to set up: you text join and write menu.

Can I add Start, or Force enter?

Yes. Create another action (labels are up to 20 characters), add a line to listen.toml and a case to the script that calls /api/v1/start or another route of freqtrade's API.

The listener says pingwa refused the key.

It needs a key with the actions:listen scope (or a full-access key) in PINGWA_KEY. It stops with that message instead of retrying.

What if the machine is off or the listener is down?

A tap waits 60 seconds for a listener. After that nothing runs and you get a message that nobody was listening, so a stale tap never fires when the machine comes back.

QR code to join pingwa on WhatsApp

Scan the code and get instant access. It opens WhatsApp with “join” ready to send, and your API key comes straight back.

pingwa carries the message over the official Meta Cloud API. Your own number stays out of it (why that matters).