@moonpay/cli 0.5.2 → 0.6.1
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.
- package/dist/{chunk-PBRXVTTG.js → chunk-DCHEUKV7.js} +529 -528
- package/dist/chunk-DCHEUKV7.js.map +1 -0
- package/dist/{chunk-V7MA7WNX.js → chunk-GSAFAKB7.js} +145 -119
- package/dist/chunk-GSAFAKB7.js.map +1 -0
- package/dist/index.js +173 -30
- package/dist/index.js.map +1 -1
- package/dist/{mcp-TDQN25MO.js → mcp-6IZ4QWFM.js} +3 -3
- package/dist/{store-HCN56E6A.js → store-UAGR3DWU.js} +2 -2
- package/package.json +1 -1
- package/skills/moonpay-auth/SKILL.md +24 -4
- package/skills/moonpay-block-explorer/SKILL.md +123 -0
- package/skills/moonpay-buy-crypto/SKILL.md +1 -1
- package/skills/moonpay-export-data/SKILL.md +111 -0
- package/skills/moonpay-mcp/SKILL.md +3 -2
- package/skills/moonpay-polymarket-ready/SKILL.md +1 -1
- package/skills/moonpay-price-alerts/SKILL.md +167 -0
- package/skills/moonpay-trading-automation/SKILL.md +276 -0
- package/skills/moonpay-virtual-account/SKILL.md +14 -18
- package/dist/chunk-PBRXVTTG.js.map +0 -1
- package/dist/chunk-V7MA7WNX.js.map +0 -1
- /package/dist/{mcp-TDQN25MO.js.map → mcp-6IZ4QWFM.js.map} +0 -0
- /package/dist/{store-HCN56E6A.js.map → store-UAGR3DWU.js.map} +0 -0
|
@@ -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)
|
|
@@ -18,6 +18,8 @@ Set up and use a MoonPay virtual account to convert fiat (USD/EUR) to stablecoin
|
|
|
18
18
|
mp virtual-account create
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
This creates the account and starts KYC verification automatically. It returns a URL to complete identity verification.
|
|
22
|
+
|
|
21
23
|
### 2. Check account status
|
|
22
24
|
|
|
23
25
|
```bash
|
|
@@ -26,30 +28,27 @@ mp virtual-account retrieve
|
|
|
26
28
|
|
|
27
29
|
The `status` field shows where you are. The `nextStep` field tells you what to do next.
|
|
28
30
|
|
|
29
|
-
### 3.
|
|
31
|
+
### 3. KYC verification
|
|
30
32
|
|
|
31
33
|
```bash
|
|
32
|
-
#
|
|
33
|
-
mp virtual-account
|
|
34
|
-
|
|
35
|
-
# Check verification status
|
|
36
|
-
mp virtual-account identification retrieve --identificationId <id>
|
|
34
|
+
# Check KYC status or get the verification link again
|
|
35
|
+
mp virtual-account kyc continue
|
|
37
36
|
|
|
38
|
-
#
|
|
39
|
-
mp virtual-account
|
|
37
|
+
# Restart KYC if something went wrong
|
|
38
|
+
mp virtual-account kyc restart
|
|
40
39
|
```
|
|
41
40
|
|
|
42
|
-
### 4.
|
|
41
|
+
### 4. Accept required agreements
|
|
43
42
|
|
|
44
43
|
```bash
|
|
45
|
-
# List
|
|
46
|
-
mp virtual-account
|
|
44
|
+
# List agreements that need to be accepted
|
|
45
|
+
mp virtual-account agreement list
|
|
47
46
|
|
|
48
|
-
#
|
|
49
|
-
mp virtual-account
|
|
47
|
+
# Accept an agreement
|
|
48
|
+
mp virtual-account agreement accept --contentId <content-id>
|
|
50
49
|
|
|
51
|
-
#
|
|
52
|
-
mp virtual-account
|
|
50
|
+
# View previously accepted agreements
|
|
51
|
+
mp virtual-account agreement list --status accepted
|
|
53
52
|
```
|
|
54
53
|
|
|
55
54
|
### 5. Register a wallet (one step)
|
|
@@ -98,9 +97,6 @@ mp virtual-account onramp payment retrieve \
|
|
|
98
97
|
```bash
|
|
99
98
|
# List transactions
|
|
100
99
|
mp virtual-account transaction list
|
|
101
|
-
|
|
102
|
-
# Delete account
|
|
103
|
-
mp virtual-account delete
|
|
104
100
|
```
|
|
105
101
|
|
|
106
102
|
## Related skills
|