Browse Source

新增-新策略对应 获取机器人状态接口

hl 5 months ago
parent
commit
c6d8f0e7ca
1 changed files with 18 additions and 36 deletions
  1. 18 36
      src/robot.js

+ 18 - 36
src/robot.js

@@ -554,42 +554,24 @@ function delRobot(app) {
 //----------------------------------------------
 
 // 新策略-获取状态
-function predictorState(port) {
-    // logger.info('#####################predictorState:');
-    // var accUrl = "http://127.0.0.1:" + port
-    // var config = getRustConfig()
-    //
-    // // curl -X GET -H "auth: 4L" -H "token: r7T\$8gBV\!f&L@E2+" "http://127.0.0.1:111/predictor_state"
-    // execSync(`curl -X GET -H "auth: ${config.headers.auth}" -H "token: ${config.headers.token}" "http://127.0.0.1:${port}/predictor_state"`, (error, stdout, stderr) => {
-    //     if (error) {
-    //         logger.info(`#####################汇报:获取状态请求失败: ${error.message}`)
-    //         return {'code': -1, 'data': null, "message": `获取状态请求失败`}
-    //     }
-    //
-    //     logger.info('#####################-d', stdout);
-    //     return {'code': 200, 'data': stdout, "message": "SUCCESS"}
-    // });
-
-    // //拿到策略余额
-    // try {
-    //     var config = getRustConfig()
-    //     var rul = `${accUrl}/predictor_state`
-    //     logger.info('#####################-rul', rul);
-    //     http.request_get(rul, {...config.headers})
-    //         .then((data) => {
-    //             logger.info('#####################-d', data);
-    //             return {'code': 200, 'data': data, "message": "SUCCESS"}
-    //         }).catch((error) => {
-    //         // 处理可能发生的错误
-    //         logger.info(`#####################汇报:获取状态请求失败: ${error.message}`)
-    //         // logger.error(`#####################汇报:获取状态请求失败: ${error.message}`)
-    //         return {'code': -1, 'data': null, "message": `获取状态请求失败${error.message}`}
-    //     });
-    // } catch (e) {
-    //     // logger.error('请求失败!:', e)
-    //     logger.info('请求失败!:', e)
-    //     return {'code': -1, 'data': null, "message": "获取状态请求出错"}
-    // }
+function predictorState(app) {
+    var accUrl = "http://127.0.0.1:" + app.port
+    //拿到策略余额
+    try {
+        var config = getRustConfig()
+        http.request_get(`${accUrl}/predictor_state`, {...config.headers})
+            .then((data) => {
+                return {'code': 200, 'data': data, "message": "SUCCESS"}
+            }).catch((error) => {
+            // 处理可能发生的错误
+            logger.error(`#####################汇报:获取状态请求失败: ${error.message}`)
+            return {'code': -1, 'data': null, "message": `获取状态请求失败${error.message}`}
+        });
+    } catch (e) {
+        logger.error('请求失败!:', e)
+        return {'code': -1, 'data': null, "message": "获取状态请求出错"}
+    }
+
 }
 
 module.exports = {