| | |
| | | import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity; |
| | | import com.xcong.excoin.modules.contract.parameter.dto.SubmitEntrustDto; |
| | | import com.xcong.excoin.modules.contract.service.ContractEntrustOrderService; |
| | | import com.xcong.excoin.modules.member.dao.MemberWalletContractDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity; |
| | | import com.xcong.excoin.utils.CacheSettingUtils; |
| | | import com.xcong.excoin.utils.CoinTypeConvert; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @Resource |
| | | private ContractEntrustOrderDao contractEntrustOrderDao; |
| | | |
| | | @Resource |
| | | private MemberWalletContractDao memberWalletContractDao; |
| | | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Resource |
| | | private CacheSettingUtils cacheSettingUtils; |
| | | |
| | | @Override |
| | | public Result addContractEntrustOrder(SubmitEntrustDto submitEntrustDto) { |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | |
| | | // 获取最新价 |
| | | BigDecimal newPirce = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(submitEntrustDto.getSymbol()))); |
| | | |
| | | |
| | | // 委托开仓 |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE || submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_LESS) { |
| | | // 开多委托价不能大于当前价 |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) { |
| | | if (submitEntrustDto.getEntrustPrice().compareTo(newPirce) > -1) { |
| | | return Result.fail("委托价不能大于当前价"); |
| | | } |
| | | } |
| | | |
| | | // 开空委托价不能小于当前价 |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_LESS) { |
| | | if (submitEntrustDto.getEntrustPrice().compareTo(newPirce) < 1) { |
| | | return Result.fail("委托价不能小于当前价"); |
| | | } |
| | | } |
| | | |
| | | MemberWalletContractEntity walletContract = memberWalletContractDao.selectById(memberEntity.getId()); |
| | | // 委托总额 |
| | | BigDecimal entrustTotalAmount = submitEntrustDto.getEntrustPrice().multiply(BigDecimal.valueOf(submitEntrustDto.getSymbolCnt())); |
| | | |
| | | if (entrustTotalAmount.compareTo(walletContract.getAvailableBalance()) > -1) { |
| | | return Result.fail("可用余额不足"); |
| | | } |
| | | |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitEntrustDto.getSymbol()); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | // 委托平仓 |
| | | // 委托平仓 (全仓模式) |
| | | if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_CLOSE_MORE || submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_CLOSE_LESS) { |
| | | |
| | | return Result.fail("功能暂未开放,敬请期待"); |
| | | } |
| | | return null; |
| | | } |