After creating a portfolio, you may need to update its structure, allocation, or rebalancing settings. The Glider API provides several endpoints for updating portfolios.

Updating Portfolio Template

To update a portfolio’s template (including its asset allocations and settings), use one of the portfolio update endpoints:

const updateResponse = await fetch(
  `/v1/portfolio/${portfolioId}/update`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": API_KEY,
    },
    body: JSON.stringify({
      templateData: {
        name: "Updated 60/40 Portfolio",
        description: "A classic 60/40 portfolio with updated weights",
        entry: {
          blockType: "weight",
          weightType: "specified-percentage",
          weightings: ["60", "40"],
          children: [
            {
              blockType: "asset",
              assetId: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE:8453" // ETH on Base
            },
            {
              blockType: "asset",
              assetId: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913:8453" // USDC on Base
            }
          ]
        },
        tradingSettings: {
          type: "threshold",
          triggerPercentage: 5
        }
      }
    }),
  }
);

const updatedPortfolio = await updateResponse.json();

Each update creates a new version of the portfolio’s blueprint (template), preserving the history of changes. The portfolio will be associated with the newly created template version.

Alternative Update Endpoints

You can also use these alternative endpoints for updating portfolios:

// PUT to the portfolio ID
const putResponse = await fetch(
  `/v1/portfolio/${portfolioId}`,
  {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": API_KEY,
    },
    body: JSON.stringify({
      templateData: {
        // Same structure as above
      }
    }),
  }
);

// POST to the portfolio ID
const postResponse = await fetch(
  `/v1/portfolio/${portfolioId}`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": API_KEY,
    },
    body: JSON.stringify({
      templateData: {
        // Same structure as above
      }
    }),
  }
);

All three endpoints function identically, providing flexibility in how you integrate with the API.

Template Data Structure

The template data object defines the portfolio structure and settings:

{
  "templateData": {
    "name": "Portfolio Name",
    "description": "Portfolio description",
    "entry": {
      "blockType": "weight",
      "weightType": "specified-percentage",
      "weightings": ["60", "40"],
      "children": [
        {
          "blockType": "asset",
          "assetId": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE:8453"
        },
        {
          "blockType": "asset",
          "assetId": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913:8453"
        }
      ]
    },
    "tradingSettings": {
      "type": "threshold",
      "triggerPercentage": 5
    }
  }
}

Template Fields

  • name: The name of the portfolio (optional)
  • description: A description of the portfolio (optional)
  • entry: The portfolio structure defining asset allocations (required)
    • blockType: Type of portfolio structure (required, must be “weight” for weighted allocation)
    • weightType: For weighted portfolios, specifies how weights are calculated (required, must be “specified-percentage”)
    • weightings: Array of string percentages for each asset (required, must match the number of children)
    • children: Array of assets or nested structures (required, at least 1 child required)
      • For assets: { blockType: "asset", assetId: "0xTokenAddress:chainId" }
      • The assetId must follow the format 0xTokenAddress:chainId where chainId is a number
      • Each asset must have a valid address on the specified chain
  • tradingSettings: Rebalancing configuration (optional)
    • type: Type of rebalancing - “threshold” or “calendar” (required if tradingSettings is provided)
    • triggerPercentage: Deviation percentage to trigger rebalancing (required if type is “threshold”)
    • frequency: Rebalance frequency (required if type is “calendar”): “daily”, “weekly”, “biweekly”, “monthly”

IMPORTANT: The sum of all percentages in weightings must equal 100, and the number of weightings must match the number of children in the template. Each percentage should be provided as a string like “60” (not a number).

Updating Rebalance Schedule Interval

You can also update just the rebalancing schedule interval without changing the portfolio template:

const updateIntervalResponse = await fetch(
  `/v1/portfolio/${portfolioId}/update-schedule-interval`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": API_KEY,
    },
    body: JSON.stringify({
      interval: {
        every: 43200000, // 12 hours in milliseconds
        offset: 0, // Optional: Offset from the start time in milliseconds
      },
    }),
  }
);

const updateIntervalResult = await updateIntervalResponse.json();

Response

The template update endpoints return a response with information about the updated portfolio:

{
  "success": true,
  "data": {
    "portfolioId": "port_1a2b3c4d5e6f",
    "message": "Portfolio template updated successfully",
    "httpMethod": "POST",
    "blueprint": {
      "blueprintId": "bp_a1b2c3d4e5f6",
      "editId": "edit_g7h8i9j0k1l2",
      "version": 2,
      "name": "Updated 60/40 Portfolio"
    }
  },
  "correlationId": "corr_abcd1234",
  "requestId": "req_efgh5678",
  "timestamp": "2023-05-21T12:34:56.789Z"
}

Validation

The API performs validation on your template updates to ensure they’re well-formed. If there are any validation errors, you’ll receive an error response:

{
  "success": false,
  "error": {
    "code": "PORTFOLIO_TEMPLATE_VALIDATION_ERROR",
    "message": "Invalid portfolio template",
    "details": {
      "errors": [
        {
          "type": "INVALID_STRUCTURE",
          "message": "Invalid asset structure",
          "blockId": "asset_123",
          "fix": "Ensure asset has valid assetId"
        }
      ]
    }
  },
  "correlationId": "corr_abcd1234",
  "requestId": "req_efgh5678",
  "timestamp": "2023-05-21T12:34:56.789Z"
}

Common validation errors include:

  1. Invalid Asset ID Format

    • Error: INVALID_ASSET_ID
    • Fix: Ensure asset IDs follow the format 0xTokenAddress:chainId
  2. Weight Mismatch

    • Error: WEIGHT_MISMATCH
    • Fix: Make sure the number of weightings matches the number of children
  3. Invalid Weight Sum

    • Error: INVALID_WEIGHT_SUM
    • Fix: Ensure that weights sum to 100
  4. Missing Required Fields

    • Error: MISSING_REQUIRED_FIELDS
    • Fix: Include all required fields in the template structure
  5. Unsupported Asset

    • Error: UNSUPPORTED_ASSET
    • Fix: Use only supported assets for the specified chain

If you encounter validation errors, correct the specified issues and resubmit the template update request.

For more detailed information about the available endpoints, see the Portfolio Management API reference.