Sep38Buy Asset
Buy asset information with price and decimal precision.
Represents a buy asset option returned from the GET /prices endpoint, including its 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 this asset in terms of the sell asset. The decimals field indicates how many decimal places should be used when displaying or entering amounts for this asset.
Example - USDC buy asset:
val buyAsset = Sep38BuyAsset(
asset = "stellar:USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
price = "5.42",
decimals = 7
)
// Interpretation: 1 USDC = 5.42 units of sell asset
// Display amounts with up to 7 decimal placesContent copied to clipboard
Example - Fiat buy asset:
val buyAsset = Sep38BuyAsset(
asset = "iso4217:BRL",
price = "0.18",
decimals = 2
)
// Interpretation: 1 BRL = 0.18 units of sell asset
// Display amounts with up to 2 decimal places (standard for fiat)Content copied to clipboard
Example - Displaying prices to users:
val pricesResponse = sep38Service.prices(
sellAsset = "stellar:USDC:G...",
sellAmount = "100"
)
pricesResponse.buyAssets.forEach { buyAsset ->
val formattedPrice = "%.${buyAsset.decimals}f".format(buyAsset.price.toDouble())
println("1 ${buyAsset.asset} = $formattedPrice USDC")
}Content copied to clipboard
See also:
Sep38PricesResponse which contains the list of buy assets
Sep38SellAsset for the equivalent sell asset representation