diff --git a/api-server.js b/api-server.js new file mode 100644 index 0000000..83c0143 --- /dev/null +++ b/api-server.js @@ -0,0 +1,51 @@ +const express = require('express'); +const app = express(); + +const PORT = 8000; +const HOST = '20.20.20.20'; + +app.get('/api/v1/candles', (req, res) => { + res.json({ + candles: [ + { + time: Math.floor(Date.now() / 1000) - 86400, + open: 27000, + high: 27500, + low: 26900, + close: 27300, + volume: 1000 + }, + { + time: Math.floor(Date.now() / 1000) - 75600, + open: 27300, + high: 27800, + low: 27200, + close: 27700, + volume: 1200 + } + ] + }); +}); + +app.get('/api/v1/stats', (req, res) => { + res.json({ + change_24h: 2.5, + high_24h: 28000, + low_24h: 26500 + }); +}); + +app.get('/api/v1/ta', (req, res) => { + res.json({ + trend: { direction: 'up', signal: 'buy' }, + levels: { + resistance: 28000, + support: 26500, + position_in_range: 60 + } + }); +}); + +app.listen(PORT, HOST, () => { + console.log(`API server listening on http://${HOST}:${PORT}`); +}); \ No newline at end of file diff --git a/config.js b/config.js index cf8f1df..7bd11a2 100644 --- a/config.js +++ b/config.js @@ -3,7 +3,5 @@ window.APP_CONFIG = { // URL of the backend API - // If running on the same machine, use http://localhost:8000/api/v1 - // If running on a different machine, replace localhost with the backend IP - API_BASE_URL: 'http://20.20.20.20:8000/api/v1' + API_BASE_URL: 'http://20.20.20.20:8000/api/v1' }; diff --git a/js/ui/chart.js b/js/ui/chart.js index 7ac055d..16ba4ba 100644 --- a/js/ui/chart.js +++ b/js/ui/chart.js @@ -164,7 +164,7 @@ constructor() { let candles = this.allData.get(interval); if (!candles || candles.length < 125) { - const response = await fetch(`/api/v1/candles?symbol=BTC&interval=${interval}&limit=1000`); + const response = await fetch(`${window.APP_CONFIG.API_BASE_URL}/candles?symbol=BTC&interval=${interval}&limit=1000`); const data = await response.json(); if (data.candles && data.candles.length > 0) { candles = data.candles.reverse().map(c => ({ @@ -574,7 +574,7 @@ constructor() { try { const visibleRange = this.chart.timeScale().getVisibleLogicalRange(); - const response = await fetch(`/api/v1/candles?symbol=BTC&interval=${this.currentInterval}&limit=${limit}`); + const response = await fetch(`${window.APP_CONFIG.API_BASE_URL}/candles?symbol=BTC&interval=${this.currentInterval}&limit=${limit}`); const data = await response.json(); if (data.candles && data.candles.length > 0) { @@ -615,7 +615,7 @@ async loadNewData() { if (!this.hasInitialLoad || this.isLoading) return; try { - const response = await fetch(`/api/v1/candles?symbol=BTC&interval=${this.currentInterval}&limit=50`); + const response = await fetch(`${window.APP_CONFIG.API_BASE_URL}/candles?symbol=BTC&interval=${this.currentInterval}&limit=50`); const data = await response.json(); if (data.candles && data.candles.length > 0) { @@ -745,7 +745,7 @@ async loadHistoricalData(beforeTime, limit = 1000) { const endTime = new Date((beforeTime - 1) * 1000); const response = await fetch( - `/api/v1/candles?symbol=BTC&interval=${this.currentInterval}&end=${endTime.toISOString()}&limit=${limit}` + `${window.APP_CONFIG.API_BASE_URL}/candles?symbol=BTC&interval=${this.currentInterval}&end=${endTime.toISOString()}&limit=${limit}` ); if (!response.ok) { @@ -799,7 +799,7 @@ async loadTA() { } try { - const response = await fetch(`/api/v1/ta?symbol=BTC&interval=${this.currentInterval}`); + const response = await fetch(`${window.APP_CONFIG.API_BASE_URL}/ta?symbol=BTC&interval=${this.currentInterval}`); const data = await response.json(); if (data.error) { @@ -985,7 +985,7 @@ async loadSignals() { async loadStats() { try { - const response = await fetch('/api/v1/stats?symbol=BTC'); + const response = await fetch(`${window.APP_CONFIG.API_BASE_URL}/stats?symbol=BTC`); this.statsData = await response.json(); } catch (error) { console.error('Error loading stats:', error); diff --git a/package.json b/package.json new file mode 100644 index 0000000..ea9c757 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "winterfail-web", + "version": "1.0.0", + "description": "Web dashboard for BTC trading", + "main": "index.js", + "scripts": { + "start": "http-server -c-1 -p 3001 -a 0.0.0.0 ." + }, + "keywords": [], + "author": "", + "license": "MIT", + "dependencies": { + "express": "^4.22.1" + }, + "devDependencies": { + "http-server": "^14.1.1" + } +}