> ## Documentation Index
> Fetch the complete documentation index at: https://docs.murmo.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Spot momentum bot

> A complete spot flow end to end: open a token proposal, scale it, then close it.

A full, runnable spot bot. It creates a group to trade in, opens a token position with an opening buy,
scales the position, and closes it. Every amount is **USDC** in and USDC out.

**Before you run it:** create an API key and fund your wallet with USDC. See the
[Quickstart](/quickstart) — funding is one step (send USDC on Solana to your wallet address).

```bash theme={null}
export MURMO_API_KEY="murmo_your_key_here"
export MURMO_BASE="https://api.alpha-labs.trade"
```

## The whole flow

<CodeGroup>
  ```javascript Node 18+ theme={null}
  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);
  ```

  ```python Python theme={null}
  import os, requests

  BASE = os.environ["MURMO_BASE"]
  KEY = os.environ["MURMO_API_KEY"]
  HEADERS = {"Authorization": f"Bearer {KEY}", "Content-Type": "application/json"}

  # Tiny helper: call /api/v1, unwrap `data`, raise on error.
  def api(method, path, body=None):
      res = requests.request(method, f"{BASE}/api/v1{path}", headers=HEADERS, json=body)
      data = res.json()
      if not res.ok:
          raise RuntimeError(f"{path} -> {res.status_code} {data.get('code','')} {data.get('message','')}")
      return data["data"]

  # 1. A group to trade in (you become admin/leader).
  group = api("POST", "/groups", {
      "name": "Momentum bot",
      "joiningFee": "0",
      "groupAccessType": "PRIVATE",
  })
  group_id = group["groupId"]

  # 2. Discover candidates (Jupiter-backed; opaque shape — see the Spot guide).
  results = api("GET", "/spot/tokens/search?q=bonk&limit=5")
  print([t["symbol"] for t in results])

  # 3. Pick a mint to trade.
  mint = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263"  # BONK

  # 4. Open with a $50 buy.
  opened = api("POST", "/spot/proposals", {
      "groupId": group_id,
      "contractAddress": mint,
      "reason": "Momentum breakout",
      "amountUsd": "50.00",
  })
  proposal_id = opened["proposal"]["id"]

  # 5. Scale in another $25.
  api("POST", f"/spot/proposals/{proposal_id}/buy", {"amountUsd": "25.00"})

  # 6. Take $37.50 of USDC back out.
  api("POST", f"/spot/proposals/{proposal_id}/sell", {"amountUsd": "37.50"})

  # 7. Close the proposal.
  closed = api("POST", f"/spot/proposals/{proposal_id}/close")
  print("closed pnl (USDC):", closed["proposal"]["exitPnlUsd"])
  ```
</CodeGroup>

## Step by step

1. **Create a group** (`POST /groups`) so you have somewhere to post calls. The caller becomes the
   group admin, which is what lets you open proposals.
2. **Find a token** (`GET /spot/tokens/search`). Results are Jupiter's shape; `symbol` is reliable,
   and you trade by the Solana **mint**.
3. **Open a proposal** (`POST /spot/proposals`) with `amountUsd` of USDC to spend. This places the
   opening buy and returns the `proposal`.
4. **Buy and sell** (`/buy`, `/sell`) to scale. On a buy, `amountUsd` is USDC spent; on a sell, it's
   USDC received. Pass `max: true` on either to skip sizing math.
5. **Close** (`/close`) sells your remaining position and ends the proposal.

<Tip>
  `max: true` is your friend for clean exits: `{ "max": true }` on `/sell` exits the whole position
  with no dust. See the [Spot trading guide](/guides/spot-trading) for every field and response shape.
</Tip>
