Skip to main content

Quick Start

This guide walks you through the complete journey from installation to executing your first trade on Cadenza.

Prerequisites

  • A Cadenza account (email/password)
  • Exchange API credentials (see Supported Venues for setup instructions)

Language requirements:

  • Python: Python 3.9+
  • TypeScript: Node.js 18+
  • Go: Go 1.21+

1. Installation

pip install git+https://github.com/cyberapper/cadenza-client-python.git

2. Environment Configuration

EnvironmentHTTP APIWebSocket
Productionhttps://cadenza-api.algo724.comwss://cadenza-ws.algo724.com
UAThttps://cadenza-api-uat.algo724.comwss://cadenza-ws-uat.algo724.com
# Production Environment
BASE_URL = "https://cadenza-api.algo724.com"
WS_URL = "wss://cadenza-ws.algo724.com/connection/websocket"

# UAT Environment
# BASE_URL = "https://cadenza-api-uat.algo724.com"
# WS_URL = "wss://cadenza-ws-uat.algo724.com/connection/websocket"

3. Authentication

Log in with your Cadenza account to get an access token:

import cadenza_client

# Create configuration
configuration = cadenza_client.Configuration(host=BASE_URL)

# Login to get access token
with cadenza_client.ApiClient(configuration) as api_client:
auth_api = cadenza_client.AuthenticationApi(api_client)

response = auth_api.auth_login(
cadenza_client.AuthLoginRequest(
email="your@email.com",
password="your-password"
)
)

session = response.data
access_token = session.access_token
print(f"Logged in, expires at: {session.expires_at}")

4. Create API Client

Configure the API client with your access token:

# Configure with access token
configuration = cadenza_client.Configuration(
host=BASE_URL,
access_token=access_token
)

# Create API client and instances
api_client = cadenza_client.ApiClient(configuration)
market_api = cadenza_client.MarketApi(api_client)
trade_order_api = cadenza_client.TradeOrderApi(api_client)
trading_account_api = cadenza_client.TradingAccountApi(api_client)
credential_api = cadenza_client.TradingAccountCredentialApi(api_client)
portfolio_api = cadenza_client.TradingAccountPortfolioApi(api_client)

5. Check Available Venues

Verify which exchanges are available:

response = market_api.list_market_venues()
venues = response.data

print("Available venues:")
for venue in venues:
print(f" - {venue.venue}")

6. Add Credential

Store your exchange API keys securely. See Supported Venues for exchange-specific setup instructions.

# Create credential with your exchange API keys
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",
# api_passphrase="your-passphrase" # Required for OKX
nickname="My Binance API"
)
)

credential = response.data
credential_id = credential.credential_id
print(f"Credential created: {credential_id}")
print(f"Status: {credential.status}") # PENDING

Verify Credential

Verify your API keys and discover available trading accounts:

response = credential_api.verify_trading_account_credential(
cadenza_client.VerifyTradingAccountCredentialRequest(
credential_id=credential_id
)
)

credential = response.data
print(f"Status: {credential.status}") # VERIFIED

# Available trading accounts on this exchange
print(f"Available accounts: {credential.identities}")
# Example: ['spot', 'margin', 'futures']

7. Connect Trading Account

Connect an exchange account using your verified credential:

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

account = response.data
trading_account_id = account.trading_account_id
print(f"Connected: {trading_account_id}")
print(f"Venue: {account.venue}")
print(f"Status: {account.status}") # CONNECTED

8. Check Portfolio

View your account balances:

response = portfolio_api.list_trading_account_portfolios(
trading_account_id=trading_account_id
)

for portfolio in response.data:
print(f"Account: {portfolio.trading_account_id}")
print("Balances:")
for balance in portfolio.balances:
if float(balance.total) > 0:
print(f" {balance.asset}: {balance.total} (free: {balance.free}, locked: {balance.locked})")

9. Get Market Data

Check the order book before trading:

response = market_api.get_market_order_book(
venue=cadenza_client.Venue.BINANCE,
symbol="BTC/USDT"
)
order_book = response.data

print(f"Best bid: {order_book.bids[0]}") # [price, quantity]
print(f"Best ask: {order_book.asks[0]}") # [price, quantity]

10. Connect WebSocket for Real-time Updates

Connect to WebSocket and subscribe for order and portfolio updates:

import asyncio
from cadenza_client.ws import Client

# Create and connect WebSocket client
ws_client = Client(WS_URL, token=access_token)
await ws_client.connect()
print("WebSocket connected")

# Subscribe to trading account updates
sub = ws_client.new_subscription(f"tradingAccount:{trading_account_id}")

def on_publication(ctx):
data = ctx.data
event_type = data.get("type")

if event_type == "tradeOrderUpdatedEvent":
order = data["data"]
print(f"[Order Update] {order['tradeOrderId']}: {order['status']}")
if order.get("executedPrice"):
print(f" Executed at: {order['executedPrice']}")
if order.get("executedQuantity"):
print(f" Quantity: {order['executedQuantity']}")

