Cross-Chain Access SDK — API Reference

Full technical reference for all classes, methods, models, and exceptions in the Cross-Chain Access SDK.

→ User Guide


CrossChainAccessClient

Location: swarm/cross_chain_access_sdk/sdk/client.py

Main entry point. Orchestrates authentication, market validation, on-chain USDC transfers, and order submission.

Constructor

CrossChainAccessClient(
    network: Network,
    private_key: str,
    user_email: Optional[str] = None,
    rpc_url: Optional[str] = None,
    is_dev: bool = False,
)

ParameterTypeRequiredDescription
networkNetworkBlockchain network
private_keystrKYC-verified wallet private key
user_emailstrEmail for trade notifications
rpc_urlstrCustom RPC endpoint
is_devboolUse development endpoints (default: False)

Attributes: networkis_devcross_chain_access_api (CrossChainAccessAPIClient), web3_helper (Web3Helper), auth (SwarmAuth), usdc_addresstopup_address

Raises: ValueError if USDC is not available on the specified network.


authenticate()

async def authenticate() -> None

Signs an EIP-191 authentication message with the wallet and obtains an access token. Called automatically when using async with.

Raises: AuthenticationError


check_trading_availability()

async def check_trading_availability() -> tuple[bool, str]

Validates all prerequisites for trading.

Returns: (is_available: bool, message: str)

Checks performed (in order):

  1. Market hours (14:30–21:00 UTC, Monday–Friday)
  2. Account not blocked
  3. Trading not suspended
  4. Transfers not restricted
  5. Market is open

Possible messages:

MessageMeaning
"Trading is available"All checks passed
"Market is closed. Opens in Xh Ym"Outside market hours
"Trading not available: account blocked"Account restriction
"Trading not available: trading blocked, transfers blocked"Multiple restrictions

get_quote()

async def get_quote(rwa_symbol: str) -> Quote

ParameterTypeRequiredDescription
rwa_symbolstrTrading symbol (e.g. "AAPL")

Returns: Quote

  • rate: ask price (for buys) or bid price (for sells)
  • source"cross_chain_access"
  • timestamp: current time

Raises: QuoteUnavailableExceptionInvalidSymbolException


buy()

async def buy(
    rwa_token_address: str,
    rwa_symbol: str,
    user_email: str,
    rwa_amount: Optional[Decimal] = None,
    usdc_amount: Optional[Decimal] = None,
    target_chain_id: Optional[int] = None,
) -> TradeResult

ParameterTypeRequiredDescription
rwa_token_addressstrRWA token contract address
rwa_symbolstrTrading symbol (e.g. "AAPL")
user_emailstrEmail for trade confirmation
rwa_amountDecimal⚠️Shares to buy (provide this or usdc_amount)
usdc_amountDecimal⚠️USDC to spend (provide this or rwa_amount)
target_chain_idintNetwork ID where assets will be delivered (any EVM chain)

Trade flow:

  1. Validate market hours and account status
  2. Fetch real-time quote
  3. Calculate amounts with 1% slippage protection
  4. Validate buying power
  5. Transfer USDC to escrow on-chain
  6. Submit order to Cross-Chain Access API
  7. Send email confirmation

Returns: TradeResult

Raises: ValueErrorMarketClosedExceptionAccountBlockedExceptionInsufficientFundsExceptionQuoteUnavailableExceptionOrderFailedException


sell()

async def sell(
    rwa_token_address: str,
    rwa_symbol: str,
    user_email: str,
    rwa_amount: Optional[Decimal] = None,
    usdc_amount: Optional[Decimal] = None,
    target_chain_id: Optional[int] = None,
) -> TradeResult

Parameters identical to buy(). Provide either rwa_amount (shares to sell) or usdc_amount (target USDC to receive).

Trade flow:

  1. Validate market hours and account status
  2. Fetch real-time quote
  3. Calculate amounts with 1% slippage protection
  4. Validate RWA token balance
  5. Transfer RWA tokens to escrow on-chain
  6. Submit order to Cross-Chain Access API
  7. Send email confirmation

Returns: TradeResult


close()

async def close() -> None

Closes HTTP clients. Called automatically with async with.


CrossChainAccessAPIClient

Location: swarm/cross_chain_access_sdk/cross_chain_access/client.py

HTTP client for the Cross-Chain Access API. Accessible via client.cross_chain_access_api.

get_account_status()

async def get_account_status() -> AccountStatus

Returns the account's current trading permissions and restrictions.


get_account_funds()

async def get_account_funds() -> AccountFunds

Returns buying power and cash balances.


get_asset_quote()

async def get_asset_quote(symbol: str) -> CrossChainAccessQuote

Fetches the raw bid/ask quote from the stock exchange for symbol.


create_order()

