| | |
| | | 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 服务器的连接。 |
| | |
| | | */ |
| | | private void triggerQuantOperations(String markPx) { |
| | | try { |
| | | |
| | | // markPx = String.valueOf(new BigDecimal(markPx).subtract(new BigDecimal("20"))); |
| | | // 1. 判断当前价格属于哪个网格 |
| | | WangGeListEnum gridByPriceNew = WangGeListEnum.getGridByPrice(new BigDecimal(markPx)); |
| | | if (gridByPriceNew == null) { |
| | |
| | | for (OkxQuantWebSocketClient client : clientManager.getAllClients()) { |
| | | String accountName = client.getAccountName(); |
| | | if (accountName != null) { |
| | | /** |
| | | * 处理历史网格的订单 |
| | | * 根据历史网格的开单方向,是否需要止损处理 |
| | | * 如果方向一致就不需要处理 |
| | | * 如果不一致则需要处理 |
| | | */ |
| | | log.error("当前价格{}属于网格: {}-{}({}-{})", markPx, gridByPriceNew.getName(),gridByPriceNew.getFang_xiang(), gridByPriceNew.getJiage_xiaxian(), gridByPriceNew.getJiage_shangxian()); |
| | | //处理历史网格信息 |
| | | String fangXiang = gridByPriceNew.getFang_xiang(); |
| | | String fangXiangOld = CoinEnums.POSSIDE_LONG.getCode().equals(fangXiang) ? CoinEnums.POSSIDE_SHORT.getCode() : CoinEnums.POSSIDE_LONG.getCode(); |
| | | if (!fangXiang.equals(fangXiangOld)){ |
| | | log.info("历史网格方向为:{}", fangXiangOld); |
| | | TradeRequestParam tradeRequestParamOld = caoZuoService.caoZuoZhiSunEvent(accountName, markPx, fangXiangOld); |
| | | TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParamOld); |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 处理当前网格的订单,触发量化操作 |
| | | */ |
| | | log.info("当前价格{}属于网格: {}-{}({}-{})", markPx, gridByPriceNew.getName(),gridByPriceNew.getFang_xiang(), gridByPriceNew.getJiage_xiaxian(), gridByPriceNew.getJiage_shangxian()); |
| | | 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)) { |
| | | boolean flag = new BigDecimal(markPx).compareTo(new BigDecimal(zhiSunDian)) > 0; |
| | | log.error("{}历史网格方向{},当前价格大于止损点{}",gridByPriceOld.name(),posSideOld,flag); |
| | | if (flag){ |
| | | TradeRequestParam tradeRequestParam = caoZuoService.caoZuoZhiSunEvent(accountName, markPx, posSideOld); |
| | | TradeOrderWs.orderEvent(client.getWebSocketClient(), tradeRequestParam); |
| | | |
| | | } |
| | | } |
| | | if (CoinEnums.POSSIDE_LONG.getCode().equals(posSideOld)) { |
| | | boolean flag = new BigDecimal(markPx).compareTo(new BigDecimal(zhiSunDian)) < 0; |
| | | log.error("{}历史网格方向{},当前价格小于止损点{}",gridByPriceOld.name(),posSideOld,flag); |
| | | if (flag){ |
| | | 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); |
| | |
| | | package com.xcong.excoin.modules.okxNewPrice; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.modules.okxNewPrice.celue.CaoZuoService; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.*; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.ExchangeInfoEnum; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.param.TradeRequestParam; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.wanggeList.WangGeListService; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.SSLConfig; |
| | | import com.xcong.excoin.modules.okxNewPrice.wangge.WangGeService; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | |
| | | import javax.annotation.PreDestroy; |
| | | import java.net.URI; |
| | | import java.net.URISyntaxException; |
| | | import java.util.List; |
| | | import java.util.concurrent.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | |
| | | public class OkxQuantWebSocketClient { |
| | | private final RedisUtils redisUtils; |
| | | private final ExchangeInfoEnum account; |
| | | |
| | | private final CaoZuoService caoZuoService; |
| | | private final WangGeListService wangGeListService; |
| | | |
| | | private WebSocketClient webSocketClient; |
| | | private ScheduledExecutorService heartbeatExecutor; |
| | |
| | | return account.name(); |
| | | } |
| | | |
| | | public OkxQuantWebSocketClient(ExchangeInfoEnum account, |
| | | RedisUtils redisUtils) { |
| | | public OkxQuantWebSocketClient( |
| | | ExchangeInfoEnum account, |
| | | RedisUtils redisUtils, |
| | | CaoZuoService caoZuoService, |
| | | WangGeListService wangGeListService |
| | | ) { |
| | | this.account = account; |
| | | this.redisUtils = redisUtils; |
| | | this.caoZuoService = caoZuoService; |
| | | this.wangGeListService = wangGeListService; |
| | | } |
| | | |
| | | private static final String WS_URL_MONIPAN = "wss://wspap.okx.com:8443/ws/v5/private"; |
| | |
| | | * 销毁方法,在 Spring Bean 销毁前执行。 |
| | | * 关闭 WebSocket 连接、停止心跳定时器及相关的线程资源。 |
| | | */ |
| | | // @PreDestroy |
| | | // public void destroy() { |
| | | // if (webSocketClient != null && webSocketClient.isOpen()) { |
| | | // subscribeAccountChannel(UNSUBSCRIBE); |
| | | // subscribePositionChannel(UNSUBSCRIBE); |
| | | // subscribeOrderInfoChannel(UNSUBSCRIBE); |
| | | // webSocketClient.close(); |
| | | // } |
| | | // shutdownExecutorGracefully(heartbeatExecutor); |
| | | // if (pongTimeoutFuture != null) { |
| | | // pongTimeoutFuture.cancel(true); |
| | | // } |
| | | // shutdownExecutorGracefully(sharedExecutor); |
| | | // |
| | | // // 移除了 reconnectScheduler 的关闭操作 |
| | | // } |
| | | @PreDestroy |
| | | public void destroy() { |
| | | log.info("开始销毁OkxQuantWebSocketClient"); |
| | |
| | | // 注意:当前实现中,OrderInfoWs等类使用静态Map存储数据 |
| | | // 这会导致多账号之间的数据冲突。需要进一步修改这些类的设计,让数据存储与特定账号关联 |
| | | if (OrderInfoWs.ORDERINFOWS_CHANNEL.equals(channel)) { |
| | | |
| | | TradeRequestParam tradeRequestParam = OrderInfoWs.handleEvent(response, redisUtils, account.name()); |
| | | TradeOrderWs.orderZhiYingEvent(webSocketClient, tradeRequestParam); |
| | | }else if (AccountWs.ACCOUNTWS_CHANNEL.equals(channel)) { |
| | | |
| | | AccountWs.handleEvent(response, account.name()); |
| | | // String side = caoZuoService.caoZuo(account.name()); |
| | | // TradeOrderWs.orderEvent(webSocketClient, side, account.name()); |
| | | } else if (PositionsWs.POSITIONSWS_CHANNEL.equals(channel)) { |
| | | |
| | | PositionsWs.handleEvent(response, account.name()); |
| | | } else if (BalanceAndPositionWs.CHANNEL_NAME.equals(channel)) { |
| | | |
| | | BalanceAndPositionWs.handleEvent(response); |
| | | } |
| | | } |
| | |
| | | // 为每个账号创建一个WebSocket客户端实例 |
| | | for (ExchangeInfoEnum account : accounts) { |
| | | try { |
| | | OkxQuantWebSocketClient client = new OkxQuantWebSocketClient(account, redisUtils); |
| | | OkxQuantWebSocketClient client = new OkxQuantWebSocketClient(account, redisUtils, caoZuoService, wangGeListService); |
| | | quantClientMap.put(account.name(), client); |
| | | client.init(); |
| | | log.info("已初始化账号 {} 的WebSocket客户端", account.name()); |
| | |
| | | |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.param.TradeRequestParam; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | */ |
| | |
| | | package com.xcong.excoin.modules.okxNewPrice.celue; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.*; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.PriorityBlockingQueue; |
| | | |
| | |
| | | tradeRequestParam.setPosSide(posSide); |
| | | tradeRequestParam.setOrdType(CoinEnums.ORDTYPE_MARKET.getCode()); |
| | | |
| | | log.info("操作账户:{},当前价格: {},仓位方向: {}", accountName,markPx,posSide); |
| | | /** |
| | | * 准备工作 |
| | | * 1、准备好下单的基本信息 |
| | |
| | | * 判断止损抗压 |
| | | */ |
| | | BigDecimal realKuiSunAmount = WsMapBuild.parseBigDecimalSafe(AccountWs.getAccountMap(accountName).get("upl")); |
| | | log.info("实际盈亏金额: {}", realKuiSunAmount); |
| | | String zhiSunPercent = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.ZHI_SUN.name()); |
| | | BigDecimal zhiSunAmount = cashBal.multiply(new BigDecimal(zhiSunPercent)); |
| | | log.info("预期亏损金额: {}", zhiSunAmount); |
| | | String kangYaPercent = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.KANG_CANG.name()); |
| | | BigDecimal kangYaAmount = cashBal.multiply(new BigDecimal(kangYaPercent)); |
| | | log.info("预期抗仓金额: {}", kangYaAmount); |
| | | |
| | | if (realKuiSunAmount.compareTo(BigDecimal.ZERO) < 0){ |
| | | String kangYaPercent = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.KANG_CANG.name()); |
| | | BigDecimal kangYaAmount = cashBal.multiply(new BigDecimal(kangYaPercent)); |
| | | String zhiSunPercent = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.ZHI_SUN.name()); |
| | | BigDecimal zhiSunAmount = cashBal.multiply(new BigDecimal(zhiSunPercent)); |
| | | log.info("实际盈亏金额: {},预期抗仓金额: {},预期亏损金额: {}", realKuiSunAmount, kangYaAmount, zhiSunAmount); |
| | | realKuiSunAmount = realKuiSunAmount.multiply(new BigDecimal("-1")); |
| | | // 账户预期亏损金额比这个还小时,立即止损 |
| | | if (realKuiSunAmount.compareTo(zhiSunAmount) > 0){ |
| | | log.error("账户冷静止损......"); |
| | | log.warn("账户冷静止损......"); |
| | | //目前止损掉损失较大的一个方向 |
| | | String positionAccountName = PositionsWs.initAccountName(accountName, posSide); |
| | | BigDecimal upl = PositionsWs.getAccountMap(positionAccountName).get("upl"); |
| | | String posSideOther = CoinEnums.POSSIDE_LONG.getCode().equals(posSide) ? CoinEnums.POSSIDE_SHORT.getCode() : CoinEnums.POSSIDE_LONG.getCode(); |
| | | String positionAccountOther = PositionsWs.initAccountName(accountName, posSideOther); |
| | | BigDecimal uplOther = PositionsWs.getAccountMap(positionAccountOther).get("upl"); |
| | | if (upl.compareTo(uplOther) > 0){ |
| | | log.warn("{}的亏损{},{}的亏损{},止损{}......",posSide,upl,posSideOther,uplOther,uplOther); |
| | | posSide = posSideOther; |
| | | } |
| | | |
| | | WsMapBuild.saveStringToMap(InstrumentsWs.getAccountMap(accountName), CoinEnums.OUT.name(), OrderParamEnums.OUT_YES.getValue()); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_YES.getValue()); |
| | | return caoZuoZhiSunEvent(accountName, markPx, posSide); |
| | | } |
| | | // 判断抗压 |
| | | if (realKuiSunAmount.compareTo(kangYaAmount) > 0 && realKuiSunAmount.compareTo(zhiSunAmount) <= 0){ |
| | | log.error("账户紧张扛仓......"); |
| | | log.warn("账户紧张扛仓......"); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return chooseEvent(tradeRequestParam); |
| | | } |
| | |
| | | String positionAccountName = PositionsWs.initAccountName(accountName, posSide); |
| | | // 判断是否保证金超标 |
| | | if (PositionsWs.getAccountMap(positionAccountName).get("imr") == null){ |
| | | log.error("没有获取到持仓信息,等待初始化......"); |
| | | log.warn("没有获取到持仓信息,等待初始化......"); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return chooseEvent(tradeRequestParam); |
| | | } |
| | | BigDecimal ordFrozImr = PositionsWs.getAccountMap(positionAccountName).get("imr"); |
| | | BigDecimal totalOrderUsdt = WsMapBuild.parseBigDecimalSafe(AccountWs.getAccountMap(accountName).get(CoinEnums.TOTAL_ORDER_USDT.name())) |
| | | .divide(new BigDecimal("2"), RoundingMode.DOWN); |
| | | BigDecimal totalOrderUsdt = WsMapBuild.parseBigDecimalSafe(AccountWs.getAccountMap(accountName).get(CoinEnums.TOTAL_ORDER_USDT.name())); |
| | | if (ordFrozImr.compareTo(totalOrderUsdt) >= 0){ |
| | | log.error("已满仓......"); |
| | | log.warn("已满仓......"); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return chooseEvent(tradeRequestParam); |
| | | } |
| | | |
| | | if (PositionsWs.getAccountMap(positionAccountName).get("pos") == null){ |
| | | log.error("没有获取到持仓信息,等待初始化......"); |
| | | log.warn("没有获取到持仓信息,等待初始化......"); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return chooseEvent(tradeRequestParam); |
| | | } |
| | | BigDecimal pos = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | if (BigDecimal.ZERO.compareTo( pos) >= 0) { |
| | | log.error("持仓数量为零,进行初始化订单"); |
| | | log.warn("持仓数量为零,进行初始化订单"); |
| | | return caoZuoInitEvent(accountName, markPx, posSide); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public TradeRequestParam caoZuoZhiSunEvent(String accountName, String markPx, String posSide) { |
| | | |
| | | log.info("历史网格:操作账户:{},当前价格: {},仓位方向: {}", accountName,markPx,posSide); |
| | | /** |
| | | * 初始化订单请求参数 |
| | | * 获取仓位数量 |
| | |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | } |
| | | tradeRequestParam.setSz(String.valueOf( pos)); |
| | | log.error("止损订单:{},方向:{}-{},数量:{}",clOrdId,posSide, side, pos); |
| | | return tradeRequestParam; |
| | | |
| | | } |
| | |
| | | |
| | | @Override |
| | | public TradeRequestParam caoZuoLong(TradeRequestParam tradeRequestParam) { |
| | | log.info("开始做{}执行操作CaoZuoServiceImpl......",tradeRequestParam.getPosSide()); |
| | | log.info("开始做{}......",tradeRequestParam.getPosSide()); |
| | | |
| | | String accountName = tradeRequestParam.getAccountName(); |
| | | String markPxStr = tradeRequestParam.getMarkPx(); |
| | |
| | | String connId = MallUtils.getOrderNum(ACCOUNTWS_CHANNEL); |
| | | JSONObject jsonObject = WsParamBuild.buildJsonObject(connId, option, argsArray); |
| | | webSocketClient.send(jsonObject.toJSONString()); |
| | | // log.info("发送账户频道:{}", option); |
| | | } catch (Exception e) { |
| | | log.error("订阅账户频道构建失败", e); |
| | | } |
| | | } |
| | | |
| | | public static void initEvent(JSONObject response, String accountName) { |
| | | // log.info("订阅成功: {}", response.getJSONObject("arg")); |
| | | JSONObject arg = response.getJSONObject("arg"); |
| | | initParam(arg, accountName); |
| | | } |
| | |
| | | public static void handleEvent(JSONObject response, String accountName) { |
| | | |
| | | |
| | | // log.info("开始执行AccountWs......{}",ACCOUNTWS_CHANNEL); |
| | | try { |
| | | JSONArray dataArray = response.getJSONArray("data"); |
| | | if (dataArray == null || dataArray.isEmpty()) { |
| | |
| | | String total_order_usdtpecent = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.TOTAL_ORDER_USDTPECENT.name()); |
| | | BigDecimal total_order_usdt_factor = WsMapBuild.parseBigDecimalSafe(total_order_usdtpecent); |
| | | BigDecimal totalOrderUsdt = cashBalDecimal.multiply(total_order_usdt_factor).setScale(2, RoundingMode.DOWN); |
| | | totalOrderUsdt = totalOrderUsdt.divide(new BigDecimal("2"), RoundingMode.DOWN); |
| | | WsMapBuild.saveStringToMap(accountMap, CoinEnums.TOTAL_ORDER_USDT.name(), String.valueOf(totalOrderUsdt)); |
| | | |
| | | /** |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | |
| | | |
| | | log.info("{}: 订单详情已完成: {}, 自定义编号: {}", accountName, CoinEnums.HE_YUE.getCode(), clOrdId); |
| | | |
| | | |
| | | |
| | | TradeRequestParam tradeRequestParam = new TradeRequestParam(); |
| | | tradeRequestParam.setAccountName(accountName); |
| | | BigDecimal zhiYingPx = getZhiYingPx( |
| | |
| | | tradeRequestParam.setSide(CoinEnums.POSSIDE_LONG.getCode().equals(posSide) ? CoinEnums.SIDE_SELL.getCode() : CoinEnums.SIDE_BUY.getCode()); |
| | | tradeRequestParam.setClOrdId(WsParamBuild.getOrderNum(side)); |
| | | tradeRequestParam.setSz(accFillSz); |
| | | |
| | | return tradeRequestParam; |
| | | |
| | | } |
| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.okxpi.MallUtils; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.WsMapBuild; |
| | | import com.xcong.excoin.modules.okxNewPrice.utils.WsParamBuild; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | |
| | | last, idxPx, bePx, realizedPnl, settledPnl, |
| | | markPx,fee,fundingFee |
| | | ); |
| | | initParam(posData, accountName,posSide); |
| | | //先更新缓存 |
| | | Map<String, BigDecimal> stringBigDecimalMap = initParam(posData, accountName, posSide); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | |
| | | private static void initParam(JSONObject posData, String accountName,String posSide) { |
| | | private static Map<String, BigDecimal> 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"))); |
| | |
| | | if (ordFrozImr.compareTo(totalOrderUsdt) <= 0){ |
| | | WsMapBuild.saveBigDecimalToMap(accountMap, CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_YES.getCode())); |
| | | } |
| | | return accountMap; |
| | | } |
| | | } |
| | |
| | | package com.xcong.excoin.modules.okxNewPrice.okxWs; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums; |
| | |
| | | import org.java_websocket.client.WebSocketClient; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | |
| | | public static void orderZhiYingEvent(WebSocketClient webSocketClient, TradeRequestParam tradeRequestParam) { |
| | | |
| | | |
| | | log.info("开始执行TradeOrderWs......"); |
| | | log.info("开始执行限价{}......",JSONUtil.parse(tradeRequestParam)); |
| | | if (tradeRequestParam == null){ |
| | | |
| | | log.warn("下单{}参数缺失,取消发送",tradeRequestParam); |
| | | log.warn("限价下单参数缺失,取消发送"); |
| | | return; |
| | | } |
| | | String accountName = tradeRequestParam.getAccountName(); |
| | |
| | | log.error("下单构建失败", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | //下单的总保障金为账户总金额cashBal * TOTAL_ORDER_USDT用来做保证金 |
| | | TOTAL_ORDER_USDTPECENT("总保证金比例total_order_usdtpecent","0.1"), |
| | | TOTAL_ORDER_USDT("总保证金totalOrderUsdt","0"), |
| | | KANG_CANG("抗压比例KANG_CANG","0.9"), |
| | | ZHI_SUN("止损比例ZHI_SUN","0.8"), |
| | | KANG_CANG("抗压比例KANG_CANG","0.1"), |
| | | ZHI_SUN("止损比例ZHI_SUN","0.2"), |
| | | //每次下单的张数 |
| | | BUY_CNT("每次开仓的张数buyCnt","0.1"), |
| | | BUY_CNT_INIT("每次初始化开仓张数的基础值buyCntInit","0.1"), |
| | |
| | | * 模拟盘账户1信息 |
| | | * 存储了模拟盘交易所需的API密钥、秘钥和通过码 |
| | | */ |
| | | OKX_PRD_xiao("f512673b-2685-4fcb-9bb1-2ae8db745d62", |
| | | "B0C1CC8F39625B41140D93DC25039E33", |
| | | "Aa12345678@", |
| | | true); |
| | | // OKX_UAT_ceshi("ffb4e79f-fcf5-4afb-82c5-2fbb64123f61", |
| | | // "AA06C5ED1D7C7F5AFE6484052E231C55", |
| | | // OKX_PRD_xiao("f512673b-2685-4fcb-9bb1-2ae8db745d62", |
| | | // "B0C1CC8F39625B41140D93DC25039E33", |
| | | // "Aa12345678@", |
| | | // false); |
| | | // true); |
| | | OKX_UAT_ceshi("ffb4e79f-fcf5-4afb-82c5-2fbb64123f61", |
| | | "AA06C5ED1D7C7F5AFE6484052E231C55", |
| | | "Aa12345678@", |
| | | false); |
| | | // |
| | | // /** |
| | | // * 模拟盘账户2信息 |
| | |
| | | */ |
| | | @Getter |
| | | public enum WangGeListEnum { |
| | | UP_ONE("上层做空", "2", "3500", "3300", "4", "long", "3500"), |
| | | UP("上层做空", "2", "3300", "3000", "4", "short", "3300"), |
| | | CENTER("中间做空", "2", "3000", "2700", "4", "short", "3000"), |
| | | DOWN("下层做空", "2", "2700", "2200", "4", "short", "2700"), |
| | | DOWN_ONE("下层做多", "2", "2200", "1800", "4", "long", "1800"); |
| | | // UP_ONE("上层做空", "2", "3500", "3300", "4", "long", "3500"), |
| | | // UP("上层做空", "2", "3300", "3000", "4", "short", "3300"), |
| | | // CENTER("中间做空", "2", "3000", "2700", "4", "short", "3000"), |
| | | // DOWN("下层做空", "2", "2700", "2200", "4", "short", "2700"), |
| | | // DOWN_ONE("下层做多", "2", "2200", "1800", "4", "long", "1800"); |
| | | UP_ONE("上层做long", "2", "3450", "3400", "4", "long", "3380"), |
| | | UP("上层做short", "2", "3400", "3350", "4", "short", "3420"), |
| | | CENTER("中间做long", "2", "3350", "3300", "4", "long", "3280"), |
| | | DOWN("下层做空", "2", "3300", "3250", "4", "short", "3320"), |
| | | DOWN_ONE("下层做多", "2", "3250", "3200", "4", "long", "3180"); |
| | | |
| | | private String name; |
| | | private String xiaoshu_weishu; |
| | |
| | | */ |
| | | @Override |
| | | public PriorityBlockingQueue<AscBigDecimal> initWangGe(String markPx) { |
| | | log.info("网格初始化中"); |
| | | PriorityBlockingQueue<AscBigDecimal> queueAsc = WangGeListQueue.getQueueAsc(); |
| | | queueAsc.clear(); |
| | | |
| | | //获取WangGeListEnum全部网格参数 |
| | | WangGeListEnum gridByPrice = WangGeListEnum.getGridByPrice(new BigDecimal(markPx)); |
| | | log.info("获取的网格参数: {}", gridByPrice); |
| | | if (gridByPrice == null){ |
| | | log.error("没有获取到网格参数......"); |
| | | return null; |
| | |
| | | } |
| | | |
| | | if (queueAsc.isEmpty()) { |
| | | log.info("网格初始化失败"); |
| | | log.error("网格初始化失败"); |
| | | return null; |
| | | } |
| | | |