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:
- Stellar developer docs
- OffersService for individual offers
-
getOrderbook(sellingAssetType:AsynchronoussellingAssetCode: sellingAssetIssuer: buyingAssetType: buyingAssetCode: buyingAssetIssuer: limit: ) 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 -> OrderbookResponseEnumParameters
sellingAssetTypeType of the asset being sold: “native”, “credit_alphanum4”, or “credit_alphanum12”
sellingAssetCodeAsset code if selling_asset_type is not “native”
sellingAssetIssuerAsset issuer if selling_asset_type is not “native”
buyingAssetTypeType of the asset being bought: “native”, “credit_alphanum4”, or “credit_alphanum12”
buyingAssetCodeAsset code if buying_asset_type is not “native”
buyingAssetIssuerAsset issuer if buying_asset_type is not “native”
limitOptional 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) -> OrderbookStreamItemParameters
orderbookTypeThe orderbook configuration specifying the trading pair to stream
Return Value
OrderbookStreamItem for receiving streaming orderbook updates
View on GitHub
Install in Dash