|
|
@@ -370,41 +370,64 @@ public class CoinServiceImpl implements CoinService {
|
|
|
BigDecimal returnRate = new BigDecimal(mixData.getString("unrealizedPL")).divide(new BigDecimal(margin), 4, RoundingMode.HALF_UP);
|
|
|
for (int j = 1; j <= 10; j++) {
|
|
|
BigDecimal grid = BigDecimal.valueOf(0.5).multiply(BigDecimal.valueOf(j));
|
|
|
- if ("long".equalsIgnoreCase(holdSide)) {
|
|
|
- if (returnRate.compareTo(grid) < 0) {
|
|
|
- if (mixMap.containsKey(key)) {
|
|
|
- mixMap.get(key).put("returnRate", returnRate);
|
|
|
- } else {
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("returnRate", returnRate);
|
|
|
- mixMap.put(key, jsonObject);
|
|
|
- }
|
|
|
- break;
|
|
|
+ if (returnRate.compareTo(grid) < 0) {
|
|
|
+ if (mixMap.containsKey(key)) {
|
|
|
+ mixMap.get(key).put("returnRate", returnRate);
|
|
|
+ } else {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("returnRate", returnRate);
|
|
|
+ mixMap.put(key, jsonObject);
|
|
|
}
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- if (returnRate.compareTo(grid) > 0) {
|
|
|
- if (mixMap.containsKey(key)) {
|
|
|
- mixMap.get(key).put("returnRate", returnRate);
|
|
|
- if (mixMap.get(key).containsKey(grid.toPlainString())) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- mixMap.get(key).put(grid.toPlainString(), true);
|
|
|
- SpringUtils.getBean(CoinServiceImpl.class).monitorAlarm(symbol.concat("回报率超过").concat(grid.toPlainString()), JOB_ALARM_MODE_CHAT_BOT);
|
|
|
- }
|
|
|
+ if (returnRate.compareTo(grid) > 0) {
|
|
|
+ if (mixMap.containsKey(key)) {
|
|
|
+ mixMap.get(key).put("returnRate", returnRate);
|
|
|
+ if (mixMap.get(key).containsKey(grid.toPlainString())) {
|
|
|
+ continue;
|
|
|
} else {
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("returnRate", returnRate);
|
|
|
- jsonObject.put(grid.toPlainString(), true);
|
|
|
- mixMap.put(key, jsonObject);
|
|
|
-
|
|
|
- SpringUtils.getBean(CoinServiceImpl.class).monitorAlarm(symbol.concat("回报率超过").concat(grid.toPlainString()), JOB_ALARM_MODE_CHAT_BOT);
|
|
|
- break;
|
|
|
+ mixMap.get(key).put(grid.toPlainString(), true);
|
|
|
+
|
|
|
+ String requestUrl = mainUrl + "/api/mix/v1/market/ticker?symbol=" + symbol;
|
|
|
+ String last = "--";
|
|
|
+ try {
|
|
|
+ Connection.Response responseTicker = JsoupUtil.requestBody(requestUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, null, null);
|
|
|
+ last = JSONObject.parseObject(responseTicker.body()).getJSONObject("data").getString("last");
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ String content = "币对名称:" + symbol + "\n" +
|
|
|
+ "持仓方向:" + InitRunner.publicParamsMap.get("holdSide").getString(mixData.getString("holdSide")) + "\n" +
|
|
|
+ "杠杆倍数:" + mixData.getString("leverage") + "\n" +
|
|
|
+ "开仓均价:" + mixData.getString("averageOpenPrice") + "\n" +
|
|
|
+ "当前价格:" + last + "\n" +
|
|
|
+ "回报率:" + returnRate.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toPlainString() + ",超过" + grid.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toPlainString();
|
|
|
+ SpringUtils.getBean(CoinServiceImpl.class).monitorAlarm4CHAT_BOT(content, null);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("returnRate", returnRate);
|
|
|
+ jsonObject.put(grid.toPlainString(), true);
|
|
|
+ mixMap.put(key, jsonObject);
|
|
|
+
|
|
|
+ String requestUrl = mainUrl + "/api/mix/v1/market/ticker?symbol=" + symbol;
|
|
|
+ String last = "--";
|
|
|
+ try {
|
|
|
+ Connection.Response responseTicker = JsoupUtil.requestBody(requestUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, null, null);
|
|
|
+ last = JSONObject.parseObject(responseTicker.body()).getJSONObject("data").getString("last");
|
|
|
+ } catch (Exception e) {
|
|
|
}
|
|
|
+ String content = "币对名称:" + symbol + "\n" +
|
|
|
+ "持仓方向:" + InitRunner.publicParamsMap.get("holdSide").getString(mixData.getString("holdSide")) + "\n" +
|
|
|
+ "杠杆倍数:" + mixData.getString("leverage") + "\n" +
|
|
|
+ "开仓均价:" + mixData.getString("averageOpenPrice") + "\n" +
|
|
|
+ "当前价格:" + last + "\n" +
|
|
|
+ "回报率:" + returnRate.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toPlainString() + ",超过" + grid.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toPlainString();
|
|
|
+ SpringUtils.getBean(CoinServiceImpl.class).monitorAlarm4CHAT_BOT(content, null);
|
|
|
+
|
|
|
+ //break;
|
|
|
}
|
|
|
}
|
|
|
- if ("short".equalsIgnoreCase(holdSide)) {
|
|
|
- // TODO
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -502,7 +525,21 @@ public class CoinServiceImpl implements CoinService {
|
|
|
@Override
|
|
|
@Async("coinTaskExecutor")
|
|
|
public void monitorAlarm4CHAT_BOT(String content, JSONObject params) {
|
|
|
+ // 调用企业微信群聊机器人发消息
|
|
|
+ WxCpGroupRobotService groupRobotService = wxCpService.getGroupRobotService();
|
|
|
+ String webhookUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=082970da-2a33-422a-81f6-15f9bde87940";
|
|
|
|
|
|
+ List<String> userList = Collections.singletonList("LvZhiQiang");
|
|
|
+ if (params != null && params.containsKey("user")) {
|
|
|
+ userList = Arrays.asList(params.getString("user").split("[|,]"));
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ log.info("企业微信推送消息,send content: {}, userIdSet: {}", content, userList);
|
|
|
+ groupRobotService.sendText(webhookUrl, content, userList, Collections.emptyList());
|
|
|
+ log.info("企业微信推送消息成功");
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ log.error("企业微信推送消息失败!Detail: ", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -907,6 +944,16 @@ public class CoinServiceImpl implements CoinService {
|
|
|
} else {
|
|
|
jsonObject.put("unrealizedPLStyle", " style=\"color:#FFFFFF;background-color:#1DA2B4;\"");
|
|
|
}
|
|
|
+
|
|
|
+ // 回报率=未实现盈亏/保证金
|
|
|
+ BigDecimal returnRate = jsonObject.getBigDecimal("unrealizedPL").divide(jsonObject.getBigDecimal("margin"), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ jsonObject.put("returnRate", returnRate);
|
|
|
+ if (returnRate.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ jsonObject.put("returnRateStyle", " style=\"color:#FFFFFF;background-color:#F1493F;\"");
|
|
|
+ } else {
|
|
|
+ jsonObject.put("returnRateStyle", " style=\"color:#FFFFFF;background-color:#1DA2B4;\"");
|
|
|
+ }
|
|
|
+
|
|
|
// 标记价格
|
|
|
jsonObject.put("marketPriceStyle", " style=\"color:#252B31;background-color:#C4ADE9;font-weight:bold;\"");
|
|
|
|