File size: 8,578 Bytes
f568a4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { useAutomatedHunt } from '@/hooks/useAutomatedHunt';
import { useState } from 'react';
import { Target, PlayCircle, StopCircle, RefreshCw, TrendingUp, Activity } from 'lucide-react';

export function AutomatedHuntControl() {
  const { huntSession, recentTargets, isScanning, startHunt, stopHunt, triggerScan } = useAutomatedHunt();
  
  const [config, setConfig] = useState({
    minVolatility: 2.0,
    minVolume: 100000,
    maxTargets: 5,
    scanInterval: 300,
  });

  const handleStart = async () => {
    await startHunt(config);
  };

  const isActive = huntSession?.status === 'active';

  return (
    <Card className="border-border/50 bg-card/50">

      <CardHeader>

        <CardTitle className="flex items-center gap-2">

          <Target className={`h-5 w-5 ${isActive ? 'text-success animate-pulse' : 'text-muted-foreground'}`} />

          🦁 Automated Hunt Loop

        </CardTitle>

        <CardDescription>

          Pride Scanner + QGITA + OMS — Continuous opportunity detection

        </CardDescription>

      </CardHeader>

      <CardContent className="space-y-6">

        {/* Hunt Status */}

        {huntSession && (

          <div className="space-y-3">

            <div className="flex items-center justify-between">

              <span className="text-sm text-muted-foreground">Status</span>

              <Badge variant={isActive ? 'default' : 'secondary'}>

                {isActive ? '🟢 Hunting' : '⏸️ Stopped'}

              </Badge>

            </div>

            

            {/* Statistics Grid */}

            <div className="grid grid-cols-2 gap-3">

              <div className="p-3 rounded-lg border border-border/50 bg-background/50">

                <div className="text-xs text-muted-foreground mb-1">Scans</div>

                <div className="text-xl font-bold text-foreground">{huntSession.total_scans}</div>

              </div>

              <div className="p-3 rounded-lg border border-border/50 bg-background/50">

                <div className="text-xs text-muted-foreground mb-1">Targets</div>

                <div className="text-xl font-bold text-foreground">{huntSession.total_targets_found}</div>

              </div>

              <div className="p-3 rounded-lg border border-border/50 bg-background/50">

                <div className="text-xs text-muted-foreground mb-1">Signals</div>

                <div className="text-xl font-bold text-success">{huntSession.total_signals_generated}</div>

              </div>

              <div className="p-3 rounded-lg border border-border/50 bg-background/50">

                <div className="text-xs text-muted-foreground mb-1">Queued</div>

                <div className="text-xl font-bold text-primary">{huntSession.total_orders_queued}</div>

              </div>

            </div>



            {/* Last Scan Time */}

            {huntSession.last_scan_at && (

              <div className="text-xs text-muted-foreground">

                Last scan: {new Date(huntSession.last_scan_at).toLocaleTimeString()}

              </div>

            )}

          </div>

        )}



        {/* Configuration (only show when not active) */}

        {!isActive && (

          <div className="space-y-3">

            <div className="grid grid-cols-2 gap-3">

              <div className="space-y-2">

                <Label className="text-xs">Min Volatility %</Label>

                <Input

                  type="number"

                  value={config.minVolatility}

                  onChange={(e) => setConfig({ ...config, minVolatility: parseFloat(e.target.value) })}

                  step={0.5}

                  min={0}

                  className="h-8"

                />

              </div>

              <div className="space-y-2">

                <Label className="text-xs">Min Volume ($)</Label>

                <Input

                  type="number"

                  value={config.minVolume}

                  onChange={(e) => setConfig({ ...config, minVolume: parseFloat(e.target.value) })}

                  step={10000}

                  min={0}

                  className="h-8"

                />

              </div>

              <div className="space-y-2">

                <Label className="text-xs">Max Targets</Label>

                <Input

                  type="number"

                  value={config.maxTargets}

                  onChange={(e) => setConfig({ ...config, maxTargets: parseInt(e.target.value) })}

                  min={1}

                  max={20}

                  className="h-8"

                />

              </div>

              <div className="space-y-2">

                <Label className="text-xs">Scan Interval (s)</Label>

                <Input

                  type="number"

                  value={config.scanInterval}

                  onChange={(e) => setConfig({ ...config, scanInterval: parseInt(e.target.value) })}

                  step={60}

                  min={60}

                  className="h-8"

                />

              </div>

            </div>

          </div>

        )}



        {/* Recent Targets */}

        {recentTargets.length > 0 && (

          <div className="space-y-2">

            <h4 className="text-sm font-semibold text-foreground flex items-center gap-2">

              <TrendingUp className="h-4 w-4" />

              Recent Targets

            </h4>

            <div className="space-y-2 max-h-[200px] overflow-y-auto">

              {recentTargets.slice(0, 5).map((target) => (

                <div 

                  key={target.id}

                  className="flex items-center justify-between p-2 rounded border border-border/50 bg-background/30"

                >

                  <div className="flex items-center gap-2">

                    <span className="text-sm font-semibold text-foreground">{target.symbol}</span>

                    {target.order_queued && (

                      <Badge variant="default" className="text-xs">Queued</Badge>

                    )}

                    {target.signal_tier && (

                      <Badge variant="outline" className="text-xs">T{target.signal_tier}</Badge>

                    )}

                  </div>

                  <div className="text-xs text-muted-foreground">

                    Score: {target.opportunity_score.toFixed(0)} | {target.volatility_24h.toFixed(1)}%

                  </div>

                </div>

              ))}

            </div>

          </div>

        )}



        {/* Controls */}

        <div className="flex gap-2">

          {isActive ? (

            <>

              <Button

                onClick={() => triggerScan()}

                disabled={isScanning}

                variant="outline"

                className="flex-1"

              >

                {isScanning ? (

                  <>

                    <Activity className="mr-2 h-4 w-4 animate-spin" />

                    Scanning...

                  </>

                ) : (

                  <>

                    <RefreshCw className="mr-2 h-4 w-4" />

                    Scan Now

                  </>

                )}

              </Button>

              <Button

                onClick={stopHunt}

                variant="destructive"

                className="flex-1"

              >

                <StopCircle className="mr-2 h-4 w-4" />

                Stop Hunt

              </Button>

            </>
          ) : (
            <Button

              onClick={handleStart}

              className="w-full"

            >

              <PlayCircle className="mr-2 h-4 w-4" />

              Start Hunt

            </Button>
          )}
        </div>

        {/* Info Box */}
        <div className="p-3 rounded-lg bg-primary/10 border border-primary/20">
          <p className="text-xs text-foreground">

            🦁 <strong>Hunt Loop:</strong> Scans all USDT pairs, calculates opportunity scores 

            (volatility × volume), generates QGITA signals for top targets, and queues orders via OMS.

          </p>
        </div>
      </CardContent>
    </Card>
  );
}