Cohort ended · self-paced
advanced 60 min

Coding lab: XRPL order-book client

Read both sides of a market, work out the best price and how much can really trade, then place and cancel your own offer.

Prerequisites

Complete these before starting this module:

What you'll learn

  • Normalize XRP and issued amounts with integer-safe arithmetic.
  • Calculate best prices, spread, and funded depth.
  • Create, monitor, and cancel an offer.
  • Reconcile the final offer state and balances.
Complete this module by self-assessment. Jump to assessment

How the provided code works

The read-only helper gives you a small, fixed sample of an order book plus a few number helpers, so you can get the maths right before touching the live network. When you press Run, it:

  1. Provides a sample list of offers shaped exactly like a real book_offers response, including the *_funded fields that show what can actually trade.
  2. Provides integer-safe helpers (decimalToScaled, dropsToScaled, ratio) so prices do not pick up floating-point error.
  3. For the live checkpoint, provides functions that read a real book and place/cancel an offer.

Your job is to summarise the book: best price and funded depth. Start on the sample data, then switch to the live book when you are ready.

Build the read side first

First you will read a market, work out the best price and how much can actually trade, then place and cancel a small order of your own. Begin with fixed sample data where the numbers are predictable, and move to the live network once that works.

Finish the deterministic fixture before you touch the live book. Prices and token values arrive as decimal strings and XRP as drops, so the starter scales both to integers and your maths never picks up binary floating-point error. Read the funded values whenever the server gives them.

On the live checkpoint, request book_offers in both directions and label each view with what the taker pays and receives. Show best bid, best ask, spread, and funded depth for the size you want.

Add the write side

Place a small limit offer in the disposable market and keep both its transaction hash and creating sequence. Query account_offers to see whether it is still open, partly consumed, or gone, then cancel any remainder with OfferCancel and query balances and offers again. A cancel reporting success does not prove the offer ever existed, so let the reconciliation be the final word rather than the response label.

Assignments

0 of 1 complete

Unlocks

Finishing this module opens up: