qs-backtest-server 0.4.1

Transport-neutral retained-job backtest service and CLI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
use std::collections::{BTreeMap, BTreeSet};
use std::fs;
use std::sync::Arc;

use chrono::{DateTime, NaiveDateTime, Utc};
use qs_backtest::{
    ReplayInstrumentArtifact, ReplayInstrumentManifest, guarded_instrument_spec,
    resolve_legacy_economics,
};
use qs_instruments::{
    AssetId, AssetKind, AssetSpec, CatalogDocument, Decimal, DecimalGrid, EconomicsModelId,
    EffectiveInterval, InstrumentAlias, InstrumentAssets, InstrumentCatalogSnapshot,
    InstrumentEconomics, InstrumentId, InstrumentResolutionContext, InstrumentResolutionError,
    InstrumentSelector, InstrumentSpec, ListingStatus, ListingVenueId, MarketDataSourceId,
    MarketKind, PriceRules, QuantityRules, QuantityUnit, StoredSeriesBinding,
};
use qs_symbols::{SymbolCurrencyMetadata, SymbolRegistry, SymbolSpec};

use crate::config::{InstrumentsSection, LinearInstrumentConfig};
use crate::error::{BacktestServerError, Result};
use crate::rpc_types::InstrumentExclusionReasonMsg;
use qs_market_loader::SymbolPartitionResolver;

const CATALOG_SCHEMA_VERSION: u32 = 1;
const COMPATIBILITY_LISTING_VENUE: &str = "repository-default";
const REGISTRY_CATALOG_VERSION: &str = "symbol-registry-1";
const SPEC_VALID_FROM: &str = "1970-01-01T00:00:00Z";

#[derive(Clone)]
pub struct InstrumentDomain {
    snapshot: Arc<InstrumentCatalogSnapshot>,
    default_listing_venue: Option<ListingVenueId>,
    data_source: MarketDataSourceId,
    source_symbols: BTreeMap<String, String>,
}

impl InstrumentDomain {
    pub fn load(config: &InstrumentsSection, registry: &SymbolRegistry) -> Result<Self> {
        let configured_listing_venue = config
            .default_listing_venue
            .as_deref()
            .map(ListingVenueId::new)
            .transpose()
            .map_err(|error| BacktestServerError::Config(error.to_string()))?;
        let data_source = MarketDataSourceId::new(&config.market_data_source)
            .map_err(|error| BacktestServerError::Config(error.to_string()))?;
        if config.catalog_path.is_some() && !config.linear_instruments.is_empty() {
            return Err(BacktestServerError::Config(
                "catalog_path and linear_instruments are alternative specification authorities"
                    .into(),
            ));
        }
        let mut source_symbols = BTreeMap::new();
        let mut physical = BTreeSet::new();
        for (symbol, source) in &config.source_symbols {
            let canonical = registry.normalize(symbol).ok_or_else(|| {
                BacktestServerError::Config(format!("unknown source binding symbol '{symbol}'"))
            })?;
            if source.is_empty()
                || source.contains(['/', '\\'])
                || source == "."
                || source == ".."
                || registry
                    .normalize(source)
                    .is_some_and(|target| target != canonical)
                || !physical.insert(source.to_ascii_lowercase())
                || source_symbols
                    .insert(canonical.into(), source.clone())
                    .is_some()
            {
                return Err(BacktestServerError::Config(format!(
                    "invalid or duplicate source binding for '{symbol}'"
                )));
            }
        }
        let (snapshot, default_listing_venue) = match &config.catalog_path {
            Some(path) => {
                let content = fs::read_to_string(path).map_err(|error| {
                    BacktestServerError::Config(format!(
                        "failed to read instrument catalog '{path}': {error}"
                    ))
                })?;
                let document = toml::from_str::<CatalogDocument>(&content).map_err(|error| {
                    BacktestServerError::Config(format!(
                        "failed to parse instrument catalog '{path}': {error}"
                    ))
                })?;
                let snapshot = InstrumentCatalogSnapshot::compile(document).map_err(|error| {
                    BacktestServerError::Config(format!(
                        "invalid instrument catalog '{path}': {error}"
                    ))
                })?;
                (snapshot, configured_listing_venue)
            }
            None => {
                let listing_venue = configured_listing_venue.unwrap_or_else(|| {
                    ListingVenueId::new(COMPATIBILITY_LISTING_VENUE)
                        .expect("valid built-in compatibility listing venue")
                });
                (
                    compatibility_snapshot(registry, &listing_venue, &config.linear_instruments)?,
                    Some(listing_venue),
                )
            }
        };
        Ok(Self {
            snapshot: Arc::new(snapshot),
            default_listing_venue,
            data_source,
            source_symbols,
        })
    }

