fix(trading): 修复交易系统中的计算错误和日志级别问题
- 修复了总保证金计算错误,添加了除法运算确保正确计算
- 将错误日志级别从error降级为warn,避免过度警报
- 修正了止损和抗压比例配置错误
- 移除了历史网格订单处理逻辑
- 修复了多账号WebSocket客户端的数据冲突问题
- 更新了网格配置参数以优化交易策略
- 实现了持仓变动时的自动止损订单生成功能
- 修复了日志级别配置,从error调整为info以便更好监控
- 添加了必要的导入包和依赖注入支持
| | |
| | | for (OkxQuantWebSocketClient client : clientManager.getAllClients()) { |
| | | String accountName = client.getAccountName(); |
| | | if (accountName != null) { |
| | | /** |
| | | * 处理历史网格的订单 |
| | | * 根据历史网格的开单方向,是否需要止损处理 |
| | | * 如果方向一致就不需要处理 |
| | | * 如果不一致则需要处理 |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 处理当前网格的订单,触发量化操作 |
| | | */ |
| | | log.info("当前价格{}属于网格: {}-{}({}-{})", markPx, gridByPriceNew.getName(),gridByPriceNew.getFang_xiang(), gridByPriceNew.getJiage_xiaxian(), gridByPriceNew.getJiage_shangxian()); |
| | | wangGeListService.initWangGe(markPx); |
| | | TradeRequestParam tradeRequestParam = caoZuoService.caoZuoHandler(accountName, markPx, gridByPriceNew.getFang_xiang()); |
| | |
| | | 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"; |
| | |
| | | // 注意:当前实现中,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()); |
| | | |
| | | List<TradeRequestParam> tradeRequestParams = PositionsWs.handleEvent(response, account.name()); |
| | | TradeOrderWs.orderZhiSunEvent(webSocketClient, tradeRequestParams); |
| | | } 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); |
| | | if (realKuiSunAmount.compareTo(BigDecimal.ZERO) < 0){ |
| | | 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 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("账户冷静止损......"); |
| | | 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.info("止损订单:{},方向:{}-{},数量:{}",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 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 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; |
| | | |
| | |
| | | initParam(arg, accountName,CoinEnums.POSSIDE_SHORT.getCode()); |
| | | } |
| | | |
| | | public static void handleEvent(JSONObject response, String accountName) { |
| | | public static List<TradeRequestParam> handleEvent(JSONObject response, String accountName) { |
| | | |
| | | |
| | | log.info("开始执行PositionsWs......"); |
| | |
| | | JSONArray dataArray = response.getJSONArray("data"); |
| | | if (dataArray == null || dataArray.isEmpty()) { |
| | | log.info("账户持仓频道数据为空,等待更新"); |
| | | return; |
| | | return null; |
| | | } |
| | | |
| | | List<TradeRequestParam> tradeRequestParamList = new ArrayList<>(); |
| | | |
| | | for (int i = 0; i < dataArray.size(); i++) { |
| | | JSONObject posData = dataArray.getJSONObject(i); |
| | |
| | | last, idxPx, bePx, realizedPnl, settledPnl, |
| | | markPx,fee,fundingFee |
| | | ); |
| | | initParam(posData, accountName,posSide); |
| | | //先更新缓存 |
| | | Map<String, BigDecimal> stringBigDecimalMap = initParam(posData, accountName, posSide); |
| | | //构建止损参数 |
| | | if (stringBigDecimalMap.get("pos").compareTo(BigDecimal.ZERO) > 0){ |
| | | TradeRequestParam tradeRequestParam = new TradeRequestParam(); |
| | | // 1. 判断当前价格属于哪个网格 |
| | | WangGeListEnum gridByPriceNew = WangGeListEnum.getGridByPrice(new BigDecimal(avgPx)); |
| | | if (gridByPriceNew != null) { |
| | | String zhiSunDian = gridByPriceNew.getZhi_sun_dian(); |
| | | String fangXiang = gridByPriceNew.getFang_xiang(); |
| | | BigDecimal fangXiangNow = stringBigDecimalMap.get("posSide"); |
| | | if (fangXiangNow.equals(fangXiang)){ |
| | | tradeRequestParam.setOrdType(CoinEnums.ORDTYPE_LIMIT.getCode()); |
| | | tradeRequestParam.setMarkPx(String.valueOf(zhiSunDian)); |
| | | }else{ |
| | | tradeRequestParam.setOrdType(CoinEnums.ORDTYPE_MARKET.getCode()); |
| | | tradeRequestParam.setMarkPx(String.valueOf(markPx)); |
| | | } |
| | | }else{ |
| | | tradeRequestParam.setOrdType(CoinEnums.ORDTYPE_MARKET.getCode()); |
| | | tradeRequestParam.setMarkPx(String.valueOf(markPx)); |
| | | } |
| | | |
| | | |
| | | tradeRequestParam.setAccountName(accountName); |
| | | tradeRequestParam.setInstId(CoinEnums.HE_YUE.getCode()); |
| | | tradeRequestParam.setTdMode(CoinEnums.CROSS.getCode()); |
| | | tradeRequestParam.setPosSide(posSide); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_YES.getValue()); |
| | | tradeRequestParam.setSide(CoinEnums.POSSIDE_LONG.getCode().equals(posSide) ? CoinEnums.SIDE_SELL.getCode() : CoinEnums.SIDE_BUY.getCode()); |
| | | tradeRequestParam.setClOrdId(WsParamBuild.getOrderNum(tradeRequestParam.getSide())); |
| | | tradeRequestParam.setSz(String.valueOf(stringBigDecimalMap.get("pos"))); |
| | | tradeRequestParamList.add(tradeRequestParam); |
| | | } |
| | | } |
| | | } |
| | | return tradeRequestParamList; |
| | | } catch (Exception e) { |
| | | log.error("处理持仓频道推送数据失败", e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | 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 orderZhiSunEvent(WebSocketClient webSocketClient, List<TradeRequestParam> tradeRequestParams) { |
| | | |
| | | log.info("开始止损......"); |
| | | if (CollUtil.isEmpty(tradeRequestParams)){ |
| | | log.error("止损下单{}参数缺失,取消发送", JSONUtil.parse(tradeRequestParams)); |
| | | return; |
| | | } |
| | | for (TradeRequestParam tradeRequestParam : tradeRequestParams){ |
| | | String accountName = tradeRequestParam.getAccountName(); |
| | | String markPx = tradeRequestParam.getMarkPx(); |
| | | String instId = tradeRequestParam.getInstId(); |
| | | String tdMode = tradeRequestParam.getTdMode(); |
| | | String posSide = tradeRequestParam.getPosSide(); |
| | | String ordType = tradeRequestParam.getOrdType(); |
| | | |
| | | String tradeType = tradeRequestParam.getTradeType(); |
| | | |
| | | String clOrdId = tradeRequestParam.getClOrdId(); |
| | | String side = tradeRequestParam.getSide(); |
| | | String sz = tradeRequestParam.getSz(); |
| | | /** |
| | | * 校验必要参数 |
| | | * 验证下单参数是否存在空值 |
| | | */ |
| | | if ( |
| | | StrUtil.isBlank(accountName) |
| | | || StrUtil.isBlank(instId) |
| | | || StrUtil.isBlank(tdMode) |
| | | || StrUtil.isBlank(posSide) |
| | | || StrUtil.isBlank(ordType) |
| | | || StrUtil.isBlank(clOrdId) |
| | | || StrUtil.isBlank(side) |
| | | || StrUtil.isBlank(sz) |
| | | || StrUtil.isBlank(markPx) |
| | | |
| | | ){ |
| | | log.error("止损下单参数缺失,取消发送"); |
| | | return; |
| | | } |
| | | log.info("止损账户:{},触发价格:{},币种:{},方向:{},买卖:{},数量:{},是否允许下单:{},编号:{},", |
| | | accountName, markPx, instId, posSide,side, sz, tradeType, clOrdId); |
| | | //验证是否允许下单 |
| | | if (StrUtil.isNotEmpty(tradeType) && OrderParamEnums.TRADE_NO.getValue().equals(tradeType)) { |
| | | log.error("止损账户{}不允许下单,取消发送", accountName); |
| | | return; |
| | | } |
| | | /** |
| | | * 检验账户和仓位是否准备就绪 |
| | | * 开多:买入开多(side 填写 buy; posSide 填写 long ) |
| | | * 开空:卖出开空(side 填写 sell; posSide 填写 short ) 需要检验账户通道是否准备就绪 |
| | | * 平多:卖出平多(side 填写 sell;posSide 填写 long ) |
| | | * 平空:买入平空(side 填写 buy; posSide 填写 short ) 需要检验仓位通道是否准备就绪 |
| | | */ |
| | | try { |
| | | JSONArray argsArray = new JSONArray(); |
| | | JSONObject args = new JSONObject(); |
| | | args.put("instId", instId); |
| | | args.put("tdMode", tdMode); |
| | | args.put("clOrdId", clOrdId); |
| | | args.put("side", side); |
| | | |
| | | args.put("posSide", posSide); |
| | | args.put("ordType", ordType); |
| | | args.put("sz", sz); |
| | | args.put("px", markPx); |
| | | argsArray.add(args); |
| | | |
| | | String connId = WsParamBuild.getOrderNum(ORDERWS_CHANNEL); |
| | | JSONObject jsonObject = WsParamBuild.buildJsonObject(connId, ORDERWS_CHANNEL, argsArray); |
| | | webSocketClient.send(jsonObject.toJSONString()); |
| | | log.info("止损已发送......"); |
| | | } catch (Exception e) { |
| | | 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; |
| | | } |
| | | |
| | |
| | | <logger name="java.sql" level="DEBUG" /> |
| | | </springProfile> |
| | | |
| | | <root level="error"> |
| | | <root level="info"> |
| | | <appender-ref ref="CONSOLE" /> |
| | | <appender-ref ref="DEBUG_FILE" /> |
| | | <appender-ref ref="INFO_FILE" /> |