{"slug": "a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs", "title": "A Safer Data Model for Crypto Price Widgets: Quotes, Scenarios and Costs", "summary": "A developer working with crypto exchange Zoomex published a design pattern for crypto price widgets that separates market observations, scenario projections and purchase estimates into distinct typed data objects, using a discriminated union so components must narrow the value's kind before rendering it. The writeup includes a small JavaScript projectScenario function that validates inputs, enforces bounds on growth rate and periods, and returns a tagged scenario object, with the worked example of 100 at 5% annual growth over two years yielding 110.25.", "body_md": "A price widget can show a current market value, a projected value and a purchase estimate within a few pixels of one another. All three may use the same currency symbol. They are still different kinds of data.\n\nThis matters when you build crypto research interfaces: a number calculated from a slider must not silently become an executable quote.\n\n*Disclosure: I work with Zoomex. The Zoomex pages linked below are examples and further reading. This is an independent design example, not a description of Zoomex's production implementation. AI assisted with drafting and code review.*\n\nStart with the meaning of the value before choosing a chart library.\n\n| Value | What it represents | Context the UI needs | \n|---|---|---|\n| Market observation | A value received from a data source | Asset, quote currency, venue, product and timestamp | \n| Scenario output | A calculation using stated assumptions | Starting value, growth assumption, time unit and horizon | \n| Purchase estimate | An illustration of an order's cost or quantity | Side, available quote, fees and expiry | \n\nA last-traded price is not necessarily the price at which a new order can fill. A spot balance is also different from a derivatives position, even if both screens include BTC in the name.\n\nKeep these distinctions in the data model. A shared variable named “price” makes it too easy to send a scenario output to a component that expects a market observation. Prefer separate objects with an explicit kind, currency and timestamp. In a typed application, use a discriminated union so components can narrow the object before displaying it.\n\nFor a simple constant-rate illustration:\n\n**scenario value = starting value × (1 + growth rate per period) ^ number of periods**\n\nThe period on both sides must match. A 5% annual assumption over two years is not a 5% monthly assumption over 24 months.\n\nHere is a deliberately small JavaScript implementation. It accepts numeric inputs that have already been parsed by the form. It does not estimate a statistically likely return.\n\n```\nfunction projectScenario({ start, growthPercent, periods }) {\n  if (typeof start !== 'number' ||\n      !Number.isFinite(start) || start <= 0) {\n    throw new RangeError('start must be a positive finite number');\n  }\n\n  if (typeof growthPercent !== 'number' ||\n      !Number.isFinite(growthPercent) ||\n      growthPercent < -100 || growthPercent > 100) {\n    throw new RangeError('growthPercent must be between -100 and 100');\n  }\n\n  if (!Number.isSafeInteger(periods) || periods < 0 || periods > 50) {\n    throw new RangeError('periods must be an integer from 0 to 50');\n  }\n\n  const value = start * (1 + growthPercent / 100) ** periods;\n  if (!Number.isFinite(value)) {\n    throw new RangeError('scenario exceeds the numeric range');\n  }\n\n  return { kind: 'scenario', value, start, growthPercent, periods };\n}\n\nconst example = projectScenario({\n  start: 100,\n  growthPercent: 5, // per year in this example\n  periods: 2      // years\n});\n\nconsole.log(example.value.toFixed(2)); // 110.25\n```\n\nThe bounds are application choices, not claims about possible market movements. A real design should explain its own input limits.\n\nJavaScript's [Number.isFinite](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite) does not coerce a numeric string into a number. Keep parsing and validation separate. In particular, do not let a blank field become a valid zero merely because a conversion function accepts it.\n\nAs a real-world example of a scenario interface, Zoomex's [Bitcoin Price Prediction page](https://www.zoomex.com/en/price-prediction/bitcoin) exposes a growth input and labels its outputs as hypothetical. The general implementation question is whether every chart, table and label agrees on what the chosen input means. A correct formula does not rescue an ambiguous time horizon.\n\nThe 110.25 example checks ordinary compounding. It is not enough on its own.\n\nUseful cases for this function include:\n\nFor decimal inputs, compare calculated results with an appropriate tolerance rather than assuming every decimal fraction has an exact binary representation. The [MDN Number reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) explains that representation. For actual balances and settlement, use an agreed precision model, explicit rounding rules and suitable decimal or integer representations; this chart example is not settlement arithmetic.\n\nEven if a scenario looks plausible, it does not answer how a transaction works.\n\nA purchase flow needs to make the product, funding route, applicable charges and custody choice clear. The [How to Buy Bitcoin guide](https://www.zoomex.com/en/how-to-buy/bitcoin) is a separate process reference; it should not be treated as proof that any forecast will occur.\n\nFor developers, the practical separation is straightforward:\n\nDo not invent fee assumptions from a public chart. Read the terms of the actual product and quote service being integrated.\n\nA green line, a precise dollar value and the word “expected” can make a toy calculation look like a promise. A disclaimer in the footer will not necessarily correct the impression created by the main component.\n\nPrefer labels such as “hypothetical scenario” and show the input near the output. Present a downside case alongside an upside case when the tool is intended for scenario comparison. Avoid calling a deterministic slider output a probability or confidence interval unless a model actually supports that interpretation.\n\nCrypto communities sometimes use [copium](https://www.zoomex.com/en/glossary/copium) for comforting rationalizations after a disappointing result. A product should not encourage that pattern by presenting an optimistic assumption as new evidence. Keep observations, assumptions and conclusions visibly separate.\n\nAsk whether a reader can identify the source of a number, its time unit, its freshness and the conditions under which it was produced. Then check whether the application enforces the same distinctions internally.\n\nA clear interface is not just a better chart. It makes the boundaries between a market observation, a mathematical illustration and a transaction explicit.\n\n*Educational software-design discussion only. These examples do not recommend an asset or predict investment returns.*", "url": "https://wpnews.pro/news/a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs", "canonical_source": "https://dev.to/li_eisen_791108fcf808176b/a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs-26im", "published_at": "2026-12-01 10:37:07+00:00", "updated_at": "2026-12-01 10:43:06.348530+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Zoomex", "JavaScript"], "also_reported_by": [], "takeaway": "Model market quotes, scenario outputs and purchase estimates as separate tagged objects (kind, currency, timestamp) rather than a shared 'price' variable, so a slider-derived projection cannot be passed to a component expecting a live quote.", "recommendation": {"advice": "Tag each computed value with its kind and assumptions and validate inputs separately from parsing, so a blank field never becomes a valid zero or a scenario output is mistaken for a market quote.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs", "markdown": "https://wpnews.pro/news/a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs.md", "text": "https://wpnews.pro/news/a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs.txt", "jsonld": "https://wpnews.pro/news/a-safer-data-model-for-crypto-price-widgets-quotes-scenarios-and-costs.jsonld"}}