commodity.delete
Delete a security that nothing uses; its prices go too only with deletePrices.
Deletes a security that nothing uses. It is refused with conflict while an account, a transaction (as its currency)
or a business object uses it, or while it has prices, unless deletePrices is true, which deletes those prices with it.
GnuCash's dialog would leave the prices of a deleted currency dangling; red-ale will not. Currencies cannot be deleted.
Examples
Example: with a new, empty book open as book.gnucash.
JSON-RPC
Request:
{"jsonrpc":"2.0","id":1,"method":"commodity.create","params":{"namespace":"NASDAQ","mnemonic":"AAPL","fullname":"Apple Inc"}}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": "…"
}
Request:
{"jsonrpc":"2.0","id":2,"method":"commodity.delete","params":{"commodity":"NASDAQ::AAPL"}}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"deletedPrices": []
}
}
Request:
{"jsonrpc":"2.0","id":3,"method":"commodity.delete","params":{"commodity":"USD"}}
Response:
{
"jsonrpc": "2.0",
"id": 3,
"error": {
"code": 2001,
"message": "…",
"data": {
"help": "error/invalid"
}
}
}
Command line
red-ale exec --book book.gnucash --script - <<'EOF'
commodity.create {"namespace":"NASDAQ","mnemonic":"AAPL","fullname":"Apple Inc"}
commodity.delete {"commodity":"NASDAQ::AAPL"}
commodity.delete {"commodity":"USD"}
EOF
It fails with exit status 2, printing on standard error:
{
"error": {
"code": 2001,
"message": "…",
"data": {
"help": "error/invalid"
}
}
}
MCP tool call
Tool call:
{"name":"commodity.create","arguments":{"namespace":"NASDAQ","mnemonic":"AAPL","fullname":"Apple Inc"}}
Result:
{
"content": [
{
"type": "text",
"text": "\"…\""
}
]
}
Tool call:
{"name":"commodity.delete","arguments":{"commodity":"NASDAQ::AAPL"}}
Result:
{
"structuredContent": {
"deletedPrices": []
}
}
Tool call:
{"name":"commodity.delete","arguments":{"commodity":"USD"}}
Result:
{
"isError": true,
"structuredContent": {
"error": {
"code": 2001,
"name": "invalid",
"message": "…",
"data": {
"help": "error/invalid"
}
}
}
}
Effect: destructive, on the Book.
Params
Params of commodity.delete.
commodity(CommodityId, required): The security to delete.deletePrices(boolean): Also delete its prices (either side). Without this, a commodity with prices is not deleted.
Result
What commodity.delete removed.
deletedPrices(array of Guid, required): The prices deleted with it.