games_app/prediqo_mobile/lib/data/models/candle_predict_instrument.dart
2026-11-09 18:14:42 +02:00

88 lines
2.8 KiB
Dart

/// Synthetic chart instrument for Candle Predict (display identity only).
///
/// OHLC always comes from the Tloto backend — never from an external market.
/// Runtime values come from game config and are edited in web Catalog → Candle.
class CandlePredictInstrument {
const CandlePredictInstrument({
required this.id,
required this.symbol,
required this.displayName,
required this.quoteCurrency,
this.instrumentType = 'SYNTHETIC',
this.priceDigits = 2,
});
/// Stable internal key (not shown on the chart).
final String id;
/// Short ticker, e.g. FO.
final String symbol;
/// Human-readable name, e.g. Full Option.
final String displayName;
/// Quote unit for the price, e.g. USDT.
final String quoteCurrency;
final String instrumentType;
/// Decimal places for price labels on the chart.
final int priceDigits;
/// Short pair ticker, e.g. FO / USDT.
String get shortPairSymbol => '$symbol / $quoteCurrency';
/// Pair ticker shown as chart title, e.g. FO (Full Option) / USDT.
String get pairSymbol => '$symbol ($displayName) / $quoteCurrency';
/// Header / semantics label for the chart instrument.
String get chartTitle => pairSymbol;
/// Price subtitle with trillion unit, e.g. FO / USDT — 105.50T.
String priceLabel(double price) =>
'$shortPairSymbol — ${price.toStringAsFixed(priceDigits)}T';
factory CandlePredictInstrument.fromJson(Map<String, dynamic>? json) {
if (json == null) return defaultCandlePredictInstrument;
final digits = (json['priceDigits'] as num?)?.toInt();
return defaultCandlePredictInstrument.copyWith(
symbol: (json['symbol'] as String?)?.trim(),
displayName: (json['displayName'] as String?)?.trim(),
quoteCurrency: (json['quoteCurrency'] as String?)?.trim(),
priceDigits: digits == null ? null : digits.clamp(0, 8),
);
}
CandlePredictInstrument copyWith({
String? id,
String? symbol,
String? displayName,
String? quoteCurrency,
String? instrumentType,
int? priceDigits,
}) {
return CandlePredictInstrument(
id: id ?? this.id,
symbol: (symbol == null || symbol.isEmpty) ? this.symbol : symbol,
displayName:
(displayName == null || displayName.isEmpty) ? this.displayName : displayName,
quoteCurrency: (quoteCurrency == null || quoteCurrency.isEmpty)
? this.quoteCurrency
: quoteCurrency,
instrumentType: instrumentType ?? this.instrumentType,
priceDigits: priceDigits ?? this.priceDigits,
);
}
}
/// Fallback branding when API config has not loaded yet.
const defaultCandlePredictInstrument = CandlePredictInstrument(
id: 'fo',
symbol: 'FO',
displayName: 'Full Option',
quoteCurrency: 'USDT',
);
/// @deprecated Prefer [defaultCandlePredictInstrument] or config.instrument.
const candlePredictInstrument = defaultCandlePredictInstrument;