85 lines
2.7 KiB
Dart
85 lines
2.7 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;
|
|
|
|
/// Pair ticker, e.g. FO/USDT.
|
|
String get pairSymbol => '$symbol/$quoteCurrency';
|
|
|
|
/// Header line, e.g. FO/USDT — Full Option.
|
|
String get chartTitle => '$pairSymbol — $displayName';
|
|
|
|
/// Price subtitle, e.g. FO/USDT — 105.50.
|
|
String priceLabel(double price) =>
|
|
'$pairSymbol — ${price.toStringAsFixed(priceDigits)}';
|
|
|
|
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;
|