@moonpay/cli 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,123 @@
1
+ ---
2
+ name: moonpay-block-explorer
3
+ description: Open transactions, wallets, and tokens in the correct block explorer. Use after swaps, bridges, or transfers to view results in the browser.
4
+ tags: [explorer]
5
+ ---
6
+
7
+ # Block explorer
8
+
9
+ ## Goal
10
+
11
+ After any swap, bridge, or transfer, open the result in the correct block explorer. Also useful for viewing wallet addresses and token contract pages.
12
+
13
+ ## Explorer URLs
14
+
15
+ | Chain | Transaction | Wallet | Token |
16
+ |-------|------------|--------|-------|
17
+ | solana | `https://solscan.io/tx/{sig}` | `https://solscan.io/account/{addr}` | `https://solscan.io/token/{addr}` |
18
+ | ethereum | `https://etherscan.io/tx/{hash}` | `https://etherscan.io/address/{addr}` | `https://etherscan.io/token/{addr}` |
19
+ | base | `https://basescan.org/tx/{hash}` | `https://basescan.org/address/{addr}` | `https://basescan.org/token/{addr}` |
20
+ | polygon | `https://polygonscan.com/tx/{hash}` | `https://polygonscan.com/address/{addr}` | `https://polygonscan.com/token/{addr}` |
21
+ | arbitrum | `https://arbiscan.io/tx/{hash}` | `https://arbiscan.io/address/{addr}` | `https://arbiscan.io/token/{addr}` |
22
+ | optimism | `https://optimistic.etherscan.io/tx/{hash}` | `https://optimistic.etherscan.io/address/{addr}` | `https://optimistic.etherscan.io/token/{addr}` |
23
+ | bnb | `https://bscscan.com/tx/{hash}` | `https://bscscan.com/address/{addr}` | `https://bscscan.com/token/{addr}` |
24
+ | avalanche | `https://snowscan.xyz/tx/{hash}` | `https://snowscan.xyz/address/{addr}` | `https://snowscan.xyz/token/{addr}` |
25
+ | bitcoin | `https://mempool.space/tx/{txid}` | `https://mempool.space/address/{addr}` | — |
26
+
27
+ ## Open a transaction
28
+
29
+ After a swap or bridge, extract the chain and tx hash, then open:
30
+
31
+ ```bash
32
+ # macOS
33
+ open "https://solscan.io/tx/5rQ52JVb6q7H..."
34
+
35
+ # Linux
36
+ xdg-open "https://etherscan.io/tx/0xabcd..."
37
+ ```
38
+
39
+ ### From swap/bridge output
40
+
41
+ `mp token swap` and `mp token bridge` return a result with the transaction signature. Use the chain to pick the correct explorer.
42
+
43
+ ```bash
44
+ RESULT=$(mp -f compact token swap --wallet main --chain solana \
45
+ --from-token EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
46
+ --from-amount 1 \
47
+ --to-token So11111111111111111111111111111111111111111)
48
+
49
+ # Open in browser
50
+ SIG=$(echo "$RESULT" | jq -r '.signature')
51
+ open "https://solscan.io/tx/$SIG"
52
+ ```
53
+
54
+ ### From transaction list
55
+
56
+ `mp transaction list` returns transactions with `from.txHash` and `to.txHash`. Use the chain field to pick the explorer:
57
+
58
+ ```bash
59
+ # View most recent transaction
60
+ TX=$(mp -f compact transaction list --wallet <addr> | jq -r '.items[0].from.txHash')
61
+ CHAIN=$(mp -f compact transaction list --wallet <addr> | jq -r '.items[0].from.chain')
62
+ # Build URL from chain → explorer table above
63
+ ```
64
+
65
+ ## Open a wallet
66
+
67
+ View all on-chain activity for a wallet address:
68
+
69
+ ```bash
70
+ # Solana wallet
71
+ open "https://solscan.io/account/N39jn2g1tA7dmdyyoHt9yiQegQoVhnfQzq1ZzuZRF9e"
72
+
73
+ # EVM wallet (same address works on any EVM explorer)
74
+ open "https://etherscan.io/address/0xf9e39F70d7636902e57a89C18B1BE39EBb5b9589"
75
+ ```
76
+
77
+ Get wallet addresses from: `mp wallet list` or `mp wallet retrieve --wallet <name>`
78
+
79
+ ## Open a token page
80
+
81
+ View token contract, holders, and market data on the explorer:
82
+
83
+ ```bash
84
+ # USDC on Solana
85
+ open "https://solscan.io/token/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
86
+
87
+ # USDC on Ethereum
88
+ open "https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
89
+ ```
90
+
91
+ Get token addresses from: `mp token search --query "USDC" --chain solana`
92
+
93
+ ## Open a checkout URL
94
+
95
+ `mp buy` returns a checkout URL. Open it directly:
96
+
97
+ ```bash
98
+ URL=$(mp -f compact buy --token sol --amount 1 --wallet <addr> --email <email> | jq -r '.url')
99
+ open "$URL"
100
+ ```
101
+
102
+ ## Platform detection
103
+
104
+ ```bash
105
+ if [[ "$OSTYPE" == "darwin"* ]]; then
106
+ open "$URL"
107
+ else
108
+ xdg-open "$URL"
109
+ fi
110
+ ```
111
+
112
+ ## Tips
113
+
114
+ - After any swap, bridge, or transfer, offer to open the result in the explorer
115
+ - EVM wallets share one address across all EVM chains — the same address works on etherscan, basescan, polygonscan, etc.
116
+ - Bitcoin uses `mempool.space` — no token pages, just transactions and addresses
117
+ - Solana signatures are base58 strings, EVM tx hashes start with `0x`
118
+
119
+ ## Related skills
120
+
121
+ - **moonpay-swap-tokens** — Swap and bridge commands that produce transaction signatures
122
+ - **moonpay-buy-crypto** — Buy commands that return checkout URLs
123
+ - **moonpay-check-wallet** — Get wallet addresses to view on explorers
@@ -22,7 +22,7 @@ mp buy \
22
22
 
