File size: 19,103 Bytes
b66240d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/**
 * ═══════════════════════════════════════════════════════════════════
 * CONFIGURATION FILE
 * Dashboard Settings - Easy Customization
 * ═══════════════════════════════════════════════════════════════════
 */

// πŸ”§ Main Backend Settings
window.DASHBOARD_CONFIG = {

    // ═══════════════════════════════════════════════════════════════
    // API and WebSocket URLs
    // ═══════════════════════════════════════════════════════════════

    // Auto-detect localhost and use port 7860, otherwise use current origin
    BACKEND_URL: (() => {
        const hostname = window.location.hostname;
        if (hostname === 'localhost' || hostname === '127.0.0.1') {
            return `http://${hostname}:7860`;
        }
        return window.location.origin || 'https://really-amin-datasourceforcryptocurrency.hf.space';
    })(),
    WS_URL: (() => {
        const hostname = window.location.hostname;
        let backendUrl;
        if (hostname === 'localhost' || hostname === '127.0.0.1') {
            backendUrl = `http://${hostname}:7860`;
        } else {
            backendUrl = window.location.origin || 'https://really-amin-datasourceforcryptocurrency.hf.space';
        }
        return backendUrl.replace('http://', 'ws://').replace('https://', 'wss://') + '/ws';
    })(),

    // ⏱️ Update Timing (milliseconds)
    UPDATE_INTERVAL: 30000,           // Every 30 seconds
    CACHE_TTL: 60000,                 // 1 minute
    HEARTBEAT_INTERVAL: 30000,        // 30 seconds

    // πŸ”„ Reconnection Settings
    MAX_RECONNECT_ATTEMPTS: 5,
    RECONNECT_DELAY: 3000,            // 3 seconds

    // ═══════════════════════════════════════════════════════════════
    // Display Settings
    // ═══════════════════════════════════════════════════════════════

    // Number of items to display
    MAX_COINS_DISPLAY: 20,            // Number of coins in table
    MAX_NEWS_DISPLAY: 20,             // Number of news items
    MAX_TRENDING_DISPLAY: 10,         // Number of trending items

    // Table settings
    TABLE_ROWS_PER_PAGE: 10,

    // ═══════════════════════════════════════════════════════════════
    // Chart Settings
    // ═══════════════════════════════════════════════════════════════

    CHART: {
        DEFAULT_SYMBOL: 'BTCUSDT',
        DEFAULT_INTERVAL: '1h',
        AVAILABLE_INTERVALS: ['1m', '5m', '15m', '1h', '4h', '1d'],
        THEME: 'dark',
    },

    // ═══════════════════════════════════════════════════════════════
    // AI Settings
    // ═══════════════════════════════════════════════════════════════

    AI: {
        ENABLE_SENTIMENT: true,
        ENABLE_NEWS_SUMMARY: true,
        ENABLE_PRICE_PREDICTION: false,    // Currently disabled
        ENABLE_PATTERN_DETECTION: false,   // Currently disabled
    },

    // ═══════════════════════════════════════════════════════════════
    // Notification Settings
    // ═══════════════════════════════════════════════════════════════

    NOTIFICATIONS: {
        ENABLE: true,
        SHOW_PRICE_ALERTS: true,
        SHOW_NEWS_ALERTS: true,
        AUTO_DISMISS_TIME: 5000,          // 5 seconds
    },

    // ═══════════════════════════════════════════════════════════════
    // UI Settings
    // ═══════════════════════════════════════════════════════════════

    UI: {
        DEFAULT_THEME: 'dark',            // 'dark' or 'light'
        ENABLE_ANIMATIONS: true,
        ENABLE_SOUNDS: false,
        LANGUAGE: 'en',                   // 'en' or 'fa'
        RTL: false,
    },

    // ═══════════════════════════════════════════════════════════════
    // Debug Settings
    // ═══════════════════════════════════════════════════════════════

    DEBUG: {
        ENABLE_CONSOLE_LOGS: true,
        ENABLE_PERFORMANCE_MONITORING: true,
        SHOW_API_REQUESTS: true,
        SHOW_WS_MESSAGES: false,
    },

    // ═══════════════════════════════════════════════════════════════
    // Default Filters and Sorting
    // ═══════════════════════════════════════════════════════════════

    FILTERS: {
        DEFAULT_MARKET_FILTER: 'all',     // 'all', 'gainers', 'losers', 'trending'
        DEFAULT_NEWS_FILTER: 'all',       // 'all', 'bitcoin', 'ethereum', 'defi', 'nft'
        DEFAULT_SORT: 'market_cap',       // 'market_cap', 'volume', 'price', 'change'
        SORT_ORDER: 'desc',               // 'asc' or 'desc'
    },

    // ═══════════════════════════════════════════════════════════════
    // HuggingFace Configuration
    // ═══════════════════════════════════════════════════════════════

    HF_TOKEN: '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',
    HF_API_BASE: 'https://api-inference.huggingface.co/models',

    // ═══════════════════════════════════════════════════════════════
    // API Endpoints (Optional - if your backend differs)
    // ═══════════════════════════════════════════════════════════════

    ENDPOINTS: {
        HEALTH: '/api/health',
        MARKET: '/api/market/stats',
        MARKET_PRICES: '/api/market/prices',
        COINS_TOP: '/api/coins/top',
        COIN_DETAILS: '/api/coins',
        TRENDING: '/api/trending',
        SENTIMENT: '/api/sentiment',
        SENTIMENT_ANALYZE: '/api/sentiment/analyze',
        NEWS: '/api/news/latest',
        NEWS_SUMMARIZE: '/api/news/summarize',
        STATS: '/api/stats',
        PROVIDERS: '/api/providers',
        PROVIDER_STATUS: '/api/providers/status',
        CHART_HISTORY: '/api/charts/price',
        CHART_ANALYZE: '/api/charts/analyze',
        OHLCV: '/api/ohlcv',
        QUERY: '/api/query',
        DATASETS: '/api/datasets/list',
        MODELS: '/api/models/list',
        HF_HEALTH: '/api/hf/health',
        HF_REGISTRY: '/api/hf/registry',
        SYSTEM_STATUS: '/api/system/status',
        SYSTEM_CONFIG: '/api/system/config',
        CATEGORIES: '/api/categories',
        RATE_LIMITS: '/api/rate-limits',
        LOGS: '/api/logs',
        ALERTS: '/api/alerts',
    },

    // ═══════════════════════════════════════════════════════════════
    // WebSocket Events
    // ═══════════════════════════════════════════════════════════════

    WS_EVENTS: {
        MARKET_UPDATE: 'market_update',
        SENTIMENT_UPDATE: 'sentiment_update',
        NEWS_UPDATE: 'news_update',
        STATS_UPDATE: 'stats_update',
        PRICE_UPDATE: 'price_update',
        API_UPDATE: 'api_update',
        STATUS_UPDATE: 'status_update',
        SCHEDULE_UPDATE: 'schedule_update',
        CONNECTED: 'connected',
        DISCONNECTED: 'disconnected',
    },

    // ═══════════════════════════════════════════════════════════════
    // Display Formats
    // ═══════════════════════════════════════════════════════════════

    FORMATS: {
        CURRENCY: {
            LOCALE: 'en-US',
            STYLE: 'currency',
            CURRENCY: 'USD',
        },
        DATE: {
            LOCALE: 'en-US',
            OPTIONS: {
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                hour: '2-digit',
                minute: '2-digit',
            },
        },
    },

    // ═══════════════════════════════════════════════════════════════
    // Rate Limiting
    // ═══════════════════════════════════════════════════════════════

    RATE_LIMITS: {
        API_REQUESTS_PER_MINUTE: 60,
        SEARCH_DEBOUNCE_MS: 300,
    },

    // ═══════════════════════════════════════════════════════════════
    // Storage Settings
    // ═══════════════════════════════════════════════════════════════

    STORAGE: {
        USE_LOCAL_STORAGE: true,
        SAVE_PREFERENCES: true,
        STORAGE_PREFIX: 'hts_dashboard_',
    },
};

