Create a Credential
Store your exchange API keys securely in Cadenza. Once created, the credential can be used to connect one or more trading accounts.
Before You Begin
- Generate API keys on your exchange (see Supported Venues for setup instructions)
- Note the required fields for your exchange
- Ensure API keys have appropriate permissions (trade, read balances)
Create Credential
- Python
- TypeScript
- Go
response = credential_api.create_trading_account_credential(
cadenza_client.CreateTradingAccountCredentialRequest(
venue=cadenza_client.Venue.BINANCE,
credential_type=cadenza_client.CredentialType.EXCHANGE,
api_key="your-api-key",
api_secret="your-api-secret",
nickname="My Binance API" # optional
)
)
credential = response.data
print(f"Credential ID: {credential.credential_id}")
print(f"Status: {credential.status}") # PENDING
const response = await credentialApi.createTradingAccountCredential({
venue: 'BINANCE',
credentialType: 'EXCHANGE',
apiKey: 'your-api-key',
apiSecret: 'your-api-secret',
nickname: 'My Binance API', // optional
})
const credential = response.data.data
console.log('Credential ID:', credential.credentialId)
console.log('Status:', credential.status) // PENDING
response, _, err := apiClient.TradingAccountCredentialAPI.CreateTradingAccountCredential(ctx).
CreateTradingAccountCredentialRequest(client.CreateTradingAccountCredentialRequest{
Venue: client.VENUE_BINANCE,
CredentialType: client.CREDENTIALTYPE_EXCHANGE,
ApiKey: client.PtrString("your-api-key"),
ApiSecret: client.PtrString("your-api-secret"),
Nickname: client.PtrString("My Binance API"),
}).Execute()
if err != nil {
panic(err)
}
credential := response.Data
fmt.Printf("Credential ID: %s\n", *credential.CredentialId)
fmt.Printf("Status: %s\n", *credential.Status) // PENDING
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
venue | Venue | Yes | Exchange venue (BINANCE, OKX, BYBIT, etc.) |
credentialType | CredentialType | Yes | Type of credential (EXCHANGE, BROKER) |
apiKey | string | Yes | API key from your exchange |
apiSecret | string | Yes | API secret from your exchange |
apiPassphrase | string | Conditional | Required for OKX and some other exchanges |
nickname | string | No | Display name for the credential |
Response
The response contains the created Credential object:
{
"data": {
"credentialId": "550e8400-e29b-41d4-a716-446655440000",
"venue": "BINANCE",
"credentialType": "EXCHANGE",
"nickname": "My Binance API",
"status": "PENDING",
"identities": [],
"createdAt": 1704067200000,
"updatedAt": 1704067200000
},
"success": true,
"errno": 0,
"error": null
}
Exchange-Specific Examples
Binance
- Python
- TypeScript
- Go
response = credential_api.create_trading_account_credential(
cadenza_client.CreateTradingAccountCredentialRequest(
venue=cadenza_client.Venue.BINANCE,
credential_type=cadenza_client.CredentialType.EXCHANGE,
api_key="your-binance-api-key",
api_secret="your-binance-api-secret"
)
)
const response = await credentialApi.createTradingAccountCredential({
venue: 'BINANCE',
credentialType: 'EXCHANGE',
apiKey: 'your-binance-api-key',
apiSecret: 'your-binance-api-secret',
})
response, _, err := apiClient.TradingAccountCredentialAPI.CreateTradingAccountCredential(ctx).
CreateTradingAccountCredentialRequest(client.CreateTradingAccountCredentialRequest{
Venue: client.VENUE_BINANCE,
CredentialType: client.CREDENTIALTYPE_EXCHANGE,
ApiKey: client.PtrString("your-binance-api-key"),
ApiSecret: client.PtrString("your-binance-api-secret"),
}).Execute()
OKX (with passphrase)
- Python
- TypeScript
- Go
response = credential_api.create_trading_account_credential(
cadenza_client.CreateTradingAccountCredentialRequest(
venue=cadenza_client.Venue.OKX,
credential_type=cadenza_client.CredentialType.EXCHANGE,
api_key="your-okx-api-key",
api_secret="your-okx-api-secret",
api_passphrase="your-okx-passphrase" # Required for OKX
)
)
const response = await credentialApi.createTradingAccountCredential({
venue: 'OKX',
credentialType: 'EXCHANGE',
apiKey: 'your-okx-api-key',
apiSecret: 'your-okx-api-secret',
apiPassphrase: 'your-okx-passphrase', // Required for OKX
})
response, _, err := apiClient.TradingAccountCredentialAPI.CreateTradingAccountCredential(ctx).
CreateTradingAccountCredentialRequest(client.CreateTradingAccountCredentialRequest{
Venue: client.VENUE_OKX,
CredentialType: client.CREDENTIALTYPE_EXCHANGE,
ApiKey: client.PtrString("your-okx-api-key"),
ApiSecret: client.PtrString("your-okx-api-secret"),
ApiPassphrase: client.PtrString("your-okx-passphrase"),
}).Execute()
Error Handling
| Error Code | Description |
|---|---|
400 | Invalid request parameters |
401 | Authentication required |
409 | Credential with same API key already exists |
422 | Invalid API key format |
- Python
- TypeScript
- Go
from cadenza_client.rest import ApiException
try:
response = credential_api.create_trading_account_credential(request)
except ApiException as e:
print(f"Error {e.status}: {e.body}")
try {
const response = await credentialApi.createTradingAccountCredential(request)
} catch (error) {
if (error.response) {
console.error('Error:', error.response.status, error.response.data)
}
}
response, httpResponse, err := apiClient.TradingAccountCredentialAPI.CreateTradingAccountCredential(ctx).
CreateTradingAccountCredentialRequest(request).Execute()
if err != nil {
fmt.Printf("Error: %v\n", err)
if httpResponse != nil {
fmt.Printf("Status: %d\n", httpResponse.StatusCode)
}
}
Next Steps
After creating a credential, you should verify it to:
- Confirm the API keys are valid
- Discover available trading accounts on the exchange
Related
- Supported Venues - Exchange-specific setup instructions
- Verify a Credential - Test and discover available accounts