const BASE = process.env.MURMO_BASE;
const KEY = process.env.MURMO_API_KEY;
const headers = { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" };
// Tiny helper: call /api/v1, unwrap `data`, throw on error.
async function api(method, path, body) {
const res = await fetch(`${BASE}/api/v1${path}`, {
method,
headers,
body: body ? JSON.stringify(body) : undefined,
});
const json = await res.json();
if (!res.ok) throw new Error(`${path} -> ${res.status} ${json.code ?? ""} ${json.message ?? ""}`);
return json.data;
}
// 1. A group to trade in. You're the admin/leader, so you can open proposals.
// Reuse one you own, or create one once.
const { groupId } = await api("POST", "/groups", {
name: "Momentum bot",
joiningFee: "0",
groupAccessType: "PRIVATE",
});
// 2. Discover candidates (Jupiter-backed; the result shape is opaque — see the Spot guide).
const results = await api("GET", "/spot/tokens/search?q=bonk&limit=5");
console.log(results.map((t) => t.symbol));
// 3. Pick a mint to trade. Grab it from search, or paste a known one.
const mint = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"; // BONK
// 4. Open the position with a $50 buy.
const { proposal } = await api("POST", "/spot/proposals", {
groupId,
contractAddress: mint,
reason: "Momentum breakout",
amountUsd: "50.00",
});
// 5. Scale in another $25.
await api("POST", `/spot/proposals/${proposal.id}/buy`, { amountUsd: "25.00" });
// 6. Take some USDC back off the table ($37.50 of output).
await api("POST", `/spot/proposals/${proposal.id}/sell`, { amountUsd: "37.50" });
// 7. Close the proposal (sells your whole remaining position).
const closed = await api("POST", `/spot/proposals/${proposal.id}/close`);
console.log("closed pnl (USDC):", closed.proposal.exitPnlUsd);