OrderBookRequestBuilder

class OrderBookRequestBuilder(httpClient: HttpClient, serverUri: Url) : RequestBuilder

Builds requests connected to order books.

Order books show the current buy and sell offers for a given asset pair. This builder allows you to specify the buying and selling assets to query the order book between them.

Note: This endpoint returns a single OrderBookResponse, not a paginated result.

Example usage:

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

// Get order book for XLM/USD trading pair
val orderBook = server.orderBook()
.buyingAsset("native")
.sellingAsset("credit_alphanum4", "USD", "GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B")
.execute()

// Access bids and asks
for (bid in orderBook.bids) {
println("Bid: ${bid.amount} at ${bid.price}")
}
for (ask in orderBook.asks) {
println("Ask: ${ask.amount} at ${ask.price}")
}

See also

Constructors

Link copied to clipboard
constructor(httpClient: HttpClient, serverUri: Url)

Functions

Link copied to clipboard
fun buyingAsset(assetType: String, assetCode: String? = null, assetIssuer: String? = null): OrderBookRequestBuilder

Sets the buying asset for the order book query.

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

Order book endpoint doesn't support cursor pagination. This method throws UnsupportedOperationException.

Link copied to clipboard
suspend fun execute(): OrderBookResponse

Build and execute request to get the order book.

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

Order book endpoint doesn't support limit parameter. This method throws UnsupportedOperationException.

Link copied to clipboard
open override fun order(direction: RequestBuilder.Order): OrderBookRequestBuilder

Order book endpoint doesn't support order parameter. This method throws UnsupportedOperationException.

Link copied to clipboard
fun sellingAsset(assetType: String, assetCode: String? = null, assetIssuer: String? = null): OrderBookRequestBuilder

Sets the selling asset for the order book query.

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.