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:
- Stellar developer docs
- TradesService for individual trade records
-
getTradeAggregations(startTime:AsynchronousendTime: resolution: baseAssetType: baseAssetCode: baseAssetIssuer: counterAssetType: counterAssetCode: counterAssetIssuer: cursor: order: limit: ) 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.
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>.ResponseEnumParameters
startTimeLower time boundary for the aggregations, in milliseconds since Unix epoch
endTimeUpper time boundary for the aggregations, in milliseconds since Unix epoch
resolutionThe segment duration in milliseconds. Supported values: 1 minute (60000), 5 minutes (300000), 15 minutes (900000), 1 hour (3600000), 1 day (86400000), 1 week (604800000)
baseAssetTypeType of the base asset: “native”, “credit_alphanum4”, or “credit_alphanum12”
baseAssetCodeAsset code of the base asset (required if not native)
baseAssetIssuerAccount ID of the base asset issuer (required if not native)
counterAssetTypeType of the counter asset: “native”, “credit_alphanum4”, or “credit_alphanum12”
counterAssetCodeAsset code of the counter asset (required if not native)
counterAssetIssuerAccount ID of the counter asset issuer (required if not native)
cursorOptional paging token, specifying where to start returning records from
orderOptional sort order - .ascending or .descending
limitOptional maximum number of records to return. Default: 10, max: 200
Return Value
PageResponse containing trade aggregation records or error
-
getTradeAggregationsFromUrl(url:Asynchronous) 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>.ResponseEnumParameters
urlThe complete URL to fetch trade aggregations from
Return Value
PageResponse containing trade aggregation records or error
View on GitHub
Install in Dash