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

# Chaining Feeds

> Purchase multiple feeds in sequence for cross-analysis

# Chaining Feeds

## Overview

`sf.chain()` purchases multiple feeds in sequence and returns all results together. This is useful for research agents that need data from multiple sources for cross-analysis.

## Basic Usage

```typescript theme={null}
const results = await sf.chain([
  'btc-sentiment',
  'whale-alerts',
  'defi-scores',
]);
```

## Response Structure

```typescript theme={null}
interface ChainResult {
  feeds: PurchaseResult[];   // Results from each feed
  total_spent_stx: number;   // Total STX spent
  timestamp: string;          // ISO timestamp
}
```

Example:

```typescript theme={null}
const results = await sf.chain([
  'btc-sentiment',
  'smart-money-flows',
  'defi-scores',
]);

console.log(results.total_spent_stx);  // 0.093
console.log(results.feeds.length);     // 3

// Access individual feed data
const sentiment = results.feeds[0].data;
const flows = results.feeds[1].data;
const defi = results.feeds[2].data;
```

## Custom Delay

By default, there's a 1-second delay between purchases. You can customize this:

```typescript theme={null}
// 2-second delay between purchases
const results = await sf.chain(
  ['btc-sentiment', 'whale-alerts', 'defi-scores'],
  2000,
);

// No delay (faster but may hit rate limits)
const results = await sf.chain(
  ['btc-sentiment', 'whale-alerts'],
  0,
);
```

## Research Agent Pattern

A common pattern is to chain feeds for comprehensive market analysis:

```typescript theme={null}
async function marketResearch(sf: ShadowFeed) {
  const results = await sf.chain([
    'btc-sentiment',        // Market mood
    'smart-money-flows',    // Institutional moves
    'liquidation-alerts',   // Risk signals
    'defi-scores',          // Protocol health
    'bridge-flows',         // Cross-chain activity
  ], 2000);

  const [sentiment, flows, liquidations, defi, bridges] = results.feeds;

  return {
    mood: sentiment.data.overall_label,
    smartMoneySignal: flows.data.signal,
    liquidationRisk: liquidations.data.total_liquidations_24h,
    topProtocol: defi.data.protocols?.[0]?.protocol,
    totalSpent: results.total_spent_stx,
  };
}
```

## Cost Estimation

Before chaining, you can check feed prices:

```typescript theme={null}
const feedIds = ['btc-sentiment', 'smart-money-flows', 'defi-scores'];

let totalCost = 0;
for (const id of feedIds) {
  const info = await sf.getFeed(id);
  if (info) {
    totalCost += info.price_stx;
    console.log(`${id}: ${info.price_stx} STX`);
  }
}
console.log(`Total estimated cost: ${totalCost} STX`);
```
