AccountStreamItem

public final class AccountStreamItem : Sendable

Streams account data from the Horizon API using Server-Sent Events (SSE) for real-time updates.

This stream provides live updates for a single account, delivering changes as they occur on the Stellar network. Each update contains the complete current state of the account including balances, signers, thresholds, and other account properties.

Example usage:

let sdk = StellarSDK()
let accountStream = sdk.accounts.streamAccount(accountId: "GACCOUNT...")

accountStream.onReceive { response in
    switch response {
    case .open:
        print("Stream connection established")
    case .response(id: let id, data: let account):
        print("Account update received - Sequence: \(account.sequenceNumber)")
        for balance in account.balances {
            print("\(balance.assetCode ?? "XLM"): \(balance.balance)")
        }
    case .error(let error):
        print("Stream error: \(error)")
    }
}

// Close stream when done
accountStream.closeStream()

See also:

  • Creates a new account stream for the specified Horizon API endpoint.

    Declaration

    Swift

    public init(requestUrl: String)

    Parameters

    requestUrl

    The complete Horizon API URL for streaming the account

  • Establishes the SSE connection and delivers account responses as they arrive from Horizon.

    The response closure is called multiple times:

    • Once with .open when the connection is established
    • Each time with .response when an account update is received
    • With .error if any error occurs during streaming

    Declaration

    Swift

    public func onReceive(response: @escaping StreamResponseEnum<AccountResponse>.ResponseClosure)

    Parameters

    response

    Closure called with stream events. Called on a background thread.

  • Closes the event stream and releases resources.

    Call this method when you no longer need to receive updates for the account. After closing, the stream cannot be reopened - create a new AccountStreamItem instead.

    Declaration

    Swift

    public func closeStream()