如何讓市場數據數值可供核查
How to make a market-data figure checkable
市場數據數值要便於核查,應為每個衍生數值保留來源、擷取時間、統計窗口、單位和計算脈絡,讓其他開發者能重現計算。示例以兩筆合成輸入 10.00 和 15.00 計算等權算術平均,得出 12.50,並核對記錄格式、窗口範圍及重算結果。JSON Schema 可驗證記錄結構,但重算只能確認結果與所提供輸入一致;來源及其準確性仍須有獨立證據。
By Binergy / LUNQ Editorial. Disclosure: this technical fieldnote was drafted with AI assistance for the Binergy / LUNQ project.
A dashboard number becomes easier to debug when another developer can reconstruct it. Keep a small evidence record beside each derived figure, rather than leaving its meaning inside an implementation. All values below are synthetic demo points.
1. Identify the source
Record the producer, endpoint or dataset revision, and retrieval parameters. Retain the relevant input or a permitted snapshot. A URL can change; a content hash identifies particular bytes but cannot establish that those bytes were truthful. In this fixture, the source is a local example identifier and the inline samples are the replay input.
2. Separate capture time from the measured window
Capture time says when your collector obtained the record. The aggregation window says which events the figure covers. Use explicit UTC timestamps and boundary rules. Here, an event at the start belongs to the window; an event exactly at the end does not. A recently captured response can still contain old observations.
3. Make units and precision explicit
Keep the unit beside the value. Specify the rounding rule and preserve decimal inputs as strings when exact decimal arithmetic matters. Converting a binary floating-point result to two displayed decimals does not document the original calculation.
{
"schema_version": 1,
"synthetic": true,
"source": "urn:example:two-samples",
"captured_at": "2026-01-01T12:01:05Z",
"window": {
"start": "2026-01-01T12:00:00Z",
"end": "2026-01-01T12:01:00Z",
"bounds": "[start,end)"
},
"metric": "arithmetic_mean",
"unit": "demo_points",
"context": "Two synthetic inputs, equally weighted.",
"samples": [
{
"at": "2026-01-01T12:00:10Z",
"value": "10.00"
},
{
"at": "2026-01-01T12:00:40Z",
"value": "15.00"
}
],
"value": "12.50",
"rounding": "nearest 0.01; ties up"
}
4. State the context
Define the metric before interpreting it. This fixture uses an unweighted arithmetic mean of two inputs. A market-data pipeline would also need the instrument, venue, quote unit, and relevant inclusion rules. Record exclusions, missing samples, and transformations that could change the result. An empty response needs an explicit state; silently replacing it with zero changes its meaning.
5. Replay the calculation
First check required fields, types, timestamp syntax, and allowed units. Then check ordering and window membership. Convert 10.00 and 15.00 to integer hundredths, add them, divide by two, and apply the documented rounding rule: the expected result is 12.50. Finally, compare that result with the stored value and retain the outcome.
These are separate checks. A JSON Schema can accept a well-shaped record containing an incorrect result. Recalculation can establish consistency with supplied inputs, while provenance and source accuracy still require independent evidence. For this teaching fixture, the local check also rejects an altered result and an event placed at the exclusive window boundary.
The useful output is a figure together with enough context for another developer to challenge and reproduce it.
Project affiliation: Binergy / LUNQ. This example is independent of any live product integration.
來源:DEV Community · dev.to