    pub fn compatibility(registry: &SymbolRegistry) -> Result<Self> {
        Self::load(&InstrumentsSection::default(), registry)
    }

    pub fn snapshot(&self) -> &InstrumentCatalogSnapshot {
        &self.snapshot
    }

    pub fn data_source(&self) -> &MarketDataSourceId {
        &self.data_source
    }

    pub fn symbol_resolver<'a>(
        &'a self,
        registry: &'a SymbolRegistry,
    ) -> SymbolPartitionResolver<'a> {
        SymbolPartitionResolver::with_source_symbols(registry, &self.source_symbols)
    }

    pub fn resolve_manifest(
        &self,
        symbols: &[String],
        at: NaiveDateTime,
        through: Option<NaiveDateTime>,
    ) -> Result<ReplayInstrumentManifest> {
        let allowed_instruments = self
            .snapshot
            .instrument_ids()
            .cloned()
            .collect::<BTreeSet<_>>();
        let context = InstrumentResolutionContext {
            allowed_instruments,
            default_listing_venue: self.default_listing_venue.clone(),
            default_market_kind: None,
        };
        let at = at.and_utc();
        let through = through.map(|value| value.and_utc());
        let mut instruments = BTreeMap::new();
        for symbol in symbols {
            let selector = InstrumentSelector::Alias {
                alias: InstrumentAlias::new(symbol).map_err(|error| {
                    BacktestServerError::InvalidRequest(format!(
                        "invalid instrument selector for '{symbol}': {error}"
                    ))
                })?,
                listing_venue: None,
                market_kind: None,
            };
            let resolved = self
                .snapshot
                .resolve(&selector, &context, at)
                .map_err(|error| resolution_error(symbol, error, at))?;
            validate_replay_spec(symbol, &resolved.spec)?;
            if let Some(through) = through {
                let end = self
                    .snapshot
                    .resolve(&selector, &context, through)
                    .map_err(|error| resolution_error(symbol, error, through))?;
                if end.reference != resolved.reference {
                    return Err(BacktestServerError::InstrumentUnavailable {
                        symbol: symbol.clone(),
                        reason: InstrumentExclusionReasonMsg::UnsupportedEconomics,
                        details:
                            "instrument changes specification during the requested replay range"
                                .into(),
                    });
                }
            }
            instruments.insert(
                symbol.clone(),
                ReplayInstrumentArtifact {
                    resolved: resolved.reference,
                    spec: resolved.spec.as_ref().clone(),
                },
            );
        }
        Ok(ReplayInstrumentManifest {
            instruments,
            stored_series: Vec::new(),
        })
    }

    pub fn attach_stored_series(
        &self,
        manifest: &mut ReplayInstrumentManifest,
        coordinates: impl IntoIterator<Item = (String, String, String)>,
    ) -> Result<()> {
        let mut bindings = Vec::new();
        for (symbol, source_partition, source_symbol) in coordinates {
            let artifact = manifest.instruments.get(&symbol).ok_or_else(|| {
                BacktestServerError::InvalidRequest(format!(
                    "stored series for '{symbol}' has no resolved instrument"
                ))
            })?;
            bindings.push(StoredSeriesBinding {
                data_source: self.data_source.clone(),
                source_partition,
                source_symbol,
                instrument: artifact.resolved.clone(),
                effective: artifact.spec.effective,
            });
        }
        bindings.sort_by(|left, right| {
            left.source_partition
                .cmp(&right.source_partition)
                .then(left.source_symbol.cmp(&right.source_symbol))
                .then(left.instrument.instrument.cmp(&right.instrument.instrument))
        });
        bindings.dedup();
        manifest.stored_series = bindings;
        Ok(())
    }
}

fn resolution_error(
    symbol: &str,
    error: InstrumentResolutionError,
    at: DateTime<Utc>,
) -> BacktestServerError {
    let details = format!("cannot resolve instrument '{symbol}': {error}");
    match error {
        InstrumentResolutionError::Inactive { .. } => BacktestServerError::InactiveInstrument {
            symbol: symbol.into(),
            at,
            details,
        },
        InstrumentResolutionError::Ambiguous { .. } => BacktestServerError::InstrumentUnavailable {
            symbol: symbol.into(),
            reason: InstrumentExclusionReasonMsg::AmbiguousMapping,
            details,
        },
        _ => BacktestServerError::InstrumentUnavailable {
            symbol: symbol.into(),
            reason: InstrumentExclusionReasonMsg::UnknownInstrument,
            details,
        },
    }
}

