| | |
| | | package kernel.util; |
| | | |
| | | import kotlin.jvm.internal.MagicApiIntrinsics; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | public class Arith{ |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | |
| | | import kernel.web.PageActionSupport; |
| | | import project.Constants; |
| | | import project.futures.AdminFuturesOrderService; |
| | | import project.futures.FuturesOrder; |
| | | import project.futures.FuturesOrderService; |
| | | import project.futures.FuturesRedisKeys; |
| | | import project.item.ItemService; |
| | | import project.item.model.Item; |
| | | import project.redis.RedisHandler; |
| | | |
| | | /** |
| | | * 交割合约单 |
| | |
| | | @Autowired |
| | | private FuturesOrderService futuresOrderService; |
| | | |
| | | protected RedisHandler redisHandler; |
| | | |
| | | @Autowired |
| | | private AdminFuturesOrderService adminFuturesOrderService; |
| | | |
| | |
| | | |
| | | /** |
| | | * 获取 交割合约单 列表 |
| | | * |
| | | * <p> |
| | | * symbol_para 币种 |
| | | * direction_para 方向 |
| | | * volume_para 下单金额 |
| | |
| | | |
| | | /** |
| | | * 获取 交割合约单 列表 |
| | | * |
| | | * <p> |
| | | * symbol_para 币种 |
| | | * direction_para 方向 |
| | | * volume_para 下单金额 |
| | |
| | | |
| | | /** |
| | | * ajax定时获取表 |
| | | * |
| | | * <p> |
| | | * symbol_para 币种 |
| | | * direction_para 方向 |
| | | * volume_para 下单金额 |
| | |
| | | |
| | | /** |
| | | * orderProfitLoss |
| | | * |
| | | * <p> |
| | | * profit_loss 盈利还是亏损 |
| | | */ |
| | | @RequestMapping(action + "orderProfitLoss.action") |
| | |
| | | return modelAndView; |
| | | } |
| | | |
| | | /** |
| | | * 交割合约一键场控 |
| | | * <p> |
| | | * profit_loss 盈利还是亏损 |
| | | */ |
| | | @RequestMapping(action + "orderProfitLossList.action") |
| | | public ModelAndView orderProfitLossList(HttpServletRequest request) { |
| | | ModelAndView modelAndView = new ModelAndView(); |
| | | modelAndView.setViewName("redirect:/" + action + "list.action"); |
| | | String stringOrderNo = request.getParameter("orderNos"); |
| | | String action = request.getParameter("action"); |
| | | logger.info("orderNos:"+stringOrderNo.toString()+"-----action:"+action); |
| | | String[] orderNos = stringOrderNo.split(","); |
| | | List<String> errorList = new ArrayList<>(); |
| | | try { |
| | | for (String orderNo : orderNos) { |
| | | logger.info("------->"+orderNo); |
| | | String error = this.futuresOrderService.saveOrderPorfitOrLoss(orderNo, action, this.getUsername_login()); |
| | | if (StringUtils.isNotEmpty(error)) { |
| | | error = "订单号:"+orderNo+",原因:"+error; |
| | | errorList.add(error); |
| | | } |
| | | } |
| | | if(errorList.size() > 0){ |
| | | throw new BusinessException("部分订单操作失败:"+errorList.toString()); |
| | | } |
| | | } catch (BusinessException e) { |
| | | modelAndView.addObject("error", e.getMessage()); |
| | | return modelAndView; |
| | | } catch (Throwable t) { |
| | | logger.error(" error ", t); |
| | | modelAndView.addObject("error", "[ERROR] " + t.getMessage()); |
| | | return modelAndView; |
| | | } |
| | | |
| | | modelAndView.addObject("message", "操作成功"); |
| | | return modelAndView; |
| | | } |
| | | |
| | | } |
| | |
| | | private Double volume_open; |
| | | |
| | | public Double getChange_ratio() { |
| | | if (STATE_SUBMITTED.equals(state)) { |
| | | change_ratio = Arith.div(Arith.sub(Arith.add(Arith.add(amount_close, profit), deposit), deposit_open), |
| | | deposit_open); |
| | | } else { |
| | | change_ratio = Arith.div(Arith.sub(Arith.add(amount_close, deposit), deposit_open), deposit_open); |
| | | |
| | | } |
| | | |
| | | change_ratio = Arith.mul(change_ratio, 100); |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | return Double.valueOf(df.format(change_ratio)); |
| | | return change_ratio; |
| | | } |
| | | |
| | | public Serializable getPartyId() { |
| | |
| | | } |
| | | } |
| | | |
| | | List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(), |
| | | order.getSymbol(), order.getDirection()); |
| | | for (int i = 0; i < order_state0_list.size(); i++) { |
| | | Double source_lever_rate = order.getLever_rate(); |
| | | source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate; |
| | | |
| | | Double target_lever_rate = order_state0_list.get(i).getLever_rate(); |
| | | target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate; |
| | | if (source_lever_rate.compareTo(target_lever_rate) != 0) { |
| | | throw new BusinessException("存在不同杠杆的持仓单"); |
| | | } |
| | | } |
| | | List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(), |
| | | order.getSymbol(), "open", order.getDirection()); |
| | | for (int i = 0; i < applyOrder_submitted_list.size(); i++) { |
| | | Double source_lever_rate = order.getLever_rate(); |
| | | source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate; |
| | | |
| | | Double target_lever_rate = applyOrder_submitted_list.get(i).getLever_rate(); |
| | | target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate; |
| | | if (source_lever_rate.compareTo(target_lever_rate) != 0) { |
| | | throw new BusinessException("存在不同杠杆的持仓单"); |
| | | } |
| | | } |
| | | // List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(), |
| | | // order.getSymbol(), order.getDirection()); |
| | | // for (int i = 0; i < order_state0_list.size(); i++) { |
| | | // Double source_lever_rate = order.getLever_rate(); |
| | | // source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate; |
| | | // |
| | | // Double target_lever_rate = order_state0_list.get(i).getLever_rate(); |
| | | // target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate; |
| | | // if (source_lever_rate.compareTo(target_lever_rate) != 0) { |
| | | // throw new BusinessException("存在不同杠杆的持仓单"); |
| | | // } |
| | | // } |
| | | // List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(), |
| | | // order.getSymbol(), "open", order.getDirection()); |
| | | // for (int i = 0; i < applyOrder_submitted_list.size(); i++) { |
| | | // Double source_lever_rate = order.getLever_rate(); |
| | | // source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate; |
| | | // |
| | | // Double target_lever_rate = applyOrder_submitted_list.get(i).getLever_rate(); |
| | | // target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate; |
| | | // if (source_lever_rate.compareTo(target_lever_rate) != 0) { |
| | | // throw new BusinessException("存在不同杠杆的持仓单"); |
| | | // } |
| | | // } |
| | | |
| | | order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8)); |
| | | order.setUnit_amount(item.getUnit_amount()); |
| | |
| | | package project.contract.internal; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.Map.Entry; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | |
| | | } |
| | | |
| | | public Map<String, Object> bulidOne(ContractOrder order) { |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a", Locale.ENGLISH); |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("order_no", order.getOrder_no()); |
| | | map.put("name", itemService.cacheBySymbol(order.getSymbol(), false).getName()); |
| | | map.put("symbol", order.getSymbol()); |
| | | map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss)); |
| | | map.put("create_time", simpleDateFormat.format(order.getCreate_time())); |
| | | if (order.getClose_time() != null) { |
| | | map.put("close_time", DateUtils.format(order.getClose_time(), DateUtils.DF_yyyyMMddHHmmss)); |
| | | map.put("close_time", simpleDateFormat.format(order.getClose_time())); |
| | | } else { |
| | | map.put("close_time", ""); |
| | | } |
| | |
| | | package project.contract.job; |
| | | |
| | | import java.text.DecimalFormat; |
| | | import java.util.List; |
| | | |
| | | import org.slf4j.Logger; |
| | |
| | | private ContractOrderService contractOrderService; |
| | | private DataService dataService; |
| | | private WalletService walletService; |
| | | public final static String STATE_SUBMITTED = "submitted"; |
| | | public final static String STATE_CREATED = "created"; |
| | | /** |
| | | * 平仓线 110%(订金价值 /收益=110%) |
| | | */ |
| | |
| | | /* |
| | | * 0 买涨 |
| | | */ |
| | | logger.info("当前价格:"+close+"---------价格:"+Arith.add(order.getTrade_avg_price(), order.getPips())); |
| | | if (close >= Arith.add(order.getTrade_avg_price(), order.getPips())) { |
| | | settle(order, "profit", close); |
| | | } |
| | |
| | | */ |
| | | public void settle(ContractOrder order, String profit_loss, double currentPrice) { |
| | | |
| | | /** |
| | | * 偏差点位 |
| | | */ |
| | | double point = Arith.div(Math.abs(Arith.sub(currentPrice, order.getTrade_avg_price())), order.getPips()); |
| | | |
| | | /* |
| | | * 根据偏 差点数和手数算出盈亏金额 |
| | | */ |
| | | double amount = Arith.mul(Arith.mul(order.getPips_amount(), point), order.getVolume()); |
| | | |
| | | double mul = Arith.mul(order.getDeposit_open(), order.getLever_rate());//仓位 |
| | | double div = Arith.div(mul, order.getTrade_avg_price());//持有币的数量 |
| | | double amount = Arith.mul(div, Arith.sub(currentPrice, order.getTrade_avg_price())); |
| | | logger.info("---------盈亏金额:"+amount); |
| | | logger.info("---------盈亏:"+profit_loss); |
| | | if ("profit".equals(profit_loss)) { |
| | | /** |
| | | * 盈 正数 |
| | | */ |
| | | order.setProfit(Arith.add(0.0D, amount)); |
| | | order.setProfit(Arith.add(0.0D, Math.abs(amount))); |
| | | } else if ("loss".equals(profit_loss)) { |
| | | order.setProfit(Arith.sub(0.0D, amount)); |
| | | order.setProfit(Arith.sub(0.0D,Math.abs(amount) )); |
| | | } |
| | | |
| | | double changeRatio; |
| | | changeRatio = Arith.mul(Arith.div(order.getProfit(), order.getDeposit_open()), 100); |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | order.setChange_ratio(Double.valueOf(df.format(changeRatio))); |
| | | |
| | | /** |
| | | * 多次平仓价格不对,后续修 |
| | | */ |
| | |
| | | * 收益 |
| | | */ |
| | | double profit = 0; |
| | | |
| | | List<ContractOrder> list = contractOrderService.findSubmitted(order.getPartyId().toString(), null, null); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | ContractOrder close_line = list.get(i); |
| | |
| | | ContractOrder close_line = list.get(i); |
| | | if (!order.getOrder_no().equals(close_line.getOrder_no())) { |
| | | try { |
| | | |
| | | while (true) { |
| | | if (ContractLock.add(close_line.getOrder_no())) { |
| | | this.contractOrderService.saveClose(close_line.getPartyId().toString(), |
| | |
| | | break; |
| | | } |
| | | ThreadUtils.sleep(500); |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | logger.error("error:", e); |
| | | } finally { |
| | |
| | | * 低于系统默认平仓线,进行强平 |
| | | */ |
| | | this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no()); |
| | | return; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | public void setDataService(DataService dataService) { |
| | | this.dataService = dataService; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import kernel.web.ApplicationUtil; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 修改止盈止损 |
| | | */ |
| | | @RequestMapping(action + "stopProfitAndLoss.action") |
| | | public Object stopProfitAndLoss(HttpServletRequest request) throws IOException { |
| | | String session_token = request.getParameter("session_token"); |
| | | String order_no = request.getParameter("order_no"); |
| | | String stop_price_profit = request.getParameter("stop_price_profit"); |
| | | String stop_price_loss = request.getParameter("stop_price_loss"); |
| | | |
| | | ResultObject resultObject = new ResultObject(); |
| | | resultObject = this.readSecurityContextFromSession(resultObject); |
| | | if (!"0".equals(resultObject.getCode())) { |
| | | return resultObject; |
| | | } |
| | | String partyId = this.getLoginPartyId(); |
| | | boolean lock = false; |
| | | |
| | | try { |
| | | |
| | | if (!ContractLock.add(partyId)) { |
| | | throw new BusinessException("请稍后再试"); |
| | | } |
| | | |
| | | lock = true; |
| | | |
| | | ContractOrder order = contractOrderService.findByOrderNo(order_no); |
| | | if (order == null || !"submitted".equals(order.getState()) || !partyId.equals(order.getPartyId().toString())) { |
| | | return resultObject; |
| | | } |
| | | |
| | | if (StringUtils.isNullOrEmpty(stop_price_profit)) { |
| | | stop_price_profit = "0"; |
| | | } |
| | | if (StringUtils.isNullOrEmpty(stop_price_loss)) { |
| | | stop_price_loss = "0"; |
| | | } |
| | | |
| | | double stop_price_profit_double = Double.valueOf(stop_price_profit).doubleValue(); |
| | | double stop_price_loss_double = Double.valueOf(stop_price_loss).doubleValue(); |
| | | |
| | | Party party = this.partyService.cachePartyBy(partyId, false); |
| | | if (!party.getEnabled()) { |
| | | resultObject.setCode("506"); |
| | | resultObject.setMsg("用户已锁定"); |
| | | return resultObject; |
| | | } |
| | | |
| | | order.setStop_price_profit(stop_price_profit_double); |
| | | order.setStop_price_loss(stop_price_loss_double); |
| | | |
| | | this.contractOrderService.update(order); |
| | | |
| | | } catch (Exception e) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg(e.getMessage()); |
| | | } finally { |
| | | if (lock) { |
| | | ThreadUtils.sleep(100); |
| | | ContractLock.remove(partyId); |
| | | } |
| | | } |
| | | |
| | | return resultObject; |
| | | } |
| | | |
| | | /** |
| | | * 平仓 |
| | | * |
| | | * symbol 币种 |
| | |
| | | page = this.adminKycService.pagedQuery(pageNo, pageSize, name_para, state_para, |
| | | rolename_para, getLoginPartyId(), idnumber_para, email_para); |
| | | |
| | | String preImg = "https://www.coinzne.com/wap/public/showimg!showImg.action?imagePath="; |
| | | |
| | | String preImg = Constants.WEB_URL + "/public/showimg!showImg.action?imagePath="; |
| | | for (Map<String, Object> map : (List<Map<String, Object>>) page.getElements()) { |
| | | map.put("name_encode", map.get("name").toString().replace("\'", "\\\'").replace("\"", "\\\"")); |
| | | map.put("nationality", Constants.COUNTRY_CODE.get(map.get("nationality"))); |
| | |
| | | <button type="button" class="btn btn-light btn-block">修改</button> |
| | | </label> |
| | | </div> |
| | | <div class="col-md-6"> |
| | | <div class="col-md-6">· |
| | | <button type="button" class="btn btn-light btn-block" onclick="submit_idimg('3')">提交</button> |
| | | </div> |
| | | </div> |