elif event_type == "portfolioUpdatedEvent":
portfolio = data["data"]
print("[Portfolio Update]")
for balance in portfolio.get("balances", []):
if float(balance.get("total", 0)) > 0:
print(f" {balance['asset']}: {balance['total']}")

sub.on_publication(on_publication)
await sub.subscribe()
print("Subscribed to real-time updates")

11. Submit Market Order

Execute your first trade with a market order:

response = trade_order_api.submit_trade_order(
cadenza_client.SubmitTradeOrderRequest(
trading_account_id=trading_account_id,
instrument_id="BINANCE:BTC/USDT",
order_side=cadenza_client.OrderSide.BUY,
order_type=cadenza_client.OrderType.MARKET,
quantity="0.001"
)
)

order = response.data
print(f"Order submitted: {order.trade_order_id}")
print(f"Status: {order.status}")

# Real-time updates will print automatically via WebSocket:
# [Order Update] xxx: FILLED
# Executed at: 50123.45
# Quantity: 0.001
# [Portfolio Update]
# BTC: 0.501
# USDT: 9949.87

After submitting, you'll receive real-time updates through the WebSocket subscription:

  1. tradeOrderUpdatedEvent - Order status changes (PENDING → FILLED) with execution details
  2. portfolioUpdatedEvent - Balance updates reflecting the trade

Limit Order

For more control over execution price:

response = trade_order_api.submit_trade_order(
cadenza_client.SubmitTradeOrderRequest(
trading_account_id=trading_account_id,
instrument_id="BINANCE:BTC/USDT",
order_side=cadenza_client.OrderSide.BUY,
order_type=cadenza_client.OrderType.LIMIT,
quantity="0.001",
limit_price="50000.00"
)
)

order = response.data
print(f"Limit order placed: {order.trade_order_id}")

Complete Example

Here's the full workflow with real-time updates:

import asyncio
import cadenza_client
from cadenza_client.ws import Client

BASE_URL = "https://cadenza-api.algo724.com"
WS_URL = "wss://cadenza-ws.algo724.com/connection/websocket"

async def main():
# 1. Authenticate
configuration = cadenza_client.Configuration(host=BASE_URL)
with cadenza_client.ApiClient(configuration) as api_client:
auth_api = cadenza_client.AuthenticationApi(api_client)
response = auth_api.auth_login(
cadenza_client.AuthLoginRequest(
email="your@email.com",
password="your-password"
)
)
access_token = response.data.access_token
print("Authenticated")

# 2. Create API clients
configuration = cadenza_client.Configuration(host=BASE_URL, access_token=access_token)
api_client = cadenza_client.ApiClient(configuration)
credential_api = cadenza_client.TradingAccountCredentialApi(api_client)
trading_account_api = cadenza_client.TradingAccountApi(api_client)
portfolio_api = cadenza_client.TradingAccountPortfolioApi(api_client)
trade_order_api = cadenza_client.TradeOrderApi(api_client)

# 3. Create and verify credential
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 = response.data.credential_id

response = credential_api.verify_trading_account_credential(
cadenza_client.VerifyTradingAccountCredentialRequest(credential_id=credential_id)
)
print(f"Available accounts: {response.data.identities}")

# 4. Connect trading account
response = trading_account_api.connect_trading_account(
cadenza_client.ConnectTradingAccountRequest(
credential_ids=[credential_id],
external_trading_account_id="spot"
)
)
trading_account_id = response.data.trading_account_id
print(f"Connected: {trading_account_id}")

# 5. Check portfolio
response = portfolio_api.list_trading_account_portfolios(
trading_account_id=trading_account_id
)
for portfolio in response.data:
for balance in portfolio.balances:
if float(balance.total) > 0:
print(f"{balance.asset}: {balance.total}")

# 6. Connect WebSocket for real-time updates
ws_client = Client(WS_URL, token=access_token)
await ws_client.connect()

sub = ws_client.new_subscription(f"tradingAccount:{trading_account_id}")

def on_publication(ctx):
data = ctx.data
if data.get("type") == "tradeOrderUpdatedEvent":
order = data["data"]
print(f"[Order Update] {order['tradeOrderId']}: {order['status']}")
elif data.get("type") == "portfolioUpdatedEvent":
print("[Portfolio Update] Balances changed")

sub.on_publication(on_publication)
await sub.subscribe()
print("Subscribed to real-time updates")

# 7. Submit market order
response = trade_order_api.submit_trade_order(
cadenza_client.SubmitTradeOrderRequest(
trading_account_id=trading_account_id,
instrument_id="BINANCE:BTC/USDT",
order_side=cadenza_client.OrderSide.BUY,
order_type=cadenza_client.OrderType.MARKET,
quantity="0.001"
)
)
print(f"Order submitted: {response.data.trade_order_id}")

# Wait for real-time updates
await asyncio.sleep(5)
await ws_client.disconnect()

asyncio.run(main())

Next Steps

Learn More

Advanced Topics

Client SDKs

LanguagePackageRepository
Pythoncadenza-clientcadenza-client-python
TypeScriptcadenza-client-typescriptcadenza-client-typescript
Gocadenza-client-gocadenza-client-go

API Documentation