import React, { useState } from 'react'; import { Cpu, Plus, Calendar, Zap, Trash2, Activity, Clock, LayoutGrid, Layers, X } from 'lucide-react'; import { StockItem, AutoTradeConfig, MarketType, WatchlistGroup } from '../types'; interface AutoTradingProps { marketMode: MarketType; stocks: StockItem[]; configs: AutoTradeConfig[]; groups: WatchlistGroup[]; onAddConfig: (config: Omit) => void; onToggleConfig: (id: string) => void; onDeleteConfig: (id: string) => void; } const AutoTrading: React.FC = ({ marketMode, stocks, configs, groups, onAddConfig, onToggleConfig, onDeleteConfig }) => { const [showAddModal, setShowAddModal] = useState(false); const [targetType, setTargetType] = useState<'SINGLE' | 'GROUP'>('SINGLE'); const [newConfig, setNewConfig] = useState>({ type: 'ACCUMULATION', frequency: 'DAILY', quantity: 1, executionTime: '09:00', specificDay: 1 }); const handleAdd = () => { if (newConfig.type) { if (targetType === 'SINGLE' && !newConfig.stockCode) return; if (targetType === 'GROUP' && !newConfig.groupId) return; const stockName = targetType === 'SINGLE' ? stocks.find(s => s.code === newConfig.stockCode)?.name || '알 수 없음' : groups.find(g => g.id === newConfig.groupId)?.name || '알 수 없는 그룹'; onAddConfig({ stockCode: targetType === 'SINGLE' ? newConfig.stockCode : undefined, groupId: targetType === 'GROUP' ? newConfig.groupId : undefined, stockName: stockName, type: newConfig.type as 'ACCUMULATION' | 'TRAILING_STOP', quantity: newConfig.quantity || 1, frequency: newConfig.frequency as 'DAILY' | 'WEEKLY' | 'MONTHLY', specificDay: newConfig.specificDay, executionTime: newConfig.executionTime || '09:00', trailingPercent: newConfig.trailingPercent, market: marketMode }); setShowAddModal(false); } }; const getDayLabel = (config: AutoTradeConfig) => { if (config.frequency === 'DAILY') return '매일'; if (config.frequency === 'WEEKLY') { const days = ['일', '월', '화', '수', '목', '금', '토']; return `매주 ${days[config.specificDay || 0]}요일`; } if (config.frequency === 'MONTHLY') return `매월 ${config.specificDay}일`; return ''; }; const filteredStocks = stocks.filter(s => s.market === marketMode); const filteredGroups = groups.filter(g => g.codes.some(code => stocks.find(s => s.code === code)?.market === marketMode)); return (

{marketMode === MarketType.DOMESTIC ? '국내' : '해외'} 매매 엔진

c.active && c.market === marketMode).length > 0 ? 'bg-emerald-400' : 'bg-slate-300'}`}> c.active && c.market === marketMode).length > 0 ? 'bg-emerald-500' : 'bg-slate-400'}`}> {configs.filter(c => c.active && c.market === marketMode).length}개의 로봇 활성화됨

{configs.filter(c => c.market === marketMode).map(config => (
{config.groupId ? : }

{config.stockName}

{config.groupId ? 'GROUP AGENT' : config.stockCode}

{/* 활성화 토글 스위치 */}
오퍼레이션 {config.groupId ? '그룹 일괄' : '개별 자산'}
코어 전략 {config.type === 'ACCUMULATION' ? '적립식 매수' : 'TS 자동매매'}
스케줄링 {getDayLabel(config)}
실행정보 {config.executionTime} / {config.quantity}주
{config.active ? '에이전트 운용 중' : '일시 중단됨'}
))}
{showAddModal && (

로봇 전략 설계

{targetType === 'SINGLE' ? ( ) : ( )}
setNewConfig({...newConfig, quantity: parseInt(e.target.value)})} />
{[ { val: 'DAILY', label: '매일' }, { val: 'WEEKLY', label: '매주' }, { val: 'MONTHLY', label: '매월' } ].map(freq => ( ))}
{newConfig.frequency !== 'DAILY' && (
)}
setNewConfig({...newConfig, executionTime: e.target.value})} />
)}
); }; export default AutoTrading;