Method

commodity.namespaces

List the commodity namespaces with how many commodities each holds.

Lists the commodity namespaces with how many commodities each holds. CURRENCY holds the 227 built-in ISO 4217 currencies; other namespaces are exchanges or types you create securities in (NASDAQ, FUND). CURRENCY and template are reserved: no security can be created in them. Note that GnuCash's old name for the currency namespace, ISO4217, is accepted as CURRENCY.

Examples

Example: with a new, empty book open as book.gnucash.

JSON-RPC

Request:

{"jsonrpc":"2.0","id":1,"method":"commodity.namespaces","params":{}}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "name": "CURRENCY",
      "commodities": 227,
      "isCurrency": true,
      "reserved": true
    },
    {
      "name": "template",
      "commodities": 1,
      "isCurrency": false,
      "reserved": true
    }
  ]
}

Request:

{"jsonrpc":"2.0","id":2,"method":"commodity.create","params":{"namespace":"NASDAQ","mnemonic":"AAPL","fullname":"Apple Inc"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": "…"
}

Request:

{"jsonrpc":"2.0","id":3,"method":"commodity.namespaces","params":{}}

Response:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": [
    {
      "name": "CURRENCY",
      "…": "…"
    },
    {
      "name": "NASDAQ",
      "commodities": 1,
      "isCurrency": false,
      "reserved": false
    },
    "…"
  ]
}

Command line

red-ale exec --book book.gnucash --script - <<'EOF'
commodity.namespaces {}
commodity.create {"namespace":"NASDAQ","mnemonic":"AAPL","fullname":"Apple Inc"}
commodity.namespaces {}
EOF

It prints:

[
  [
    {
      "name": "CURRENCY",
      "commodities": 227,
      "isCurrency": true,
      "reserved": true
    },
    {
      "name": "template",
      "commodities": 1,
      "isCurrency": false,
      "reserved": true
    }
  ],
  "…",
  [
    {
      "name": "CURRENCY",
      "…": "…"
    },
    {
      "name": "NASDAQ",
      "commodities": 1,
      "isCurrency": false,
      "reserved": false
    },
    "…"
  ]
]

MCP tool call

Tool call:

{"name":"commodity.namespaces","arguments":{}}

Result:

{
  "content": [
    {
      "type": "text",
      "text": "[{\"name\":\"CURRENCY\",\"commodities\":227,\"isCurrency\":true,\"reserved\":true},{\"name\":\"template\",\"commodities\":1,\"isCurrency\":false,\"reserved\":true}]"
    }
  ]
}

Tool call:

{"name":"commodity.create","arguments":{"namespace":"NASDAQ","mnemonic":"AAPL","fullname":"Apple Inc"}}

Result:

{
  "content": [
    {
      "type": "text",
      "text": "\"…\""
    }
  ]
}

Tool call:

{"name":"commodity.namespaces","arguments":{}}

Result:

{
  "content": [
    {
      "type": "text",
      "text": "[{\"name\":\"CURRENCY\",\"…\":\"…\"},{\"name\":\"NASDAQ\",\"commodities\":1,\"isCurrency\":false,\"reserved\":false},\"…\"]"
    }
  ]
}

Effect: read.

Params

Params for methods that take none.

Type: NoParams.

Result

Type: array of NamespaceInfo.