LiquidityPoolsService
public class LiquidityPoolsService : @unchecked Sendable
Service for querying liquidity pools from the Stellar Horizon API.
Liquidity pools enable automated market making (AMM) on Stellar. Each pool contains reserves of two assets and allows swapping between them at algorithmically determined prices.
Example usage:
let sdk = StellarSDK()
// Get liquidity pool details
let response = await sdk.liquidityPools.getLiquidityPoolDetails(
liquidityPoolId: "L..."
)
switch response {
case .success(let pool):
print("Total shares: \(pool.totalShares)")
for reserve in pool.reserves {
print("\(reserve.asset): \(reserve.amount)")
}
case .failure(let error):
print("Error: \(error)")
}
See also:
- Stellar developer docs
- LiquidityPoolDepositOperation and LiquidityPoolWithdrawOperation
-
getLiquidityPool(poolId:Asynchronous) Retrieves details for a specific liquidity pool by its ID.
Declaration
Swift
open func getLiquidityPool(poolId: String) async -> LiquidityPoolDetailsResponseEnumParameters
poolIdThe liquidity pool ID (L-address or hex format)
Return Value
LiquidityPoolDetailsResponseEnum with pool details or error
-
getLiquidityPools(account:Asynchronouscursor: order: limit: ) Retrieves all liquidity pools with optional filtering and pagination parameters.
Declaration
Swift
open func getLiquidityPools(account: String? = nil, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<LiquidityPoolResponse>.ResponseEnumParameters
accountOptional account ID (G… address) to filter pools by participation. When provided, returns only liquidity pools the account participates in.
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 liquidity pools or error
-
Retrieves liquidity pools filtered by reserve assets with optional pagination parameters.
Declaration
Swift
open func getLiquidityPools(reserveAssetA: Asset, reserveAssetB: Asset, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> PageResponse<LiquidityPoolResponse>.ResponseEnumParameters
reserveAssetAFirst reserve asset to filter by
reserveAssetBSecond reserve asset to filter by
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 liquidity pools matching the reserve assets or error
-
getLiquidityPoolTrades(poolId:Asynchronouscursor: order: limit: ) Retrieves trade history for a specific liquidity pool with optional pagination parameters.
Declaration
Swift
open func getLiquidityPoolTrades(poolId: String, cursor: String? = nil, order: Order? = nil, limit: Int? = nil) async -> LiquidityPoolTradesResponseEnumParameters
poolIdThe liquidity pool ID (L-address or hex format)
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
LiquidityPoolTradesResponseEnum with trade history or error
-
Streams real-time trade updates for a specific liquidity pool.
Creates a Server-Sent Events (SSE) stream that delivers live trade updates as they occur on the Stellar network for the specified liquidity pool. The stream provides continuous updates until explicitly closed.
Example usage:
let sdk = StellarSDK() let poolId = "L..." // Liquidity pool ID (L-address or hex format) let tradesStream = sdk.liquidityPools.streamTrades(forPoolId: poolId) tradesStream.onReceive { response in switch response { case .open: print("Stream opened") case .response(id: let id, data: let trade): print("New trade: \(trade.baseAmount) for \(trade.counterAmount)") case .error(let error): print("Error: \(error)") } } // Close when done tradesStream.closeStream()Declaration
Swift
open func streamTrades(forPoolId poolId: String) -> LiquidityPoolTradesStreamItemParameters
poolIdThe liquidity pool ID (L-address or hex format)
Return Value
LiquidityPoolTradesStreamItem for receiving live trade updates
-
getLiquidityPoolsFromUrl(url:Asynchronous) Retrieves liquidity pools from a specific Horizon URL.
Used for pagination. Pass URLs from PageResponse links (e.g., next, prev).
Declaration
Swift
open func getLiquidityPoolsFromUrl(url: String) async -> PageResponse<LiquidityPoolResponse>.ResponseEnumParameters
urlThe complete URL to fetch liquidity pools from
Return Value
PageResponse containing liquidity pools or error
View on GitHub
Install in Dash