Skip to main content

Connect a Trading Account

Connect an exchange account to Cadenza using a verified credential.

Prerequisites

Before connecting a trading account:

  1. Create a Credential with your exchange API keys
  2. Verify the Credential to get the list of available identities

Connect Trading Account

Use the credential ID and an external trading account ID (from the verification response):

response = trading_account_api.connect_trading_account(
cadenza_client.ConnectTradingAccountRequest(
credential_ids=[credential_id],
external_trading_account_id="spot",
nickname="My Binance Spot" # optional
)
)

account = response.data
trading_account_id = account.trading_account_id
print(f"Connected: {trading_account_id}")
print(f"Venue: {account.venue}")
print(f"Account Type: {account.account_type}")
print(f"Status: {account.status}")

Request Parameters

ParameterTypeRequiredDescription
credentialIdsUUID[]YesList of credential IDs to use
externalTradingAccountIdstringYesAccount identifier from verification (e.g., "spot", "futures")
nicknamestringNoDisplay name for the trading account

Response

The response contains the connected TradingAccount object:

{
"data": {
"tradingAccountId": "660e8400-e29b-41d4-a716-446655440000",
"externalTradingAccountId": "spot",
"venue": "BINANCE",
"nickname": "My Binance Spot",
"accountType": "SPOT",
"externalAccountType": "SPOT",
"credentials": [
{
"credentialId": "550e8400-e29b-41d4-a716-446655440000",
"venue": "BINANCE",
"status": "VERIFIED"
}
],
"status": "CONNECTED",
"createdAt": 1704067200000,
"updatedAt": 1704067200000
},
"success": true,
"errno": 0,
"error": null
}

Common External Trading Account IDs

Binance

IDDescription
spotSpot trading account
marginCross margin account
isolated_marginIsolated margin accounts
futuresUSDT-M Futures
coin_futuresCOIN-M Futures

OKX

IDDescription
tradingUnified trading account
fundingFunding account

Bybit

IDDescription
unifiedUnified Trading Account
spotSpot account
contractDerivatives account

Complete Flow Example

import cadenza_client

# 1. Create credential
create_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"
)
)
credential_id = create_response.data.credential_id

# 2. Verify credential
verify_response = credential_api.verify_trading_account_credential(
cadenza_client.VerifyTradingAccountCredentialRequest(
credential_id=credential_id
)
)

if verify_response.data.status != cadenza_client.CredentialStatus.VERIFIED:
raise Exception("Credential verification failed")

available_accounts = verify_response.data.identities
print(f"Available accounts: {available_accounts}")

# 3. Connect spot trading account
connect_response = trading_account_api.connect_trading_account(
cadenza_client.ConnectTradingAccountRequest(
credential_ids=[credential_id],
external_trading_account_id="spot",
nickname="My Binance Spot"
)
)

trading_account_id = connect_response.data.trading_account_id
print(f"Connected trading account: {trading_account_id}")

# 4. Now you can trade!

Connecting Multiple Account Types

You can connect multiple account types using the same credential:

# Connect spot account
spot_response = trading_account_api.connect_trading_account(
cadenza_client.ConnectTradingAccountRequest(
credential_ids=[credential_id],
external_trading_account_id="spot",
nickname="Binance Spot"
)
)
spot_account_id = spot_response.data.trading_account_id

# Connect futures account
futures_response = trading_account_api.connect_trading_account(
cadenza_client.ConnectTradingAccountRequest(
credential_ids=[credential_id],
external_trading_account_id="futures",
nickname="Binance Futures"
)
)
futures_account_id = futures_response.data.trading_account_id

print(f"Spot Account: {spot_account_id}")
print(f"Futures Account: {futures_account_id}")

Error Handling

Error CodeDescription
400Invalid request parameters
401Authentication required
404Credential not found
409Trading account already connected
422Invalid external trading account ID

Next Steps

After connecting a trading account: