-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
49 lines (41 loc) · 1.68 KB
/
index.ts
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
import dotenv from 'dotenv';
dotenv.config();
import './db';
import express from 'express';
import cors from 'cors';
import { createServer } from 'http';
import { Server as SocketIOServer } from 'socket.io';
import { setSocketServerInstance } from './utils/socketUtils';
import balanceRoutes from './routes/balanceRoutes';
import tradeRoutes from './routes/tradeRoutes';
import strategyRoutes from './routes/strategyRoutes';
const app = express();
app.use(express.json());
app.use(cors({
origin: process.env.CORS_ORIGIN
}));
const server = createServer(app);
const io = new SocketIOServer(server, { cors: { origin: process.env.CORS_ORIGIN }});
setSocketServerInstance(io);
app.use('/api', balanceRoutes);
app.use('/api', tradeRoutes);
app.use('/api', strategyRoutes);
const port: number = parseInt(process.env.PORT || '5000');
server.listen(port, () => console.log(`Server started on http://localhost:${port}`));
const endpoints = [
{ method: "GET", path: "/api/balance", description: "Get account balance" },
{ method: "POST", path: "/api/order", description: "Create a new order" },
{ method: "DELETE", path: "/api/order/:id", description: "Cancel an order" },
{ method: "POST", path: "/api/strategy", description: "Set or update a trading strategy" },
{ method: "POST", path: "/api/strategy/:baseAsset/execute", description: "Execute a trading strategy" }
];
app.get('/', (req, res) => {
const html = `
<h1>EffiTrade Server</h1>
<h2>Available API Endpoints</h2>
<ul>
${endpoints.map(endpoint => `<li><strong>${endpoint.method}</strong> ${endpoint.path} - ${endpoint.description}</li>`).join('')}
</ul>
`;
res.send(html);
});