> loading_
# Walk through a book_offers call with limit set to 1
# This demonstrates the new minimum limit behavior on an updated rippled node.
# -----------------------------------------------------------
# Step 1: Connect to a rippled WebSocket endpoint.
# You can use any WebSocket client library. Here we use
# Python's `websockets` for clarity.
# -----------------------------------------------------------
import asyncio
import json
import websockets
async def get_single_offer():
# Replace with your own rippled node or a public endpoint
# running a version that includes commit #6812.
uri = "wss://s1.ripple.com" # public mainnet cluster
async with websockets.connect(uri) as ws:
# ---------------------------------------------------------
# Step 2: Build the book_offers request.
# We ask for the XRP → USD (Bitstamp) order book with
# limit: 1. Before this fix, the server would have
# returned more offers than requested because the
# internal minimum was higher than 1.
# ---------------------------------------------------------
request = {
"id": 1,
"command": "book_offers",
"taker_gets": {
"currency": "XRP" # native asset, no issuer needed
},
"taker_pays": {
"currency": "USD",
"issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B" # Bitstamp
},
"limit": 1 # <-- now respected as-is
}
await ws.send(json.dumps(request))
response = json.loads(await ws.recv())
# ---------------------------------------------------------
# Step 3: Inspect the response.
# With the fix, `offers` should contain exactly 1 entry
# (assuming at least one offer exists on this book).
# ---------------------------------------------------------
offers = response.get("result", {}).get("offers", [])
print(f"Offers returned: {len(offers)}") # Expected: 1
# Print the top-of-book offer
if offers:
top = offers[0]
print(json.dumps(top, indent=2))
# ---------------------------------------------------------
# Step 4: Paginate if needed.
# If a `marker` is present you can send a follow-up
# request with that marker to fetch the next offer,
# one at a time — useful for streaming best-price UIs.
# ---------------------------------------------------------
marker = response.get("result", {}).get("marker")
if marker:
print(f"Pagination marker present — more offers available.")
else:
print("No marker — this is the only offer on the book.")
asyncio.run(get_single_offer())