Spaces:
Running
Running
Upload pages/index.js with huggingface_hub
Browse files3 unmodified lines456778910112 unmodified lines14151617181920213 unmodified lines2526272829303133 unmodified lines656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510615 unmodified lines12212312412512612712812913013113213313412 unmodified lines14714814910315015115215315415515615715815 unmodified lines1741751761251771781791802 unmodified lines1831841851861871881891901911921931943 unmodified linesimport KnowledgePanel from '../components/KnowledgePanel'import MarketChart from '../components/MarketChart'import SignalPanel from '../components/SignalPanel'import { getKnowledgeBase } from '../lib/knowledge-base'import JsonUploadModal from '../components/JsonUploadModal'import { getKnowledgeBase, addKnowledgeBaseRules, removeCustomRule, clearAllCustomRules, getCustomRulesCount } from '../lib/knowledge-base'import { initializeMarket, getMarketTick, analyzeMarket } from '../lib/market-simulator'
export default function Home() {2 unmodified lines const [currentTick, setCurrentTick] = useState({ price: 0, rsi: 0, volume: 0, trend: 'UP' }) const [signals, setSignals] = useState([]) const [isRunning, setIsRunning] = useState(false) const [isModalOpen, setIsModalOpen] = useState(false) const [customRulesCount, setCustomRulesCount] = useState(0) // Keep only last 50 points for chart const MAX_DATA_POINTS = 503 unmodified lines // Load Knowledge Base const kb = getKnowledgeBase() setKnowledgeBase(kb) setCustomRulesCount(getCustomRulesCount()) // Initialize Market Simulator initializeMarket()33 unmodified lines setIsRunning(!isRunning) }
const handleFileUpload = (event) => { const file = event.target.files[0] if (!file) return
const reader = new FileReader() reader.onload = (e) => { try { const rules = JSON.parse(e.target.result) if (Array.isArray(rules)) { const added = addKnowledgeBaseRules(rules) setKnowledgeBase(getKnowledgeBase()) setCustomRulesCount(getCustomRulesCount()) } } catch (error) { console.error('Invalid JSON file:', error) } } reader.readAsText(file) }
const handleTextUpload = (rules) => { addKnowledgeBaseRules(rules) setKnowledgeBase(getKnowledgeBase()) setCustomRulesCount(getCustomRulesCount()) }
const handleRemoveRule = (ruleId) => { if (ruleId === 'all') { clearAllCustomRules() } else { removeCustomRule(ruleId) } setKnowledgeBase(getKnowledgeBase()) setCustomRulesCount(getCustomRulesCount()) }
return ( <> <Head>15 unmodified lines <p className="text-sm text-dark-400">Real-time analysis based on loaded JSON rules</p> </div> <div className="flex items-center space-x-4"> <button onClick={() => setIsModalOpen(true)} className="btn-secondary flex items-center space-x-2" > <span>📄</span> <span>Add JSON Rules</span> </button> <button onClick={toggleSimulation} className={`px-6 py-2 rounded-lg font-medium transition-all ${12 unmodified lines {/* Left Column: Knowledge Base (1/4 width) */} <div className="lg:col-span-1 h-[600px]"> <KnowledgePanel rules={knowledgeBase} /> <KnowledgePanel rules={knowledgeBase} onUpload={handleFileUpload} onRemoveRule={handleRemoveRule} customRulesCount={customRulesCount} /> </div>
{/* Right Column: Trading Interface (3/4 width) */}15 unmodified lines <div> <h4 className="text-sm font-medium text-primary-300">How it works</h4> <p className="text-sm text-dark-400 mt-1"> This application loads trading strategies from a JSON knowledge base. It simulates real-time market data and compares current indicators (RSI, Volume, Price) against your rules to generate Long/Short signals automatically. This application loads trading strategies from a JSON knowledge base. You can add your own custom rules by uploading JSON files or pasting JSON directly. The system simulates real-time market data and compares current indicators (RSI, Volume, Price) against your rules to generate Long/Short signals automatically. </p> </div> </div>2 unmodified lines </div> </main> </div>
<JsonUploadModal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)} onUpload={handleTextUpload} /> </> )}pages/index.js+61-3