23
23
  ## Supported tokens
24
24
 
25
- `sol`, `usdc_sol`, `eth`, `usdc`, `usdc_base`, `usdc_arbitrum`, `usdc_optimism`, `usdc_polygon`, `eth_polygon`, `eth_optimism`, `eth_base`, `eth_arbitrum`
25
+ `btc`, `sol`, `eth`, `trx`, `pol_polygon`, `usdc`, `usdc_sol`, `usdc_base`, `usdc_arbitrum`, `usdc_optimism`, `usdc_polygon`, `usdt_trx`, `eth_polygon`, `eth_optimism`, `eth_base`, `eth_arbitrum`
26
26
 
27
27
  ## Example flow
28
28
 
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: moonpay-export-data
3
+ description: Export portfolio balances and transaction history to CSV or JSON files. Use for spreadsheets, tax reporting, or record-keeping.
4
+ tags: [portfolio, export]
5
+ ---
6
+
7
+ # Export data
8
+
9
+ ## Goal
10
+
11
+ Save portfolio snapshots and transaction history to CSV or JSON files using `mp` output piped through `jq`. Useful for spreadsheets, tax reporting, and record-keeping.
12
+
13
+ ## Prerequisites
14
+
15
+ - `jq` installed: `which jq`
16
+ - Default output directory: `~/Documents/moonpay/` (create if needed)
17
+
18
+ ## Portfolio to CSV
19
+
20
+ Export all token balances for a wallet on a specific chain:
21
+
22
+ ```bash
23
+ mkdir -p ~/Documents/moonpay
24
+
25
+ # Header + data
26
+ echo "symbol,name,amount,usd_value,price" > ~/Documents/moonpay/portfolio-$(date +%Y%m%d).csv
27
+
28
+ mp -f compact token balance list --wallet <address> --chain solana \
29
+ | jq -r '.items[] | [.symbol, .name, .balance.amount, .balance.value, .balance.price] | @csv' \
30
+ >> ~/Documents/moonpay/portfolio-$(date +%Y%m%d).csv
31
+ ```
32
+
33
+ ### Multi-chain portfolio
34
+
35
+ Loop over chains and append to one file:
36
+
37
+ ```bash
38
+ FILE=~/Documents/moonpay/portfolio-$(date +%Y%m%d).csv
39
+ echo "chain,symbol,name,amount,usd_value,price" > "$FILE"
40
+
41
+ for CHAIN in solana ethereum base polygon arbitrum; do
42
+ mp -f compact token balance list --wallet <address> --chain "$CHAIN" \
43
+ | jq -r --arg chain "$CHAIN" '.items[] | [$chain, .symbol, .name, .balance.amount, .balance.value, .balance.price] | @csv' \
44
+ >> "$FILE" 2>/dev/null
45
+ done
46
+ ```
47
+
48
+ Note: EVM wallets share one address across all EVM chains. Solana uses a different address.
49
+
50
+ ## Transaction history to CSV
51
+
52
+ Export swap and bridge history. These are transactions executed via the CLI and registered with swaps.xyz — not all on-chain activity.
53
+
54
+ ```bash
55
+ echo "date,type,from_chain,from_token,from_amount,to_chain,to_token,to_amount,usd,status" \
56
+ > ~/Documents/moonpay/transactions-$(date +%Y%m%d).csv
57
+
58
+ mp -f compact transaction list --wallet <address> \
59
+ | jq -r '.items[] | [
60
+ .transactionId,
61
+ .type,
62
+ .from.chain, .from.token, .from.amount,
63
+ .to.chain, .to.token, .to.amount,
64
+ .usd,
65
+ .status
66
+ ] | @csv' \
67
+ >> ~/Documents/moonpay/transactions-$(date +%Y%m%d).csv
68
+ ```
69
+
70
+ ### Filter by chain
71
+
72
+ ```bash
73
+ mp -f compact transaction list --wallet <address> --chain solana \
74
+ | jq -r '.items[] | ...' >> transactions.csv
75
+ ```
76
+
77
+ ## Portfolio to JSON
78
+
79
+ For structured data or programmatic use:
80
+
81
+ ```bash
82
+ mp -f compact token balance list --wallet <address> --chain solana \
83
+ | jq '.items | map({symbol, amount: .balance.amount, usd: .balance.value})' \
84
+ > ~/Documents/moonpay/portfolio-$(date +%Y%m%d).json
85
+ ```
86
+
87
+ ## Open exported file
88
+
89
+ After writing the file, open it in the default app:
90
+
91
+ ```bash
92
+ # macOS — opens in Numbers/Excel
93
+ open ~/Documents/moonpay/portfolio-$(date +%Y%m%d).csv
94
+
95
+ # Linux
96
+ xdg-open ~/Documents/moonpay/portfolio-$(date +%Y%m%d).csv
97
+ ```
98
+
99
+ ## Tips
100
+
101
+ - `jq @csv` handles proper CSV escaping (quotes, commas in values)
102
+ - Date-stamp filenames to keep a history: `portfolio-20260222.csv`
103
+ - `mp transaction list` only includes CLI-executed swaps/bridges registered via swaps.xyz, not all on-chain transactions
104
+ - For a quick summary without exporting, use `mp token balance list --wallet <addr> --chain <chain>` directly
105
+ - EVM address is the same across ethereum, base, polygon, arbitrum, optimism, bnb, avalanche
106
+
107
+ ## Related skills
108
+
109
+ - **moonpay-check-wallet** — View balances interactively
110
+ - **moonpay-block-explorer** — Open exported transactions in block explorers
111
+ - **moonpay-trading-automation** — Combine with scheduled exports for daily snapshots
@@ -51,7 +51,7 @@ If the wallet already has POL and USDC.e, they're set.
51
51
  Buy POL directly with fiat — easiest way to get gas on Polygon:
