update_exchange_credentials
Write exchange API credentials to OctoBot's global configuration after explicit confirmation, returning only the key's last four digits to avoid exposing secrets.
Instructions
Write an exchange's API credentials to OctoBot's global config. Confirm-gated (ADR-0003).
If confirm is not exactly true, no OctoBot call is made at all --
this returns require_confirmation's structured refusal (a normal
return, not an error) instead. Reason given: "writes exchange API
credentials; verify the exchange name and that you intend to grant this
key trading access" (per spec).
Once confirmed, maps to POST /config with JSON body
{"global_config": {"exchanges_<exchange>_api-key": api_key, "exchanges_<exchange>_api-secret": api_secret[, "exchanges_<exchange>_ api-password": api_password]}} -- see this module's docstring
("Milestone 12") for the full, source-verified derivation of this exact
shape (open question #2, now resolved) and its known limitation.
Refuses locally, before any OctoBot call, if exchange contains an
underscore -- confirmed against source
(octobot_commons.configuration.config_operations.parse_and_update)
that OctoBot's own config-path decoder would otherwise split the
generated "exchanges_<exchange>_api-key" key on every literal "_"
positionally, silently writing the credential into the wrong nested
config location instead of the intended exchange's. Raises
ExchangeCredentialsUpdateRejectedError for this case.
INV-4/NFR-6, this tool's one consumer of redact_secrets: OctoBot's
own success response for this route (global_updated_config, confirmed
against source) echoes the ENTIRE submitted global_config dict back
verbatim -- including the raw api_key/api_secret/api_password just
sent. This tool therefore never reads OR forwards any part of OctoBot's
response body on success: a 2xx status alone is trusted (this route's
status code IS a faithful (success, err_message) signal, confirmed
against source models/configuration.py::update_global_config, unlike
several profiles.py routes that needed a post-hoc re-check), and the
tool's own output below is built from only what it already knows
locally. On failure, OctoBot's raw error text is passed through
redact_secrets with the literal api_key/api_secret/api_password
values from THIS call before being included in the raised exception's
message -- the single boundary INV-4 requires, not scattered ad-hoc
scrubbing.
Output on success: {"exchange": str, "updated": true, "api_key_last4": str} -- never the full api_key/api_secret, per NFR-6.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | Yes | ||
| confirm | No | ||
| exchange | Yes | ||
| api_secret | Yes | ||
| api_password | No |