| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.modules.okxNewPrice.celue.CaoZuoService; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.AccountWs; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.PositionsWs; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.TradeOrderWs; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.OrderParamEnums; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.param.TradeRequestParam; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.wanggeList.WangGeListEnum; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.wanggeList.WangGeListService; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.SSLConfig; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.WsMapBuild; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import java.math.BigDecimal; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | private static final String WS_URL_MONIPAN = "wss://wspap.okx.com:8443/ws/v5/public"; |
| | | private static final String WS_URL_SHIPAN = "wss://ws.okx.com:8443/ws/v5/public"; |
| | | private static final boolean isAccountType = true; |
| | | private static final boolean isAccountType = false; |
| | | |
| | | /** |
| | | * 建立与 OKX WebSocket 服务器的连接。 |
| | |
| | | String accountName = client.getAccountName(); |
| | | if (accountName != null) { |
| | | log.info("当前价格{}属于网格: {}-{}({}-{})", markPx, gridByPriceNew.getName(),gridByPriceNew.getFang_xiang(), gridByPriceNew.getJiage_xiaxian(), gridByPriceNew.getJiage_shangxian()); |
| | | //处理历史网格信息 |
| | | String fangXiang = gridByPriceNew.getFang_xiang(); |
| | | String posSideOld = null; |
| | | if (CoinEnums.POSSIDE_LONG.getCode().equals(fangXiang)) { |
| | | posSideOld = CoinEnums.POSSIDE_SHORT.getCode(); |
| | | } |
| | | if (CoinEnums.POSSIDE_SHORT.getCode().equals(fangXiang)) { |
| | | posSideOld = CoinEnums.POSSIDE_LONG.getCode(); |
| | | } |
| | | |
| | | String positionAccountName = PositionsWs.initAccountName(accountName, posSideOld); |
| | | // 判断是否保证金超标 |
| | | if ( |
| | | PositionsWs.getAccountMap(positionAccountName).get("pos") != null |
| | | && PositionsWs.getAccountMap(positionAccountName).get("pos").compareTo(BigDecimal.ZERO) > 0 |
| | | ){ |
| | | BigDecimal avgPx = PositionsWs.getAccountMap(positionAccountName).get("avgPx"); |
| | | WangGeListEnum gridByPriceOld = WangGeListEnum.getGridByPrice(avgPx); |
| | | if (gridByPriceOld != null){ |
| | | String zhiSunDian = gridByPriceOld.getZhi_sun_dian(); |
| | | if (CoinEnums.POSSIDE_SHORT.getCode().equals(posSideOld)) { |
| | | if (new BigDecimal(markPx).compareTo(new BigDecimal(zhiSunDian)) > 0){ |
| | | TradeRequestParam tradeRequestParam = caoZuoService.caoZuoZhiSunEvent(accountName, markPx, posSideOld); |
| | | TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParam); |
| | | |
| | | } |
| | | } |
| | | if (CoinEnums.POSSIDE_LONG.getCode().equals(posSideOld)) { |
| | | if (new BigDecimal(markPx).compareTo(new BigDecimal(zhiSunDian)) < 0){ |
| | | TradeRequestParam tradeRequestParam = caoZuoService.caoZuoZhiSunEvent(accountName, markPx, posSideOld); |
| | | TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParam); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //当前下单 |
| | | wangGeListService.initWangGe(markPx); |
| | | TradeRequestParam tradeRequestParam = caoZuoService.caoZuoHandler(accountName, markPx, gridByPriceNew.getFang_xiang()); |
| | | TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParam); |