fn compatibility_snapshot(
    registry: &SymbolRegistry,
    listing_venue: &ListingVenueId,
    linear_instruments: &[LinearInstrumentConfig],
) -> Result<InstrumentCatalogSnapshot> {
    let effective = EffectiveInterval::new(
        SPEC_VALID_FROM
            .parse::<DateTime<Utc>>()
            .expect("valid built-in instrument epoch"),
        None,
    )
    .expect("valid built-in instrument interval");
    let mut assets = BTreeMap::<AssetId, AssetSpec>::new();
    let mut instruments = Vec::new();
    for (symbol, currencies) in registry.entries() {
        let Ok(economics) = resolve_legacy_economics(symbol) else {
            continue;
        };
        register_assets(&mut assets, symbol, currencies)?;
        let instrument = InstrumentId::new(
            listing_venue.clone(),
            market_kind(symbol)?,
            symbol.canonical.parse().map_err(|error| {
                BacktestServerError::Config(format!(
                    "invalid listing ID for '{}': {error}",
                    symbol.canonical
                ))
            })?,
        );
        instruments.push(
            guarded_instrument_spec(symbol, currencies, economics, instrument, effective)
                .map_err(|error| BacktestServerError::Config(error.to_string()))?,
        );
    }
    let mut configured = BTreeSet::new();
    for rules in linear_instruments {
        let canonical = registry.normalize(&rules.symbol).ok_or_else(|| {
            BacktestServerError::Config(format!("unknown linear instrument '{}'", rules.symbol))
        })?;
        if !configured.insert(canonical.to_owned()) {
            return Err(BacktestServerError::Config(format!(
                "duplicate linear instrument '{canonical}'"
            )));
        }
        let symbol = registry
            .spec(canonical)
            .expect("normalized registered symbol");
        let currencies = registry.currency_metadata(canonical).ok_or_else(|| {
            BacktestServerError::Config(format!("missing currencies for '{canonical}'"))
        })?;
        register_assets(&mut assets, symbol, currencies)?;
        let settlement = AssetId::new(&currencies.pnl_currency)
            .map_err(|error| BacktestServerError::Config(error.to_string()))?;
        let spec = InstrumentSpec {
            revision: "1.0.0"
                .parse()
                .map_err(|error: qs_instruments::IdentifierError| {
                    BacktestServerError::Config(error.to_string())
                })?,
            instrument: InstrumentId::new(
                listing_venue.clone(),
                MarketKind::new(MarketKind::LINEAR_EXPOSURE)
                    .map_err(|error| BacktestServerError::Config(error.to_string()))?,
                canonical
                    .parse()
                    .map_err(|error: qs_instruments::IdentifierError| {
                        BacktestServerError::Config(error.to_string())
                    })?,
            ),
            effective,
            status: ListingStatus::Trading,
            assets: InstrumentAssets {
                base: currencies
                    .base_currency
                    .as_deref()
                    .map(AssetId::new)
                    .transpose()
                    .map_err(|error| BacktestServerError::Config(error.to_string()))?,
                quote: currencies
                    .quote_currency
                    .as_deref()
                    .map(AssetId::new)
                    .transpose()
                    .map_err(|error| BacktestServerError::Config(error.to_string()))?,
                settlement: settlement.clone(),
                fee_assets: BTreeSet::new(),
            },
            price: PriceRules {
                grid: DecimalGrid::new(Decimal::ZERO, rules.price_step),
                display_scale: rules.display_scale,
            },
            quantity: QuantityRules {
                grid: DecimalGrid::new(Decimal::ZERO, rules.quantity_step),
                minimum: rules.minimum,
                maximum: Some(rules.maximum),
                storage_scale: rules
                    .quantity_step
                    .get()
                    .scale()
                    .max(rules.minimum.get().scale())
                    .max(rules.maximum.get().scale()),
            },
            notional: None,
            economics: InstrumentEconomics {
                pnl_model: EconomicsModelId::new(EconomicsModelId::CFD_QUOTE_LINEAR_V1)
                    .map_err(|error| BacktestServerError::Config(error.to_string()))?,
                quantity_unit: QuantityUnit::StandardLot,
                contract_multiplier: rules.contract_multiplier,
                settlement_asset: settlement,
                fee_model: None,
                funding_model: None,
                margin_model: None,
            },
            aliases: BTreeSet::from([InstrumentAlias::new(canonical)
                .map_err(|error| BacktestServerError::Config(error.to_string()))?]),
        };
        spec.validate()
            .map_err(|error| BacktestServerError::Config(error.to_string()))?;
        instruments.retain(|existing| {
            !existing
                .aliases
                .contains(&InstrumentAlias::new(canonical).expect("validated alias"))
        });
        instruments.push(spec);
    }
    InstrumentCatalogSnapshot::compile(CatalogDocument {
        schema_version: CATALOG_SCHEMA_VERSION,
        version: REGISTRY_CATALOG_VERSION.into(),
        assets: assets.into_values().collect(),
        instruments,
    })
    .map_err(|error| BacktestServerError::Config(error.to_string()))
}

