TradeAggregationsService

public class TradeAggregationsService : @unchecked Sendable

Service for querying aggregated trade statistics from the Stellar Horizon API.

Trade aggregations provide OHLCV (Open, High, Low, Close, Volume) candlestick data for asset pairs over specified time intervals. Useful for charts and market analysis.

Example usage:

let sdk = StellarSDK()

// Get hourly trade aggregations for the last 24 hours
let oneDayAgo = Int64(Date().timeIntervalSince1970 * 1000) - (24 * 60 * 60 * 1000)
let now = Int64(Date().timeIntervalSince1970 * 1000)

let response = await sdk.tradeAggregations.getTradeAggregations(
    startTime: oneDayAgo,
    endTime: now,
    resolution: 3600000, // 1 hour in milliseconds
    baseAssetType: AssetTypeAsString.CREDIT_ALPHANUM4,
    baseAssetCode: "USD",
    baseAssetIssuer: "GISSUER...",
    counterAssetType: AssetTypeAsString.NATIVE,
    limit: 24
)

See also:

  • Retrieves aggregated trade statistics for an asset pair over a time interval.

    Returns OHLCV (Open, High, Low, Close, Volume) candlestick data for the specified trading pair.

    See: Stellar developer docs

    Declaration

    Swift

    open func getTradeAggregations(startTime: Int64? = nil, endTime: Int64? = nil, resolution: Int64? = nil, baseAssetType: String? = nil, baseAssetCode: String? = nil, baseAssetIssuer: String? = nil, counterAssetType: String? = nil, counterAssetCode: String? = nil, counterAssetIssuer: String? = nil, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<TradeAggregationResponse>.ResponseEnum

    Parameters

    startTime

    Lower time boundary for the aggregations, in milliseconds since Unix epoch

    endTime

    Upper time boundary for the aggregations, in milliseconds since Unix epoch

    resolution

    The segment duration in milliseconds. Supported values: 1 minute (60000), 5 minutes (300000), 15 minutes (900000), 1 hour (3600000), 1 day (86400000), 1 week (604800000)

    baseAssetType

    Type of the base asset: “native”, “credit_alphanum4”, or “credit_alphanum12”

    baseAssetCode

    Asset code of the base asset (required if not native)

    baseAssetIssuer

    Account ID of the base asset issuer (required if not native)

    counterAssetType

    Type of the counter asset: “native”, “credit_alphanum4”, or “credit_alphanum12”

    counterAssetCode

    Asset code of the counter asset (required if not native)

    counterAssetIssuer

    Account ID of the counter asset issuer (required if not native)

    cursor

    Optional paging token, specifying where to start returning records from

    order

    Optional sort order - .ascending or .descending

    limit

    Optional maximum number of records to return. Default: 10, max: 200

    Return Value

    PageResponse containing trade aggregation records or error

  • Retrieves trade aggregations from a specific Horizon URL.

    Useful for pagination with “next” or “prev” links from a PageResponse.

    Declaration

    Swift

    open func getTradeAggregationsFromUrl(url: String) async -> PageResponse<TradeAggregationResponse>.ResponseEnum

    Parameters

    url

    The complete URL to fetch trade aggregations from

    Return Value

    PageResponse containing trade aggregation records or error