OffersService
public class OffersService : @unchecked Sendable
Service for querying offer information from the Stellar Horizon API.
Offers represent open orders on the Stellar decentralized exchange (DEX). Each offer specifies an amount and price to buy or sell an asset. Can query offers by account, asset pair, or sponsor.
Example usage:
let sdk = StellarSDK()
// Get all offers for an account
let response = await sdk.offers.getOffers(forAccount: "GACCOUNT...")
switch response {
case .success(let page):
for offer in page.records {
print("Selling: \(offer.amount) \(offer.selling.assetCode ?? "XLM")")
print("Buying: \(offer.buying.assetCode ?? "XLM")")
print("Price: \(offer.price)")
}
case .failure(let error):
print("Error: \(error)")
}
See also:
- Stellar developer docs
- OrderbookService for orderbook snapshots
-
getOffers(forAccount:Asynchronouscursor: order: limit: ) Retrieves all offers created by a specific account with optional pagination parameters.
Declaration
Swift
open func getOffers(forAccount accountId: String, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<OfferResponse>.ResponseEnumParameters
accountIdThe Stellar account ID of the offer creator
cursorOptional paging token, specifying where to start returning records from
orderOptional sort order - .ascending or .descending
limitOptional maximum number of records to return. Default: 10, max: 200
Return Value
PageResponse containing offers for the account or error
-
getOffers(seller:AsynchronoussellingAssetType: sellingAssetCode: sellingAssetIssuer: buyingAssetType: buyingAssetCode: buyingAssetIssuer: sponsor: cursor: order: limit: ) Retrieves all current offers, allowing filtering by seller, selling_asset or buying_asset.
People on the Stellar network can make offers to buy or sell assets. This endpoint represents all the current offers. This function responds with a page of offers. Pages represent a subset of a larger collection of objects to avoid returning millions of records in a single request.
Declaration
Swift
open func getOffers(seller: String?, sellingAssetType: String, sellingAssetCode: String? = nil, sellingAssetIssuer: String? = nil, buyingAssetType: String, buyingAssetCode: String? = nil, buyingAssetIssuer: String? = nil, sponsor: String? = nil, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<OfferResponse>.ResponseEnumParameters
sellerOptional. Account ID of the offer creator.
sellingAssetTypeRequired. Type of the Asset being sold: “native”, “credit_alphanum4”, or “credit_alphanum12”
sellingAssetCodeRequired if selling_asset_type is not “native”.
sellingAssetIssuerRequired if selling_asset_type is not “native”.
buyingAssetTypeRequired. Type of the Asset being bought: “native”, “credit_alphanum4”, or “credit_alphanum12”
buyingAssetCodeRequired if buying_asset_type is not “native”.
buyingAssetIssuerRequired if buying_asset_type is not “native”.
sponsorOptional. Account ID of the sponsor.
cursorOptional. A paging token, specifying where to start returning records from.
orderOptional. The order in which to return rows, “asc” or “desc”, ordered by assetCode then by assetIssuer.
limitOptional. Maximum number of records to return. Default: 10
Return Value
PageResponse containing offers matching the filters or error
-
Streams real-time offer updates via Server-Sent Events from Horizon.
Declaration
Swift
open func stream(for offersType: OffersChange) -> OffersStreamItemParameters
offersTypeThe filter specifying which offers to stream (all offers with filters, or by account)
Return Value
OffersStreamItem for receiving streaming offer updates
-
Streams real-time trade updates for a specific offer via Server-Sent Events.
Declaration
Swift
open func streamTrades(forOffer offerId: String, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) -> TradesStreamItemParameters
offerIdThe ID of the Offer to stream trades for
cursorOptional paging token, specifying where to start streaming from
orderOptional sort order - .ascending or .descending
limitOptional maximum number of records to return
Return Value
TradesStreamItem for receiving streaming trade updates
-
getOfferDetails(offerId:Asynchronous) Provides information and links relating to a single offer. See Stellar developer docs
Declaration
Swift
open func getOfferDetails(offerId: String) async -> OfferResponseEnumParameters
offerIdThe ID of the Offer
Return Value
OfferResponseEnum with offer details on success or error on failure
-
getTrades(forOffer:Asynchronouscursor: order: limit: ) This endpoint represents all trades for a given offer and can be used in streaming mode. Streaming mode allows you to listen for new trades for this offer as they are added to the Stellar ledger. If called in streaming mode, Horizon will start at the earliest known trade unless a cursor is set, in which case it will start from that cursor. By setting the cursor value to now, you can stream trades created since your request time.
Declaration
Swift
open func getTrades(forOffer offerId: String, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<TradeResponse>.ResponseEnumParameters
offerIdThe ID of the Offer
cursorOptional. A paging token, specifying where to start returning records from.
orderOptional. The order in which to return rows, “asc” or “desc”, ordered by ledger sequence number.
limitOptional. Maximum number of records to return. Default: 10
Return Value
PageResponse containing trades for the offer or error
View on GitHub
Install in Dash