| | |
| | | package com.xcong.excoin.utils;
|
| | |
|
| | |
|
| | | import com.xcong.excoin.common.exception.GlobalException;
|
| | | import com.xcong.excoin.common.response.Result;
|
| | | import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
|
| | | import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
|
| | | import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
|
| | | import com.xcong.excoin.modules.member.dao.MemberSettingDao;
|
| | | import com.xcong.excoin.modules.member.entity.MemberEntity;
|
| | | import com.xcong.excoin.modules.member.entity.MemberSettingEntity;
|
| | |
| | | /**
|
| | | * 计算预估强平价
|
| | | *
|
| | | * @param bondAmount 保证金
|
| | | * @param bondAmount 保证金
|
| | | * @param openPrice 开仓价
|
| | | * @param symbolSkuNumber 张数
|
| | | * @param lotNumber 规格
|
| | |
| | | }
|
| | | return forcePrice;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算保证金 -- 建仓价*规格*手数*(1/杠杆倍率)
|
| | | *
|
| | | * @param openingPrice 开仓价
|
| | | * @param lotNumber 规格
|
| | | * @param symbolCnt 张数
|
| | | * @param leverRatio 杠杆倍率
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getBondAmount(BigDecimal openingPrice, BigDecimal lotNumber, Integer symbolCnt, Integer leverRatio) {
|
| | | return openingPrice.multiply(lotNumber).multiply(new BigDecimal(symbolCnt))
|
| | | .multiply(BigDecimal.ONE.divide(new BigDecimal(leverRatio)))
|
| | | .setScale(8, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 全仓模式 -- 预估强平价
|
| | | * 面值*(多单张数*多单开仓价-空单张数*空单开仓价)-余额-已实现盈亏 / 面值*(多单张数-空单张数)-(维持保证金率+TAKER手续费)*面值*(开多张数+开空张数)
|
| | | *
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getForceSetPriceForWhole(MemberEntity memberEntity) {
|
| | | ContractHoldOrderDao holdOrderDao = SpringContextHolder.getBean(ContractHoldOrderDao.class);
|
| | | MemberWalletContractDao walletContractDao = SpringContextHolder.getBean(MemberWalletContractDao.class);
|
| | | CacheSettingUtils cacheSettingUtils = SpringContextHolder.getBean(CacheSettingUtils.class);
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算开仓价
|
| | | *
|
| | | * @param orderType 订单类型
|
| | | * @param newPrice 当前价
|
| | | * @param spread 划点
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getOpeningPrice(int orderType, BigDecimal newPrice, BigDecimal spread) {
|
| | | BigDecimal openingPrice = BigDecimal.ZERO;
|
| | | if (orderType == ContractHoldOrderEntity.OPENING_TYPE_MORE) {
|
| | | // 市场价*(1 + (点差/10000))
|
| | | openingPrice = newPrice.multiply(BigDecimal.ONE.add(spread.divide(new BigDecimal(10000)))).setScale(8, BigDecimal.ROUND_DOWN);
|
| | |
|
| | | // 开空
|
| | | } else if (orderType == ContractHoldOrderEntity.OPENING_TYPE_LESS) {
|
| | | // 市场价*(1 - (点差/10000))
|
| | | openingPrice = newPrice.multiply(BigDecimal.ONE.subtract(spread.divide(new BigDecimal(10000)))).setScale(8, BigDecimal.ROUND_DOWN);
|
| | | } else {
|
| | | throw new GlobalException(MessageSourceUtils.getString("unknown_type"));
|
| | | }
|
| | | return openingPrice;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 计算开仓手续费
|
| | | *
|
| | | * @param openingPrice 开仓价
|
| | | * @param lotNumber 规格
|
| | | * @param count 张数
|
| | | * @param feeRatio 手续费率
|
| | | * @return
|
| | | */
|
| | | public static BigDecimal getOpenFeePrice(BigDecimal openingPrice, BigDecimal lotNumber, int count, BigDecimal feeRatio) {
|
| | | return openingPrice.multiply(lotNumber)
|
| | | .multiply(new BigDecimal(count))
|
| | | .multiply(feeRatio.divide(new BigDecimal(100)))
|
| | | .setScale(8, BigDecimal.ROUND_DOWN);
|
| | | }
|
| | | }
|