fn register_assets(
    assets: &mut BTreeMap<AssetId, AssetSpec>,
    symbol: &SymbolSpec,
    currencies: &SymbolCurrencyMetadata,
) -> Result<()> {
    let values = [
        currencies.base_currency.as_deref(),
        currencies.quote_currency.as_deref(),
        Some(currencies.pnl_currency.as_str()),
    ];
    for value in values.into_iter().flatten() {
        let asset =
            AssetId::new(value).map_err(|error| BacktestServerError::Config(error.to_string()))?;
        let kind = match symbol.category.as_str() {
            "crypto" if currencies.base_currency.as_deref() == Some(value) => AssetKind::Crypto,
            "metal" | "commodity" if currencies.base_currency.as_deref() == Some(value) => {
                AssetKind::Commodity
            }
            _ => AssetKind::Fiat,
        };
        assets.entry(asset.clone()).or_insert(AssetSpec {
            asset,
            kind,
            display_code: value.to_ascii_uppercase(),
            storage_scale: None,
        });
    }
    Ok(())
}

fn market_kind(symbol: &SymbolSpec) -> Result<MarketKind> {
    let kind = match symbol.category.as_str() {
        "forex" => MarketKind::FX_CFD,
        "metal" => MarketKind::METAL_CFD,
        "commodity" => MarketKind::COMMODITY_CFD,
        "index" => MarketKind::INDEX_CFD,
        category => {
            return Err(BacktestServerError::Config(format!(
                "unsupported registry category '{category}' for {}",
                symbol.canonical
            )));
        }
    };
    MarketKind::new(kind).map_err(|error| BacktestServerError::Config(error.to_string()))
}

