Cryptocurrency Exchange API Demonstrator

Cryptocurrency Exchange API - Client Demo

Fetch Crypto Quote (Mock Data)

24h Change: ${changeSign}${Math.abs(data.change24h).toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits:4})} ${escapeHtml(quoteCurrency)} (${changeSign}${data.change24hPercent.toFixed(2)}%)

24h High: ${data.high24h.toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits: (data.high24h < 1 ? 4 : 2)})} ${escapeHtml(quoteCurrency)}

24h Low: ${data.low24h.toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits: (data.low24h < 1 ? 4 : 2)})} ${escapeHtml(quoteCurrency)}

24h Volume (${escapeHtml(data.pair.split('/')[0])}): ${data.volume24h.toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits:2})}

24h Volume (${escapeHtml(quoteCurrency)}): ${data.volume24hQuote.toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits:2})}

Timestamp: ${escapeHtml(data.timestamp)}

`; notesContainerEl.style.display = 'block'; downloadPdfBtn.style.display = 'block'; } else { resultsHTML = `

No mock data found for trading pair "${escapeHtml(pairInput)}". Try BTC/USD, ETH/USD, ADA/USDT, or SOL/USD.

`; notesContainerEl.style.display = 'none'; downloadPdfBtn.style.display = 'none'; } resultsOutputDiv.innerHTML = resultsHTML; resultsOutputDiv.style.display = 'block'; }); downloadPdfBtn?.addEventListener('click', function () { const { jsPDF } = window.jspdf; const pdfOutputArea = document.getElementById('cxdPdfOutputArea'); if (!pdfOutputArea || resultsOutputDiv.style.display === 'none' || resultsOutputDiv.querySelector('.cxd-error')) { alert('Please fetch a valid mock quote first before downloading PDF.'); return; } // Ensure notes are visible for PDF capture document.getElementById('cxdNotesContainer').style.display = 'block'; html2canvas(pdfOutputArea, { scale: 1.5, useCORS: true, backgroundColor: '#ffffff' }) .then(canvas => { const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const margin = 40; const contentWidth = pdfWidth - 2 * margin; const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; let imgWidth = contentWidth; let imgHeight = imgWidth / ratio; if (imgHeight > pdfHeight - 2 * margin) { imgHeight = pdfHeight - 2 * margin; imgWidth = imgHeight * ratio; } const x = (pdfWidth - imgWidth) / 2; pdf.addImage(imgData, 'JPEG', x, margin, imgWidth, imgHeight, undefined, 'MEDIUM'); pdf.save('Crypto_Quote_Demo.pdf'); }) .catch(err => { console.error("Error generating PDF:", err); alert("Error generating PDF. See console for details."); }); }); function escapeHtml(unsafe) { if (typeof unsafe !== 'string') return unsafe === undefined || unsafe === null ? '' : String(unsafe); return unsafe.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); } });
Scroll to Top