feat(app): add evaluation history, bot control panel, simulation visualizer, and vendored signalr_core
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
import '../models/bot_models.dart';
|
||||
|
||||
class BotKpiHeader extends StatelessWidget {
|
||||
final AccountSummaryModel summary;
|
||||
final BotStatusModel status;
|
||||
final double totalUnrealizedPnL;
|
||||
final double totalRealizedPnL;
|
||||
|
||||
const BotKpiHeader({
|
||||
super.key,
|
||||
required this.summary,
|
||||
required this.status,
|
||||
required this.totalUnrealizedPnL,
|
||||
required this.totalRealizedPnL,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isPositiveUnrealized = totalUnrealizedPnL >= 0;
|
||||
final isPositiveRealized = totalRealizedPnL >= 0;
|
||||
|
||||
return GlassContainer(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: status.isRunning ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: (status.isRunning ? AppTheme.primaryEmerald : AppTheme.accentRed).withValues(alpha: 0.5),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
status.isRunning ? 'AUTONOMOUS BOT ONLINE' : 'BOT PAUSED',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1.2,
|
||||
color: status.isRunning ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: status.autoExecutionEnabled ? AppTheme.primaryEmerald.withValues(alpha: 0.15) : Colors.amber.withValues(alpha: 0.15),
|
||||
border: Border.all(
|
||||
color: status.autoExecutionEnabled ? AppTheme.primaryEmerald : Colors.amber,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
status.autoExecutionEnabled ? 'AUTO-EXECUTE ON' : 'MANUAL APPROVAL',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: status.autoExecutionEnabled ? AppTheme.primaryEmerald : Colors.amber,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: summary.hasAccountData
|
||||
? _buildMetricCard(
|
||||
title: 'Portfolio Equity',
|
||||
value: '€${summary.equity!.toStringAsFixed(2)}',
|
||||
subtitle: 'Buying Power: €${summary.buyingPower!.toStringAsFixed(0)}',
|
||||
valueColor: Colors.white,
|
||||
)
|
||||
: _buildUnavailableMetricCard('Portfolio Equity'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildMetricCard(
|
||||
title: 'Unrealized PnL',
|
||||
value: '${isPositiveUnrealized ? '+' : ''}€${totalUnrealizedPnL.toStringAsFixed(2)}',
|
||||
subtitle: 'Realized: ${isPositiveRealized ? '+' : ''}€${totalRealizedPnL.toStringAsFixed(2)}',
|
||||
valueColor: isPositiveUnrealized ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUnavailableMetricCard(String title) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.white.withValues(alpha: 0.03),
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.06)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: TextStyle(color: AppTheme.textMuted, fontSize: 11)),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 14, color: AppTheme.textMuted),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Portfoliodaten nicht verfügbar',
|
||||
style: TextStyle(color: AppTheme.textMuted, fontSize: 12, fontWeight: FontWeight.w600),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMetricCard({
|
||||
required String title,
|
||||
required String value,
|
||||
required String subtitle,
|
||||
required Color valueColor,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.white.withValues(alpha: 0.03),
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.06)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: TextStyle(color: AppTheme.textMuted, fontSize: 11)),
|
||||
const SizedBox(height: 4),
|
||||
Text(value, style: TextStyle(color: valueColor, fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
Text(subtitle, style: TextStyle(color: AppTheme.textMuted, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/widgets/asset_logo_widget.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
import '../models/bot_models.dart';
|
||||
|
||||
class BotPositionCard extends StatelessWidget {
|
||||
final BotTradeOrderModel position;
|
||||
final VoidCallback? onClosePressed;
|
||||
|
||||
const BotPositionCard({
|
||||
super.key,
|
||||
required this.position,
|
||||
this.onClosePressed,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isLong = position.isLong;
|
||||
final isProfitable = position.unrealizedPnlEur >= 0;
|
||||
final pnlPercent = position.pnlPercent;
|
||||
final rMult = position.rMultiple;
|
||||
|
||||
return GlassContainer(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
AssetLogoWidget(
|
||||
symbolOrName: position.symbol.isNotEmpty ? position.symbol : position.isin,
|
||||
imageUrl: '/api/v1/logo/${position.isin}',
|
||||
size: 36,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
position.symbol,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: isLong ? AppTheme.primaryEmerald.withValues(alpha: 0.2) : AppTheme.accentRed.withValues(alpha: 0.2),
|
||||
),
|
||||
child: Text(
|
||||
position.direction.toUpperCase(),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isLong ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
_buildVenueBadge(position.venue),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
position.isin,
|
||||
style: TextStyle(color: AppTheme.textMuted, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${isProfitable ? '+' : ''}€${position.unrealizedPnlEur.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isProfitable ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${isProfitable ? '+' : ''}${pnlPercent.toStringAsFixed(2)}% (${rMult >= 0 ? '+' : ''}${rMult.toStringAsFixed(1)}R)',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isProfitable ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Divider(height: 1, color: Colors.white10),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildPriceInfo('Entry / Buy-In', '€${position.averageBuyIn > 0 ? position.averageBuyIn.toStringAsFixed(2) : position.entryPrice.toStringAsFixed(2)}'),
|
||||
_buildPriceInfo('Current Price', '€${position.currentPrice.toStringAsFixed(2)}'),
|
||||
_buildPriceInfo('Stop Loss', '€${position.currentStopLoss.toStringAsFixed(2)}'),
|
||||
_buildPriceInfo('Take Profit 1', '€${position.takeProfit1.toStringAsFixed(2)}'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildDynamicStateBadge(position),
|
||||
if (position.isActive && onClosePressed != null)
|
||||
TextButton.icon(
|
||||
onPressed: onClosePressed,
|
||||
icon: Icon(Icons.close, size: 14, color: AppTheme.accentRed),
|
||||
label: Text('Glattstellen', style: TextStyle(fontSize: 12, color: AppTheme.accentRed)),
|
||||
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPriceInfo(String label, String value) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: TextStyle(color: AppTheme.textMuted, fontSize: 10)),
|
||||
const SizedBox(height: 2),
|
||||
Text(value, style: const TextStyle(color: Colors.white70, fontSize: 12, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildVenueBadge(String venue) {
|
||||
final isAlpaca = venue.toLowerCase().contains('alpaca');
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: isAlpaca ? Colors.blue.withValues(alpha: 0.15) : Colors.purple.withValues(alpha: 0.15),
|
||||
),
|
||||
child: Text(
|
||||
isAlpaca ? 'Alpaca US' : 'Synthetic KO',
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isAlpaca ? Colors.lightBlueAccent : Colors.purpleAccent,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDynamicStateBadge(BotTradeOrderModel position) {
|
||||
String text = 'Pending TP1';
|
||||
Color color = Colors.amber;
|
||||
|
||||
if (position.isBreakEven) {
|
||||
text = 'Free-Roll Active (BE)';
|
||||
color = AppTheme.primaryEmerald;
|
||||
} else if (position.isTp1Hit) {
|
||||
text = 'TP1 Hit (Trailing Active)';
|
||||
color = Colors.cyanAccent;
|
||||
} else if (position.isClosed) {
|
||||
text = 'Closed';
|
||||
color = Colors.grey;
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: color.withValues(alpha: 0.15),
|
||||
border: Border.all(color: color.withValues(alpha: 0.4), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.bolt, size: 12, color: color),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(color: color, fontSize: 11, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../models/bot_models.dart';
|
||||
|
||||
class BotSettingsSheet extends StatefulWidget {
|
||||
final BotStatusModel currentStatus;
|
||||
final Function(bool autoExec, int maxPos, double risk, int minScore) onSave;
|
||||
final VoidCallback onPanicClose;
|
||||
|
||||
const BotSettingsSheet({
|
||||
super.key,
|
||||
required this.currentStatus,
|
||||
required this.onSave,
|
||||
required this.onPanicClose,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BotSettingsSheet> createState() => _BotSettingsSheetState();
|
||||
}
|
||||
|
||||
class _BotSettingsSheetState extends State<BotSettingsSheet> {
|
||||
late bool _autoExec;
|
||||
late int _maxPositions;
|
||||
late double _riskPerTrade;
|
||||
late int _minScore;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_autoExec = widget.currentStatus.autoExecutionEnabled;
|
||||
_maxPositions = widget.currentStatus.maxPositions;
|
||||
_riskPerTrade = widget.currentStatus.riskPerTradePercent;
|
||||
_minScore = widget.currentStatus.minCompositeScore;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.cardSurface,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Bot Konfiguration & Kill-Switch',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.close, color: Colors.white70),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
title: const Text('Automatische Ausführung (Auto-Trade)', style: TextStyle(color: Colors.white)),
|
||||
subtitle: Text('Führt geprüfte Signale ab Score ≥ $_minScore automatisch aus', style: TextStyle(color: AppTheme.textMuted, fontSize: 12)),
|
||||
value: _autoExec,
|
||||
activeThumbColor: AppTheme.primaryEmerald,
|
||||
onChanged: (val) => setState(() => _autoExec = val),
|
||||
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text('Max. Parallele Positionen: $_maxPositions', style: const TextStyle(color: Colors.white70)),
|
||||
Slider(
|
||||
value: _maxPositions.toDouble(),
|
||||
min: 1,
|
||||
max: 10,
|
||||
divisions: 9,
|
||||
activeColor: AppTheme.primaryEmerald,
|
||||
label: '$_maxPositions',
|
||||
onChanged: (val) => setState(() => _maxPositions = val.toInt()),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text('Risiko pro Trade: ${_riskPerTrade.toStringAsFixed(1)}% des Portfolios', style: const TextStyle(color: Colors.white70)),
|
||||
Slider(
|
||||
value: _riskPerTrade,
|
||||
min: 0.2,
|
||||
max: 3.0,
|
||||
divisions: 28,
|
||||
activeColor: AppTheme.primaryEmerald,
|
||||
label: '${_riskPerTrade.toStringAsFixed(1)}%',
|
||||
onChanged: (val) => setState(() => _riskPerTrade = val),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text('Mindest-Score für Einstieg: $_minScore Punkte', style: const TextStyle(color: Colors.white70)),
|
||||
Slider(
|
||||
value: _minScore.toDouble(),
|
||||
min: 60,
|
||||
max: 95,
|
||||
divisions: 35,
|
||||
activeColor: AppTheme.primaryEmerald,
|
||||
label: '$_minScore Pkt',
|
||||
onChanged: (val) => setState(() => _minScore = val.toInt()),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
widget.onSave(_autoExec, _maxPositions, _riskPerTrade, _minScore);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: const Icon(Icons.check),
|
||||
label: const Text('Speichern'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppTheme.primaryEmerald,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_showPanicConfirmation(context);
|
||||
},
|
||||
icon: const Icon(Icons.warning, color: Colors.white),
|
||||
label: const Text('PANIC CLOSE', style: TextStyle(color: Colors.white)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppTheme.accentRed,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 16),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showPanicConfirmation(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: AppTheme.cardSurface,
|
||||
title: Text('🚨 Notverkauf bestätigen', style: TextStyle(color: AppTheme.accentRed)),
|
||||
|
||||
content: const Text(
|
||||
'Möchtest du wirklich SOFORT alle offenen Bot-Positionen schließen? Dieser Vorgang kann nicht rückgängig gemacht werden.',
|
||||
style: TextStyle(color: Colors.white70),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
child: const Text('Abbrechen', style: TextStyle(color: Colors.white70)),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
widget.onPanicClose();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(backgroundColor: AppTheme.accentRed),
|
||||
child: const Text('ALLE POSITIONEN SCHLIESSEN'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user