Add external API server, configure fetch URLs, fix stats endpoint, update API config
This commit is contained in:
51
api-server.js
Normal file
51
api-server.js
Normal file
@ -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}`);
|
||||||
|
});
|
||||||
@ -3,7 +3,5 @@
|
|||||||
|
|
||||||
window.APP_CONFIG = {
|
window.APP_CONFIG = {
|
||||||
// URL of the backend API
|
// URL of the backend API
|
||||||
// If running on the same machine, use http://localhost:8000/api/v1
|
API_BASE_URL: 'http://20.20.20.20: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'
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -164,7 +164,7 @@ constructor() {
|
|||||||
let candles = this.allData.get(interval);
|
let candles = this.allData.get(interval);
|
||||||
|
|
||||||
if (!candles || candles.length < 125) {
|
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();
|
const data = await response.json();
|
||||||
if (data.candles && data.candles.length > 0) {
|
if (data.candles && data.candles.length > 0) {
|
||||||
candles = data.candles.reverse().map(c => ({
|
candles = data.candles.reverse().map(c => ({
|
||||||
@ -574,7 +574,7 @@ constructor() {
|
|||||||
try {
|
try {
|
||||||
const visibleRange = this.chart.timeScale().getVisibleLogicalRange();
|
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();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.candles && data.candles.length > 0) {
|
if (data.candles && data.candles.length > 0) {
|
||||||
@ -615,7 +615,7 @@ async loadNewData() {
|
|||||||
if (!this.hasInitialLoad || this.isLoading) return;
|
if (!this.hasInitialLoad || this.isLoading) return;
|
||||||
|
|
||||||
try {
|
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();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.candles && data.candles.length > 0) {
|
if (data.candles && data.candles.length > 0) {
|
||||||
@ -745,7 +745,7 @@ async loadHistoricalData(beforeTime, limit = 1000) {
|
|||||||
const endTime = new Date((beforeTime - 1) * 1000);
|
const endTime = new Date((beforeTime - 1) * 1000);
|
||||||
|
|
||||||
const response = await fetch(
|
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) {
|
if (!response.ok) {
|
||||||
@ -799,7 +799,7 @@ async loadTA() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
@ -985,7 +985,7 @@ async loadSignals() {
|
|||||||
|
|
||||||
async loadStats() {
|
async loadStats() {
|
||||||
try {
|
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();
|
this.statsData = await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading stats:', error);
|
console.error('Error loading stats:', error);
|
||||||
|
|||||||
18
package.json
Normal file
18
package.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user