price

suspend fun price(context: String, sellAsset: String, buyAsset: String, sellAmount: String? = null, buyAmount: String? = null, sellDeliveryMethod: String? = null, buyDeliveryMethod: String? = null, countryCode: String? = null, jwtToken: String? = null): Sep38PriceResponse

Fetches an indicative price for a specific asset pair and amount.

Returns a non-binding price quote for exchanging one asset for another. Either sellAmount or buyAmount must be provided, but not both.

This price is indicative and non-binding. The actual price will be calculated at conversion time once the anchor receives funds. For binding commitments, use postQuote to request a firm quote.

Return

Sep38PriceResponse containing price details and fees

Parameters

context

Context for quote usage ("sep6", "sep24", or "sep31")

sellAsset

Asset to sell (e.g., "stellar:USDC:G...", "iso4217:USD")

buyAsset

Asset to buy

sellAmount

Optional amount of sellAsset to exchange (mutually exclusive with buyAmount)

buyAmount

Optional amount of buyAsset to receive (mutually exclusive with sellAmount)

sellDeliveryMethod

Optional delivery method name from info endpoint

buyDeliveryMethod

Optional delivery method name from info endpoint

countryCode

Optional ISO 3166-1 alpha-2 or ISO 3166-2 country code

jwtToken

Optional JWT token from SEP-10 authentication

Throws

If both or neither amount parameters are provided

If request parameters are invalid (400)

For unexpected HTTP status codes

Example:

val priceResponse = quoteService.price(
context = "sep6",
sellAsset = "iso4217:BRL",
buyAsset = "stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
sellAmount = "542",
sellDeliveryMethod = "PIX",
countryCode = "BR"
)

println("Exchange rate: ${priceResponse.price} BRL per USDC")
println("Effective rate (with fees): ${priceResponse.totalPrice} BRL per USDC")
println("You'll receive: ${priceResponse.buyAmount} USDC")
println("Total cost: ${priceResponse.sellAmount} BRL")
println("Fee: ${priceResponse.fee.total} ${priceResponse.fee.asset}")