// ═══════════════════════════════════════════════════════════════════
// Predefined Profiles
// ═══════════════════════════════════════════════════════════════════

window.DASHBOARD_PROFILES = {

    // High Performance Profile
    HIGH_PERFORMANCE: {
        UPDATE_INTERVAL: 15000,           // Faster updates
        CACHE_TTL: 30000,                 // Shorter cache
        ENABLE_ANIMATIONS: false,         // No animations
        MAX_COINS_DISPLAY: 50,
    },

    // Data Saver Profile
    DATA_SAVER: {
        UPDATE_INTERVAL: 60000,           // Less frequent updates
        CACHE_TTL: 300000,                // Longer cache (5 minutes)
        MAX_COINS_DISPLAY: 10,
        MAX_NEWS_DISPLAY: 10,
    },

    // Presentation Profile
    PRESENTATION: {
        ENABLE_ANIMATIONS: true,
        UPDATE_INTERVAL: 20000,
        SHOW_API_REQUESTS: false,
        ENABLE_CONSOLE_LOGS: false,
    },

    // Development Profile
    DEVELOPMENT: {
        DEBUG: {
            ENABLE_CONSOLE_LOGS: true,
            ENABLE_PERFORMANCE_MONITORING: true,
            SHOW_API_REQUESTS: true,
            SHOW_WS_MESSAGES: true,
        },
        UPDATE_INTERVAL: 10000,
    },
};

