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

# Build and Distribute Strategies

> Create, manage, and publish strategies for distribution through partner applications and Glider.

Use this guide to create your first strategy through the B2B API, update its
allocation, and make it available to distributors.

Read [Becoming a Strategy Provider](/guides/strategy-provider-overview)
for the provider role, distribution options, and update lifecycle.

## Before you start

Keep your API key on your backend. The key needs:

* `strategies:write` to validate, create, and update strategies.
* `strategies:read` to list strategies and read their configuration,
  performance, and version history.

If you do not have a key,
[request B2B API access](https://console.glidercloud.dev/).

The examples below use these shared values:

```javascript theme={null}
const API_BASE = "https://api.glider.fi/v2";
const headers = {
  "content-type": "application/json",
  "x-api-key": process.env.GLIDER_API_KEY,
};
```

## 1. Define and validate your first strategy

Allocations use [CAIP-19 asset IDs](/guides/caip-identifiers). A strategy can
contain from 1 through 50 assets. Each weight must be a positive percentage
string with no more than two decimal places. All weights must total `100`.

Start with a private draft:

```javascript theme={null}
const strategyDraft = {
  name: "Balanced Growth",
  description: "A diversified USDC and WETH strategy",
  allocation: {
    assets: [
      {
        assetId:
          "eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        weight: "60",
      },
      {
        assetId:
          "eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        weight: "40",
      },
    ],
  },
  schedule: { type: "interval", frequency: "daily" },
  preferences: {
    swap: {
      slippageBps: 300,
      priceImpactBps: 300,
      thresholdUsd: "5.00",
    },
  },
  isPublic: false,
};

const validationResponse = await fetch(`${API_BASE}/strategies/validate`, {
  method: "POST",
  headers,
  body: JSON.stringify(strategyDraft),
});

const validation = await validationResponse.json();
if (!validationResponse.ok) {
  throw new Error(validation.error.message);
}
```

The validation route accepts the same body as the create route. It checks the
allocation structure and whether Glider supports the requested assets. The
create route repeats these checks.

## 2. Create the strategy

```javascript theme={null}
const createResponse = await fetch(`${API_BASE}/strategies`, {
  method: "POST",
  headers,
  body: JSON.stringify(strategyDraft),
});

const created = await createResponse.json();
if (!createResponse.ok) {
  throw new Error(created.error.message);
}

const strategyId = created.data.strategyId;
console.log("Created strategy", strategyId);
```

Store the returned `strategyId`. It identifies the strategy across all future
versions and is the value that distributors use.

## 3. Manage the strategy

Use these routes to operate your strategy:

| Task                                    | Route                                                    |
| --------------------------------------- | -------------------------------------------------------- |
| List your strategies                    | `GET /v2/strategies`                                     |
| Read the current strategy               | `GET /v2/strategies/{strategyId}`                        |
| Change name, description, or visibility | `PATCH /v2/strategies/{strategyId}`                      |
| Read allocation history                 | `GET /v2/strategies/{strategyId}/versions`               |
| Publish a new allocation                | `POST /v2/strategies/{strategyId}/versions`              |
| Read or change cadence                  | `GET` or `PUT /v2/strategies/{strategyId}/schedule`      |
| Read or change swap preferences         | `GET` or `PATCH /v2/strategies/{strategyId}/preferences` |
| Read strategy performance               | `GET /v2/strategies/{strategyId}/performance`            |

For example, update the display metadata without changing the allocation:

```javascript theme={null}
await fetch(`${API_BASE}/strategies/${strategyId}`, {
  method: "PATCH",
  headers,
  body: JSON.stringify({
    name: "Balanced Growth Index",
    description: "A diversified strategy for long-term growth",
  }),
});
```

The metadata route accepts only `name`, `description`, and `isPublic`.

## 4. Change weights or add assets

Allocation versions are immutable. Publish a new version with the complete
target allocation. The request is not a partial patch. If you omit an existing
asset, it is not part of the new target.

This example changes both weights and adds WBTC:

```javascript theme={null}
const versionResponse = await fetch(
  `${API_BASE}/strategies/${strategyId}/versions`,
  {
    method: "POST",
    headers,
    body: JSON.stringify({
      allocation: {
        assets: [
          {
            assetId:
              "eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
            weight: "50",
          },
          {
            assetId:
              "eip155:1/erc20:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
            weight: "30",
          },
          {
            assetId:
              "eip155:1/erc20:0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
            weight: "20",
          },
        ],
      },
      changeLog: "Added WBTC and reduced the USDC and WETH targets",
    }),
  },
);

const version = await versionResponse.json();
if (!versionResponse.ok) {
  throw new Error(version.error.message);
}
```

<Warning>
  A new strategy version becomes active immediately. Every enrolled portfolio
  uses the new target during its next rebalance.
</Warning>

Previous versions remain available from
`GET /v2/strategies/{strategyId}/versions`. To restore an old allocation,
publish that allocation again as a new version.

See [Updating Strategies](/guides/strategy-updating) for the complete update
route reference.

## 5. Make the strategy public

After you review the strategy, set `isPublic` to `true`:

```javascript theme={null}
const publishResponse = await fetch(
  `${API_BASE}/strategies/${strategyId}`,
  {
    method: "PATCH",
    headers,
    body: JSON.stringify({ isPublic: true }),
  },
);

const published = await publishResponse.json();
if (!publishResponse.ok) {
  throw new Error(published.error.message);
}
```

You can also send `isPublic: true` when you first create the strategy. Keeping
it private until review is safer because it prevents distribution of an
unfinished allocation.

When the strategy is public:

* Give distributors the `strategyId`. They use their own Glider API key, not
  yours.
* A distributor with `strategies:read` can read the strategy configuration.
* A distributor with `enroll:write` can use the `strategyId` in the
  [two-stage enrollment flow](/guides/two-stage-enrollment).
* You can share its Glider page at
  `https://glider.fi/strategy/{strategyId}`.

<Info>
  Public status does not guarantee placement in Glider's curated or
  top-performing collections. Curated placement is managed by Glider.
  Top-performing placement depends on live strategy analytics. Contact Glider
  if you want the strategy considered for a featured surface.
</Info>

Other applications can browse Glider-selected public strategies through
`GET /v2/discovery/strategies`. That endpoint returns the `curated` and
`top_performing` collections. A partner that already has your `strategyId` can
integrate the strategy directly without waiting for curated placement.

## Reference

* [Create strategy](/api-reference/endpoints/v2-create-strategy)
* [Patch strategy metadata](/api-reference/endpoints/v2-patch-strategy)
* [Publish strategy version](/api-reference/endpoints/v2-publish-strategy-version)
* [List strategy versions](/api-reference/endpoints/v2-list-strategy-versions)
* [Set strategy schedule](/api-reference/endpoints/v2-set-strategy-schedule)
* [Discover strategies](/api-reference/endpoints/v2-discovery-strategies)
