OffersRequestBuilder

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

Builds requests connected to offers.

Offers represent an intent to trade one asset for another at a pre-determined exchange rate. This builder allows you to query offers based on various criteria such as seller, sponsor, or the assets being bought and sold.

Example usage:

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

// Get a specific offer by ID
val offer = server.offers().offer(12345)

// Get offers by seller
val sellerOffers = server.offers()
.forSeller("GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B")
.limit(20)
.execute()

// Get offers selling a specific asset
val assetOffers = server.offers()
.forSellingAsset("credit_alphanum4", "USD", "GCDNJUBQSX7AJWLJACMJ7I4BC3Z47BQUTMHEICZLE6MU4KQBRYG5JY6B")
.execute()

See also

Constructors

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

Functions

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

Sets the cursor parameter for pagination.

Link copied to clipboard
suspend fun execute(): Page<OfferResponse>

Build and execute request to get a page of offers.

Link copied to clipboard

Returns all offers where the given account is the seller.

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

Returns all offers buying an asset.

Link copied to clipboard

Returns all offers where the given account is the seller.

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

Returns all offers selling an asset.

Link copied to clipboard

Returns all offers sponsored by a given account.

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

Sets the limit parameter defining maximum number of offers to return.

Link copied to clipboard
suspend fun offer(offerId: Long): OfferResponse

Requests a specific offer by ID.

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

Sets the order parameter defining the order in which to return offers.

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.