async def create_order(
    symbol: str,
    side: OrderSide,
    quantity: Decimal,
    notional: Optional[Decimal],
    rwa_token_address: str,
    user_email: str,
    target_chain_id: Optional[int],
) -> CrossChainAccessOrderResponse

Submits a buy or sell order to the Cross-Chain Access API.


MarketHours

Location: swarm/cross_chain_access_sdk/market_hours/market_hours.py

Utility class for US stock market timing.

Market schedule

  • Open: 14:30 UTC (9:30 AM EST)
  • Close: 21:00 UTC (4:00 PM EST)
  • Days: Monday–Friday
  • Closed: weekends and US market holidays

is_market_open()

@staticmethod
def is_market_open() -> bool

Returns True if the market is currently open.


time_until_open()

@staticmethod
def time_until_open() -> timedelta

Returns the time remaining until the next market open.


time_until_close()

@staticmethod
def time_until_close() -> timedelta

Returns the time remaining until market close (only meaningful when market is open).


get_market_status()

@staticmethod
def get_market_status() -> tuple[bool, str]

Returns (is_open: bool, human_readable_message: str). Message examples:

  • "Market is open. Closes in 3h 15m"
  • "Market is closed. Opens in 8h 30m"

Data models

Quote

Shared with the Trading SDK. See Trading SDK API Reference — Data Models.

For Cross-Chain Access quotes: source = "cross_chain_access"rate = ask price for buys, bid price for sells.


TradeResult

Shared with the Trading SDK. See Trading SDK API Reference — Data Models.

For Cross-Chain Access results: source = "cross_chain_access".


OrderSide

class OrderSide(str, Enum):
    BUY = "buy"
    SELL = "sell"


AccountStatus

Location: swarm/cross_chain_access_sdk/cross_chain_access/models.py

FieldTypeDescription
account_blockedboolAccount is blocked
trading_blockedboolTrading is blocked
transfers_blockedboolTransfers are blocked
trade_suspended_by_userboolUser has suspended their own trading
market_openboolMarket is currently open
account_statusstrStatus string (e.g. "ACTIVE")

Methods: is_trading_allowed() -> bool — returns True only if all restrictions are clear.


AccountFunds

Location: swarm/cross_chain_access_sdk/cross_chain_access/models.py

FieldTypeDescription
cashDecimalAvailable cash
buying_powerDecimalTotal buying power
day_trading_buying_powerDecimalDay trading buying power
effective_buying_powerDecimalEffective buying power
non_margin_buying_powerDecimalNon-margin buying power
reg_t_buying_powerDecimalRegulation T buying power

Methods: has_sufficient_funds(required_amount: Decimal) -> bool


CrossChainAccessQuote

Raw quote from the stock exchange.

FieldTypeDescription
bid_priceDecimalBest bid price
ask_priceDecimalBest ask price
bid_sizeDecimalSize at bid
ask_sizeDecimalSize at ask
timestampdatetimeQuote timestamp
bid_exchangestrExchange providing bid
ask_exchangestrExchange providing ask

Methods: get_price_for_side(side: OrderSide) -> Decimal — returns ask for BUY, bid for SELL.


CrossChainAccessOrderResponse

FieldTypeDescription
order_idstrUnique order identifier
symbolstrTrading symbol
sidestr"buy" or "sell"
quantityDecimalOrder quantity
filled_qtyDecimalFilled quantity
statusstrOrder status
created_atdatetimeCreation timestamp
filled_atdatetime | NoneFill timestamp

Methods: to_dict() -> dict


Exceptions

Exception hierarchy

CrossChainAccessException (base)
├── MarketClosedException
├── AccountBlockedException
├── InsufficientFundsException
├── QuoteUnavailableException
├── OrderFailedException
└── InvalidSymbolException

ExceptionLocationWhen it occurs
CrossChainAccessExceptioncross_chain_access/exceptions.pyBase for all errors
MarketClosedExceptionTrade attempted outside market hours
AccountBlockedExceptionAccount blocked, trading/transfers suspended
InsufficientFundsExceptionInsufficient USDC (buy) or RWA tokens (sell)
QuoteUnavailableExceptionReal-time quote cannot be retrieved
OrderFailedExceptionOrder submission rejected by API
InvalidSymbolExceptionStock symbol not recognised

Supported networks

NetworkChain IDSource networkDelivery via target_chain_id
Polygon137
Ethereum1
BSC56
Base8453
Any other EVM

USDC addresses are automatically configured per source network. The target_chain_id for delivery can be any EVM-compatible network.


Rate limits & performance

  • Quote latency: near real-time via API
  • Order processing: near real-time (settlement depends on blockchain confirmation time)
  • Retry logic: 3 attempts, exponential backoff — 1s, 2s, 4s
    • Retried: network timeouts, 5xx errors, 429 rate limits
    • Not retried: 4xx client errors (bad parameters, auth failures)