# Automated Crypto Spot DCA & Portfolio Rebalance Agent (MCP Script)

> Use `eterna.getAllCoinsBalance()` to inspect current spot holdings, compare against target portfolio weights (for example 50% BTC, 30% ETH, 20% SOL), and buy underweight assets with `eterna.placeOrder({ market: 'spot', side: 'Buy', ... })` or trim overweight holdings cleanly with `eterna.sellSpotBalance()`.

- Canonical URL: https://ai.eterna.exchange/strategies/spot-dca-and-rebalance-agent
- Last updated: November 23, 2026
- Author: Eterna Quant & AI Team (Systematic Execution & MCP Playbooks)
- MCP endpoint: https://mcp.eterna.exchange/mcp

Not every AI agent needs leverage or perpetual futures. Eterna's 380+ USDT spot pairs let you build calm, zero-liquidation accumulation and rebalancing agents with the exact same MCP endpoint.

## Key Facts

| Metric | Value | Notes |
|--------|-------|-------|
| Spot Markets | 380+ USDT pairs | Zero funding fees, zero liquidation |
| Exit Method | sellSpotBalance() | Clean spot trims without dust math |
| Funding Tools | swapToUsdt() | Convert non-USDT deposits automatically |
| Cost | $0 platform fee | No SaaS rebalance subscription |

## 1. Runnable Spot Portfolio Drift Calculator

### spot-rebalance-plan.ts

```typescript
const targets: Record<string, number> = { BTC: 0.5, ETH: 0.3, SOL: 0.2 };
const balances = await eterna.getAllCoinsBalance();

const holdings: Record<string, { qty: number; price: number; usd: number }> = {};
let totalUsd = 0;

for (const coin of Object.keys(targets)) {
  const row = balances.find((b: any) => b.coin === coin);
  const qty = Number(row?.walletBalance ?? 0);
  const ticker = await eterna.getTickers({ symbol: coin + "USDT", market: "spot" });
  const price = Number(ticker[0].lastPrice);
  const usd = qty * price;
  holdings[coin] = { qty, price, usd };
  totalUsd += usd;
}

return Object.entries(targets).map(([coin, targetWeight]) => {
  const currentUsd = holdings[coin].usd;
  const targetUsd = totalUsd * targetWeight;
  const deltaUsd = targetUsd - currentUsd;
  return {
    coin,
    currentWeightPct: totalUsd > 0 ? Number(((currentUsd / totalUsd) * 100).toFixed(1)) : 0,
    targetWeightPct: targetWeight * 100,
    action: Math.abs(deltaUsd) < 15 ? "HOLD" : deltaUsd > 0 ? "BUY_SPOT" : "SELL_SPOT",
    deltaUsd: Number(deltaUsd.toFixed(2)),
  };
});
```

**Returns:** Exact USD buy/sell rebalancing deltas with a $15 deadband to prevent over-trading.

## Frequently Asked Questions

### Why use `eterna.sellSpotBalance()` instead of `eterna.closePosition()` for spot?

`closePosition()` is for linear USDT perpetual contracts. For spot holdings, Eterna provides `sellSpotBalance()` so you never hit spot/perp market-type mismatch errors.

## References & Primary Sources

- [Spot & Perpetual Futures MCP Guide](https://ai.eterna.exchange/guides/spot-and-perpetual-futures-mcp): Exact parameter differences between linear perps and spot.

## Related Guides

- [Trading 800+ USDT Perpetuals & 380+ Spot Pairs from One MCP Server](https://ai.eterna.exchange/guides/spot-and-perpetual-futures-mcp)
- [Eterna CLI Guide: Terminal TypeScript Strategies with `@eterna-hybrid-exchange/cli`](https://ai.eterna.exchange/guides/eterna-cli-trading-automation)
- [AI Trading for Bitcoin (BTCUSDT) via Eterna MCP](https://ai.eterna.exchange/markets/btc)
- [AI Trading for Ethereum (ETHUSDT) via Eterna MCP](https://ai.eterna.exchange/markets/eth)
