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:

  • 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>.ResponseEnum

    Parameters

    accountId

    The Stellar account ID of the offer creator

    cursor

    Optional paging token, specifying where to start returning records from

    order

    Optional sort order - .ascending or .descending

    limit

    Optional maximum number of records to return. Default: 10, max: 200

    Return Value

    PageResponse containing offers for the account or error

  • 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.

    See: Stellar developer docs

    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>.ResponseEnum

    Parameters

    seller

    Optional. Account ID of the offer creator.

    sellingAssetType

    Required. Type of the Asset being sold: “native”, “credit_alphanum4”, or “credit_alphanum12”

    sellingAssetCode

    Required if selling_asset_type is not “native”.

    sellingAssetIssuer

    Required if selling_asset_type is not “native”.

    buyingAssetType

    Required. Type of the Asset being bought: “native”, “credit_alphanum4”, or “credit_alphanum12”

    buyingAssetCode

    Required if buying_asset_type is not “native”.

    buyingAssetIssuer

    Required if buying_asset_type is not “native”.

    sponsor

    Optional. Account ID of the sponsor.

    cursor

    Optional. A paging token, specifying where to start returning records from.

    order

    Optional. The order in which to return rows, “asc” or “desc”, ordered by assetCode then by assetIssuer.

    limit

    Optional. 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) -> OffersStreamItem

    Parameters

    offersType

    The 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) -> TradesStreamItem

    Parameters

    offerId

    The ID of the Offer to stream trades for

    cursor

    Optional paging token, specifying where to start streaming from

    order

    Optional sort order - .ascending or .descending

    limit

    Optional maximum number of records to return

    Return Value

    TradesStreamItem for receiving streaming trade updates

  • Provides information and links relating to a single offer. See Stellar developer docs

    Declaration

    Swift

    open func getOfferDetails(offerId: String) async -> OfferResponseEnum

    Parameters

    offerId

    The ID of the Offer

    Return Value

    OfferResponseEnum with offer details on success or error on failure

  • 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.

    See Stellar developer docs

    Declaration

    Swift

    open func getTrades(forOffer offerId: String, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<TradeResponse>.ResponseEnum

    Parameters

    offerId

    The ID of the Offer

    cursor

    Optional. A paging token, specifying where to start returning records from.

    order

    Optional. The order in which to return rows, “asc” or “desc”, ordered by ledger sequence number.

    limit

    Optional. Maximum number of records to return. Default: 10

    Return Value

    PageResponse containing trades for the offer or error