This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 5f35e6e88a02 CAMEL-27626: camel-xchange - check currencyPair at 
endpoint creation, apiKey and secretKey options, doc (#31012)
5f35e6e88a02 is described below

commit 5f35e6e88a02e020a4f47cacb5a3f9016d027722
Author: allthingssecurity <[email protected]>
AuthorDate: Sat Nov 28 00:26:41 2026 +0530

    CAMEL-27626: camel-xchange - check currencyPair at endpoint creation, 
apiKey and secretKey options, doc (#31012)
    
    1. The currencyPair option was parsed with new CurrencyPair(String) for
       each message, which registers an unknown currency in the JVM wide
       registry of XChange, so a typo such as BTC/USTD went to the exchange.
       getAsCurrencyPair() now uses XChangeConverters.toCurrencyPair, and the
       component calls it once when it creates the endpoint, so an unknown
       currency fails there, as the currency option does. The check runs after
       the exchange is created, so the currencies that the exchange module
       registers are accepted. The option stays a String.
       XChangeConfiguration.setCurrency(String) is not called by Camel and sets
       null for an unknown currency; it is deprecated, not removed.
    
    2. The doc page said the component has an interface for trading and can
       query historical data and place orders. It now lists what the component
       does, and says that it does not place orders or query historical data.
    
    3. The new apiKey and secretKey options (label security, secret) set the
       keys on the default ExchangeSpecification of the exchange module, with
       ExchangeFactory.createExchange(Class, String, String), which sets only
       the keys that are not null. The component keeps one exchange per name
       for the endpoints without keys, as before, and one per name and keys for
       the others, so endpoints with other keys do not share an exchange.
    
    Rebased on the descriptions of CAMEL-23832 (#30957). Their texts are kept.
    The description of currencyPair now also says that a currency XChange does
    not know fails the creation of the endpoint, as the one of currency does.
    
    Regenerated xchange.json (component and catalog copy), the catalog copy of
    the doc page, the endpoint configurer and URI factory, and the endpoint
    DSL. Upgrade guide entry for 4.24.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../apache/camel/catalog/components/xchange.json   |  6 +-
 .../camel/catalog/docs/xchange-component.adoc      | 14 +++-
 .../xchange/XChangeEndpointConfigurer.java         | 12 +++
 .../xchange/XChangeEndpointUriFactory.java         |  9 +-
 .../apache/camel/component/xchange/xchange.json    |  6 +-
 .../src/main/docs/xchange-component.adoc           | 14 +++-
 .../camel/component/xchange/XChangeComponent.java  | 42 ++++++++--
 .../component/xchange/XChangeConfiguration.java    | 42 +++++++++-
 .../xchange/XChangeApiKeysCurrencyPairTest.java    | 93 +++++++++++++++++++++
 .../knowm/xchange/camelkeys/CamelkeysExchange.java | 95 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    | 11 +++
 .../dsl/XChangeEndpointBuilderFactory.java         | 36 +++++++-
 12 files changed, 356 insertions(+), 24 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/xchange.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/xchange.json
index 5187638c200e..7d50e8fd5ce5 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/xchange.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/xchange.json
@@ -38,9 +38,11 @@
   "properties": {
     "name": { "index": 0, "kind": "path", "displayName": "Name", "group": 
"producer", "label": "", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The name of the exchange 
in XChange, for example binance, for which the component loads the class 
org.knowm.xchange.binance.Binance [...]
     "currency": { "index": 1, "kind": "parameter", "displayName": "Currency", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.knowm.xchange.currency.Currency", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The currency, such as 
BTC, for the currencyMetaData method when neither the Currency header nor th 
[...]
-    "currencyPair": { "index": 2, "kind": "parameter", "displayName": 
"Currency Pair", "group": "producer", "label": "", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The currency pair, such 
as BTC\/USDT, for the ticker and currencyPairMetaData methods when neither the 
Curre [...]
+    "currencyPair": { "index": 2, "kind": "parameter", "displayName": 
"Currency Pair", "group": "producer", "label": "", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The currency pair, such 
as BTC\/USDT, for the ticker and currencyPairMetaData methods when neither the 
Curre [...]
     "method": { "index": 3, "kind": "parameter", "displayName": "Method", 
"group": "producer", "label": "", "required": true, "type": "enum", "javaType": 
"org.apache.camel.component.xchange.XChangeConfiguration.XChangeMethod", 
"enum": [ "balances", "fundingHistory", "wallets", "currencies", 
"currencyMetaData", "currencyPairs", "currencyPairMetaData", "ticker" ], 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConf [...]
     "service": { "index": 4, "kind": "parameter", "displayName": "Service", 
"group": "producer", "label": "", "required": true, "type": "enum", "javaType": 
"org.apache.camel.component.xchange.XChangeConfiguration.XChangeService", 
"enum": [ "marketdata", "metadata", "account" ], "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The XChange service [...]
-    "lazyStartProducer": { "index": 5, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
+    "lazyStartProducer": { "index": 5, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
+    "apiKey": { "index": 6, "kind": "parameter", "displayName": "Api Key", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "security": "secret", "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The API key of the 
account at the exchange, for the account service. If not set, the exchan [...]
+    "secretKey": { "index": 7, "kind": "parameter", "displayName": "Secret 
Key", "group": "security", "label": "security", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": true, "security": "secret", "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The secret key of the 
account at the exchange, for the account service. If not set, t [...]
   }
 }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xchange-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xchange-component.adoc
index 6a8b9bf697c6..26f818957e22 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xchange-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/xchange-component.adoc
@@ -13,9 +13,10 @@
 *{component-header}*
 
 The XChange component uses the https://knowm.org/open-source/xchange/[XChange] 
Java library to provide access to 60+ Bitcoin and Altcoin exchanges.
-It comes with a consistent interface for trading and accessing market data. 
 
-Camel can get crypto currency market data, query historical data, place market 
orders and much more.
+Camel can get the ticker of a currency pair, the currencies and currency pairs 
of an exchange with their metadata, and
+the balances, wallets and funding history of an account. The component does 
not place orders and does not query
+historical market data.
 
 Maven users will need to add the following dependency to their `pom.xml`
 for this component:
@@ -53,7 +54,11 @@ For most of the interesting stuff, however, you'd need an 
account with the excha
 These API access keys need to be guarded tightly, especially so when they also 
allow for the withdraw functionality. 
 In which case, anyone who can get hold of your API keys can easily transfer 
funds from your account to some other address i.e. steal your money.   
 
-Your API access keys can be stored in an exchange specific properties file in 
your SSH directory.
+The `apiKey` and `secretKey` options set the API access keys of an endpoint, 
for example from property placeholders
+or a vault: 
`xchange:binance?service=account&method=balances&apiKey={{binance.apiKey}}&secretKey={{binance.secretKey}}`.
+
+If they are not set, the XChange module of the exchange decides. Some modules 
read the keys from an exchange specific
+properties file in your SSH directory.
 For Binance, for example, this would be: `~/.ssh/binance-secret.keys`
 
 ----
@@ -85,7 +90,8 @@ header, else of the message body, else of the `currency` 
option.
 
 The header, the body and the option can be an XChange `CurrencyPair` or 
`Currency`, or text such as `BTC/USDT` and
 `BTC`. Text in the header or the body with a currency that XChange does not 
know fails the exchange: Camel does not
-register a new currency in XChange for text that comes with a message.
+register a new currency in XChange for text that comes with a message. A 
`currency` or `currencyPair` option with a
+currency that XChange does not know fails the creation of the endpoint.
 
 == Examples
 
diff --git 
a/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointConfigurer.java
 
b/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointConfigurer.java
index 18c170bc43f2..837cd2cf1b6b 100644
--- 
a/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointConfigurer.java
+++ 
b/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointConfigurer.java
@@ -24,12 +24,16 @@ public class XChangeEndpointConfigurer extends 
PropertyConfigurerSupport impleme
     public boolean configure(CamelContext camelContext, Object obj, String 
name, Object value, boolean ignoreCase) {
         XChangeEndpoint target = (XChangeEndpoint) obj;
         switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
+        case "apikey":
+        case "apiKey": 
target.getConfiguration().setApiKey(property(camelContext, 
java.lang.String.class, value)); return true;
         case "currency": 
target.getConfiguration().setCurrency(property(camelContext, 
org.knowm.xchange.currency.Currency.class, value)); return true;
         case "currencypair":
         case "currencyPair": 
target.getConfiguration().setCurrencyPair(property(camelContext, 
java.lang.String.class, value)); return true;
         case "lazystartproducer":
         case "lazyStartProducer": 
target.setLazyStartProducer(property(camelContext, boolean.class, value)); 
return true;
         case "method": 
target.getConfiguration().setMethod(property(camelContext, 
org.apache.camel.component.xchange.XChangeConfiguration.XChangeMethod.class, 
value)); return true;
+        case "secretkey":
+        case "secretKey": 
target.getConfiguration().setSecretKey(property(camelContext, 
java.lang.String.class, value)); return true;
         case "service": 
target.getConfiguration().setService(property(camelContext, 
org.apache.camel.component.xchange.XChangeConfiguration.XChangeService.class, 
value)); return true;
         default: return false;
         }
@@ -38,12 +42,16 @@ public class XChangeEndpointConfigurer extends 
PropertyConfigurerSupport impleme
     @Override
     public Class<?> getOptionType(String name, boolean ignoreCase) {
         switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
+        case "apikey":
+        case "apiKey": return java.lang.String.class;
         case "currency": return org.knowm.xchange.currency.Currency.class;
         case "currencypair":
         case "currencyPair": return java.lang.String.class;
         case "lazystartproducer":
         case "lazyStartProducer": return boolean.class;
         case "method": return 
org.apache.camel.component.xchange.XChangeConfiguration.XChangeMethod.class;
+        case "secretkey":
+        case "secretKey": return java.lang.String.class;
         case "service": return 
org.apache.camel.component.xchange.XChangeConfiguration.XChangeService.class;
         default: return null;
         }
@@ -53,12 +61,16 @@ public class XChangeEndpointConfigurer extends 
PropertyConfigurerSupport impleme
     public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
         XChangeEndpoint target = (XChangeEndpoint) obj;
         switch (ignoreCase ? name.toLowerCase(Locale.ROOT) : name) {
+        case "apikey":
+        case "apiKey": return target.getConfiguration().getApiKey();
         case "currency": return target.getConfiguration().getCurrency();
         case "currencypair":
         case "currencyPair": return 
target.getConfiguration().getCurrencyPair();
         case "lazystartproducer":
         case "lazyStartProducer": return target.isLazyStartProducer();
         case "method": return target.getConfiguration().getMethod();
+        case "secretkey":
+        case "secretKey": return target.getConfiguration().getSecretKey();
         case "service": return target.getConfiguration().getService();
         default: return null;
         }
diff --git 
a/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointUriFactory.java
 
b/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointUriFactory.java
index 95303a076f1f..0a947e02ace9 100644
--- 
a/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointUriFactory.java
+++ 
b/components/camel-xchange/src/generated/java/org/apache/camel/component/xchange/XChangeEndpointUriFactory.java
@@ -24,15 +24,20 @@ public class XChangeEndpointUriFactory extends 
org.apache.camel.support.componen
     private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
     private static final Map<String, String> MULTI_VALUE_PREFIXES;
     static {
-        Set<String> props = new HashSet<>(6);
+        Set<String> props = new HashSet<>(8);
+        props.add("apiKey");
         props.add("currency");
         props.add("currencyPair");
         props.add("lazyStartProducer");
         props.add("method");
         props.add("name");
+        props.add("secretKey");
         props.add("service");
         PROPERTY_NAMES = Collections.unmodifiableSet(props);
-        SECRET_PROPERTY_NAMES = Collections.emptySet();
+        Set<String> secretProps = new HashSet<>(2);
+        secretProps.add("apiKey");
+        secretProps.add("secretKey");
+        SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps);
         ENDPOINT_IDENTITY_PROPERTY_NAMES = Collections.emptySet();
         MULTI_VALUE_PREFIXES = Collections.emptyMap();
     }
diff --git 
a/components/camel-xchange/src/generated/resources/META-INF/org/apache/camel/component/xchange/xchange.json
 
b/components/camel-xchange/src/generated/resources/META-INF/org/apache/camel/component/xchange/xchange.json
index 5187638c200e..7d50e8fd5ce5 100644
--- 
a/components/camel-xchange/src/generated/resources/META-INF/org/apache/camel/component/xchange/xchange.json
+++ 
b/components/camel-xchange/src/generated/resources/META-INF/org/apache/camel/component/xchange/xchange.json
@@ -38,9 +38,11 @@
   "properties": {
     "name": { "index": 0, "kind": "path", "displayName": "Name", "group": 
"producer", "label": "", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The name of the exchange 
in XChange, for example binance, for which the component loads the class 
org.knowm.xchange.binance.Binance [...]
     "currency": { "index": 1, "kind": "parameter", "displayName": "Currency", 
"group": "producer", "label": "", "required": false, "type": "object", 
"javaType": "org.knowm.xchange.currency.Currency", "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The currency, such as 
BTC, for the currencyMetaData method when neither the Currency header nor th 
[...]
-    "currencyPair": { "index": 2, "kind": "parameter", "displayName": 
"Currency Pair", "group": "producer", "label": "", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The currency pair, such 
as BTC\/USDT, for the ticker and currencyPairMetaData methods when neither the 
Curre [...]
+    "currencyPair": { "index": 2, "kind": "parameter", "displayName": 
"Currency Pair", "group": "producer", "label": "", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The currency pair, such 
as BTC\/USDT, for the ticker and currencyPairMetaData methods when neither the 
Curre [...]
     "method": { "index": 3, "kind": "parameter", "displayName": "Method", 
"group": "producer", "label": "", "required": true, "type": "enum", "javaType": 
"org.apache.camel.component.xchange.XChangeConfiguration.XChangeMethod", 
"enum": [ "balances", "fundingHistory", "wallets", "currencies", 
"currencyMetaData", "currencyPairs", "currencyPairMetaData", "ticker" ], 
"deprecated": false, "autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConf [...]
     "service": { "index": 4, "kind": "parameter", "displayName": "Service", 
"group": "producer", "label": "", "required": true, "type": "enum", "javaType": 
"org.apache.camel.component.xchange.XChangeConfiguration.XChangeService", 
"enum": [ "marketdata", "metadata", "account" ], "deprecated": false, 
"autowired": false, "secret": false, "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The XChange service [...]
-    "lazyStartProducer": { "index": 5, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
+    "lazyStartProducer": { "index": 5, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
+    "apiKey": { "index": 6, "kind": "parameter", "displayName": "Api Key", 
"group": "security", "label": "security", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": true, "security": "secret", "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The API key of the 
account at the exchange, for the account service. If not set, the exchan [...]
+    "secretKey": { "index": 7, "kind": "parameter", "displayName": "Secret 
Key", "group": "security", "label": "security", "required": false, "type": 
"string", "javaType": "java.lang.String", "deprecated": false, "autowired": 
false, "secret": true, "security": "secret", "configurationClass": 
"org.apache.camel.component.xchange.XChangeConfiguration", 
"configurationField": "configuration", "description": "The secret key of the 
account at the exchange, for the account service. If not set, t [...]
   }
 }
diff --git a/components/camel-xchange/src/main/docs/xchange-component.adoc 
b/components/camel-xchange/src/main/docs/xchange-component.adoc
index 6a8b9bf697c6..26f818957e22 100644
--- a/components/camel-xchange/src/main/docs/xchange-component.adoc
+++ b/components/camel-xchange/src/main/docs/xchange-component.adoc
@@ -13,9 +13,10 @@
 *{component-header}*
 
 The XChange component uses the https://knowm.org/open-source/xchange/[XChange] 
Java library to provide access to 60+ Bitcoin and Altcoin exchanges.
-It comes with a consistent interface for trading and accessing market data. 
 
-Camel can get crypto currency market data, query historical data, place market 
orders and much more.
+Camel can get the ticker of a currency pair, the currencies and currency pairs 
of an exchange with their metadata, and
+the balances, wallets and funding history of an account. The component does 
not place orders and does not query
+historical market data.
 
 Maven users will need to add the following dependency to their `pom.xml`
 for this component:
@@ -53,7 +54,11 @@ For most of the interesting stuff, however, you'd need an 
account with the excha
 These API access keys need to be guarded tightly, especially so when they also 
allow for the withdraw functionality. 
 In which case, anyone who can get hold of your API keys can easily transfer 
funds from your account to some other address i.e. steal your money.   
 
-Your API access keys can be stored in an exchange specific properties file in 
your SSH directory.
+The `apiKey` and `secretKey` options set the API access keys of an endpoint, 
for example from property placeholders
+or a vault: 
`xchange:binance?service=account&method=balances&apiKey={{binance.apiKey}}&secretKey={{binance.secretKey}}`.
+
+If they are not set, the XChange module of the exchange decides. Some modules 
read the keys from an exchange specific
+properties file in your SSH directory.
 For Binance, for example, this would be: `~/.ssh/binance-secret.keys`
 
 ----
@@ -85,7 +90,8 @@ header, else of the message body, else of the `currency` 
option.
 
 The header, the body and the option can be an XChange `CurrencyPair` or 
`Currency`, or text such as `BTC/USDT` and
 `BTC`. Text in the header or the body with a currency that XChange does not 
know fails the exchange: Camel does not
-register a new currency in XChange for text that comes with a message.
+register a new currency in XChange for text that comes with a message. A 
`currency` or `currencyPair` option with a
+currency that XChange does not know fails the creation of the endpoint.
 
 == Examples
 
diff --git 
a/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeComponent.java
 
b/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeComponent.java
index 650a9bafb159..600106e51060 100644
--- 
a/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeComponent.java
+++ 
b/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeComponent.java
@@ -32,6 +32,8 @@ import org.knowm.xchange.utils.Assert;
 public class XChangeComponent extends DefaultComponent {
 
     private final Map<String, XChange> xchanges = new ConcurrentHashMap<>();
+    // the exchanges created with the API keys of an endpoint, one per 
exchange name and keys
+    private final Map<Credentials, XChange> xchangesWithKeys = new 
ConcurrentHashMap<>();
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
@@ -53,9 +55,12 @@ public class XChangeComponent extends DefaultComponent {
         }
 
         // after configuring endpoint then get or create xchange instance
-        XChange xchange = getOrCreateXChange(remaining);
+        XChange xchange = getOrCreateXChange(remaining, 
configuration.getApiKey(), configuration.getSecretKey());
         endpoint.setXchange(xchange);
 
+        // parse the currency pair once, after the exchange is created, as it 
may register the currencies it trades:
+        // like the currency option, a currency that XChange does not know 
fails here, not with each message
+        configuration.getAsCurrencyPair();
         return endpoint;
     }
 
@@ -71,18 +76,41 @@ public class XChangeComponent extends DefaultComponent {
     protected void doShutdown() throws Exception {
         super.doShutdown();
         xchanges.clear();
+        xchangesWithKeys.clear();
     }
 
     protected Exchange createExchange(Class<? extends Exchange> exchangeClass) 
{
         return ExchangeFactory.INSTANCE.createExchange(exchangeClass);
     }
 
-    private XChange getOrCreateXChange(String name) {
-        return xchanges.computeIfAbsent(name, xc -> {
-            Class<? extends Exchange> exchangeClass = 
XChangeHelper.loadXChangeClass(getCamelContext(), name);
-            Assert.notNull(exchangeClass, "XChange not supported: " + name);
-            return new XChange(createExchange(exchangeClass));
-        });
+    /**
+     * Creates the exchange with the default specification of its XChange 
module and the given API keys, which are only
+     * set when not null.
+     */
+    protected Exchange createExchange(Class<? extends Exchange> exchangeClass, 
String apiKey, String secretKey) {
+        return ExchangeFactory.INSTANCE.createExchange(exchangeClass, apiKey, 
secretKey);
+    }
+
+    private XChange getOrCreateXChange(String name, String apiKey, String 
secretKey) {
+        if (apiKey == null && secretKey == null) {
+            return xchanges.computeIfAbsent(name, xc -> new 
XChange(createExchange(loadExchangeClass(name))));
+        }
+        return xchangesWithKeys.computeIfAbsent(new Credentials(name, apiKey, 
secretKey),
+                c -> new XChange(createExchange(loadExchangeClass(name), 
apiKey, secretKey)));
+    }
+
+    private Class<? extends Exchange> loadExchangeClass(String name) {
+        Class<? extends Exchange> exchangeClass = 
XChangeHelper.loadXChangeClass(getCamelContext(), name);
+        Assert.notNull(exchangeClass, "XChange not supported: " + name);
+        return exchangeClass;
+    }
+
+    private record Credentials(String name, String apiKey, String secretKey) {
+        @Override
+        public String toString() {
+            // never show the keys
+            return name;
+        }
     }
 
 }
diff --git 
a/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeConfiguration.java
 
b/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeConfiguration.java
index c4da0e06f86c..6280c4b4344c 100644
--- 
a/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeConfiguration.java
+++ 
b/components/camel-xchange/src/main/java/org/apache/camel/component/xchange/XChangeConfiguration.java
@@ -91,8 +91,19 @@ public class XChangeConfiguration {
                             + " endpoint.")
     private Currency currency;
     @UriParam(description = "The currency pair, such as BTC/USDT, for the 
ticker and currencyPairMetaData methods when"
-                            + " neither the CurrencyPair header nor the 
message body gives one.")
+                            + " neither the CurrencyPair header nor the 
message body gives one. A currency that XChange does"
+                            + " not know fails the creation of the endpoint.")
     private String currencyPair;
+    @UriParam(label = "security", security = "secret",
+              description = "The API key of the account at the exchange, for 
the account service. If not set, the exchange"
+                            + " module of XChange decides, for example the one 
of Binance reads it from the file"
+                            + " binance-secret.keys.")
+    private String apiKey;
+    @UriParam(label = "security", security = "secret",
+              description = "The secret key of the account at the exchange, 
for the account service. If not set, the"
+                            + " exchange module of XChange decides, for 
example the one of Binance reads it from the file"
+                            + " binance-secret.keys.")
+    private String secretKey;
 
     public String getName() {
         return name;
@@ -126,13 +137,25 @@ public class XChangeConfiguration {
         this.currency = currency;
     }
 
+    /**
+     * Sets the currency from its code, or null if XChange does not know the 
currency.
+     *
+     * @deprecated Camel does not call this method, the currency option is 
converted with
+     *             {@link XChangeConverters#toCurrency(String)}, which fails 
for an unknown currency.
+     */
+    @Deprecated(since = "4.24.0")
     public void setCurrency(String curr) {
         this.currency = Currency.getInstanceNoCreate(curr);
     }
 
+    /**
+     * The currency pair option as an XChange {@link CurrencyPair}, or null if 
the option is not set.
+     *
+     * @throws IllegalArgumentException if a currency of the pair is not known 
to XChange
+     */
     public CurrencyPair getAsCurrencyPair() {
         if (currencyPair != null) {
-            return new CurrencyPair(currencyPair);
+            return XChangeConverters.toCurrencyPair(currencyPair);
         }
         return null;
     }
@@ -145,4 +168,19 @@ public class XChangeConfiguration {
         this.currencyPair = currencyPair;
     }
 
+    public String getApiKey() {
+        return apiKey;
+    }
+
+    public void setApiKey(String apiKey) {
+        this.apiKey = apiKey;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
+    }
 }
diff --git 
a/components/camel-xchange/src/test/java/org/apache/camel/component/xchange/XChangeApiKeysCurrencyPairTest.java
 
b/components/camel-xchange/src/test/java/org/apache/camel/component/xchange/XChangeApiKeysCurrencyPairTest.java
new file mode 100644
index 000000000000..419dc7249da6
--- /dev/null
+++ 
b/components/camel-xchange/src/test/java/org/apache/camel/component/xchange/XChangeApiKeysCurrencyPairTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.xchange;
+
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.knowm.xchange.ExchangeSpecification;
+import org.knowm.xchange.camelkeys.CamelkeysExchange;
+import org.knowm.xchange.currency.Currency;
+import org.knowm.xchange.currency.CurrencyPair;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The apiKey and secretKey options reach the specification of the exchange, 
and the currencyPair option is checked when
+ * the endpoint is created. The exchange is the camelkeys module of the tests, 
which makes no remote call.
+ */
+public class XChangeApiKeysCurrencyPairTest extends CamelTestSupport {
+
+    private static final String TICKER = 
"xchange:camelkeys?service=marketdata&method=ticker";
+    private static final String BALANCES = 
"xchange:camelkeys?service=account&method=balances";
+
+    @Test
+    void theApiKeysAreSetOnTheExchangeSpecification() {
+        ExchangeSpecification specification = specification(BALANCES + 
"&apiKey=key-1&secretKey=secret-1");
+
+        assertEquals("key-1", specification.getApiKey());
+        assertEquals("secret-1", specification.getSecretKey());
+    }
+
+    @Test
+    void endpointsWithOtherKeysGetAnExchangeOfTheirOwn() {
+        XChange first = xchange(BALANCES + "&apiKey=key-1&secretKey=secret-1");
+        XChange same = xchange(TICKER + 
"&apiKey=key-1&secretKey=secret-1&currencyPair=BTC/USDT");
+        XChange other = xchange(BALANCES + "&apiKey=key-2&secretKey=secret-2");
+        XChange withoutKeys = xchange(BALANCES);
+
+        assertSame(first, same);
+        assertNotSame(first, other);
+        assertNotSame(first, withoutKeys);
+        assertEquals("key-2", other.getExchangeSpecification().getApiKey());
+        assertNull(withoutKeys.getExchangeSpecification().getApiKey());
+        assertSame(withoutKeys, context.getComponent("xchange", 
XChangeComponent.class).getXChange("camelkeys"));
+    }
+
+    @Test
+    void aCurrencyPairWithAnUnknownCurrencyFailsTheEndpoint() {
+        Exception e = assertThrows(ResolveEndpointFailedException.class,
+                () -> context.getEndpoint(TICKER + "&currencyPair=BTC/QQZZ"));
+
+        assertInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertTrue(e.getCause().getMessage().contains("QQZZ"), 
e.getCause().getMessage());
+        assertNull(Currency.getInstanceNoCreate("QQZZ"), "the unknown currency 
is not registered in XChange");
+    }
+
+    @Test
+    void aCurrencyPairWithACurrencyOfTheExchangeIsAccepted() {
+        XChangeEndpoint endpoint
+                = context.getEndpoint(TICKER + "&currencyPair=btc/" + 
CamelkeysExchange.CURRENCY, XChangeEndpoint.class);
+
+        assertEquals(new CurrencyPair(Currency.BTC, 
Currency.getInstance(CamelkeysExchange.CURRENCY)),
+                endpoint.getConfiguration().getAsCurrencyPair());
+    }
+
+    private XChange xchange(String uri) {
+        return context.getEndpoint(uri, XChangeEndpoint.class).getXchange();
+    }
+
+    private ExchangeSpecification specification(String uri) {
+        return xchange(uri).getExchangeSpecification();
+    }
+}
diff --git 
a/components/camel-xchange/src/test/java/org/knowm/xchange/camelkeys/CamelkeysExchange.java
 
b/components/camel-xchange/src/test/java/org/knowm/xchange/camelkeys/CamelkeysExchange.java
new file mode 100644
index 000000000000..06f9dc5a99a0
--- /dev/null
+++ 
b/components/camel-xchange/src/test/java/org/knowm/xchange/camelkeys/CamelkeysExchange.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.knowm.xchange.camelkeys;
+
+import java.util.List;
+
+import org.knowm.xchange.Exchange;
+import org.knowm.xchange.ExchangeSpecification;
+import org.knowm.xchange.currency.Currency;
+import org.knowm.xchange.dto.meta.ExchangeMetaData;
+import org.knowm.xchange.instrument.Instrument;
+import org.knowm.xchange.service.account.AccountService;
+import org.knowm.xchange.service.marketdata.MarketDataService;
+import org.knowm.xchange.service.trade.TradeService;
+import si.mazi.rescu.SynchronizedValueFactory;
+
+/**
+ * An exchange module for the tests, found by camel-xchange for the name 
camelkeys as XChange modules are. It keeps the
+ * specification it is given, makes no remote call, and registers the currency 
CMLK when it is created, as an exchange
+ * module registers the currencies that it trades.
+ */
+public class CamelkeysExchange implements Exchange {
+
+    public static final String CURRENCY = "CMLK";
+
+    private ExchangeSpecification specification;
+
+    @Override
+    public ExchangeSpecification getDefaultExchangeSpecification() {
+        ExchangeSpecification answer = new ExchangeSpecification(getClass());
+        answer.setExchangeName("camelkeys");
+        answer.setShouldLoadRemoteMetaData(false);
+        return answer;
+    }
+
+    @Override
+    public void applySpecification(ExchangeSpecification specification) {
+        this.specification = specification;
+        Currency.getInstance(CURRENCY);
+    }
+
+    @Override
+    public ExchangeSpecification getExchangeSpecification() {
+        return specification;
+    }
+
+    @Override
+    public ExchangeMetaData getExchangeMetaData() {
+        return null;
+    }
+
+    @Override
+    public List<Instrument> getExchangeInstruments() {
+        return List.of();
+    }
+
+    @Override
+    public SynchronizedValueFactory<Long> getNonceFactory() {
+        return null;
+    }
+
+    @Override
+    public MarketDataService getMarketDataService() {
+        return null;
+    }
+
+    @Override
+    public TradeService getTradeService() {
+        return null;
+    }
+
+    @Override
+    public AccountService getAccountService() {
+        return null;
+    }
+
+    @Override
+    public void remoteInit() {
+        // no remote call
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 103ec6885c40..be5ab321caf4 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -3692,6 +3692,17 @@ another service, such as 
`service=marketdata&method=currencies`. Before, its pro
 unchanged. The `Currency` and `CurrencyPair` headers and the body can now be 
text such as `BTC` and `BTC/USDT`; text
 with a currency that XChange does not know fails the exchange.
 
+=== camel-xchange - the currencyPair option is checked when the endpoint is 
created, and apiKey and secretKey options
+
+A `currencyPair` option with a currency that XChange does not know, such as 
`BTC/USTD`, now fails the creation of the
+endpoint, in the same way as the `currency` option. Before, the pair was 
parsed for each message, which registered the
+unknown currency in XChange and sent the request to the exchange. The check 
runs after the exchange is created, so
+the currencies that the exchange module registers are accepted.
+
+The new `apiKey` and `secretKey` options set the API keys of the account on 
the exchange, for example from property
+placeholders or a vault. Without them the exchange module decides, as before. 
The deprecated
+`XChangeConfiguration.setCurrency(String)` is not called by Camel and sets 
null for an unknown currency.
+
 === camel-gson, camel-jsonb - the unmarshal type header needs 
allowUnmarshallType
 
 The Gson and JSON-B data formats now use the `CamelGsonUnmarshalType` and 
`CamelJsonbUnmarshallType` headers to choose
diff --git 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/XChangeEndpointBuilderFactory.java
 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/XChangeEndpointBuilderFactory.java
index aef26304b371..aa030dc886cd 100644
--- 
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/XChangeEndpointBuilderFactory.java
+++ 
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/XChangeEndpointBuilderFactory.java
@@ -84,7 +84,8 @@ public interface XChangeEndpointBuilderFactory {
         /**
          * The currency pair, such as BTC/USDT, for the ticker and
          * currencyPairMetaData methods when neither the CurrencyPair header 
nor
-         * the message body gives one.
+         * the message body gives one. A currency that XChange does not know
+         * fails the creation of the endpoint.
          * 
          * The option is a: <code>java.lang.String</code> type.
          * 
@@ -169,6 +170,39 @@ public interface XChangeEndpointBuilderFactory {
             doSetProperty("service", service);
             return this;
         }
+        /**
+         * The API key of the account at the exchange, for the account service.
+         * If not set, the exchange module of XChange decides, for example the
+         * one of Binance reads it from the file binance-secret.keys.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         * 
+         * @param apiKey the value to set
+         * @return the dsl builder
+         */
+        default XChangeEndpointBuilder apiKey(String apiKey) {
+            doSetProperty("apiKey", apiKey);
+            return this;
+        }
+        /**
+         * The secret key of the account at the exchange, for the account
+         * service. If not set, the exchange module of XChange decides, for
+         * example the one of Binance reads it from the file
+         * binance-secret.keys.
+         * 
+         * The option is a: <code>java.lang.String</code> type.
+         * 
+         * Group: security
+         * 
+         * @param secretKey the value to set
+         * @return the dsl builder
+         */
+        default XChangeEndpointBuilder secretKey(String secretKey) {
+            doSetProperty("secretKey", secretKey);
+            return this;
+        }
     }
 
     /**

Reply via email to