510 lines
16 KiB
Dart
510 lines
16 KiB
Dart
/// Candle Predict game models parsed from API responses.
|
|
|
|
class GameStateModel {
|
|
const GameStateModel({
|
|
required this.config,
|
|
required this.intervals,
|
|
required this.selectedIntervalMinutes,
|
|
required this.interval,
|
|
this.round,
|
|
this.userBet,
|
|
this.userMultiBet,
|
|
this.multiLevels = const [],
|
|
this.autoSettings,
|
|
});
|
|
|
|
final PredictConfigModel config;
|
|
final List<IntervalModel> intervals;
|
|
final int selectedIntervalMinutes;
|
|
final IntervalModel interval;
|
|
final RoundModel? round;
|
|
final PredictionModel? userBet;
|
|
final MultiCandlePredictionModel? userMultiBet;
|
|
final List<MultiLevelModel> multiLevels;
|
|
final AutoSettingsModel? autoSettings;
|
|
|
|
GameStateModel copyWith({
|
|
PredictConfigModel? config,
|
|
List<IntervalModel>? intervals,
|
|
int? selectedIntervalMinutes,
|
|
IntervalModel? interval,
|
|
RoundModel? round,
|
|
PredictionModel? userBet,
|
|
MultiCandlePredictionModel? userMultiBet,
|
|
List<MultiLevelModel>? multiLevels,
|
|
AutoSettingsModel? autoSettings,
|
|
bool clearRound = false,
|
|
bool clearUserBet = false,
|
|
bool clearUserMultiBet = false,
|
|
}) {
|
|
return GameStateModel(
|
|
config: config ?? this.config,
|
|
intervals: intervals ?? this.intervals,
|
|
selectedIntervalMinutes:
|
|
selectedIntervalMinutes ?? this.selectedIntervalMinutes,
|
|
interval: interval ?? this.interval,
|
|
round: clearRound ? null : (round ?? this.round),
|
|
userBet: clearUserBet ? null : (userBet ?? this.userBet),
|
|
userMultiBet: clearUserMultiBet
|
|
? null
|
|
: (userMultiBet ?? this.userMultiBet),
|
|
multiLevels: multiLevels ?? this.multiLevels,
|
|
autoSettings: autoSettings ?? this.autoSettings,
|
|
);
|
|
}
|
|
|
|
factory GameStateModel.fromJson(Map<String, dynamic> json) => GameStateModel(
|
|
config: PredictConfigModel.fromJson(json['config'] as Map<String, dynamic>),
|
|
intervals: (json['intervals'] as List<dynamic>? ?? [])
|
|
.map((e) => IntervalModel.fromJson(e as Map<String, dynamic>))
|
|
.toList(),
|
|
selectedIntervalMinutes:
|
|
(json['selectedIntervalMinutes'] as num?)?.toInt() ?? 1,
|
|
interval: IntervalModel.fromJson(json['interval'] as Map<String, dynamic>),
|
|
round: json['round'] != null
|
|
? RoundModel.fromJson(json['round'] as Map<String, dynamic>)
|
|
: null,
|
|
userBet: json['userBet'] != null
|
|
? PredictionModel.fromJson(json['userBet'] as Map<String, dynamic>)
|
|
: null,
|
|
userMultiBet: json['userMultiBet'] != null
|
|
? MultiCandlePredictionModel.fromJson(
|
|
json['userMultiBet'] as Map<String, dynamic>,
|
|
)
|
|
: null,
|
|
multiLevels: (json['multiLevels'] as List<dynamic>? ?? [])
|
|
.map((e) => MultiLevelModel.fromJson(e as Map<String, dynamic>))
|
|
.where((l) => l.enabled)
|
|
.toList(),
|
|
autoSettings: json['autoSettings'] != null
|
|
? AutoSettingsModel.fromJson(
|
|
json['autoSettings'] as Map<String, dynamic>,
|
|
)
|
|
: null,
|
|
);
|
|
}
|
|
|
|
class PredictConfigModel {
|
|
const PredictConfigModel({
|
|
required this.stakeAmounts,
|
|
required this.minStakeAmount,
|
|
required this.maxStakeAmount,
|
|
required this.payoutMultiplier,
|
|
required this.predictionWindowSeconds,
|
|
required this.isActive,
|
|
this.walletTypeCode = 'USDT_TRC20',
|
|
this.predictionTypes = const PredictionTypesModel(),
|
|
this.autoModes = const ['each_round'],
|
|
});
|
|
|
|
final List<double> stakeAmounts;
|
|
final double minStakeAmount;
|
|
final double maxStakeAmount;
|
|
final double payoutMultiplier;
|
|
final int predictionWindowSeconds;
|
|
final bool isActive;
|
|
final String walletTypeCode;
|
|
final PredictionTypesModel predictionTypes;
|
|
final List<String> autoModes;
|
|
|
|
factory PredictConfigModel.fromJson(Map<String, dynamic> json) =>
|
|
PredictConfigModel(
|
|
stakeAmounts: (json['stakeAmounts'] as List<dynamic>? ?? [])
|
|
.map((e) => (e as num).toDouble())
|
|
.toList(),
|
|
minStakeAmount: (json['minStakeAmount'] as num?)?.toDouble() ?? 1,
|
|
maxStakeAmount: (json['maxStakeAmount'] as num?)?.toDouble() ?? 1000,
|
|
payoutMultiplier: (json['payoutMultiplier'] as num?)?.toDouble() ?? 1.8,
|
|
predictionWindowSeconds:
|
|
(json['predictionWindowSeconds'] as num?)?.toInt() ?? 30,
|
|
isActive: json['isActive'] != false,
|
|
walletTypeCode: (json['walletTypeCode'] ?? 'USDT_TRC20').toString(),
|
|
predictionTypes: json['predictionTypes'] != null
|
|
? PredictionTypesModel.fromJson(
|
|
json['predictionTypes'] as Map<String, dynamic>,
|
|
)
|
|
: const PredictionTypesModel(),
|
|
autoModes: (json['autoModes'] as List<dynamic>? ?? ['each_round'])
|
|
.map((e) => e.toString())
|
|
.toList(),
|
|
);
|
|
}
|
|
|
|
class PredictionTypesModel {
|
|
const PredictionTypesModel({
|
|
this.single = true,
|
|
this.auto = true,
|
|
this.multiCandle = true,
|
|
});
|
|
|
|
final bool single;
|
|
final bool auto;
|
|
final bool multiCandle;
|
|
|
|
factory PredictionTypesModel.fromJson(Map<String, dynamic> json) =>
|
|
PredictionTypesModel(
|
|
single: json['single'] != false,
|
|
auto: json['auto'] != false,
|
|
multiCandle: json['multiCandle'] != false,
|
|
);
|
|
}
|
|
|
|
class IntervalModel {
|
|
const IntervalModel({
|
|
required this.id,
|
|
required this.intervalMinutes,
|
|
required this.label,
|
|
required this.isDefault,
|
|
required this.isActive,
|
|
required this.payoutMultiplier,
|
|
this.chartCandleLimit = 80,
|
|
});
|
|
|
|
final int id;
|
|
final int intervalMinutes;
|
|
final String label;
|
|
final bool isDefault;
|
|
final bool isActive;
|
|
final double payoutMultiplier;
|
|
final int chartCandleLimit;
|
|
|
|
factory IntervalModel.fromJson(Map<String, dynamic> json) => IntervalModel(
|
|
id: (json['id'] as num).toInt(),
|
|
intervalMinutes: (json['intervalMinutes'] as num).toInt(),
|
|
label: (json['label'] ?? '${json['intervalMinutes']}m').toString(),
|
|
isDefault: json['isDefault'] == true,
|
|
isActive: json['isActive'] != false,
|
|
payoutMultiplier: (json['payoutMultiplier'] as num?)?.toDouble() ?? 1.8,
|
|
chartCandleLimit: (json['chartCandleLimit'] as num?)?.toInt() ?? 80,
|
|
);
|
|
}
|
|
|
|
class RoundModel {
|
|
const RoundModel({
|
|
required this.id,
|
|
required this.status,
|
|
required this.secondsToBettingEnd,
|
|
required this.secondsToBettingStart,
|
|
required this.secondsToClose,
|
|
this.outcome,
|
|
this.shortPoolPercent,
|
|
this.longPoolPercent,
|
|
this.serverNowMs,
|
|
this.bettingEndMs,
|
|
this.bettingStartMs,
|
|
});
|
|
|
|
final String id;
|
|
final String status;
|
|
final int secondsToBettingEnd;
|
|
final int secondsToBettingStart;
|
|
final int secondsToClose;
|
|
final String? outcome;
|
|
final double? shortPoolPercent;
|
|
final double? longPoolPercent;
|
|
final int? serverNowMs;
|
|
|
|
/// Absolute ms when the open (betting) window ends — preferred for smooth countdown.
|
|
final int? bettingEndMs;
|
|
final int? bettingStartMs;
|
|
|
|
bool get isBetting => status == 'betting';
|
|
|
|
factory RoundModel.fromJson(Map<String, dynamic> json) => RoundModel(
|
|
id: json['id'] as String,
|
|
status: (json['status'] ?? 'waiting').toString(),
|
|
secondsToBettingEnd: (json['secondsToBettingEnd'] as num?)?.toInt() ?? 0,
|
|
secondsToBettingStart:
|
|
(json['secondsToBettingStart'] as num?)?.toInt() ?? 0,
|
|
secondsToClose: (json['secondsToClose'] as num?)?.toInt() ?? 0,
|
|
outcome: json['outcome'] as String?,
|
|
shortPoolPercent: (json['shortPoolPercent'] as num?)?.toDouble(),
|
|
longPoolPercent: (json['longPoolPercent'] as num?)?.toDouble(),
|
|
serverNowMs: (json['serverNowMs'] as num?)?.toInt(),
|
|
bettingEndMs: (json['bettingEndMs'] as num?)?.toInt(),
|
|
bettingStartMs: (json['bettingStartMs'] as num?)?.toInt(),
|
|
);
|
|
}
|
|
|
|
class PredictionModel {
|
|
const PredictionModel({
|
|
required this.id,
|
|
required this.direction,
|
|
required this.stakeDisplay,
|
|
required this.status,
|
|
required this.payoutDisplay,
|
|
required this.createdAt,
|
|
this.roundId,
|
|
this.stakeAccountKind = 'main',
|
|
this.isAuto = false,
|
|
this.predictionMode = 'single',
|
|
this.level,
|
|
this.sequenceDirections = const [],
|
|
this.sequenceStep = 0,
|
|
this.intervalMinutes = 1,
|
|
});
|
|
|
|
final String id;
|
|
final String direction;
|
|
final double stakeDisplay;
|
|
final String status;
|
|
final double payoutDisplay;
|
|
final String createdAt;
|
|
final String? roundId;
|
|
final String stakeAccountKind;
|
|
final bool isAuto;
|
|
final String predictionMode;
|
|
final int? level;
|
|
final List<String> sequenceDirections;
|
|
final int sequenceStep;
|
|
final int intervalMinutes;
|
|
|
|
bool get isMulti =>
|
|
predictionMode == 'multi_candle' ||
|
|
(sequenceDirections.length > 1 && (level ?? 0) > 1);
|
|
|
|
/// Whether this bet belongs to the currently displayed round.
|
|
bool belongsToRound(RoundModel? round) {
|
|
if (round == null) return false;
|
|
final rid = roundId;
|
|
if (rid == null || rid.isEmpty) return false;
|
|
return rid == round.id;
|
|
}
|
|
|
|
factory PredictionModel.fromJson(Map<String, dynamic> json) =>
|
|
PredictionModel(
|
|
id: json['id'] as String,
|
|
direction: (json['direction'] ?? 'long').toString(),
|
|
stakeDisplay: (json['stakeDisplay'] as num?)?.toDouble() ?? 0,
|
|
status: (json['status'] ?? 'pending').toString(),
|
|
payoutDisplay: (json['payoutDisplay'] as num?)?.toDouble() ?? 0,
|
|
createdAt: (json['createdAt'] ?? '').toString(),
|
|
roundId: json['roundId']?.toString(),
|
|
stakeAccountKind: (json['stakeAccountKind'] ?? 'main').toString(),
|
|
isAuto: json['isAuto'] == true,
|
|
predictionMode: (json['predictionMode'] ?? 'single').toString(),
|
|
level: (json['level'] as num?)?.toInt(),
|
|
sequenceDirections: (json['sequenceDirections'] as List<dynamic>? ?? [])
|
|
.map((e) => e.toString())
|
|
.toList(),
|
|
sequenceStep: (json['sequenceStep'] as num?)?.toInt() ?? 0,
|
|
intervalMinutes: (json['intervalMinutes'] as num?)?.toInt() ?? 1,
|
|
);
|
|
}
|
|
|
|
class MultiCandlePredictionModel {
|
|
const MultiCandlePredictionModel({
|
|
required this.id,
|
|
required this.level,
|
|
required this.sequenceDirections,
|
|
required this.sequenceStep,
|
|
required this.stakeDisplay,
|
|
required this.status,
|
|
required this.payoutDisplay,
|
|
required this.intervalMinutes,
|
|
this.stakeAccountKind = 'main',
|
|
});
|
|
|
|
final String id;
|
|
final int level;
|
|
final List<String> sequenceDirections;
|
|
final int sequenceStep;
|
|
final double stakeDisplay;
|
|
final String status;
|
|
final double payoutDisplay;
|
|
final int intervalMinutes;
|
|
final String stakeAccountKind;
|
|
|
|
factory MultiCandlePredictionModel.fromJson(Map<String, dynamic> json) =>
|
|
MultiCandlePredictionModel(
|
|
id: json['id'] as String,
|
|
level: (json['level'] as num?)?.toInt() ?? 0,
|
|
sequenceDirections: (json['sequenceDirections'] as List<dynamic>? ?? [])
|
|
.map((e) => e.toString())
|
|
.toList(),
|
|
sequenceStep: (json['sequenceStep'] as num?)?.toInt() ?? 0,
|
|
stakeDisplay: (json['stakeDisplay'] as num?)?.toDouble() ?? 0,
|
|
status: (json['status'] ?? 'pending').toString(),
|
|
payoutDisplay: (json['payoutDisplay'] as num?)?.toDouble() ?? 0,
|
|
intervalMinutes: (json['intervalMinutes'] as num?)?.toInt() ?? 1,
|
|
stakeAccountKind: (json['stakeAccountKind'] ?? 'main').toString(),
|
|
);
|
|
}
|
|
|
|
class MultiLevelModel {
|
|
const MultiLevelModel({
|
|
required this.level,
|
|
required this.candleCount,
|
|
required this.enabled,
|
|
required this.payoutMultiplier,
|
|
});
|
|
|
|
final int level;
|
|
final int candleCount;
|
|
final bool enabled;
|
|
final double payoutMultiplier;
|
|
|
|
factory MultiLevelModel.fromJson(Map<String, dynamic> json) =>
|
|
MultiLevelModel(
|
|
level: (json['level'] as num).toInt(),
|
|
candleCount:
|
|
(json['candleCount'] as num?)?.toInt() ??
|
|
(json['level'] as num).toInt(),
|
|
enabled: json['enabled'] != false,
|
|
payoutMultiplier: (json['payoutMultiplier'] as num?)?.toDouble() ?? 1.8,
|
|
);
|
|
}
|
|
|
|
class AutoSettingsModel {
|
|
const AutoSettingsModel({
|
|
required this.enabled,
|
|
this.direction,
|
|
this.stakeDisplay = 0,
|
|
this.mode = 'each_round',
|
|
this.periodMinutes = 1,
|
|
this.stakeAccountKind = 'main',
|
|
this.intervalSeconds,
|
|
this.lastAutoBetAt,
|
|
this.autoBetPlaced = false,
|
|
this.autoBetError,
|
|
});
|
|
|
|
final bool enabled;
|
|
final String? direction;
|
|
final double stakeDisplay;
|
|
final String mode;
|
|
final int periodMinutes;
|
|
final String stakeAccountKind;
|
|
final int? intervalSeconds;
|
|
final String? lastAutoBetAt;
|
|
final bool autoBetPlaced;
|
|
final String? autoBetError;
|
|
|
|
factory AutoSettingsModel.fromJson(Map<String, dynamic> json) =>
|
|
AutoSettingsModel(
|
|
enabled: json['enabled'] == true,
|
|
direction: json['direction'] as String?,
|
|
stakeDisplay: (json['stakeDisplay'] as num?)?.toDouble() ?? 0,
|
|
mode: (json['mode'] ?? 'each_round').toString(),
|
|
periodMinutes: (json['periodMinutes'] as num?)?.toInt() ?? 1,
|
|
stakeAccountKind: (json['stakeAccountKind'] ?? 'main').toString(),
|
|
intervalSeconds: (json['intervalSeconds'] as num?)?.toInt(),
|
|
lastAutoBetAt: json['lastAutoBetAt'] as String?,
|
|
autoBetPlaced: json['autoBetPlaced'] == true,
|
|
autoBetError: json['autoBetError'] as String?,
|
|
);
|
|
|
|
Map<String, dynamic> toSaveJson({
|
|
required bool enabled,
|
|
String? direction,
|
|
required double stakeAmount,
|
|
required String mode,
|
|
required int periodMinutes,
|
|
required String stakeAccountKind,
|
|
int? intervalSeconds,
|
|
bool attemptImmediateBet = true,
|
|
bool validateWalletBalance = true,
|
|
}) => {
|
|
'enabled': enabled,
|
|
'direction': direction,
|
|
'stakeDisplay': stakeAmount,
|
|
'stakeAmount': stakeAmount,
|
|
'mode': mode,
|
|
'periodMinutes': periodMinutes,
|
|
'stakeAccountKind': stakeAccountKind,
|
|
if (intervalSeconds != null) 'intervalSeconds': intervalSeconds,
|
|
'attemptImmediateBet': attemptImmediateBet,
|
|
'validateWalletBalance': validateWalletBalance,
|
|
};
|
|
}
|
|
|
|
class OhlcCandleModel {
|
|
const OhlcCandleModel({
|
|
required this.time,
|
|
required this.open,
|
|
required this.high,
|
|
required this.low,
|
|
required this.close,
|
|
this.candleOpenMs,
|
|
});
|
|
|
|
/// Unix seconds (chart axis).
|
|
final int time;
|
|
final double open;
|
|
final double high;
|
|
final double low;
|
|
final double close;
|
|
|
|
/// Absolute open timestamp in ms — required for paginated `beforeOpenMs` queries.
|
|
final int? candleOpenMs;
|
|
|
|
bool get isGreen => close >= open;
|
|
|
|
int get openMs => candleOpenMs ?? time * 1000;
|
|
|
|
factory OhlcCandleModel.fromJson(Map<String, dynamic> json) =>
|
|
OhlcCandleModel(
|
|
time: (json['time'] as num?)?.toInt() ?? 0,
|
|
open: (json['open'] as num?)?.toDouble() ?? 0,
|
|
high: (json['high'] as num?)?.toDouble() ?? 0,
|
|
low: (json['low'] as num?)?.toDouble() ?? 0,
|
|
close: (json['close'] as num?)?.toDouble() ?? 0,
|
|
candleOpenMs: (json['candleOpenMs'] as num?)?.toInt(),
|
|
);
|
|
}
|
|
|
|
class CandlesPageModel {
|
|
const CandlesPageModel({
|
|
required this.items,
|
|
required this.hasMore,
|
|
this.pageSize = 80,
|
|
});
|
|
|
|
final List<OhlcCandleModel> items;
|
|
final bool hasMore;
|
|
final int pageSize;
|
|
|
|
factory CandlesPageModel.fromJson(Map<String, dynamic> json) {
|
|
final items = (json['items'] as List<dynamic>? ?? [])
|
|
.map((e) => OhlcCandleModel.fromJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
return CandlesPageModel(
|
|
items: items,
|
|
hasMore: json['hasMore'] == true,
|
|
pageSize: (json['pageSize'] as num?)?.toInt() ?? items.length,
|
|
);
|
|
}
|
|
}
|
|
|
|
class PredictionsPageModel {
|
|
const PredictionsPageModel({
|
|
required this.items,
|
|
required this.total,
|
|
required this.page,
|
|
required this.totalPages,
|
|
});
|
|
|
|
final List<PredictionModel> items;
|
|
final int total;
|
|
final int page;
|
|
final int totalPages;
|
|
|
|
factory PredictionsPageModel.fromJson(Map<String, dynamic> json) =>
|
|
PredictionsPageModel(
|
|
items: (json['items'] as List<dynamic>? ?? [])
|
|
.map((e) => PredictionModel.fromJson(e as Map<String, dynamic>))
|
|
.toList(),
|
|
total: (json['total'] as num?)?.toInt() ?? 0,
|
|
page: (json['page'] as num?)?.toInt() ?? 1,
|
|
totalPages: (json['totalPages'] as num?)?.toInt() ?? 1,
|
|
);
|
|
}
|
|
|
|
enum PredictionPlayMode { single, multi, auto }
|
|
|
|
enum StakeAccountKind { main, bonus, test }
|
|
|
|
extension StakeAccountKindX on StakeAccountKind {
|
|
String get apiValue => name;
|
|
}
|