-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
50 lines (40 loc) · 1.45 KB
/
api.js
File metadata and controls
50 lines (40 loc) · 1.45 KB
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
const axios = require("axios");
const logger = require('./utils/logger');
const dotenv = require('dotenv');
// 加载环境变量
dotenv.config();
// 创建API实例
const api = axios.create({
baseURL: process.env.API_BASE_URL,
timeout: process.env.API_TIMEOUT || 10000,
headers: {
"Content-Type": "application/json",
}
});
// 错误处理中间件
api.interceptors.response.use(
response => response.data,
error => {
logger.error(`API请求失败: ${error.message}`);
return Promise.reject(error);
}
);
// API方法封装
module.exports = {
// 用户相关
register: (userData) => api.post("/api/v1/user/register", userData),
getExchangeApi: (telegramId) => api.get("/api/v1/exchange-apis", { params: { telegram_id: telegramId } }),
// 策略相关
createStrategyTask: (taskData) => api.post("/api/v1/strategy/create", taskData),
getStrategyTaskList: (telegramId, statusList = [-1, 1, -2, 2, -3]) =>
api.get("/api/v1/strategy/list", {
params: {
status_list: statusList.join(','),
telegram_id: telegramId,
}
}),
updateStrategyTaskStatus: (taskId, status) =>
api.post("/api/v1/strategy/update", { task_id: taskId, status: status }),
getStrategyTaskDetail: (taskId) =>
api.get("/api/telegram/strategy/get", { params: { task_id: taskId } })
};