// ═══════════════════════════════════════════════════════════════════
// Helper Function to Change Profile
// ═══════════════════════════════════════════════════════════════════

window.applyDashboardProfile = function (profileName) {
    if (window.DASHBOARD_PROFILES[profileName]) {
        const profile = window.DASHBOARD_PROFILES[profileName];
        Object.assign(window.DASHBOARD_CONFIG, profile);
        console.log(`βœ… Profile "${profileName}" applied`);

        // Reload application with new settings
        if (window.app) {
            window.app.destroy();
            window.app = new DashboardApp();
            window.app.init();
        }
    } else {
        console.error(`❌ Profile "${profileName}" not found`);
    }
};

// ═══════════════════════════════════════════════════════════════════
// Helper Function to Change Backend URL
// ═══════════════════════════════════════════════════════════════════

window.changeBackendURL = function (httpUrl, wsUrl) {
    window.DASHBOARD_CONFIG.BACKEND_URL = httpUrl;
    window.DASHBOARD_CONFIG.WS_URL = wsUrl || httpUrl.replace('https://', 'wss://').replace('http://', 'ws://') + '/ws';

    console.log('βœ… Backend URL changed:');
    console.log('  HTTP:', window.DASHBOARD_CONFIG.BACKEND_URL);
    console.log('  WS:', window.DASHBOARD_CONFIG.WS_URL);

    // Reload application
    if (window.app) {
        window.app.destroy();
        window.app = new DashboardApp();
        window.app.init();
    }
};

// ═══════════════════════════════════════════════════════════════════
// Save Settings to LocalStorage
// ═══════════════════════════════════════════════════════════════════

window.saveConfig = function () {
    if (window.DASHBOARD_CONFIG.STORAGE.USE_LOCAL_STORAGE) {
        try {
            const configString = JSON.stringify(window.DASHBOARD_CONFIG);
            localStorage.setItem(
                window.DASHBOARD_CONFIG.STORAGE.STORAGE_PREFIX + 'config',
                configString
            );
            console.log('βœ… Settings saved');
        } catch (error) {
            console.error('❌ Error saving settings:', error);
        }
    }
};

// ═══════════════════════════════════════════════════════════════════
// Load Settings from LocalStorage
// ═══════════════════════════════════════════════════════════════════

window.loadConfig = function () {
    if (window.DASHBOARD_CONFIG.STORAGE.USE_LOCAL_STORAGE) {
        try {
            const configString = localStorage.getItem(
                window.DASHBOARD_CONFIG.STORAGE.STORAGE_PREFIX + 'config'
            );
            if (configString) {
                const savedConfig = JSON.parse(configString);
                Object.assign(window.DASHBOARD_CONFIG, savedConfig);
                console.log('βœ… Settings loaded');
            }
        } catch (error) {
            console.error('❌ Error loading settings:', error);
        }
    }
};

// ═══════════════════════════════════════════════════════════════════
// Auto-load Settings on Page Load
// ═══════════════════════════════════════════════════════════════════

if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', () => {
        window.loadConfig();
    });
} else {
    window.loadConfig();
}

// ═══════════════════════════════════════════════════════════════════
// Console Usage Guide
// ═══════════════════════════════════════════════════════════════════

console.log(`
╔═══════════════════════════════════════════════════════════════╗
β•‘          HTS CRYPTO DASHBOARD - CONFIGURATION                 β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“‹ Available Commands:

1. Change Profile:
   applyDashboardProfile('HIGH_PERFORMANCE')
   applyDashboardProfile('DATA_SAVER')
   applyDashboardProfile('PRESENTATION')
   applyDashboardProfile('DEVELOPMENT')

2. Change Backend:
   changeBackendURL('https://your-backend.com')

3. Save/Load Settings:
   saveConfig()
   loadConfig()

4. View Current Settings:
   console.log(DASHBOARD_CONFIG)

5. Manual Settings Change:
   DASHBOARD_CONFIG.UPDATE_INTERVAL = 20000
   saveConfig()

═══════════════════════════════════════════════════════════════════
`);