TradeAggregationsRequestBuilder

class TradeAggregationsRequestBuilder(httpClient: HttpClient, serverUri: Url, baseAssetType: String, baseAssetCode: String?, baseAssetIssuer: String?, counterAssetType: String, counterAssetCode: String?, counterAssetIssuer: String?, startTime: Long, endTime: Long, resolution: Long, offset: Long) : RequestBuilder

Builds requests connected to trade aggregations.

Trade aggregations divide a given time range into segments and aggregate statistics about trading activity for each segment. They are similar to candlestick charts used in traditional trading platforms, showing open, high, low, and close (OHLC) prices along with trading volume.

All parameters are required for this endpoint:

  • Base asset (the asset being bought)

  • Counter asset (the asset being sold)

  • Start time (beginning of time range, in milliseconds since epoch)

  • End time (end of time range, in milliseconds since epoch)

  • Resolution (size of each time bucket, in milliseconds)

  • Offset (offset from start time for bucketing, in milliseconds, defaults to 0)

Example usage:

val server = HorizonServer("https://horizon.stellar.org")

// Get hourly trade aggregations for XLM/USD over the last 24 hours
val startTime = System.currentTimeMillis() - (24 * 60 * 60 * 1000)
val endTime = System.currentTimeMillis()
val oneHour = 60 * 60 * 1000L // 1 hour in milliseconds

val aggregations = server.tradeAggregations(
baseAssetType = "native",
baseAssetCode = null,
baseAssetIssuer = null,
counterAssetType = "credit_alphanum4",
counterAssetCode = "USD",
counterAssetIssuer = "ISSUER_ID",
startTime = startTime,
endTime = endTime,
resolution = oneHour,
offset = 0
).execute()

for (agg in aggregations.records) {
println("Time: ${agg.timestamp}, Open: ${agg.open}, High: ${agg.high}, Low: ${agg.low}, Close: ${agg.close}")
}

See also

Constructors

Link copied to clipboard
constructor(httpClient: HttpClient, serverUri: Url, baseAssetType: String, baseAssetCode: String?, baseAssetIssuer: String?, counterAssetType: String, counterAssetCode: String?, counterAssetIssuer: String?, startTime: Long, endTime: Long, resolution: Long, offset: Long)

Functions

Link copied to clipboard
open override fun cursor(cursor: String): TradeAggregationsRequestBuilder

Sets the cursor parameter for pagination.

Link copied to clipboard

Build and execute request to get a page of trade aggregations.

Link copied to clipboard
open override fun limit(number: Int): TradeAggregationsRequestBuilder

Sets the limit parameter defining maximum number of trade aggregations to return.

Link copied to clipboard

Sets the order parameter defining the order in which to return trade aggregations.

Link copied to clipboard
fun <T : Response> stream(serializer: KSerializer<T>, listener: EventListener<T>, reconnectTimeout: Duration = SSEStream.DEFAULT_RECONNECT_TIMEOUT): SSEStream<T>

Creates a Server-Sent Events (SSE) stream for this request. The stream will automatically reconnect on connection loss and resume from the last received event.