| | |
| | | String connId = MallUtils.getOrderNum(POSITIONSWS_CHANNEL); |
| | | JSONObject jsonObject = WsParamBuild.buildJsonObject(connId, option, argsArray); |
| | | webSocketClient.send(jsonObject.toJSONString()); |
| | | // log.info("发送持仓频道频道:{}", option); |
| | | log.info("发送持仓频道频道:{}", option); |
| | | } catch (Exception e) { |
| | | log.error("订阅持仓频道频道构建失败", e); |
| | | } |
| | | } |
| | | |
| | | public static String initAccountName(String accountName, String posSide) { |
| | | return accountName+"_"+ posSide; |
| | | } |
| | | |
| | | public static void initEvent(JSONObject response, String accountName) { |
| | | // log.info("订阅成功,数据初始化: {}", response.getJSONObject("arg")); |
| | | log.info("订阅成功,数据初始化: {}", response.getJSONObject("arg")); |
| | | JSONObject arg = response.getJSONObject("arg"); |
| | | initParam(arg, accountName); |
| | | initParam(arg, accountName,CoinEnums.POSSIDE_LONG.getCode()); |
| | | initParam(arg, accountName,CoinEnums.POSSIDE_SHORT.getCode()); |
| | | } |
| | | |
| | | public static void handleEvent(JSONObject response, String accountName) { |
| | | |
| | | |
| | | // log.info("开始执行PositionsWs......"); |
| | | log.info("开始执行PositionsWs......"); |
| | | try { |
| | | JSONArray dataArray = response.getJSONArray("data"); |
| | | if (dataArray == null || dataArray.isEmpty()) { |
| | | // log.info("账户持仓频道数据为空,已当前价买入,并且初始化网格"); |
| | | log.info("账户持仓频道数据为空,已当前价买入,并且初始化网格"); |
| | | JSONObject posData = new JSONObject(); |
| | | initParam(posData, accountName); |
| | | initParam(posData, accountName,CoinEnums.POSSIDE_LONG.getCode()); |
| | | initParam(posData, accountName,CoinEnums.POSSIDE_SHORT.getCode()); |
| | | return; |
| | | } |
| | | |
| | |
| | | JSONObject posData = dataArray.getJSONObject(i); |
| | | String instId = posData.getString("instId"); |
| | | if (CoinEnums.HE_YUE.getCode().equals(instId)) { |
| | | // log.info("查询到账户{}持仓数据",CoinEnums.HE_YUE.getCode()); |
| | | log.info("查询到账户{}持仓数据",CoinEnums.HE_YUE.getCode()); |
| | | String mgnMode = posData.getString("mgnMode"); |
| | | String posSide = posData.getString("posSide"); |
| | | String pos = posData.getString("pos"); |
| | |
| | | last, idxPx, bePx, realizedPnl, settledPnl, |
| | | markPx,fee,fundingFee |
| | | ); |
| | | |
| | | initParam(posData, accountName); |
| | | initParam(posData, accountName,posSide); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | |
| | | private static void initParam(JSONObject posData, String accountName) { |
| | | Map<String, BigDecimal> accountMap = getAccountMap(accountName); |
| | | private static void initParam(JSONObject posData, String accountName,String posSide) { |
| | | String accountNamePositons = initAccountName(accountName, posSide); |
| | | Map<String, BigDecimal> accountMap = getAccountMap(accountNamePositons); |
| | | WsMapBuild.saveBigDecimalToMap(accountMap, "avgPx", WsMapBuild.parseBigDecimalSafe(posData.getString("avgPx"))); |
| | | WsMapBuild.saveBigDecimalToMap(accountMap, "pos", WsMapBuild.parseBigDecimalSafe(posData.getString("pos"))); |
| | | WsMapBuild.saveBigDecimalToMap(accountMap, "upl", WsMapBuild.parseBigDecimalSafe(posData.getString("upl"))); |