> For the complete documentation index, see [llms.txt](https://docs.kiiglobal.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kiiglobal.io/docs/kiichain-pay/api-reference/portfolio.md).

# Portfolio

## GenerateReport generates and streams a report file for download

> Uses the reporters registered for report\_type/format (see\
> x/portfolio/infra/reporters) — account\_id defaults to the caller's own\
> account and requires the :all scope to query on behalf of another

```json
{"openapi":"3.0.0","info":{"title":"KiiChain Pay Backend","version":"v1"},"tags":[{"description":"Queries (read operations)","name":"PortfolioQueryService"}],"servers":[{"description":"Production","url":"https://backend.pay.kiichain.io"},{"description":"Staging","url":"https://backend.pay.staging.kiichain.io"}],"security":[{"ApiKeyAuth":["reports.generate.read","reports.generate.read:all"]},{"BearerAuth":["reports.generate.read","reports.generate.read:all"]}],"components":{"securitySchemes":{"ApiKeyAuth":{"description":"Send 'Authorization: APIKey <api-key>' to authenticate with a API key.","in":"header","name":"Authorization","type":"apiKey"},"BearerAuth":{"flows":{"password":{"scopes":{},"tokenUrl":"https://backend.pay.kiichain.io/users/v1/auth/login"}},"type":"oauth2"}},"schemas":{"apiHttpBody":{"description":"Message that represents an arbitrary HTTP body. It should only be used for\npayload formats that can't be represented as JSON, such as raw binary or\nan HTML page.\n\n\nThis message can be used both in streaming and non-streaming API methods in\nthe request as well as the response.\n\nIt can be used as a top-level request field, which is convenient if one\nwants to extract parameters from either the URL or HTTP template into the\nrequest fields and also want access to the raw HTTP body.\n\nExample:\n\n    message GetResourceRequest {\n      // A unique request id.\n      string request_id = 1;\n\n      // The raw HTTP body is bound to this field.\n      google.api.HttpBody http_body = 2;\n\n    }\n\n    service ResourceService {\n      rpc GetResource(GetResourceRequest)\n        returns (google.api.HttpBody);\n      rpc UpdateResource(google.api.HttpBody)\n        returns (google.protobuf.Empty);\n\n    }\n\nExample with streaming methods:\n\n    service CaldavService {\n      rpc GetCalendar(stream google.api.HttpBody)\n        returns (stream google.api.HttpBody);\n      rpc UpdateCalendar(stream google.api.HttpBody)\n        returns (stream google.api.HttpBody);\n\n    }\n\nUse of this type only changes how the request and response bodies are\nhandled, all other features will continue to work unchanged.","properties":{"contentType":{"description":"The HTTP Content-Type header value specifying the content type of the body.","type":"string"},"data":{"description":"The HTTP request/response body as raw binary.","format":"byte","type":"string"},"extensions":{"description":"Application specific response metadata. Must be set in the first response\nfor streaming APIs.","items":{"$ref":"#/components/schemas/protobufAny"},"type":"array"}},"type":"object"},"protobufAny":{"additionalProperties":{},"description":"`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n    Foo foo = ...;\n    Any any;\n    any.PackFrom(foo);\n    ...\n    if (any.UnpackTo(&foo)) {\n      ...\n    }\n\nExample 2: Pack and unpack a message in Java.\n\n    Foo foo = ...;\n    Any any = Any.pack(foo);\n    ...\n    if (any.is(Foo.class)) {\n      foo = any.unpack(Foo.class);\n    }\n    // or ...\n    if (any.isSameTypeAs(Foo.getDefaultInstance())) {\n      foo = any.unpack(Foo.getDefaultInstance());\n    }\n\n Example 3: Pack and unpack a message in Python.\n\n    foo = Foo(...)\n    any = Any()\n    any.Pack(foo)\n    ...\n    if any.Is(Foo.DESCRIPTOR):\n      any.Unpack(foo)\n      ...\n\n Example 4: Pack and unpack a message in Go\n\n     foo := &pb.Foo{...}\n     any, err := anypb.New(foo)\n     if err != nil {\n       ...\n     }\n     ...\n     foo := &pb.Foo{}\n     if err := any.UnmarshalTo(foo); err != nil {\n       ...\n     }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n    package google.profile;\n    message Person {\n      string first_name = 1;\n      string last_name = 2;\n    }\n\n    {\n      \"@type\": \"type.googleapis.com/google.profile.Person\",\n      \"firstName\": <string>,\n      \"lastName\": <string>\n    }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n    {\n      \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n      \"value\": \"1.212s\"\n    }","properties":{"@type":{"description":"A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n  value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n  URL, or have them precompiled into a binary to avoid any\n  lookup. Therefore, binary compatibility needs to be preserved\n  on changes to types. (Use versioned type names to manage\n  breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com. As of May 2023, there are no widely used type server\nimplementations and no plans to implement one.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics.","type":"string"}},"type":"object"},"AppErrorStatus":{"description":"The error envelope this API returns for every non-2xx response. `details` always contains exactly one AppError.","properties":{"code":{"description":"gRPC status code","format":"int32","type":"integer"},"details":{"description":"Always contains exactly one AppError","items":{"$ref":"#/components/schemas/AppError"},"type":"array"},"message":{"description":"Human-readable error message","type":"string"}},"type":"object"},"AppError":{"description":"Structured error detail responded by any non-2xx response.","properties":{"@type":{"description":"Protobuf Any type URL, always \"type.googleapis.com/pay.common.error.v1.AppError\" for this API","type":"string"},"internalCode":{"description":"Internal error code, unique within the module","format":"int32","type":"integer"},"message":{"description":"Human-readable error message","type":"string"},"meta":{"additionalProperties":{"type":"string"},"description":"Additional structured context for the error, if any","type":"object"},"module":{"description":"Module name where the error occurred (e.g. \"accounts\", \"market\")","type":"string"}},"type":"object"}},"responses":{"AppError":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppErrorStatus"}}},"description":"An unexpected error response. `details[0]` is always an AppError, see #/components/schemas/AppError"}}},"paths":{"/portfolio/v1/generate":{"get":{"description":"Uses the reporters registered for report_type/format (see\nx/portfolio/infra/reporters) — account_id defaults to the caller's own\naccount and requires the :all scope to query on behalf of another","operationId":"PortfolioQueryService_GenerateReport","parameters":[{"description":"report_type identifies the kind of report to generate (e.g. \"trade\")","in":"query","name":"reportType","required":true,"schema":{"type":"string"}},{"description":"format identifies the output format (e.g. \"csv\", \"pdf\")","in":"query","name":"format","required":true,"schema":{"type":"string"}},{"description":"start_date is the optional inclusive start of the report date range","in":"query","name":"startDate","required":false,"schema":{"format":"date-time","type":"string"}},{"description":"end_date is the optional inclusive end of the report date range","in":"query","name":"endDate","required":false,"schema":{"format":"date-time","type":"string"}},{"description":"account_id is optional; absent means self-service (from auth context).\nProviding it requires the reports.generate.read:all scope (admin).","in":"query","name":"accountId","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/apiHttpBody"}}},"description":"A successful response."},"default":{"$ref":"#/components/responses/AppError"}},"summary":"GenerateReport generates and streams a report file for download","tags":["PortfolioQueryService"]}}}}
```

## GetPortfolio returns the aggregated holdings for an account

> Aggregates custodial ledger balances, Privy-managed wallet balances, and\
> caller-supplied external wallet balances into a single USD-valued view

```json
{"openapi":"3.0.0","info":{"title":"KiiChain Pay Backend","version":"v1"},"tags":[{"description":"Queries (read operations)","name":"PortfolioBalancesQueryService"}],"servers":[{"description":"Production","url":"https://backend.pay.kiichain.io"},{"description":"Staging","url":"https://backend.pay.staging.kiichain.io"}],"security":[{"ApiKeyAuth":["portfolio.portfolio.read","portfolio.portfolio.read:all"]},{"BearerAuth":["portfolio.portfolio.read","portfolio.portfolio.read:all"]}],"components":{"securitySchemes":{"ApiKeyAuth":{"description":"Send 'Authorization: APIKey <api-key>' to authenticate with a API key.","in":"header","name":"Authorization","type":"apiKey"},"BearerAuth":{"flows":{"password":{"scopes":{},"tokenUrl":"https://backend.pay.kiichain.io/users/v1/auth/login"}},"type":"oauth2"}},"schemas":{"v1GetPortfolioResponse":{"properties":{"crypto":{"items":{"$ref":"#/components/schemas/v1TokenByWallet"},"title":"crypto is every on-chain token balance held, in the same shape GetTokensByWallet returns","type":"array"},"fiat":{"items":{"$ref":"#/components/schemas/v1FiatHolding"},"type":"array"},"summary":{"$ref":"#/components/schemas/v1Summary"}},"required":["summary","crypto","fiat"],"title":"GetPortfolioResponse is the aggregated portfolio view","type":"object"},"v1TokenByWallet":{"properties":{"address":{"title":"address is the wallet address holding the token","type":"string"},"chainId":{"title":"chain_id is the blockchain network of the token","type":"string"},"tokenAddress":{"title":"token_address is the contract address of the token (empty for native tokens)","type":"string"},"tokenBalance":{"title":"token_balance is the balance of the token held by the wallet","type":"string"},"tokenMetadata":{"$ref":"#/components/schemas/v1Token"}},"required":["address","chainId","tokenBalance","tokenMetadata"],"title":"TokenByWallet represents a token held by a wallet","type":"object"},"v1Token":{"properties":{"decimals":{"format":"int32","title":"decimals is the number of decimal places the token uses","type":"integer"},"enabled":{"title":"enabled indicates whether the token is enabled on the platform","type":"boolean"},"id":{"format":"int32","title":"id is the surrogate identifier of the token","type":"integer"},"logo":{"title":"logo is the URL to the token's logo image","type":"string"},"name":{"title":"name is the full name of the token","type":"string"},"stable":{"title":"stable indicates whether the token is a stablecoin","type":"boolean"},"symbol":{"title":"symbol is the ticker symbol of the token","type":"string"}},"required":["id","name","symbol","decimals","logo","enabled","stable"],"title":"Token represents a coin/token supported by the platform","type":"object"},"v1FiatHolding":{"properties":{"amount":{"type":"string"},"available":{"type":"string"},"decimals":{"format":"int32","type":"integer"},"fiatAssetCode":{"type":"string"},"locked":{"type":"string"},"logo":{"type":"string"},"name":{"type":"string"},"symbol":{"type":"string"},"usdValue":{"type":"string"}},"required":["symbol","name","logo","decimals","fiatAssetCode","amount","available","locked","usdValue"],"title":"FiatHolding is a custodial ledger balance for a fiat asset","type":"object"},"v1Summary":{"properties":{"external":{"$ref":"#/components/schemas/v1GroupBreakdown"},"internal":{"$ref":"#/components/schemas/v1GroupBreakdown"},"totalUsd":{"type":"string"}},"required":["totalUsd","internal","external"],"title":"Summary holds the portfolio totals and per-group breakdowns","type":"object"},"v1GroupBreakdown":{"properties":{"sources":{"items":{"$ref":"#/components/schemas/v1SourceContribution"},"type":"array"},"usdValue":{"type":"string"}},"required":["usdValue","sources"],"title":"GroupBreakdown is a placement group total with per-source contributions","type":"object"},"v1SourceContribution":{"properties":{"address":{"type":"string"},"network":{"title":"network is the wallet chain family (EVM, Tron), set only for wallet sources","type":"string"},"type":{"title":"type is fiat_ledger or wallet","type":"string"},"usdValue":{"type":"string"}},"required":["type","usdValue"],"title":"SourceContribution is one source's USD contribution to a group","type":"object"},"AppErrorStatus":{"description":"The error envelope this API returns for every non-2xx response. `details` always contains exactly one AppError.","properties":{"code":{"description":"gRPC status code","format":"int32","type":"integer"},"details":{"description":"Always contains exactly one AppError","items":{"$ref":"#/components/schemas/AppError"},"type":"array"},"message":{"description":"Human-readable error message","type":"string"}},"type":"object"},"AppError":{"description":"Structured error detail responded by any non-2xx response.","properties":{"@type":{"description":"Protobuf Any type URL, always \"type.googleapis.com/pay.common.error.v1.AppError\" for this API","type":"string"},"internalCode":{"description":"Internal error code, unique within the module","format":"int32","type":"integer"},"message":{"description":"Human-readable error message","type":"string"},"meta":{"additionalProperties":{"type":"string"},"description":"Additional structured context for the error, if any","type":"object"},"module":{"description":"Module name where the error occurred (e.g. \"accounts\", \"market\")","type":"string"}},"type":"object"}},"responses":{"AppError":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppErrorStatus"}}},"description":"An unexpected error response. `details[0]` is always an AppError, see #/components/schemas/AppError"}}},"paths":{"/portfolio/v1/portfolio":{"get":{"description":"Aggregates custodial ledger balances, Privy-managed wallet balances, and\ncaller-supplied external wallet balances into a single USD-valued view","operationId":"PortfolioBalancesQueryService_GetPortfolio","parameters":[{"in":"query","name":"accountId","required":true,"schema":{"type":"string"}},{"description":"evm is a caller-owned EVM wallet to include alongside the internal ones","in":"query","name":"evm","required":false,"schema":{"type":"string"}},{"description":"tron is a caller-owned Tron wallet to include alongside the internal ones","in":"query","name":"tron","required":false,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/v1GetPortfolioResponse"}}},"description":"A successful response."},"default":{"$ref":"#/components/responses/AppError"}},"summary":"GetPortfolio returns the aggregated holdings for an account","tags":["PortfolioBalancesQueryService"]}}}}
```

## GetTokensByWallet returns tokens held by EVM and/or Tron wallet addresses across supported chains

> Queries on-chain balances directly, not the internal ledger. At least\
> one of evm or tron must be provided

```json
{"openapi":"3.0.0","info":{"title":"KiiChain Pay Backend","version":"v1"},"tags":[{"description":"Queries (read operations)","name":"PortfolioBalancesQueryService"}],"servers":[{"description":"Production","url":"https://backend.pay.kiichain.io"},{"description":"Staging","url":"https://backend.pay.staging.kiichain.io"}],"paths":{"/portfolio/v1/tokens-by-wallet":{"get":{"description":"Queries on-chain balances directly, not the internal ledger. At least\none of evm or tron must be provided","operationId":"PortfolioBalancesQueryService_GetTokensByWallet","parameters":[{"description":"evm is an EVM-compatible wallet address (0x-prefixed, 20 bytes)","in":"query","name":"evm","required":false,"schema":{"type":"string"}},{"description":"tron is a Tron wallet address (base58, starts with T)","in":"query","name":"tron","required":false,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/v1GetTokensByWalletResponse"}}},"description":"A successful response."},"default":{"$ref":"#/components/responses/AppError"}},"summary":"GetTokensByWallet returns tokens held by EVM and/or Tron wallet addresses across supported chains","tags":["PortfolioBalancesQueryService"]}}},"components":{"schemas":{"v1GetTokensByWalletResponse":{"properties":{"tokens":{"items":{"$ref":"#/components/schemas/v1TokenByWallet"},"title":"tokens is the list of tokens held by the wallet","type":"array"}},"required":["tokens"],"title":"GetTokensByWalletResponse is the response message for GetTokensByWallet","type":"object"},"v1TokenByWallet":{"properties":{"address":{"title":"address is the wallet address holding the token","type":"string"},"chainId":{"title":"chain_id is the blockchain network of the token","type":"string"},"tokenAddress":{"title":"token_address is the contract address of the token (empty for native tokens)","type":"string"},"tokenBalance":{"title":"token_balance is the balance of the token held by the wallet","type":"string"},"tokenMetadata":{"$ref":"#/components/schemas/v1Token"}},"required":["address","chainId","tokenBalance","tokenMetadata"],"title":"TokenByWallet represents a token held by a wallet","type":"object"},"v1Token":{"properties":{"decimals":{"format":"int32","title":"decimals is the number of decimal places the token uses","type":"integer"},"enabled":{"title":"enabled indicates whether the token is enabled on the platform","type":"boolean"},"id":{"format":"int32","title":"id is the surrogate identifier of the token","type":"integer"},"logo":{"title":"logo is the URL to the token's logo image","type":"string"},"name":{"title":"name is the full name of the token","type":"string"},"stable":{"title":"stable indicates whether the token is a stablecoin","type":"boolean"},"symbol":{"title":"symbol is the ticker symbol of the token","type":"string"}},"required":["id","name","symbol","decimals","logo","enabled","stable"],"title":"Token represents a coin/token supported by the platform","type":"object"},"AppErrorStatus":{"description":"The error envelope this API returns for every non-2xx response. `details` always contains exactly one AppError.","properties":{"code":{"description":"gRPC status code","format":"int32","type":"integer"},"details":{"description":"Always contains exactly one AppError","items":{"$ref":"#/components/schemas/AppError"},"type":"array"},"message":{"description":"Human-readable error message","type":"string"}},"type":"object"},"AppError":{"description":"Structured error detail responded by any non-2xx response.","properties":{"@type":{"description":"Protobuf Any type URL, always \"type.googleapis.com/pay.common.error.v1.AppError\" for this API","type":"string"},"internalCode":{"description":"Internal error code, unique within the module","format":"int32","type":"integer"},"message":{"description":"Human-readable error message","type":"string"},"meta":{"additionalProperties":{"type":"string"},"description":"Additional structured context for the error, if any","type":"object"},"module":{"description":"Module name where the error occurred (e.g. \"accounts\", \"market\")","type":"string"}},"type":"object"}},"responses":{"AppError":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppErrorStatus"}}},"description":"An unexpected error response. `details[0]` is always an AppError, see #/components/schemas/AppError"}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kiiglobal.io/docs/kiichain-pay/api-reference/portfolio.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
