Sep38SellAsset

@Serializable
data class Sep38SellAsset(val asset: String, val price: String, val decimals: Int)

Sell asset information with price and decimal precision.

Represents a sell asset option returned from the GET /prices endpoint when querying by buy asset and amount. Includes the indicative price and the number of decimal places for amount precision. Used to display multiple exchange options to users before they select a specific asset pair.

The price is an indicative (non-binding) rate for one unit of the buy asset in terms of this sell asset. The decimals field indicates how many decimal places should be used when displaying or entering amounts for this asset.

Example - USDC sell asset:

val sellAsset = Sep38SellAsset(
asset = "stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
price = "5.42",
decimals = 7
)
// Interpretation: Need to sell 5.42 USDC to buy 1 unit of buy asset
// Display amounts with up to 7 decimal places

Example - Fiat sell asset:

val sellAsset = Sep38SellAsset(
asset = "iso4217:BRL",
price = "0.18",
decimals = 2
)
// Interpretation: Need to sell 0.18 BRL to buy 1 unit of buy asset
// Display amounts with up to 2 decimal places (standard for fiat)

Example - Displaying prices from buy perspective:

val pricesResponse = sep38Service.prices(
buyAsset = "stellar:USDC:G...",
buyAmount = "100"
)

pricesResponse.sellAssets.forEach { sellAsset ->
val formattedPrice = "%.${sellAsset.decimals}f".format(sellAsset.price.toDouble())
println("Need to sell $formattedPrice ${sellAsset.asset} to buy 1 USDC")
}

See also:

Constructors

Link copied to clipboard
constructor(asset: String, price: String, decimals: Int)

Properties

Link copied to clipboard
@SerialName(value = "asset")
val asset: String

Asset identifier in Asset Identification Format (e.g., "stellar:CODE:ISSUER", "iso4217:USD")

Link copied to clipboard
@SerialName(value = "decimals")
val decimals: Int

Number of decimal places for amount precision when displaying this asset

Link copied to clipboard
@SerialName(value = "price")
val price: String

Indicative price for one unit of the buy asset in terms of this sell asset