75trust / 100

Portfolio Rebalancing Calculator

by Sindri in Other

x402 APIPassing, checked 1 h ago

Portfolio rebalancing calculator. Given current holdings and target allocation percentages, computes the dollar gap per asset and the monthly buy/sell inflow needed to reach the target allocation over a chosen rebalancing period.

POST https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator

Last 30 days

All checks passedSome failedAll failedNot checked

Status and outage history · Atom feed

Uptime
100%
Response time
413 ms typical, 524 ms slowest 5%
Last check
1 h ago
Next check
any minute now

How to call it

POST https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator

Each call costs $0.01 in USDC on Base, paid with the request over x402.

Run a free test callOne unpaid request, the way an agent sends it. You see the payment challenge it gets back. Nothing is charged.

Example request

From the listing.

POST https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator
content-type: application/json

{
  "holdings": [
    {
      "currentAmount": 60000,
      "name": "stocks",
      "targetPercent": 0.7
    },
    {
      "currentAmount": 40000,
      "name": "bonds",
      "targetPercent": 0.3
    }
  ],
  "rebalancingPeriodMonths": 1
}

Parameters

ParameterTypeRequiredDescription
holdingsarray of objectYesArray of holdings, each with name, currentAmount, and targetPercent (must sum to 1 across all holdings). Max 50 entries.
rebalancingPeriodMonthsnumberNoNumber of months to spread the rebalancing over. Default 1 (immediate lump-sum rebalance). Default: 1.

Example response

The provider's example. We can't check it without paying.

Example response, 37 lines
{
  "data": {
    "holdings": [
      {
        "currentAmount": 60000,
        "gap": 10000,
        "monthlyInflow": 10000,
        "name": "stocks",
        "targetAmount": 70000
      },
      {
        "currentAmount": 40000,
        "gap": -10000,
        "monthlyInflow": -10000,
        "name": "bonds",
        "targetAmount": 30000
      }
    ],
    "params": {
      "holdings": [
        {
          "currentAmount": 60000,
          "name": "stocks",
          "targetPercent": 0.7
        },
        {
          "currentAmount": 40000,
          "name": "bonds",
          "targetPercent": 0.3
        }
      ],
      "rebalancingPeriodMonths": 1
    },
    "totalValue": 100000
  },
  "ok": true
}

Call it from code

The curl command shows the payment challenge. The JavaScript and Python versions pay and call, and never pay more than $0.01.

curl: see the payment challenge
# bash or zsh: see the payment challenge. Nothing is charged.
curl -sS -g -i -X POST 'https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator' \
  -H 'content-type: application/json' \
  --data-raw '{"holdings":[{"currentAmount":60000,"name":"stocks","targetPercent":0.7},{"currentAmount":40000,"name":"bonds","targetPercent":0.3}],"rebalancingPeriodMonths":1}'

# x402 v2 sends the challenge base64-encoded in the PAYMENT-REQUIRED header (v1 sends it in the body).
# To read the header:
curl -sS -g -o /dev/null -D - -X POST 'https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator' \
  -H 'content-type: application/json' \
  --data-raw '{"holdings":[{"currentAmount":60000,"name":"stocks","targetPercent":0.7},{"currentAmount":40000,"name":"bonds","targetPercent":0.3}],"rebalancingPeriodMonths":1}' \
  | grep -i '^payment-required:' | cut -d' ' -f2 | tr -d '\r' | base64 --decode
JavaScript: pay and call
// npm i @x402/fetch @x402/evm viem
import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

// Pays at most $0.01 per call.
const client = new x402Client().setSpendControls({ maxAmountPerPayment: "$0.01" });
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.EVM_PRIVATE_KEY) });
const pay = wrapFetchWithPayment(fetch, client);

// Not sure it's safe to pay? ToolVet checks it first for $0.005. Pay for that from a separate
// client: this one is capped at $0.01 per payment. GET https://toolvet.app/api/v1/check?url=https%3A%2F%2Fppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws%2FportfolioRebalancingCalculator&method=POST
const res = await pay("https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    "holdings": [
      {
        "currentAmount": 60000,
        "name": "stocks",
        "targetPercent": 0.7
      },
      {
        "currentAmount": 40000,
        "name": "bonds",
        "targetPercent": 0.3
      }
    ],
    "rebalancingPeriodMonths": 1
  }),
});
console.log(res.status, await res.text());
Python: pay and call
# pip install "x402[requests,evm]"
import os
from eth_account import Account
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client

# Pays at most $0.01 per call.
client = x402ClientSync().set_spend_controls({"max_amount_per_payment": "$0.01"})
register_exact_evm_client(client, EthAccountSigner(Account.from_key(os.environ["EVM_PRIVATE_KEY"])))

with x402_requests(client) as session:
    res = session.post(
        "https://ppu43fkyhimq5fiqpmo42eh5ri0yypid.lambda-url.us-east-1.on.aws/portfolioRebalancingCalculator",
        json={
            "holdings": [
                {
                    "currentAmount": 60000,
                    "name": "stocks",
                    "targetPercent": 0.7,
                },
                {
                    "currentAmount": 40000,
                    "name": "bonds",
                    "targetPercent": 0.3,
                },
            ],
            "rebalancingPeriodMonths": 1,
        },
    )
    print(res.status_code, res.text)

Security scan

  • No findings. We scan names, descriptions and tool definitions for hidden instructions and other prompt-injection patterns.

Recent checks

WhenResultHTTPTimePrice
1 h agoPassed402520 ms$0.01
5 h agoPassed402333 ms$0.01
9 h agoPassed402386 ms$0.01
13 h agoPassed402126 ms$0.01
17 h agoPassed402454 ms$0.01
21 h agoPassed402524 ms$0.01
25 h agoPassed402379 ms$0.01
28 h agoPassed402423 ms$0.01
32 h agoPassed402622 ms$0.01
35 h agoPassed402450 ms$0.01
39 h agoPassed402425 ms$0.01
42 h agoPassed402400 ms$0.01
46 h agoPassed402479 ms$0.01
2 days agoPassed402387 ms$0.01
2 days agoPassed402391 ms$0.01