52
52
 
53
53
  ```bash
54
- mp buy --token pol --amount 5 --wallet <eth-address> --email <email>
54
+ mp buy --token pol_polygon --amount 5 --wallet <eth-address> --email <email>
55
55
  ```
56
56
 
57
57
  Alternatively, bridge ETH → POL if the user already has ETH:
@@ -0,0 +1,167 @@
1
+ ---
2
+ name: moonpay-price-alerts
3
+ description: Set up desktop price alerts that notify you when tokens hit target prices. Observe-only — no trading, just notifications.
4
+ tags: [alerts, research]
5
+ ---
6
+
7
+ # Price alerts
8
+
9
+ ## Goal
10
+
11
+ Monitor token prices and get desktop notifications when they cross a threshold. Uses `mp token retrieve` for price checks and OS notifications (`osascript`/`notify-send`) for alerts. Observe-only — no funds at risk.
12
+
13
+ ## Prerequisites
14
+
15
+ - `mp` binary on PATH: `which mp`
16
+ - `jq` installed: `which jq`
17
+ - macOS: `osascript` (built-in) or Linux: `notify-send` (`sudo apt install libnotify-bin`)
18
+
19
+ ## One-shot alert
20
+
21
+ "Tell me when SOL drops below $80" — checks every 5 minutes, fires once, then disables itself.
22
+
23
+ ### Script: `~/.config/moonpay/scripts/alert-sol-below-80.sh`
24
+
25
+ ```bash
26
+ #!/bin/bash
27
+ set -euo pipefail
28
+
29
+ MP="$(which mp)"
30
+ LOG="$HOME/.config/moonpay/logs/alerts.log"
31
+ mkdir -p "$(dirname "$LOG")"
32
+ log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*" >> "$LOG"; }
33
+
34
+ # --- Config ---
35
+ TOKEN="So11111111111111111111111111111111111111111"
36
+ CHAIN="solana"
37
+ SYMBOL="SOL"
38
+ TARGET=80
39
+ DIRECTION="below" # "above" or "below"
40
+ SCRIPT_NAME="alert-sol-below-80"
41
+
42
+ # --- Check price ---
43
+ PRICE=$("$MP" -f compact token retrieve --token "$TOKEN" --chain "$CHAIN" | jq -r '.marketData.price')
44
+
45
+ if [ -z "$PRICE" ] || [ "$PRICE" = "null" ]; then
46
+ log "ALERT $SCRIPT_NAME: price fetch failed, skipping"
47
+ exit 0
48
+ fi
49
+
50
+ # --- Compare ---
51
+ TRIGGERED=false
52
+ if [ "$DIRECTION" = "below" ] && (( $(echo "$PRICE < $TARGET" | bc -l) )); then
53
+ TRIGGERED=true
54
+ elif [ "$DIRECTION" = "above" ] && (( $(echo "$PRICE > $TARGET" | bc -l) )); then
55
+ TRIGGERED=true
56
+ fi
57
+
58
+ if [ "$TRIGGERED" = true ]; then
59
+ MSG="$SYMBOL is $DIRECTION \$$TARGET — currently \$$PRICE"
60
+ log "ALERT $SCRIPT_NAME: $MSG"
61
+
62
+ # Desktop notification
63
+ if [[ "$OSTYPE" == "darwin"* ]]; then
64
+ osascript -e "display notification \"$MSG\" with title \"MoonPay Alert\" sound name \"Glass\""
65
+ else
66
+ notify-send "MoonPay Alert" "$MSG"
67
+ fi
68
+
69
+ # Self-disable (one-shot)
70
+ if [[ "$OSTYPE" == "darwin"* ]]; then
71
+ launchctl unload "$HOME/Library/LaunchAgents/com.moonpay.${SCRIPT_NAME}.plist" 2>/dev/null || true
72
+ else
73
+ crontab -l | grep -v "$SCRIPT_NAME" | crontab -
74
+ fi
75
+ log "ALERT $SCRIPT_NAME: disabled after trigger"
76
+ else
77
+ log "ALERT $SCRIPT_NAME: $SYMBOL at \$$PRICE — not triggered ($DIRECTION $TARGET)"
78
+ fi
79
+ ```
80
+
81
+ ### Schedule
82
+
83
+ Check every 5 minutes:
84
+
85
+ ```bash
86
+ # cron (Linux)
87
+ */5 * * * * ~/.config/moonpay/scripts/alert-sol-below-80.sh # moonpay:alert-sol-below-80
88
+
89
+ # launchd (macOS) — use StartInterval of 300 seconds in the plist
90
+ ```
91
+
92
+ Launchd plist at `~/Library/LaunchAgents/com.moonpay.alert-sol-below-80.plist`:
93
+
94
+ ```xml
95
+ <?xml version="1.0" encoding="UTF-8"?>
96
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
97
+ <plist version="1.0">
98
+ <dict>
99
+ <key>Label</key>
100
+ <string>com.moonpay.alert-sol-below-80</string>
101
+ <key>ProgramArguments</key>
102
+ <array>
103
+ <string>/bin/bash</string>
104
+ <string>/Users/USERNAME/.config/moonpay/scripts/alert-sol-below-80.sh</string>
105
+ </array>
106
+ <key>StartInterval</key>
107
+ <integer>300</integer>
108
+ <key>StandardErrorPath</key>
109
+ <string>/Users/USERNAME/.config/moonpay/logs/alert-sol-below-80.err</string>
110
+ </dict>
111
+ </plist>
112
+ ```
113
+
114
+ Load: `launchctl load ~/Library/LaunchAgents/com.moonpay.alert-sol-below-80.plist`
115
+
116
+ **Important:** Replace `USERNAME` with the actual username. Tilde does not expand in plist files.
117
+
118
+ ## Recurring alert
119
+
120
+ "Alert me every hour while ETH is above $2000" — keeps firing on each check, doesn't self-disable.
121
+
122
+ Same script as above but remove the self-disable block. The alert fires every time the condition is met, until the user manually removes it.
123
+
124
+ ## Managing alerts
125
+
126
+ ### List active alerts
127
+
128
+ ```bash
129
+ # macOS
130
+ launchctl list | grep moonpay
131
+
132
+ # Linux
133
+ crontab -l | grep moonpay
134
+ ```
135
+
136
+ ### Remove an alert
137
+
138
+ ```bash
139
+ # macOS
140
+ launchctl unload ~/Library/LaunchAgents/com.moonpay.alert-sol-below-80.plist
141
+ rm ~/Library/LaunchAgents/com.moonpay.alert-sol-below-80.plist
142
+
143
+ # Linux
144
+ crontab -l | grep -v "alert-sol-below-80" | crontab -
145
+ ```
146
+
147
+ ### View alert history
148
+
149
+ ```bash
150
+ tail -50 ~/.config/moonpay/logs/alerts.log
151
+ ```
152
+
153
+ ## Tips
154
+
155
+ - Price checks via `mp token retrieve` are free — no gas costs
156
+ - 5-minute intervals are reasonable; don't go below 1 minute
157
+ - Use `mp token search --query "SOL" --chain solana` to resolve token addresses
158
+ - Alerts log to `~/.config/moonpay/logs/alerts.log` — check this to verify they're running
159
+ - The machine must be logged in for notifications and keychain access to work
160
+ - `bc -l` handles decimal comparison; if unavailable, use `awk "BEGIN {exit !($PRICE < $TARGET)}"`
161
+ - This skill is observe-only — for automated buying/selling, see **moonpay-trading-automation**
162
+
163
+ ## Related skills
164
+
165
+ - **moonpay-trading-automation** — Automated trading (DCA, limit orders, stop losses)
166
+ - **moonpay-discover-tokens** — Research tokens and get current prices
167
+ - **moonpay-check-wallet** — Check portfolio before setting alerts
@@ -0,0 +1,276 @@
1
+ ---
2
+ name: moonpay-trading-automation
3
+ description: Set up automated trading strategies — DCA, limit orders, and stop losses — by composing mp CLI commands with OS scheduling (cron/launchd).
4
+ tags: [trading, automation]
5
+ ---
6
+
7
+ # Trading automation
8
+
9
+ ## Goal
10
+
11
+ Compose `mp` CLI commands with OS scheduling (cron/launchd) to run unattended trading strategies: dollar-cost averaging, limit orders, and stop losses. The agent generates shell scripts and schedules them — no new tools needed.
12
+
13
+ ## Prerequisites
14
+
15
+ - Authenticated: `mp user retrieve`
16
+ - Funded wallet: `mp token balance list --wallet <name> --chain <chain>`
17
+ - `mp` binary on PATH: `which mp` (note the full path for scheduled scripts)
18
+ - `jq` installed: `which jq`
19
+
20
+ ## Shell script pattern
21
+
22
+ Every strategy uses the same base pattern. Scripts live in `~/.config/moonpay/scripts/` and log to `~/.config/moonpay/logs/trading.log`.
23
+
24
+ ```bash
25
+ #!/bin/bash
26
+ set -euo pipefail
27
+
28
+ MP="$(which mp)" # absolute path for cron/launchd
29
+ LOG="$HOME/.config/moonpay/logs/trading.log"
30
+ mkdir -p "$(dirname "$LOG")"
31
+
32
+ log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*" >> "$LOG"; }
33
+
34
+ # --- Config (agent fills these in) ---
35
+ WALLET="main"
36
+ CHAIN="solana"
37
+ FROM_TOKEN="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" # USDC
38
+ TO_TOKEN="So11111111111111111111111111111111111111111" # SOL
39
+ AMOUNT=5
40
+
41
+ # --- Execute ---
42
+ log "SWAP: $AMOUNT $FROM_TOKEN -> $TO_TOKEN on $CHAIN"
43
+ RESULT=$("$MP" -f compact token swap \
44
+ --wallet "$WALLET" --chain "$CHAIN" \
45
+ --from-token "$FROM_TOKEN" --from-amount "$AMOUNT" \
46
+ --to-token "$TO_TOKEN" 2>&1) || {
47
+ log "FAILED: $RESULT"
48
+ exit 1
49
+ }
50
+ log "OK: $RESULT"
51
+ ```
52
+
53
+ Key points:
54
+ - `mp -f compact` outputs single-line JSON, ideal for `jq` parsing
55
+ - Use `$(which mp)` and store as `MP` — cron/launchd have minimal PATH
56
+ - Wallet names only in scripts — `mp` handles keychain decryption at runtime
57
+ - If the user gives token names/symbols, resolve to addresses first with `mp token search`
58
+
59
+ ## DCA (Dollar-Cost Averaging)
60
+
61
+ "Buy $5 of SOL every day at 9am"
62
+
63
+ ### Script: `~/.config/moonpay/scripts/dca-sol.sh`
64
+
65
+ Use the base pattern above with the user's token, amount, wallet, and chain.
66
+
67
+ ### Schedule with cron (Linux)
68
+
69
+ ```bash
70
+ # Buy $5 of SOL daily at 9am UTC — moonpay:dca-sol
71
+ 0 9 * * * ~/.config/moonpay/scripts/dca-sol.sh
72
+ ```
73
+
74
+ Add with: `(crontab -l 2>/dev/null; echo '0 9 * * * ~/.config/moonpay/scripts/dca-sol.sh # moonpay:dca-sol') | crontab -`
75
+
76
+ Common intervals:
77
+ - Every hour: `0 * * * *`
78
+ - Every 4 hours: `0 */4 * * *`
79
+ - Daily at 9am: `0 9 * * *`
80
+ - Weekly Monday 9am: `0 9 * * 1`
81
+
82
+ ### Schedule with launchd (macOS)
83
+
84
+ Write a plist to `~/Library/LaunchAgents/com.moonpay.dca-sol.plist`:
85
+
86
+ ```xml
87
+ <?xml version="1.0" encoding="UTF-8"?>
88
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
89
+ <plist version="1.0">
90
+ <dict>
91
+ <key>Label</key>
92
+ <string>com.moonpay.dca-sol</string>
93
+ <key>ProgramArguments</key>
94
+ <array>
95
+ <string>/bin/bash</string>
96
+ <string>/Users/USERNAME/.config/moonpay/scripts/dca-sol.sh</string>
97
+ </array>
98
+ <key>StartCalendarInterval</key>
99
+ <dict>
100
+ <key>Hour</key>
101
+ <integer>9</integer>
102
+ <key>Minute</key>
103
+ <integer>0</integer>
104
+ </dict>
105
+ <key>StandardErrorPath</key>
106
+ <string>/Users/USERNAME/.config/moonpay/logs/dca-sol.err</string>
107
+ </dict>
108
+ </plist>
109
+ ```
110
+
111
+ Load with: `launchctl load ~/Library/LaunchAgents/com.moonpay.dca-sol.plist`
112
+
113
+ **Important:** Tilde (`~`) does NOT expand in plist files. Always use the full path (e.g., `/Users/USERNAME/...`). Get it with `echo $HOME`.
114
+
115
+ ## Limit order
116
+
117
+ "Buy SOL when price drops below $80"
118
+
119
+ ### Script: `~/.config/moonpay/scripts/limit-buy-sol.sh`
120
+
121
+ ```bash
122
+ #!/bin/bash
123
+ set -euo pipefail
124
+
125
+ MP="$(which mp)"
126
+ LOG="$HOME/.config/moonpay/logs/trading.log"
127
+ mkdir -p "$(dirname "$LOG")"
128
+ log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*" >> "$LOG"; }
129
+
130
+ # --- Config ---
131
+ WALLET="main"
132
+ CHAIN="solana"
133
+ TOKEN="So11111111111111111111111111111111111111111"
134
+ BUY_WITH="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" # USDC
135
+ BUY_AMOUNT=50
136
+ TARGET_PRICE=80
137
+ SCRIPT_NAME="limit-buy-sol"
138
+
139
+ # --- Check price ---
140
+ PRICE=$("$MP" -f compact token retrieve --token "$TOKEN" --chain "$CHAIN" | jq -r '.marketData.price')
141
+
142
+ if [ -z "$PRICE" ] || [ "$PRICE" = "null" ]; then
143
+ log "LIMIT $SCRIPT_NAME: price fetch failed, skipping"
144
+ exit 0
145
+ fi
146
+
147
+ # --- Compare ---
148
+ if (( $(echo "$PRICE < $TARGET_PRICE" | bc -l) )); then
149
+ log "LIMIT $SCRIPT_NAME: price $PRICE < $TARGET_PRICE — executing buy"
150
+ RESULT=$("$MP" -f compact token swap \
151
+ --wallet "$WALLET" --chain "$CHAIN" \
152
+ --from-token "$BUY_WITH" --from-amount "$BUY_AMOUNT" \
153
+ --to-token "$TOKEN" 2>&1) || {
154
+ log "LIMIT $SCRIPT_NAME FAILED: $RESULT"
155
+ exit 1
156
+ }
157
+ log "LIMIT $SCRIPT_NAME OK: bought at $PRICE — $RESULT"
158
+
159
+ # Self-disable after fill
160
+ if [[ "$OSTYPE" == "darwin"* ]]; then
161
+ launchctl unload "$HOME/Library/LaunchAgents/com.moonpay.${SCRIPT_NAME}.plist" 2>/dev/null || true
162
+ else
163
+ crontab -l | grep -v "$SCRIPT_NAME" | crontab -
164
+ fi
165
+ log "LIMIT $SCRIPT_NAME: disabled after fill"
166
+ else
167
+ log "LIMIT $SCRIPT_NAME: price $PRICE >= $TARGET_PRICE — waiting"
168
+ fi
169
+ ```
170
+
171
+ Schedule every 5 minutes:
172
+ - Cron: `*/5 * * * * ~/.config/moonpay/scripts/limit-buy-sol.sh # moonpay:limit-buy-sol`
173
+ - Launchd: use `<key>StartInterval</key><integer>300</integer>` instead of `StartCalendarInterval`
174
+
175
+ ## Stop loss
176
+
177
+ "Sell all my SOL if price drops below $70"
178
+
179
+ Same structure as limit order but sells instead of buys. For "sell all", query the balance first:
180
+
181
+ ```bash
182
+ # --- Config ---
183
+ SELL_TOKEN="So11111111111111111111111111111111111111111" # SOL
184
+ TO_TOKEN="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" # USDC
185
+ TRIGGER_PRICE=70
186
+ SCRIPT_NAME="stop-loss-sol"
187
+
188
+ # --- Check price ---
189
+ PRICE=$("$MP" -f compact token retrieve --token "$SELL_TOKEN" --chain "$CHAIN" | jq -r '.marketData.price')
190
+
191
+ if (( $(echo "$PRICE < $TRIGGER_PRICE" | bc -l) )); then
192
+ # Get current balance to sell all
193
+ BALANCE=$("$MP" -f compact token balance list --wallet "$WALLET" --chain "$CHAIN" \
194
+ | jq -r --arg addr "$SELL_TOKEN" '.items[] | select(.address == $addr) | .balance.amount')
195
+
196
+ if [ -n "$BALANCE" ] && (( $(echo "$BALANCE > 0" | bc -l) )); then
197
+ log "STOP-LOSS $SCRIPT_NAME: price $PRICE < $TRIGGER_PRICE — selling $BALANCE"
198
+ RESULT=$("$MP" -f compact token swap \
199
+ --wallet "$WALLET" --chain "$CHAIN" \
200
+ --from-token "$SELL_TOKEN" --from-amount "$BALANCE" \
201
+ --to-token "$TO_TOKEN" 2>&1) || {
202
+ log "STOP-LOSS $SCRIPT_NAME FAILED: $RESULT"
203
+ exit 1
204
+ }
205
+ log "STOP-LOSS $SCRIPT_NAME OK: sold at $PRICE — $RESULT"
206
+ # Self-disable (same pattern as limit order)
207
+ fi
208
+ fi
209
+ ```
210
+
211
+ ## Managing automations
212
+
213
+ ### List active automations
214
+
215
+ ```bash
216
+ # macOS
217
+ launchctl list | grep moonpay
218
+
219
+ # Linux
220
+ crontab -l | grep moonpay
221
+ ```
222
+
223
+ ### Remove an automation
224
+
225
+ ```bash
226
+ # macOS
227
+ launchctl unload ~/Library/LaunchAgents/com.moonpay.dca-sol.plist
228
+ rm ~/Library/LaunchAgents/com.moonpay.dca-sol.plist
229
+
230
+ # Linux
231
+ crontab -l | grep -v "moonpay:dca-sol" | crontab -
232
+ ```
233
+
234
+ ### View logs
235
+
236
+ ```bash
237
+ tail -50 ~/.config/moonpay/logs/trading.log
238
+ ```
239
+
240
+ ### Pause / resume (macOS only)
241
+
242
+ ```bash
243
+ launchctl unload ~/Library/LaunchAgents/com.moonpay.dca-sol.plist # pause
244
+ launchctl load ~/Library/LaunchAgents/com.moonpay.dca-sol.plist # resume
245
+ ```
246
+
247
+ ## Platform detection
248
+
249
+ Detect the OS and use the appropriate scheduler:
250
+
251
+ ```bash
252
+ if [[ "$OSTYPE" == "darwin"* ]]; then
253
+ # macOS: use launchd (fires even if machine was asleep)
254
+ else
255
+ # Linux: use crontab
256
+ fi
257
+ ```
258
+
259
+ ## Tips
260
+
261
+ - Start with a small DCA amount to verify the setup works before going bigger
262
+ - Check logs after the first run: `tail -20 ~/.config/moonpay/logs/trading.log`
263
+ - Scripts don't contain secrets — `mp` decrypts wallets via OS keychain at runtime
264
+ - The machine must be logged in (user session active) for keychain access to work
265
+ - Price checks via `mp token retrieve` are free; swaps cost gas
266
+ - Limit order checks every 5 minutes is reasonable — don't go below 1 minute
267
+ - Use `bc -l` for decimal price comparison (bash can't compare floats natively)
268
+ - If `bc` isn't available, use: `awk "BEGIN {exit !($PRICE < $TARGET)}"`
269
+ - Always tag cron entries with `# moonpay:{name}` so they can be found and removed
270
+
271
+ ## Related skills
272
+
273
+ - **moonpay-swap-tokens** — Swap and bridge command syntax
274
+ - **moonpay-check-wallet** — Check balances before setting up automation
275
+ - **moonpay-discover-tokens** — Research tokens and resolve addresses
276
+ - **moonpay-price-alerts** — Observe-only price notifications (no trading)