Order Book Request Builder
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
Functions
Sets the buying asset for the order book query.
Order book endpoint doesn't support cursor pagination. This method throws UnsupportedOperationException.
Build and execute request to get the order book.
Order book endpoint doesn't support limit parameter. This method throws UnsupportedOperationException.
Order book endpoint doesn't support order parameter. This method throws UnsupportedOperationException.
Sets the selling asset for the order book query.
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.