Markers and Pagination
Some methods return more data than can efficiently fit into one response. When there are more results than contained, the response includes a marker
field. You can use this to retrieve more pages of data across multiple calls. In each request, pass the marker
value from the previous response to resume from the point where you left off. If the marker
is omitted from a response, then you have reached the end of the data set.
The format of the marker
field is intentionally undefined. Each server can define a marker
field as desired, so it may take the form of a string, a nested object, or another type. Different servers, and different methods provided by the same server, can have different marker
definitions. Each marker
is ephemeral, and may not work as expected after 10 minutes.
from xrpl.clients import JsonRpcClient
from xrpl.models.requests import LedgerData
# Create a client to connect to the network.
client = JsonRpcClient("https://xrplcluster.com/")
# Query the most recently validated ledger for info.
ledger = LedgerData(ledger_index="validated")
ledger_data = client.request(ledger).result
ledger_data_index = ledger_data["ledger_index"]
# Create a function to run on each API call.
def printLedgerResult():
print(ledger_data)
# Execute function at least once before checking for markers.
while True:
printLedgerResult()
if "marker" not in ledger_data:
break
# Specify the same ledger and add the marker to continue querying.
ledger_marker = LedgerData(ledger_index=ledger_data_index, marker=ledger_data["marker"])
ledger_data = client.request(ledger_marker).result
const xrpl = require("xrpl")
async function main() {
// Create a client and connect to the network.
const client = new xrpl.Client("wss://xrplcluster.com/")
await client.connect()
// Query the most recently validated ledger for info.
let ledger = await client.request({
"command": "ledger_data",
"ledger_index": "validated",
})
const ledger_data_index = ledger["result"]["ledger_index"]
// Create a function to run on each API call.
function printLedgerResult(){
console.log(ledger["result"])
}
// Execute function at least once before checking for markers.
do {
printLedgerResult()
if (ledger["result"]["marker"] === undefined) {
break
}
// Specify the same ledger and add the marker to continue querying.
const ledger_marker = await client.request({
"command": "ledger_data",
"ledger_index": ledger_data_index,
"marker": ledger["result"]["marker"]
})
ledger = ledger_marker
} while (true)
// Disconnect when done. If you omit this, Node.js won't end the process.
client.disconnect()
}
main()