diff --git a/apps/tradebot/indodax/README.md b/apps/tradebot/indodax/README.md index 32cc8400..e0b3e9f9 100644 --- a/apps/tradebot/indodax/README.md +++ b/apps/tradebot/indodax/README.md @@ -36,6 +36,34 @@ practice account holds, and holds a small copy of the same coins on Indodax's ru .\run-windows.ps1 # keep copying in practice, one cycle a minute ``` +### On a Mac + +`run-mac.sh` is the same launcher for macOS, added on 23 Nov 2026 when the Windows PC the sender ran on +went down: + +``` +./run-mac.sh show # what it would do: no orders, no report +./run-mac.sh # keep copying in practice, one cycle a minute, in this Terminal window +./run-mac.sh check # does the Indodax API key work? orders nothing +./run-mac.sh background on # keep it running with no window (a launch agent); off stops it +``` + +What was found on the Mac it was written on (an Intel MacBook Pro, macOS, 23 Nov 2026): + +- All 424 tests pass with Python 3.14. With Apple's own Python 3.9 three fail (two of the desk window, one + of the Trade API 2.0 client), so the launcher takes the first Python that is 3.10 or newer. +- A Python from python.org has no list of certificate authorities until its "Install Certificates" step + is run, and every call then fails with CERTIFICATE_VERIFY_FAILED. The launcher points Python at + macOS's own list (`/etc/ssl/cert.pem`) unless `SSL_CERT_FILE` is already set. With that, TradeBot's + server, `indodax.com` and `api.indodax.com` all answered. +- In the background the sender runs under `caffeinate -i`, so the Mac does not fall asleep by itself. A + closed lid without a screen attached, an empty battery or signing out still stop it, and then nothing + is watched and nothing is sold. +- Not checked on a Mac: a cycle with a sender key, the key check, and a real order. The desk window + (`desk.py`, `TradeBot.exe`) is for Windows; on a Mac the sender's lines are in `desk_sender.log`. +- The sender must run on one computer only. A new sender key (`newKey`, above) switches the old one off, + so the computer that had it can no longer reach TradeBot. + `/indodax` in TradeBot's Telegram chat then shows the copies: what is open, what was closed, the result so far, and what the sender last said. Practice and real money are always labelled. The same chat can pause the buying, see [Control from Telegram](#control-from-telegram). diff --git a/apps/tradebot/indodax/run-mac.sh b/apps/tradebot/indodax/run-mac.sh new file mode 100755 index 00000000..a283fff7 --- /dev/null +++ b/apps/tradebot/indodax/run-mac.sh @@ -0,0 +1,148 @@ +#!/bin/sh +# Runs TradeBot's Indodax sender on a Mac. PRACTICE BY DEFAULT: no order reaches Indodax. +# +# ./run-mac.sh keep copying, one cycle a minute (in this Terminal window) +# ./run-mac.sh show what it would do right now: no orders, no report +# ./run-mac.sh once one cycle, then stop +# ./run-mac.sh check does the Indodax API key work? prints the free rupiah, orders nothing +# ./run-mac.sh clear clear the safety stop, after you have looked at Indodax +# ./run-mac.sh test the sender's own tests (a pretend exchange, no network) +# +# ./run-mac.sh background on keep the sender running with no window: macOS starts it when you +# sign in and again within a minute if it ever ends +# ./run-mac.sh background off stop that, and stop the sender +# ./run-mac.sh background is it running in the background? +# +# The Python to use: $INDODAX_PYTHON, then .venv next to this script, then the first python3 that is +# 3.10 or newer. +# A proxy: HTTPS_PROXY in the environment, or in .env. +# +# It is off until .env next to this script holds INDODAX_BRIDGE_KEY: without the key it says so and +# stops. Real money needs more than that, on purpose. See README.md before switching anything on. +# +# In the background the sender runs under `caffeinate -i`, so the Mac does not fall asleep by itself +# while it runs. A closed lid without a screen attached, an empty battery or signing out still stop +# it, and then nothing is watched and nothing is sold. The same sender must not run on two computers. +# +# Nothing to install: the sender uses only what comes with Python. + +set -eu + +here=$(cd "$(dirname "$0")" && pwd) +cd "$here" + +label="dev.juw12.tradebot-sender" +plist="$HOME/Library/LaunchAgents/$label.plist" +log="$here/desk_sender.log" + +# The first Python that is 3.10 or newer: the sender's tests pass on 3.10 and up, three of them fail on 3.9 +# (the one Apple ships as /usr/bin/python3). +python="" +older="" +for candidate in "${INDODAX_PYTHON:-}" "$here/.venv/bin/python" "$(command -v python3 || true)" \ + /usr/local/bin/python3 /opt/homebrew/bin/python3 /usr/bin/python3; do + if [ -z "$candidate" ] || [ ! -x "$candidate" ]; then + continue + fi + if "$candidate" -c 'import sys; sys.exit(sys.version_info < (3, 10))' 2>/dev/null; then + python=$candidate + break + fi + older=${older:-$candidate} +done +if [ -z "$python" ] && [ -n "$older" ]; then + python=$older + echo "Only an older Python was found ($python). The sender is tested on Python 3.10 and newer." >&2 +fi +if [ -z "$python" ]; then + echo "Python not found. Install Python 3.10 or newer, then run this again." >&2 + exit 1 +fi + +# A Python from python.org comes without the list of certificate authorities until its "Install +# Certificates" step is run, and then every call to TradeBot and to Indodax fails. macOS has that list. +if [ -z "${SSL_CERT_FILE:-}" ] && [ -f /etc/ssl/cert.pem ]; then + SSL_CERT_FILE=/etc/ssl/cert.pem + export SSL_CERT_FILE +fi + +background_running() { + launchctl print "gui/$(id -u)/$label" >/dev/null 2>&1 +} + +background_on() { + if [ ! -f "$here/.env" ]; then + echo "No .env: nothing was started. Copy .env.example to .env and fill in INDODAX_BRIDGE_KEY." >&2 + exit 1 + fi + mkdir -p "$(dirname "$plist")" + cat > "$plist" < + + + + Label$label + ProgramArguments + + /usr/bin/caffeinate + -i + $python + $here/bridge.py + --log + $log + + WorkingDirectory$here + EnvironmentVariables + + SSL_CERT_FILE${SSL_CERT_FILE:-} + + RunAtLoad + KeepAlive + ThrottleInterval60 + ProcessTypeStandard + StandardOutPath$here/background.out + StandardErrorPath$here/background.out + + +EOF + launchctl bootout "gui/$(id -u)/$label" >/dev/null 2>&1 || true + launchctl bootstrap "gui/$(id -u)" "$plist" + echo "The sender now runs in the background, with no window. macOS starts it at sign-in and looks after it." + echo "Its lines: $log" +} + +background_off() { + launchctl bootout "gui/$(id -u)/$label" >/dev/null 2>&1 || true + rm -f "$plist" + echo "The sender no longer runs in the background." +} + +case "${1:-}" in + "") exec "$python" bridge.py ;; + show) exec "$python" bridge.py --show ;; + once) exec "$python" bridge.py --once ;; + check) exec "$python" bridge.py --check ;; + clear) exec "$python" bridge.py --clear ;; + test) exec "$python" -m unittest ;; + background) + case "${2:-}" in + on) background_on ;; + off) background_off ;; + "") + if background_running; then + echo "The sender runs in the background. Its lines: $log" + else + echo "The sender does not run in the background." + fi + ;; + *) + echo "background takes on or off." >&2 + exit 2 + ;; + esac + ;; + *) + sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//' + exit 2 + ;; +esac