fn validate_replay_spec(symbol: &str, spec: &qs_instruments::InstrumentSpec) -> Result<()> {
    if spec.status != ListingStatus::Trading {
        return Err(BacktestServerError::InstrumentUnavailable {
            symbol: symbol.into(),
            reason: InstrumentExclusionReasonMsg::UnsupportedEconomics,
            details: "instrument is not in trading status".into(),
        });
    }
    if spec.economics.quantity_unit != QuantityUnit::StandardLot {
        return Err(BacktestServerError::InstrumentUnavailable {
            symbol: symbol.into(),
            reason: InstrumentExclusionReasonMsg::UnsupportedEconomics,
            details: "unsupported quantity unit".into(),
        });
    }
    let model = spec.economics.pnl_model.as_str();
    if model != EconomicsModelId::FX_QUOTE_LINEAR_V1
        && model != EconomicsModelId::CFD_QUOTE_LINEAR_V1
    {
        return Err(BacktestServerError::InstrumentUnavailable {
            symbol: symbol.into(),
            reason: InstrumentExclusionReasonMsg::UnsupportedEconomics,
            details: format!("unsupported P&L model: {model}"),
        });
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use std::collections::BTreeSet;
    use std::time::{SystemTime, UNIX_EPOCH};

    use qs_instruments::{
        Decimal, DecimalGrid, InstrumentAssets, InstrumentEconomics, InstrumentSpec, PriceRules,
        QuantityRules,
    };

    use super::*;

    fn registry() -> SymbolRegistry {
        SymbolRegistry::from_toml(
            r#"
[[symbol]]
canonical = "eurusd"
aliases = ["eur/usd"]
pip_position = 4
digits = 5
category = "forex"
base_currency = "EUR"
quote_currency = "USD"
pnl_currency = "USD"
lot_base_units = 100000
lot_step_units = 1000

[[symbol]]
canonical = "btcusd"
aliases = ["btc/usd"]
pip_position = 1
digits = 2
category = "crypto"
base_currency = "BTC"
quote_currency = "USD"
pnl_currency = "USD"
lot_base_units = 100000000
lot_step_units = 100000
"#,
        )
        .unwrap()
    }

    #[test]
    fn compatibility_catalog_uses_owned_listing_namespace_not_data_platform() {
        let domain = InstrumentDomain::compatibility(&registry()).unwrap();
        let manifest = domain
            .resolve_manifest(
                &["eurusd".into()],
                "2026-01-01T00:00:00".parse().unwrap(),
                None,
            )
            .unwrap();
        let instrument = &manifest.instruments["eurusd"].resolved.instrument;
        assert_eq!(instrument.listing_venue.as_str(), "repository-default");
        assert_ne!(instrument.listing_venue.as_str(), "ctrader");
        assert_eq!(instrument.market_kind.as_str(), MarketKind::FX_CFD);
    }

    #[test]
    fn unsupported_registry_rows_do_not_enter_the_compatibility_catalog() {
        let domain = InstrumentDomain::compatibility(&registry()).unwrap();
        let error = domain
            .resolve_manifest(
                &["btcusd".into()],
                "2026-01-01T00:00:00".parse().unwrap(),
                None,
            )
            .unwrap_err();
        assert!(error.to_string().contains("cannot resolve instrument"));
    }

    #[test]
    fn explicit_catalog_loader_preserves_broker_listing_and_rejects_unknown_fields() {
        let usd: AssetId = "USD".parse().unwrap();
        let document = CatalogDocument {
            schema_version: 1,
            version: "broker-catalog-1".into(),
            assets: vec![
                AssetSpec {
                    asset: "EUR".parse().unwrap(),
                    kind: AssetKind::Fiat,
                    display_code: "EUR".into(),
                    storage_scale: Some(2),
                },
                AssetSpec {
                    asset: usd.clone(),
                    kind: AssetKind::Fiat,
                    display_code: "USD".into(),
                    storage_scale: Some(2),
                },
            ],
            instruments: vec![InstrumentSpec {
                revision: "1.0.0".parse().unwrap(),
                instrument: InstrumentId::new(
                    "ic-markets".parse().unwrap(),
                    MarketKind::new(MarketKind::FX_CFD).unwrap(),
                    "EURUSD".parse().unwrap(),
                ),
                effective: EffectiveInterval::new("2026-01-01T00:00:00Z".parse().unwrap(), None)
                    .unwrap(),
                status: ListingStatus::Trading,
                assets: InstrumentAssets {
                    base: Some("EUR".parse().unwrap()),
                    quote: Some(usd.clone()),
                    settlement: usd.clone(),
                    fee_assets: BTreeSet::new(),
                },
                price: PriceRules {
                    grid: DecimalGrid::new(Decimal::ZERO, "0.00001".parse().unwrap()),
                    display_scale: 5,
                },
                quantity: QuantityRules {
                    grid: DecimalGrid::new(Decimal::ZERO, "0.01".parse().unwrap()),
                    minimum: "0.01".parse().unwrap(),
                    maximum: Some("100".parse().unwrap()),
                    storage_scale: 2,
                },
                notional: None,
                economics: InstrumentEconomics {
                    pnl_model: EconomicsModelId::new(EconomicsModelId::FX_QUOTE_LINEAR_V1).unwrap(),
                    quantity_unit: QuantityUnit::StandardLot,
                    contract_multiplier: "100000".parse().unwrap(),
                    settlement_asset: usd,
                    fee_model: None,
                    funding_model: None,
                    margin_model: None,
                },
                aliases: BTreeSet::from(["EURUSD".parse().unwrap()]),
            }],
        };
        let unique = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos();
        let path = std::env::temp_dir().join(format!(
            "qs_instrument_catalog_{}_{}.toml",
            std::process::id(),
            unique
        ));
        let content = toml::to_string(&document).unwrap();
        fs::write(&path, &content).unwrap();
        let config = InstrumentsSection {
            catalog_path: Some(path.to_string_lossy().into_owned()),
            default_listing_venue: None,
            market_data_source: "test-parquet".into(),
            ..InstrumentsSection::default()
        };

        let domain = InstrumentDomain::load(&config, &registry()).unwrap();
        let manifest = domain
            .resolve_manifest(
                &["eurusd".into()],
                "2026-02-01T00:00:00".parse().unwrap(),
                None,
            )
            .unwrap();
        let instrument = &manifest.instruments["eurusd"].resolved.instrument;
        assert_eq!(instrument.listing_venue.as_str(), "ic-markets");
        assert_ne!(instrument.listing_venue.as_str(), "ctrader");

        fs::write(&path, format!("unexpected = true\n{content}")).unwrap();
        let error = match InstrumentDomain::load(&config, &registry()) {
            Ok(_) => panic!("catalog with an unknown field must be rejected"),
            Err(error) => error,
        };
        assert!(error.to_string().contains("unknown field"));
        fs::remove_file(path).unwrap();
    }
}