Closed joaquinsoza closed 3 months ago
You can access the liquidity pool data through the Horizon server or by using the Stellar SDK.
https://developers.stellar.org/api/horizon/resources/list-liquidity-pools
You can customize the request by setting the following queries:
reserves: any
Comma-separated list of assets in canonical form (Code:IssuerAccountID), to only include liquidity pools which have reserves matching all listed assets.
account: any
A Stellar account ID, to only include liquidity pools in which this account is participating in (i.e. holds pool shares to).
cursor: integer
A number that points to a specific location in a collection of responses and is pulled from the paging_token value of a record.
order: string
Possible values: [asc, desc]
A designation of the order in which records should appear. Options include asc (ascending) or desc (descending). If this argument isn’t set, it defaults to asc.
limit: integer
The maximum number of records returned. The limit can range from 1 to 200 - an upper limit that is hardcoded in Horizon for performance reasons. If this argument isn’t designated, it defaults to 10.
However, for this example, we will keep it simple.
Http request:
curl -L -X GET '<https://horizon.stellar.org/liquidity_pools>' \\\\\\\\
-H 'Accept: application/json'
Stellar SDK request:
As previously mentioned, you can access the Stellar liquidity pools data using the Stellar SDK.
import * as sdk from 'stellar-sdk'
const server = new sdk.Horizon.Server('<https://horizon-testnet.stellar.org>');
// Get liquidity pools (by default returns 10)
server.liquidityPools().call().then((response) => {
console.log(response);
});
// Get liquidity pools with queries
server.liquidityPools().limit(10).call().then((response) => {
console.log(response);
});
// Get changes of liquidity pools on stream
server.liquidityPools().stream({
onmessage: (response) => {
console.log(response);
}
});
For more information about the
liquidityPools
method, visit the following link: https://stellar.github.io/js-stellar-sdk/LiquidityPoolCallBuilder.html
{
"_links": {
"self": {
"href": "<https://horizon.stellar.org/liquidity_pools?cursor=\\\\\\\\u0026limit=10\\\\\\\\u0026order=asc>"
},
"next": {
"href": "<https://horizon.stellar.org/liquidity_pools?cursor=0027db149e56e0f68faf2711cccae613c26addb799dbe25af37c5ab1aeb4fa22\\\\\\\\u0026limit=10\\\\\\\\u0026order=asc>"
},
"prev": {
"href": "<https://horizon.stellar.org/liquidity_pools?cursor=0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a\\\\\\\\u0026limit=10\\\\\\\\u0026order=desc>"
}
},
"_embedded": {
"records": [
{
"_links": {
"self": {
"href": "<https://horizon.stellar.org/liquidity_pools/0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a>"
},
"transactions": {
"href": "<https://horizon.stellar.org/liquidity_pools/0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a/transactions{?cursor,limit,order}>",
"templated": true
},
"operations": {
"href": "<https://horizon.stellar.org/liquidity_pools/0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a/operations{?cursor,limit,order}>",
"templated": true
}
},
"id": "0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a",
"paging_token": "0000a8198b5e25994c1ca5b0556faeb27325ac746296944144e0a7406d501e8a",
"fee_bp": 30,
"type": "constant_product",
"total_trustlines": "1",
"total_shares": "5494.2144063",
"reserves": [
{
"asset": "native",
"amount": "6.6856700"
},
{
"asset": "GOLDBANK001:GDEUQ2MX3YXMITFOTC3CO3GW5V3XE3IVG7JKLZZAOZ7WFYIN256INDUS",
"amount": "6047277.1455088"
}
],
"last_modified_ledger": 50193936,
"last_modified_time": "2024-02-02T13:17:46Z"
},
...
]
}
}
In the response, you'll find detailed information about each liquidity pool. This includes its ID, the fee in basis points, the type of pool, the total number of trustlines and shares, the assets and amounts in the pool's reserves, and the last time the pool was modified.
The main objective of this Study is to know how to index the information from the Stellar AMM on Mercury, good job while using horizon server it might useful in the future but we need to use an indexer!
Re-do this issue using mercury
Mercury team are currently working on this feature
Do it with Zephyr
Index Stellar AMM
study: