A step-by-step guide to building trading applications on the XRP Ledger using the XRPL.to API for data, WebSocket for real-time updates, and rippled for transaction submission.
The XRP Ledger's open DEX and native token support make it ideal for building trading applications. With the XRPL.to API handling data aggregation, you can focus on your application logic instead of building infrastructure. Common projects include:
A typical XRPL trading app uses three layers:
XRPL.to handles the heavy lifting of data aggregation, price calculations, and market analytics. Your app reads processed data via REST and WebSocket, then submits transactions directly to the XRP Ledger through rippled or xrpl.js.
Start by listing available tokens with prices, volume, and market cap:
// Fetch top tokens sorted by volume
const res = await fetch('https://api.xrpl.to/v1/tokens?sortBy=volume&limit=20');
const data = await res.json();
data.tokens.forEach(token => {
console.log(token.name, token.price_usd, token.volume_24h);
});Connect to the WebSocket stream for real-time price updates without polling:
const ws = new WebSocket('wss://api.xrpl.to/ws/sync/');
ws.onopen = () => {
ws.send(JSON.stringify({
action: 'subscribe',
tokens: ['token_md5_hash']
}));
};
ws.onmessage = (event) => {
const update = JSON.parse(event.data);
updatePriceDisplay(update);
};Fetch OHLC (candlestick) data for any token to render price charts:
// Get 1-hour candles for the last 24 hours
curl "https://api.xrpl.to/v1/ohlc/{md5}?interval=1h&limit=24"The response contains open, high, low, close, and volume for each interval. Feed this directly into charting libraries like Lightweight Charts or Chart.js.
Use the swap quote endpoint to get optimal routing, then sign and submit via xrpl.js:
// 1. Get a swap quote
const quote = await fetch('https://api.xrpl.to/v1/swap/quote', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
from: 'XRP',
to: { currency: 'USD', issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' },
amount: '100'
})
}).then(r => r.json());
// 2. Sign with xrpl.js
const { Wallet, Client } = require('xrpl');
const wallet = Wallet.fromSeed('sYourSeed...');
const signed = wallet.sign(quote.tx);
// 3. Submit to ledger
const client = new Client('wss://xrplcluster.com');
await client.connect();
const result = await client.submitAndWait(signed.tx_blob);Combine balance, trustline, and LP position endpoints for a complete portfolio view:
const account = 'rYourAddress...';
// Parallel requests for full portfolio data
const [balance, trustlines, lpPositions] = await Promise.all([
fetch(`https://api.xrpl.to/v1/account/balance/${account}`).then(r => r.json()),
fetch(`https://api.xrpl.to/v1/trustlines/${account}`).then(r => r.json()),
fetch(`https://api.xrpl.to/v1/lp-positions/${account}`).then(r => r.json()),
]);
console.log('XRP:', balance.balance);
console.log('Tokens:', trustlines.length);
console.log('LP Positions:', lpPositions.length);Embeddable widget showing live XRPL token prices on any website.
Monitor large trades and wallet movements, send notifications via Telegram or Discord.
Track token allocations and suggest rebalancing trades based on target weights.
Compare prices across AMM pools and DEX orderbooks to find profitable spreads.
Everything you need to build on the XRP Ledger is available for free. Explore the documentation and related guides: