OrderbookService

public class OrderbookService : @unchecked Sendable

Service for querying orderbook information from the Stellar Horizon API.

The orderbook shows current bids and asks for a given asset pair on the Stellar DEX. Provides a snapshot of available offers at different price levels.

Example usage:

let sdk = StellarSDK()

// Get orderbook for USD/XLM
let response = await sdk.orderbook.getOrderbook(
    sellingAssetType: AssetTypeAsString.CREDIT_ALPHANUM4,
    sellingAssetCode: "USD",
    sellingAssetIssuer: "GISSUER...",
    buyingAssetType: AssetTypeAsString.NATIVE,
    limit: 20
)
switch response {
case .success(let orderbook):
    print("Bids: \(orderbook.bids.count)")
    print("Asks: \(orderbook.asks.count)")
case .failure(let error):
    print("Error: \(error)")
}

See also:

  • Retrieves current orderbook bids and asks for a trading pair.

    Declaration

    Swift

    open func getOrderbook(sellingAssetType: String, sellingAssetCode: String? = nil, sellingAssetIssuer: String? = nil, buyingAssetType: String, buyingAssetCode: String? = nil, buyingAssetIssuer: String? = nil, limit: Int? = nil) async -> OrderbookResponseEnum

    Parameters

    sellingAssetType

    Type of the asset being sold: “native”, “credit_alphanum4”, or “credit_alphanum12”

    sellingAssetCode

    Asset code if selling_asset_type is not “native”

    sellingAssetIssuer

    Asset issuer if selling_asset_type is not “native”

    buyingAssetType

    Type of the asset being bought: “native”, “credit_alphanum4”, or “credit_alphanum12”

    buyingAssetCode

    Asset code if buying_asset_type is not “native”

    buyingAssetIssuer

    Asset issuer if buying_asset_type is not “native”

    limit

    Optional maximum number of bids/asks to return. Default: 20

    Return Value

    OrderbookResponseEnum with bids and asks or error

  • Streams real-time orderbook updates via Server-Sent Events for a trading pair.

    Declaration

    Swift

    open func stream(for orderbookType: OrderbookChange) -> OrderbookStreamItem

    Parameters

    orderbookType

    The orderbook configuration specifying the trading pair to stream

    Return Value

    OrderbookStreamItem for receiving streaming orderbook updates