Trade Aggregations Request Builder
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
Functions
Sets the cursor parameter for pagination.
Build and execute request to get a page of trade aggregations.
Sets the limit parameter defining maximum number of trade aggregations to return.
Sets the order parameter defining the order in which to return trade aggregations.
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.