盈利计算 资产计算 新增持仓参数 持仓挂单分页等

pull/1/head
yz 2 years ago
parent 0e378eb739
commit 73f9db939f

@ -13,6 +13,7 @@ import com.sztzjy.forex.trading_trading.entity.Training;
import com.sztzjy.forex.trading_trading.service.GradeWeightService; import com.sztzjy.forex.trading_trading.service.GradeWeightService;
import com.sztzjy.forex.trading_trading.service.MemberService; import com.sztzjy.forex.trading_trading.service.MemberService;
import com.sztzjy.forex.trading_trading.service.TrainingService; import com.sztzjy.forex.trading_trading.service.TrainingService;
import com.sztzjy.forex.trading_trading.util.BigDecimalUtils;
import com.sztzjy.forex.trading_trading.util.ResultEntity; import com.sztzjy.forex.trading_trading.util.ResultEntity;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -40,6 +41,9 @@ public class MemberController {
@Autowired @Autowired
TakeStashController takeStashController; TakeStashController takeStashController;
@Autowired
BigDecimalUtils bigDecimalUtils;
@AnonymousAccess @AnonymousAccess
@PostMapping("getMemberById") @PostMapping("getMemberById")
public ResultEntity getMember(@RequestBody String memberId) { public ResultEntity getMember(@RequestBody String memberId) {
@ -58,11 +62,11 @@ public class MemberController {
Double positionProfitLoss = takeStashController.flashTotalPositionProfitLoss(member.getMemberId()); Double positionProfitLoss = takeStashController.flashTotalPositionProfitLoss(member.getMemberId());
member.setPositionProfitLoss(positionProfitLoss); //设置持仓盈亏 member.setPositionProfitLoss(positionProfitLoss); //设置持仓盈亏
Double totalAssets = member.getTotalAssets(); Double totalAssets = member.getTotalAssets();
Double netValue=totalAssets+positionProfitLoss; Double netValue=bigDecimalUtils.add(totalAssets,positionProfitLoss);
member.setNetValue(netValue); //设置净值 member.setNetValue(netValue); //设置净值
Double marginUsed = member.getMarginUsed(); //获取已用保证金 Double marginUsed = member.getMarginUsed(); //获取已用保证金
member.setAvailableFunds(netValue-marginUsed); //设置可用资金 member.setAvailableFunds(bigDecimalUtils.sub(netValue,marginUsed)); //设置可用资金
member.setMarginLevel(netValue/marginUsed); //设置保证金水平 member.setMarginLevel(bigDecimalUtils.div(netValue,marginUsed,2)); //设置保证金水平
return new ResultEntity(HttpStatus.OK, "获取成员ID",member); return new ResultEntity(HttpStatus.OK, "获取成员ID",member);
} }

@ -3,6 +3,7 @@ package com.sztzjy.forex.trading_trading.controller;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess; import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess;
import com.sztzjy.forex.trading_trading.dto.PengdingVo; import com.sztzjy.forex.trading_trading.dto.PengdingVo;
import com.sztzjy.forex.trading_trading.dto.TakeStashVO; import com.sztzjy.forex.trading_trading.dto.TakeStashVO;
@ -14,15 +15,13 @@ import com.sztzjy.forex.trading_trading.util.RedisUtil;
import com.sztzjy.forex.trading_trading.util.ResultEntity; import com.sztzjy.forex.trading_trading.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Set;
@RestController @RestController
@RequestMapping("api/pendingOrder") @RequestMapping("api/pendingOrder")
@ -36,84 +35,134 @@ public class PendingOrderController {
@Autowired @Autowired
RedisUtil redisUtil; RedisUtil redisUtil;
@Autowired
TradingController tradingController;
@Autowired
ForexMarketDateUtil forexMarketDateUtil;
//查询挂单数据 //查询挂单数据
@AnonymousAccess @AnonymousAccess
@PostMapping("getPendingOrder") @PostMapping("getPendingOrder")
public ResultEntity<List<PengdingVo>> getPendingOrder(@RequestBody JSONObject jsonObject){ public ResultEntity<List<PengdingVo>> getPendingOrder(@RequestBody JSONObject jsonObject) {
String trainingId = String.valueOf(jsonObject.get("trainingId")); String trainingId = String.valueOf(jsonObject.get("trainingId"));
String memberId = String.valueOf(jsonObject.get("memberId")); String memberId = String.valueOf(jsonObject.get("memberId"));
PendingOrder pendingOrder=new PendingOrder(); Integer pageIndex = jsonObject.getInteger("index");
Integer pageSize = jsonObject.getInteger("size");
PendingOrder pendingOrder = new PendingOrder();
pendingOrder.setStatus(0); pendingOrder.setStatus(0);
pendingOrder.setTrainingId(trainingId); pendingOrder.setTrainingId(trainingId);
pendingOrder.setMemberId(memberId); pendingOrder.setMemberId(memberId);
List<PendingOrder> pendingOrders = pendingOrderService.selectByTrainingIdAndStatusAndMemberId(pendingOrder); PageInfo<PendingOrder> pendingOrderPageInfo = pendingOrderService.selectByTrainingIdAndStatusAndMemberId(pendingOrder, pageIndex, pageSize);
List<PengdingVo> pengdingVoList=new ArrayList<>(); List<PendingOrder> pendingOrders = pendingOrderPageInfo.getList();
List<PengdingVo> pengdingVoList = new ArrayList<>();
for (int i = 0; i < pendingOrders.size(); i++) { for (int i = 0; i < pendingOrders.size(); i++) {
PengdingVo pengdingVo=new PengdingVo(pendingOrders.get(i)); PengdingVo pengdingVo = new PengdingVo(pendingOrders.get(i));
pengdingVoList.add(pengdingVo); pengdingVoList.add(pengdingVo);
} }
List<TakeStashVO> data = flashPendingCurrentPrice(pengdingVoList).getBody().getData(); List<TakeStashVO> data = flashPendingCurrentPrice(pengdingVoList).getBody().getData();
return new ResultEntity(HttpStatus.OK, "获取挂单数据成功",data); PageInfo<TakeStashVO> pageInfo=new PageInfo<>();
pageInfo.setTotal(pendingOrderPageInfo.getTotal());
pageInfo.setList(data);
return new ResultEntity(HttpStatus.OK, "获取挂单数据成功", pageInfo);
} }
//撤单 撤单成功后 根据pendingOrderId删除redis键 //撤单 撤单成功后 根据pendingOrderId删除redis键
@AnonymousAccess @AnonymousAccess
@PostMapping("cancelOrder") @PostMapping("cancelOrder")
public ResultEntity cancelOrder(@RequestBody JSONObject jsonObject){ public ResultEntity cancelOrder(@RequestBody JSONObject jsonObject) {
String pendingOrderId = String.valueOf(jsonObject.get("pendingOrderId")); String pendingOrderId = String.valueOf(jsonObject.get("pendingOrderId"));
pendingOrderService.cancelOrder(pendingOrderId); pendingOrderService.cancelOrder(pendingOrderId);
redisUtil.del("pengingOrder_"+pendingOrderId); redisUtil.del("pengingOrder_" + pendingOrderId);
return new ResultEntity(HttpStatus.OK, "撤单成功"); return new ResultEntity(HttpStatus.OK, "撤单成功");
} }
//挂单自动撤单(到期自动撤单) 扫描redis pengingOrder_id 进行自动撤单
public void pendingOrderQuest(){
Set<String> pendingOrderSet = redisUtil.keys("pengingOrder_" + "*"); //获取所有挂单键
for(String key : pendingOrderSet){
// System.out.print(value+" ");
//判断是否开仓
public Boolean isOpenTakeStash(Map<Object, Object> pengingOrderMap,Map<String, ForexMarketData> forexMarketDataMap) {
String buySellType = (String) pengingOrderMap.get("buySellType");
String tradingCode = (String) pengingOrderMap.get("tradingCode");
Double priceCommission = (Double) pengingOrderMap.get("priceCommission");
ForexMarketData forexDate = forexMarketDataMap.get(tradingCode);
Double buyPic = forexDate.getBuyPic();
Double sellPic = Double.valueOf(forexDate.getSellPic());
if ("buyLimit".equals(buySellType)) { //限价买进
if (buyPic < priceCommission) {
return true;
}
} }
} if ("sellLimit".equals(buySellType)) { //限价卖出
if (sellPic > priceCommission) {
return true;
}
}
if ("buyStop".equals(buySellType)) { //止损买入
if (buyPic > priceCommission) {
return true;
}
}
if ("sellStop".equals(buySellType)) {
if (sellPic < priceCommission) {
return true;
}
}
return false;
//挂单自动开仓 }
//返回挂单对象 //判断是否到期 到期则删除挂单数据和redis中的键
public PendingOrder returnPendingOrder(String memberId, String trainingId, String tradingCode,String currencyName, String buySellType, Double transactionVolume, Double priceCommission, Double stopLoss, Double stopWin,Date validityTime) { public Boolean isExpire(Map<Object, Object> pengingOrderMap, String key) {
Date now = new Date(); Date validityTime = (Date) pengingOrderMap.get("validityTime"); //获取有效期
String commissionNumber = DateUtil.format(now, "yyyyMMddHHmmss") + System.currentTimeMillis(); Date currentDate = new Date();
PendingOrder pendingOrder=new PendingOrder(); if (validityTime.after(currentDate)) {
pendingOrder.setMemberId(memberId); pendingOrderService.cancelOrder((String) pengingOrderMap.get("pendingOrderId"));
pendingOrder.setTrainingId(trainingId); redisUtil.del(key);
pendingOrder.setCommissionTime(now); return true;
pendingOrder.setTradingCode(tradingCode); }
pendingOrder.setCurrencyName(currencyName); return false;
pendingOrder.setCommissionNumber(commissionNumber);
pendingOrder.setBuySellType(buySellType);
pendingOrder.setVolumeTransaction(transactionVolume);
pendingOrder.setPriceCommission(priceCommission);
pendingOrder.setStopLoss(stopLoss);
pendingOrder.setStopWin(stopWin);
pendingOrder.setValidityTime(validityTime);
pendingOrder.setStatus(0);
return pendingOrder;
} }
//保存挂单 挂单保存后 将挂单ID和有效期存入redis public JSONObject pengingKeyReturnJSONObject(Map<Object, Object> pengingOrderMap) {
public void insertPendingOrder(PendingOrder pendingOrder){ Object tradingCode = pengingOrderMap.get("tradingCode");
String uuid = IdUtil.simpleUUID(); Object currencyName = pengingOrderMap.get("currencyName");
pendingOrder.setPendingOrderId(uuid); Object transactionType = pengingOrderMap.get("transactionType");
pendingOrderService.insert(pendingOrder); Object transactionVolume = pengingOrderMap.get("transactionVolume");
redisUtil.set("pengingOrder_"+pendingOrder.getPendingOrderId(),pendingOrder.getValidityTime()); Object buySellTypeObj = pengingOrderMap.get("buySellType");
String buySellType= String.valueOf(buySellTypeObj);
if(buySellType.contains("buy")){
buySellType="buy";
}else {
buySellType="sell";
}
Object stopLoss = pengingOrderMap.get("stopLoss");
Object stopWin = pengingOrderMap.get("stopWin");
Object memberId = pengingOrderMap.get("memberId");
Object trainingId = pengingOrderMap.get("trainingId");
Object priceCommission = pengingOrderMap.get("priceCommission");
JSONObject jsonObject = new JSONObject();
jsonObject.put("tradingCode", tradingCode);
jsonObject.put("currencyName", currencyName);
jsonObject.put("transactionType", transactionType);
jsonObject.put("transactionVolume", transactionVolume);
jsonObject.put("buySellType", buySellType);
jsonObject.put("stopLoss", stopLoss);
jsonObject.put("stopWin", stopWin);
jsonObject.put("memberId", memberId);
jsonObject.put("trainingId", trainingId);
jsonObject.put("priceCommission", priceCommission);
return jsonObject;
} }
//挂单刷新当前价位 //挂单刷新当前价位
@AnonymousAccess @AnonymousAccess
@PostMapping("flashPendingCurrentPrice") @PostMapping("flashPendingCurrentPrice")
public ResultEntity<List<TakeStashVO>> flashPendingCurrentPrice(@RequestBody List<PengdingVo> pengdingVoList){ public ResultEntity<List<TakeStashVO>> flashPendingCurrentPrice(@RequestBody List<PengdingVo> pengdingVoList) {
List<PengdingVo> pengdingVos=new ArrayList<>(); List<PengdingVo> pengdingVos = new ArrayList<>();
for (int i = 0; i < pengdingVoList.size(); i++) { for (int i = 0; i < pengdingVoList.size(); i++) {
PengdingVo pengdingVo = pengdingVoList.get(i); PengdingVo pengdingVo = pengdingVoList.get(i);
if(0!=pengdingVo.getStatus()){ if (0 != pengdingVo.getStatus()) {
continue; continue;
} }
String buySellType = pengdingVo.getBuySellType(); //买入或卖出 String buySellType = pengdingVo.getBuySellType(); //买入或卖出
@ -122,23 +171,23 @@ public class PendingOrderController {
Double nowBuyPic = forexData.getBuyPic(); //当前买价 Double nowBuyPic = forexData.getBuyPic(); //当前买价
Double nowSellPic = Double.valueOf(forexData.getSellPic()); //当前卖价 Double nowSellPic = Double.valueOf(forexData.getSellPic()); //当前卖价
if (tradingCode.startsWith("USD")) { //美元在前 if (tradingCode.startsWith("USD")) { //美元在前
if("buy".equals(buySellType)){ //买 if ("buy".equals(buySellType)) { //买
pengdingVo.setCurrentPrice(nowBuyPic); pengdingVo.setCurrentPrice(nowBuyPic);
}else { //卖 } else { //卖
pengdingVo.setCurrentPrice(nowSellPic); pengdingVo.setCurrentPrice(nowSellPic);
} }
}else { //美元在后 } else { //美元在后
if("buy".equals(buySellType)){ //买 if ("buy".equals(buySellType)) { //买
pengdingVo.setCurrentPrice(nowBuyPic); pengdingVo.setCurrentPrice(nowBuyPic);
}else { //卖 } else { //卖
pengdingVo.setCurrentPrice(nowSellPic); pengdingVo.setCurrentPrice(nowSellPic);
} }
} }
pengdingVos.add(pengdingVo); pengdingVos.add(pengdingVo);
} }
if(0==pengdingVos.size()){ if (0 == pengdingVos.size()) {
return new ResultEntity(HttpStatus.OK, "挂单数据为空",null); return new ResultEntity(HttpStatus.OK, "挂单数据为空", null);
} }
return new ResultEntity(HttpStatus.OK, "挂单当前价格刷新",pengdingVos); return new ResultEntity(HttpStatus.OK, "挂单当前价格刷新", pengdingVos);
} }
} }

@ -2,6 +2,7 @@ package com.sztzjy.forex.trading_trading.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess; import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess;
import com.sztzjy.forex.trading_trading.dto.TakeStashVO; import com.sztzjy.forex.trading_trading.dto.TakeStashVO;
import com.sztzjy.forex.trading_trading.entity.ForexMarketData; import com.sztzjy.forex.trading_trading.entity.ForexMarketData;
@ -10,6 +11,7 @@ import com.sztzjy.forex.trading_trading.entity.TakeStash;
import com.sztzjy.forex.trading_trading.service.MemberService; import com.sztzjy.forex.trading_trading.service.MemberService;
import com.sztzjy.forex.trading_trading.service.TakeStashService; import com.sztzjy.forex.trading_trading.service.TakeStashService;
import com.sztzjy.forex.trading_trading.service.TrainingService; import com.sztzjy.forex.trading_trading.service.TrainingService;
import com.sztzjy.forex.trading_trading.util.BigDecimalUtils;
import com.sztzjy.forex.trading_trading.util.ForexMarketDateUtil; import com.sztzjy.forex.trading_trading.util.ForexMarketDateUtil;
import com.sztzjy.forex.trading_trading.util.RedisUtil; import com.sztzjy.forex.trading_trading.util.RedisUtil;
import com.sztzjy.forex.trading_trading.util.ResultEntity; import com.sztzjy.forex.trading_trading.util.ResultEntity;
@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
@RestController @RestController
@ -44,11 +47,18 @@ public class TakeStashController {
@Autowired @Autowired
TrainingService trainingService; TrainingService trainingService;
@Autowired
BigDecimalUtils bigDecimalUtils;
//获取当前持仓表 status 0为获取当前持仓/1为挂单持仓/2为历史持仓 //获取当前持仓表 status 0为获取当前持仓/1为挂单持仓/2为历史持仓
@AnonymousAccess @AnonymousAccess
@PostMapping("getTakeStashList") @PostMapping("getTakeStashList")
public ResultEntity getTakeStashList(@RequestBody TakeStash takeStash) { public ResultEntity getTakeStashList(@RequestBody JSONObject jsonObject) {
List<TakeStash> takeStashList = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(takeStash.getTrainingId(), takeStash.getMemberId(), takeStash.getStatus()); Integer pageIndex = jsonObject.getInteger("index");
Integer pageSize = jsonObject.getInteger("size");
TakeStash takeStash = jsonObject.getObject("takeStash", TakeStash.class);
PageInfo<TakeStash> pageInfo = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(takeStash.getTrainingId(), takeStash.getMemberId(), takeStash.getStatus(), pageIndex, pageSize);
List<TakeStash> takeStashList = pageInfo.getList();
List<TakeStashVO> takeStashVOList = new ArrayList<>(); List<TakeStashVO> takeStashVOList = new ArrayList<>();
for (int i = 0; i < takeStashList.size(); i++) { for (int i = 0; i < takeStashList.size(); i++) {
TakeStashVO takeStashVO = new TakeStashVO(takeStashList.get(i)); TakeStashVO takeStashVO = new TakeStashVO(takeStashList.get(i));
@ -57,7 +67,10 @@ public class TakeStashController {
if (takeStash.getStatus() == 0) { if (takeStash.getStatus() == 0) {
takeStashVOList = flashProfitAndLoss(takeStashVOList).getBody().getData(); takeStashVOList = flashProfitAndLoss(takeStashVOList).getBody().getData();
} }
return new ResultEntity(HttpStatus.OK, "返回持仓数据", takeStashVOList); PageInfo<TakeStashVO> voPageInfo = new PageInfo<>();
voPageInfo.setTotal(pageInfo.getTotal());
voPageInfo.setList(takeStashVOList);
return new ResultEntity(HttpStatus.OK, "返回持仓数据", voPageInfo);
} }
//根据持仓ID获取单个持仓数据 //根据持仓ID获取单个持仓数据
@ -89,19 +102,23 @@ public class TakeStashController {
Double profitAndLoss; Double profitAndLoss;
if (tradingCode.startsWith("USD")) { //美元在前 if (tradingCode.startsWith("USD")) { //美元在前
if ("buy".equals(buySellType)) { //买 if ("buy".equals(buySellType)) { //买
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000 / nowBuyPic; // profitAndLoss =(nowBuyPic - priceTransaction) * volumeTransaction * 100000.0 / nowBuyPic;
takeStashVO.setCurrentPrice(nowBuyPic); profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000), nowSellPic, 2);
} else { //卖
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000 / nowSellPic;
takeStashVO.setCurrentPrice(nowSellPic); takeStashVO.setCurrentPrice(nowSellPic);
} else { //卖
// profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0 / nowSellPic;
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000), nowBuyPic, 2);
takeStashVO.setCurrentPrice(nowBuyPic);
} }
} else { //美元在后 } else { //美元在后
if ("buy".equals(buySellType)) { //买 if ("buy".equals(buySellType)) { //买
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000; // profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000.0;
takeStashVO.setCurrentPrice(nowBuyPic); profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000, 2);
} else { //卖
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000;
takeStashVO.setCurrentPrice(nowSellPic); takeStashVO.setCurrentPrice(nowSellPic);
} else { //卖
// profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0;
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000, 2);
takeStashVO.setCurrentPrice(nowBuyPic);
} }
} }
takeStashVO.setProfitAndLoss(profitAndLoss); takeStashVO.setProfitAndLoss(profitAndLoss);
@ -114,8 +131,8 @@ public class TakeStashController {
} }
//总持仓盈亏刷新 获取member下所有持仓数据 //总持仓盈亏刷新 获取member下所有持仓数据
public Double flashTotalPositionProfitLoss(String memberId){ public Double flashTotalPositionProfitLoss(String memberId) {
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId,0); List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
Double totalProfitAndLoss = 0.0; Double totalProfitAndLoss = 0.0;
for (int i = 0; i < takeStashList.size(); i++) { for (int i = 0; i < takeStashList.size(); i++) {
TakeStash takeStash = takeStashList.get(i); TakeStash takeStash = takeStashList.get(i);
@ -129,18 +146,23 @@ public class TakeStashController {
Double profitAndLoss; Double profitAndLoss;
if (tradingCode.startsWith("USD")) { //美元在前 if (tradingCode.startsWith("USD")) { //美元在前
if ("buy".equals(buySellType)) { //买 if ("buy".equals(buySellType)) { //买
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000 / nowBuyPic; // profitAndLoss =(nowBuyPic - priceTransaction) * volumeTransaction * 100000.0 / nowBuyPic;
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000), nowSellPic, 2);
} else { //卖 } else { //卖
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000 / nowSellPic; // profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0 / nowSellPic;
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000), nowBuyPic, 2);
} }
} else { //美元在后 } else { //美元在后
if ("buy".equals(buySellType)) { //买 if ("buy".equals(buySellType)) { //买
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000; // profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000.0;
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000, 2);
} else { //卖 } else { //卖
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000; // profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0;
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000, 2);
} }
} }
totalProfitAndLoss=totalProfitAndLoss+profitAndLoss; // totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
totalProfitAndLoss=bigDecimalUtils.add(totalProfitAndLoss,profitAndLoss);
} }
return totalProfitAndLoss; return totalProfitAndLoss;
@ -188,83 +210,94 @@ public class TakeStashController {
String buySellType = takeStashNew.getBuySellType(); String buySellType = takeStashNew.getBuySellType();
String tradingCode = takeStashNew.getTradingCode(); String tradingCode = takeStashNew.getTradingCode();
Double volumeTransaction = takeStashNew.getVolumeTransaction(); Double volumeTransaction = takeStashNew.getVolumeTransaction();
Double priceTransaction = takeStashNew.getPriceTransaction(); Double priceTransaction = takeStashNew.getPriceTransaction(); //获取进仓时交易价格
Double priceTransactionCloser = 0.0; //记录出仓时交易价格
ForexMarketData forexData = forexMarketDateController.getForexMarketDateByCode(tradingCode); ForexMarketData forexData = forexMarketDateController.getForexMarketDateByCode(tradingCode);
Double backFund = 0.0; //返还资金 Double backFund = 0.0; //返还资金
Double CumulativeProfitLoss=0.0; //盈亏 Double profitAndLoss = 0.0; //盈亏
Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价 Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价
Double nowBuyPic = forexData.getBuyPic(); //当前买价 Double nowBuyPic = forexData.getBuyPic(); //当前买价
if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为 if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为
if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖
CumulativeProfitLoss=(nowSellPic - priceTransaction) * volumeTransaction * 100000 / nowSellPic; priceTransactionCloser = nowSellPic;
backFund = 1000 * volumeTransaction+CumulativeProfitLoss; // CumulativeProfitLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0 / nowSellPic;
availableFunds = availableFunds + backFund; profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000), nowSellPic, 2);
backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
} else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手 } else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
CumulativeProfitLoss=( priceTransaction-nowBuyPic ) * volumeTransaction * 100000 / nowBuyPic; priceTransactionCloser = nowBuyPic;
backFund = 1000 * volumeTransaction+CumulativeProfitLoss; profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000), nowBuyPic, 2);
availableFunds = availableFunds + backFund; backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
} }
} else { //美元在后 } else { //美元在后
backFund = 1000 * volumeTransaction; backFund = 1000 * volumeTransaction;
if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手 if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手
CumulativeProfitLoss=(priceTransaction-nowSellPic)*volumeTransaction*100000/nowSellPic; priceTransactionCloser = nowSellPic;
backFund=1000*volumeTransaction*nowSellPic+CumulativeProfitLoss; profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000, 2);
availableFunds = availableFunds + backFund; backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
} else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手 } else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
CumulativeProfitLoss=( priceTransaction-nowBuyPic)*volumeTransaction*100000/nowBuyPic; priceTransactionCloser = nowBuyPic;
backFund=1000*volumeTransaction*nowBuyPic+CumulativeProfitLoss; profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000, 2);
availableFunds = availableFunds + backFund; backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
} }
} }
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金 Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
Double tradingMargin = takeStashNew.getTradingMargin(); //进仓时使用的保证金 Double tradingMargin = takeStashNew.getTradingMargin(); //进仓时使用的保证金
marginUsed = marginUsed - tradingMargin; //修改成员保证金 marginUsed = bigDecimalUtils.sub(marginUsed,tradingMargin); //修改成员保证金
member.setAvailableFunds(availableFunds); member.setAvailableFunds(availableFunds);
member.setMarginUsed(marginUsed); member.setMarginUsed(marginUsed);
Integer closingTrades = member.getClosingTrades(); Integer closingTrades = member.getClosingTrades();
member.setClosingTrades(closingTrades++); member.setClosingTrades(closingTrades++);
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏 Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
member.setCumulativeProfitLoss(cumulativeProfitLoss+CumulativeProfitLoss); //修改累计盈亏 member.setCumulativeProfitLoss(bigDecimalUtils.add(cumulativeProfitLoss,profitAndLoss)); //修改累计盈亏
member.setTotalAssets(member.getInitialCapital()+cumulativeProfitLoss+CumulativeProfitLoss); //设置总资产 member.setTotalAssets(bigDecimalUtils.add(bigDecimalUtils.add(member.getInitialCapital(),cumulativeProfitLoss),profitAndLoss)); //设置总资产
memberService.updateByPrimaryKeySelective(member); memberService.updateByPrimaryKeySelective(member);
TakeStash takeStash = new TakeStash(); TakeStash takeStash = new TakeStash();
takeStash.setStashId(stashId); takeStash.setStashId(stashId);
takeStash.setStatus(2); takeStash.setStatus(2);
takeStash.setProfitAndLossByClose(backFund - tradingMargin); //盈亏=返还资金-进仓时使用的保证金 takeStash.setPriceTransactionClose(priceTransactionCloser);
takeStash.setProfitAndLossByClose(profitAndLoss);
takeStash.setTimeTransactionClose(new Date());
takeStashService.updateByPrimaryKeySelective(takeStash); takeStashService.updateByPrimaryKeySelective(takeStash);
return new ResultEntity(HttpStatus.OK, "平仓成功"); return new ResultEntity(HttpStatus.OK, "平仓成功");
} }
public void updateMemberAndTakeStash(String memberId,String stashId,Double backFund,Double CumulativeProfitLoss){ public void updateMemberAndTakeStash(String memberId, String stashId, Double backFund, Double CumulativeProfitLoss) {
TakeStash takeStashNew = takeStashService.selectByPrimaryKey(stashId); TakeStash takeStashNew = takeStashService.selectByPrimaryKey(stashId);
Member member = memberService.selectByPrimaryKey(memberId); Member member = memberService.selectByPrimaryKey(memberId);
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金 Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
Double tradingMargin = takeStashNew.getTradingMargin(); //进仓时使用的保证金 Double tradingMargin;//进仓时使用的保证金
marginUsed = marginUsed - tradingMargin; //修改成员保证金 if (takeStashNew.getTradingMargin()!=null){
tradingMargin=0.0;
}else {
tradingMargin = takeStashNew.getTradingMargin();
}
marginUsed = bigDecimalUtils.sub(marginUsed,tradingMargin); //修改成员保证金
Double availableFunds = member.getAvailableFunds(); //可用资金 Double availableFunds = member.getAvailableFunds(); //可用资金
availableFunds=availableFunds+backFund; availableFunds = bigDecimalUtils.add(availableFunds,backFund);
member.setAvailableFunds(availableFunds); member.setAvailableFunds(availableFunds);
member.setMarginUsed(marginUsed); member.setMarginUsed(marginUsed);
Integer closingTrades = member.getClosingTrades(); Integer closingTrades = member.getClosingTrades();
member.setClosingTrades(closingTrades++); member.setClosingTrades(closingTrades++);
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏 Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
member.setCumulativeProfitLoss(cumulativeProfitLoss+CumulativeProfitLoss); //修改累计盈亏 member.setCumulativeProfitLoss(bigDecimalUtils.add(cumulativeProfitLoss,CumulativeProfitLoss)); //修改累计盈亏
member.setTotalAssets(member.getInitialCapital()+cumulativeProfitLoss+CumulativeProfitLoss); //设置总资产 member.setTotalAssets(bigDecimalUtils.add(CumulativeProfitLoss,bigDecimalUtils.add(member.getInitialCapital(),cumulativeProfitLoss))); //设置总资产
memberService.updateByPrimaryKeySelective(member); memberService.updateByPrimaryKeySelective(member);
TakeStash takeStash = new TakeStash(); TakeStash takeStash = new TakeStash();
takeStash.setStashId(stashId); takeStash.setStashId(stashId);
takeStash.setStatus(2); takeStash.setStatus(2);
takeStash.setProfitAndLossByClose(backFund - tradingMargin); //盈亏=返还资金-进仓时使用的保证金 takeStash.setProfitAndLossByClose(bigDecimalUtils.sub(backFund,tradingMargin)); //盈亏=返还资金-进仓时使用的保证金
takeStashService.updateByPrimaryKeySelective(takeStash); takeStashService.updateByPrimaryKeySelective(takeStash);
} }
} }

@ -2,6 +2,7 @@ package com.sztzjy.forex.trading_trading.controller;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess; import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess;
import com.sztzjy.forex.trading_trading.entity.ForexMarketData; import com.sztzjy.forex.trading_trading.entity.ForexMarketData;
@ -10,7 +11,9 @@ import com.sztzjy.forex.trading_trading.entity.PendingOrder;
import com.sztzjy.forex.trading_trading.entity.TakeStash; import com.sztzjy.forex.trading_trading.entity.TakeStash;
import com.sztzjy.forex.trading_trading.service.ForexMarketDataService; import com.sztzjy.forex.trading_trading.service.ForexMarketDataService;
import com.sztzjy.forex.trading_trading.service.MemberService; import com.sztzjy.forex.trading_trading.service.MemberService;
import com.sztzjy.forex.trading_trading.service.PendingOrderService;
import com.sztzjy.forex.trading_trading.service.TakeStashService; import com.sztzjy.forex.trading_trading.service.TakeStashService;
import com.sztzjy.forex.trading_trading.util.BigDecimalUtils;
import com.sztzjy.forex.trading_trading.util.RedisUtil; import com.sztzjy.forex.trading_trading.util.RedisUtil;
import com.sztzjy.forex.trading_trading.util.ResultEntity; import com.sztzjy.forex.trading_trading.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -36,8 +39,6 @@ public class TradingController {
@Autowired @Autowired
TakeStashService takeStashService; TakeStashService takeStashService;
@Autowired
PendingOrderController pendingOrderController;
@Autowired @Autowired
RedisUtil redisUtil; RedisUtil redisUtil;
@ -45,6 +46,12 @@ public class TradingController {
@Autowired @Autowired
ForexMarketDataService forexMarketDataService; ForexMarketDataService forexMarketDataService;
@Autowired
PendingOrderService pendingOrderService;
@Autowired
BigDecimalUtils bigDecimalUtils;
//获取市场报价 //获取市场报价
@AnonymousAccess @AnonymousAccess
@PostMapping("getMarketQuotation") @PostMapping("getMarketQuotation")
@ -93,15 +100,19 @@ public class TradingController {
Double stopWin = jsonObject.getDouble("stopWin"); Double stopWin = jsonObject.getDouble("stopWin");
String memberId = jsonObject.getString("memberId"); String memberId = jsonObject.getString("memberId");
String trainingId = jsonObject.getString("trainingId"); String trainingId = jsonObject.getString("trainingId");
Member member = memberService.getMemberByMemberIdAndTrainingId(memberId, trainingId); Double priceCommission = jsonObject.getDouble("priceCommission"); //获取挂单开仓用户输入的价位
Double availableFunds = member.getAvailableFunds(); //获取账户可用资金
ForexMarketData forexData = getMarketQuotationByCode(tradingCode).getBody().getData();//获取当前买卖价格 ForexMarketData forexData = getMarketQuotationByCode(tradingCode).getBody().getData();//获取当前买卖价格
Double buyPic = forexData.getBuyPic();//当前买价 Double buyPic = forexData.getBuyPic();//当前买价
Double sellPic = Double.valueOf(forexData.getSellPic());//当前买价 Double sellPic = Double.valueOf(forexData.getSellPic());//当前买价
Double priceTransaction=0.0; //记录当前交易价格(买价或卖价)
if(priceCommission!=-1){
buyPic=priceCommission;
sellPic=priceCommission;
}
Member member = memberService.getMemberByMemberIdAndTrainingId(memberId, trainingId);
Double availableFunds = member.getAvailableFunds(); //获取账户可用资金
Double margin = 0.0; //记录所需保证金 Double margin = 0.0; //记录所需保证金
String stashId = IdUtil.simpleUUID();
Boolean stopLossWinFlag=false; Boolean stopLossWinFlag=false;
Double priceTransaction=0.0; //记录当前交易价格(买价或卖价)
if (null != stopLoss || null != stopWin) { //判断止损止赢是否合理 如果stopLoss stopWin都为null则跳过 if (null != stopLoss || null != stopWin) { //判断止损止赢是否合理 如果stopLoss stopWin都为null则跳过
stopLossWinFlag=true; stopLossWinFlag=true;
boolean winOrLossStopBoolean = getWinOrLossStop(stopLoss, stopWin, buySellType, forexData); boolean winOrLossStopBoolean = getWinOrLossStop(stopLoss, stopWin, buySellType, forexData);
@ -111,12 +122,13 @@ public class TradingController {
} }
//如果方式为卖 则止损高于卖价 获利低于买价 //如果方式为卖 则止损高于卖价 获利低于买价
if (transactionType.equals("sjkc")) {//市价开仓 if (transactionType.equals("sjkc")) {//市价开仓
String stashId = IdUtil.simpleUUID(); //设置市价开仓ID
if (tradingCode.startsWith("USD")) { //美元在前 if (tradingCode.startsWith("USD")) { //美元在前
if (availableFunds < transactionVolume * 1000) { //判断可用资金是否足够 if (availableFunds < transactionVolume * 1000.0) { //判断可用资金是否足够
return new ResultEntity(HttpStatus.BAD_REQUEST, "可用资金不足"); return new ResultEntity(HttpStatus.BAD_REQUEST, "可用资金不足");
} }
margin=transactionVolume * 1000; //所需保证金 margin=bigDecimalUtils.mul(transactionVolume,1000,2); //所需保证金
availableFunds = availableFunds - margin; availableFunds = bigDecimalUtils.sub(availableFunds,margin);
if ("buy".equals(buySellType)) { if ("buy".equals(buySellType)) {
priceTransaction=buyPic; priceTransaction=buyPic;
TakeStash takeStash = returnTakeStash(stashId,memberId, trainingId, tradingCode, currencyName, buySellType, transactionVolume, buyPic, stopLoss, stopWin , margin); TakeStash takeStash = returnTakeStash(stashId,memberId, trainingId, tradingCode, currencyName, buySellType, transactionVolume, buyPic, stopLoss, stopWin , margin);
@ -130,7 +142,8 @@ public class TradingController {
} else { //美元在后 使用可用资金表达式为 买卖手*1000*卖/买价 判断可用资金是否足够 先判断是买还是卖 } else { //美元在后 使用可用资金表达式为 买卖手*1000*卖/买价 判断可用资金是否足够 先判断是买还是卖
if ("buy".equals(buySellType)) { if ("buy".equals(buySellType)) {
priceTransaction=buyPic; priceTransaction=buyPic;
margin=transactionVolume * 1000 * buyPic; //所需保证金 // margin=transactionVolume * 1000.0 * buyPic; //所需保证金
margin=bigDecimalUtils.mul(bigDecimalUtils.mul(transactionVolume,1000,2),buyPic,2);
if (availableFunds < margin) { if (availableFunds < margin) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "可用资金不足"); return new ResultEntity(HttpStatus.BAD_REQUEST, "可用资金不足");
} }
@ -139,7 +152,8 @@ public class TradingController {
takeStashService.insertTakeStash(takeStash); takeStashService.insertTakeStash(takeStash);
} else if ("sell".equals(buySellType)) { } else if ("sell".equals(buySellType)) {
priceTransaction=sellPic; priceTransaction=sellPic;
margin=transactionVolume * 1000 * sellPic; //所需保证金 // margin=transactionVolume * 1000.0 * sellPic; //所需保证金
margin=bigDecimalUtils.mul(bigDecimalUtils.mul(transactionVolume,1000,2),sellPic,2);
if (availableFunds < margin) { if (availableFunds < margin) {
return new ResultEntity(HttpStatus.BAD_REQUEST, "可用资金不足"); return new ResultEntity(HttpStatus.BAD_REQUEST, "可用资金不足");
} }
@ -171,7 +185,7 @@ public class TradingController {
redisUtil.hmset("trainingId_"+trainingId+"_stashId_"+stashId,map); redisUtil.hmset("trainingId_"+trainingId+"_stashId_"+stashId,map);
} }
} else if (transactionType.equals("gdkc")) {//挂单开仓 生成的数据为挂单数据 挂单数据生效 判断可用资金是否充足 } else if (transactionType.equals("gdkc")) {//挂单开仓 生成的数据为挂单数据 挂单数据生效 判断可用资金是否充足
Double priceCommission = jsonObject.getDouble("priceCommission");//获取用户输入的价位 String pendingOrderId = IdUtil.simpleUUID(); //设置市价开仓ID
Date validityTime = jsonObject.getDate("validityTime"); //获取挂单有效期 Date validityTime = jsonObject.getDate("validityTime"); //获取挂单有效期
if ("buyLimit".equals(buySellType)) { //限价买进(低价买进) 下单时买入价低于当前买价 if ("buyLimit".equals(buySellType)) { //限价买进(低价买进) 下单时买入价低于当前买价
if (priceCommission >= buyPic) { if (priceCommission >= buyPic) {
@ -193,8 +207,24 @@ public class TradingController {
return new ResultEntity(HttpStatus.BAD_REQUEST, "止损卖出价位不能高于当前卖价"); return new ResultEntity(HttpStatus.BAD_REQUEST, "止损卖出价位不能高于当前卖价");
} }
} }
PendingOrder pendingOrder = pendingOrderController.returnPendingOrder(memberId, trainingId, tradingCode,currencyName,buySellType, transactionVolume, priceCommission, stopLoss, stopWin, validityTime); PendingOrder pendingOrder = returnPendingOrder(pendingOrderId,memberId, trainingId, tradingCode,currencyName,buySellType, transactionVolume, priceCommission, stopLoss, stopWin, validityTime);
pendingOrderController.insertPendingOrder(pendingOrder);//保存挂单 insertPendingOrder(pendingOrder);//保存挂单
//保存挂单数据后 保存到redis中
Map map=new HashMap();
map.put("tradingCode",tradingCode);
map.put("currencyName",currencyName);
map.put("transactionType",transactionType);
map.put("transactionVolume",transactionVolume);
map.put("buySellType",buySellType);
map.put("stopLoss",stopLoss);
map.put("stopWin",stopWin);
map.put("memberId",memberId);
map.put("trainingId",trainingId);
map.put("validityTime",validityTime);
map.put("pendingOrderId",pendingOrderId);
map.put("priceCommission",priceCommission);
redisUtil.hmset("trainingId_"+trainingId+"_pengingOrderId_"+pendingOrderId,map);
} }
//获取交易次数预警 memberID tradingID 获取预警次数 判断是否超过 如果超过 则报警 //获取交易次数预警 memberID tradingID 获取预警次数 判断是否超过 如果超过 则报警
//checkopeningTrades(memberID,tradingID){} //checkopeningTrades(memberID,tradingID){}
@ -282,5 +312,34 @@ public class TradingController {
return false; return false;
} }
//返回挂单对象
public PendingOrder returnPendingOrder(String pendingOrderId,String memberId, String trainingId, String tradingCode,String currencyName, String buySellType, Double transactionVolume, Double priceCommission, Double stopLoss, Double stopWin,Date validityTime) {
Date now = new Date();
String commissionNumber = DateUtil.format(now, "yyyyMMddHHmmss") + System.currentTimeMillis();
PendingOrder pendingOrder=new PendingOrder();
pendingOrder.setPendingOrderId(pendingOrderId);
pendingOrder.setMemberId(memberId);
pendingOrder.setTrainingId(trainingId);
pendingOrder.setCommissionTime(now);
pendingOrder.setTradingCode(tradingCode);
pendingOrder.setCurrencyName(currencyName);
pendingOrder.setCommissionNumber(commissionNumber);
pendingOrder.setBuySellType(buySellType);
pendingOrder.setVolumeTransaction(transactionVolume);
pendingOrder.setPriceCommission(priceCommission);
pendingOrder.setStopLoss(stopLoss);
pendingOrder.setStopWin(stopWin);
pendingOrder.setValidityTime(validityTime);
pendingOrder.setStatus(0);
return pendingOrder;
}
//保存挂单 挂单保存后 将挂单ID和有效期存入redis
public void insertPendingOrder(PendingOrder pendingOrder){
String uuid = IdUtil.simpleUUID();
pendingOrder.setPendingOrderId(uuid);
pendingOrderService.insert(pendingOrder);
}
} }

@ -30,6 +30,9 @@ public class TakeStashVO {
this.timeTransaction = takeStash.getTimeTransaction(); this.timeTransaction = takeStash.getTimeTransaction();
this.status = takeStash.getStatus(); this.status = takeStash.getStatus();
this.currencyName=takeStash.getCurrencyName(); this.currencyName=takeStash.getCurrencyName();
this.profitAndLossByClose=takeStash.getProfitAndLossByClose();
this.priceTransactionClose=takeStash.getPriceTransactionClose();
this.timeTransactionClose=takeStash.getTimeTransactionClose();
} }
private String stashId; private String stashId;
@ -60,4 +63,10 @@ public class TakeStashVO {
private Double profitAndLoss; private Double profitAndLoss;
private String currencyName; private String currencyName;
private Double profitAndLossByClose;
private Double priceTransactionClose;
private Date timeTransactionClose;
} }

@ -615,7 +615,7 @@ public class ForexMarketData {
marketData.setDate((String) data.get("date")); marketData.setDate((String) data.get("date"));
marketData.setHighPic((String) data.get("highPic")); marketData.setHighPic((String) data.get("highPic"));
marketData.setLowPic((String) data.get("lowPic")); marketData.setLowPic((String) data.get("lowPic"));
marketData.setOpenPri((String) data.get("openPic")); marketData.setOpenPri((String) data.get("openPri"));
marketData.setRanges((String) data.get("range")); marketData.setRanges((String) data.get("range"));
marketData.setSellPic((String) data.get("sellPic")); marketData.setSellPic((String) data.get("sellPic"));
marketData.setYesPic((String) data.get("yesPic")); marketData.setYesPic((String) data.get("yesPic"));

@ -8,7 +8,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.stash_id * This field corresponds to the database column sys_take_stash.stash_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String stashId; private String stashId;
@ -17,7 +17,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.member_id * This field corresponds to the database column sys_take_stash.member_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String memberId; private String memberId;
@ -26,7 +26,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.training_id * This field corresponds to the database column sys_take_stash.training_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String trainingId; private String trainingId;
@ -35,7 +35,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.trading_code * This field corresponds to the database column sys_take_stash.trading_code
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String tradingCode; private String tradingCode;
@ -44,7 +44,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.currency_name * This field corresponds to the database column sys_take_stash.currency_name
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String currencyName; private String currencyName;
@ -53,7 +53,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.order_number * This field corresponds to the database column sys_take_stash.order_number
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String orderNumber; private String orderNumber;
@ -62,7 +62,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.buy_sell_type * This field corresponds to the database column sys_take_stash.buy_sell_type
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private String buySellType; private String buySellType;
@ -71,7 +71,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.volume_transaction * This field corresponds to the database column sys_take_stash.volume_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Double volumeTransaction; private Double volumeTransaction;
@ -80,16 +80,25 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.price_transaction * This field corresponds to the database column sys_take_stash.price_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Double priceTransaction; private Double priceTransaction;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.price_transaction_close
*
* @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/
private Double priceTransactionClose;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.stop_loss * This field corresponds to the database column sys_take_stash.stop_loss
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Double stopLoss; private Double stopLoss;
@ -98,7 +107,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.stop_win * This field corresponds to the database column sys_take_stash.stop_win
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Double stopWin; private Double stopWin;
@ -107,16 +116,25 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.time_transaction * This field corresponds to the database column sys_take_stash.time_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Date timeTransaction; private Date timeTransaction;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.time_transaction_close
*
* @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/
private Date timeTransactionClose;
/** /**
* *
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.status * This field corresponds to the database column sys_take_stash.status
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Integer status; private Integer status;
@ -125,7 +143,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.profit_and_loss_by_close * This field corresponds to the database column sys_take_stash.profit_and_loss_by_close
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Double profitAndLossByClose; private Double profitAndLossByClose;
@ -134,7 +152,7 @@ public class TakeStash {
* This field was generated by MyBatis Generator. * This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_take_stash.trading_margin * This field corresponds to the database column sys_take_stash.trading_margin
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
private Double tradingMargin; private Double tradingMargin;
@ -144,7 +162,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.stash_id * @return the value of sys_take_stash.stash_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getStashId() { public String getStashId() {
return stashId; return stashId;
@ -156,7 +174,7 @@ public class TakeStash {
* *
* @param stashId the value for sys_take_stash.stash_id * @param stashId the value for sys_take_stash.stash_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setStashId(String stashId) { public void setStashId(String stashId) {
this.stashId = stashId == null ? null : stashId.trim(); this.stashId = stashId == null ? null : stashId.trim();
@ -168,7 +186,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.member_id * @return the value of sys_take_stash.member_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getMemberId() { public String getMemberId() {
return memberId; return memberId;
@ -180,7 +198,7 @@ public class TakeStash {
* *
* @param memberId the value for sys_take_stash.member_id * @param memberId the value for sys_take_stash.member_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setMemberId(String memberId) { public void setMemberId(String memberId) {
this.memberId = memberId == null ? null : memberId.trim(); this.memberId = memberId == null ? null : memberId.trim();
@ -192,7 +210,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.training_id * @return the value of sys_take_stash.training_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getTrainingId() { public String getTrainingId() {
return trainingId; return trainingId;
@ -204,7 +222,7 @@ public class TakeStash {
* *
* @param trainingId the value for sys_take_stash.training_id * @param trainingId the value for sys_take_stash.training_id
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setTrainingId(String trainingId) { public void setTrainingId(String trainingId) {
this.trainingId = trainingId == null ? null : trainingId.trim(); this.trainingId = trainingId == null ? null : trainingId.trim();
@ -216,7 +234,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.trading_code * @return the value of sys_take_stash.trading_code
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getTradingCode() { public String getTradingCode() {
return tradingCode; return tradingCode;
@ -228,7 +246,7 @@ public class TakeStash {
* *
* @param tradingCode the value for sys_take_stash.trading_code * @param tradingCode the value for sys_take_stash.trading_code
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setTradingCode(String tradingCode) { public void setTradingCode(String tradingCode) {
this.tradingCode = tradingCode == null ? null : tradingCode.trim(); this.tradingCode = tradingCode == null ? null : tradingCode.trim();
@ -240,7 +258,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.currency_name * @return the value of sys_take_stash.currency_name
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getCurrencyName() { public String getCurrencyName() {
return currencyName; return currencyName;
@ -252,7 +270,7 @@ public class TakeStash {
* *
* @param currencyName the value for sys_take_stash.currency_name * @param currencyName the value for sys_take_stash.currency_name
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setCurrencyName(String currencyName) { public void setCurrencyName(String currencyName) {
this.currencyName = currencyName == null ? null : currencyName.trim(); this.currencyName = currencyName == null ? null : currencyName.trim();
@ -264,7 +282,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.order_number * @return the value of sys_take_stash.order_number
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getOrderNumber() { public String getOrderNumber() {
return orderNumber; return orderNumber;
@ -276,7 +294,7 @@ public class TakeStash {
* *
* @param orderNumber the value for sys_take_stash.order_number * @param orderNumber the value for sys_take_stash.order_number
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setOrderNumber(String orderNumber) { public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber == null ? null : orderNumber.trim(); this.orderNumber = orderNumber == null ? null : orderNumber.trim();
@ -288,7 +306,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.buy_sell_type * @return the value of sys_take_stash.buy_sell_type
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public String getBuySellType() { public String getBuySellType() {
return buySellType; return buySellType;
@ -300,7 +318,7 @@ public class TakeStash {
* *
* @param buySellType the value for sys_take_stash.buy_sell_type * @param buySellType the value for sys_take_stash.buy_sell_type
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setBuySellType(String buySellType) { public void setBuySellType(String buySellType) {
this.buySellType = buySellType == null ? null : buySellType.trim(); this.buySellType = buySellType == null ? null : buySellType.trim();
@ -312,7 +330,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.volume_transaction * @return the value of sys_take_stash.volume_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Double getVolumeTransaction() { public Double getVolumeTransaction() {
return volumeTransaction; return volumeTransaction;
@ -324,7 +342,7 @@ public class TakeStash {
* *
* @param volumeTransaction the value for sys_take_stash.volume_transaction * @param volumeTransaction the value for sys_take_stash.volume_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setVolumeTransaction(Double volumeTransaction) { public void setVolumeTransaction(Double volumeTransaction) {
this.volumeTransaction = volumeTransaction; this.volumeTransaction = volumeTransaction;
@ -336,7 +354,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.price_transaction * @return the value of sys_take_stash.price_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Double getPriceTransaction() { public Double getPriceTransaction() {
return priceTransaction; return priceTransaction;
@ -348,19 +366,43 @@ public class TakeStash {
* *
* @param priceTransaction the value for sys_take_stash.price_transaction * @param priceTransaction the value for sys_take_stash.price_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setPriceTransaction(Double priceTransaction) { public void setPriceTransaction(Double priceTransaction) {
this.priceTransaction = priceTransaction; this.priceTransaction = priceTransaction;
} }
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_take_stash.price_transaction_close
*
* @return the value of sys_take_stash.price_transaction_close
*
* @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/
public Double getPriceTransactionClose() {
return priceTransactionClose;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column sys_take_stash.price_transaction_close
*
* @param priceTransactionClose the value for sys_take_stash.price_transaction_close
*
* @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/
public void setPriceTransactionClose(Double priceTransactionClose) {
this.priceTransactionClose = priceTransactionClose;
}
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_take_stash.stop_loss * This method returns the value of the database column sys_take_stash.stop_loss
* *
* @return the value of sys_take_stash.stop_loss * @return the value of sys_take_stash.stop_loss
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Double getStopLoss() { public Double getStopLoss() {
return stopLoss; return stopLoss;
@ -372,7 +414,7 @@ public class TakeStash {
* *
* @param stopLoss the value for sys_take_stash.stop_loss * @param stopLoss the value for sys_take_stash.stop_loss
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setStopLoss(Double stopLoss) { public void setStopLoss(Double stopLoss) {
this.stopLoss = stopLoss; this.stopLoss = stopLoss;
@ -384,7 +426,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.stop_win * @return the value of sys_take_stash.stop_win
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Double getStopWin() { public Double getStopWin() {
return stopWin; return stopWin;
@ -396,7 +438,7 @@ public class TakeStash {
* *
* @param stopWin the value for sys_take_stash.stop_win * @param stopWin the value for sys_take_stash.stop_win
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setStopWin(Double stopWin) { public void setStopWin(Double stopWin) {
this.stopWin = stopWin; this.stopWin = stopWin;
@ -408,7 +450,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.time_transaction * @return the value of sys_take_stash.time_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Date getTimeTransaction() { public Date getTimeTransaction() {
return timeTransaction; return timeTransaction;
@ -420,19 +462,43 @@ public class TakeStash {
* *
* @param timeTransaction the value for sys_take_stash.time_transaction * @param timeTransaction the value for sys_take_stash.time_transaction
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setTimeTransaction(Date timeTransaction) { public void setTimeTransaction(Date timeTransaction) {
this.timeTransaction = timeTransaction; this.timeTransaction = timeTransaction;
} }
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_take_stash.time_transaction_close
*
* @return the value of sys_take_stash.time_transaction_close
*
* @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/
public Date getTimeTransactionClose() {
return timeTransactionClose;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column sys_take_stash.time_transaction_close
*
* @param timeTransactionClose the value for sys_take_stash.time_transaction_close
*
* @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/
public void setTimeTransactionClose(Date timeTransactionClose) {
this.timeTransactionClose = timeTransactionClose;
}
/** /**
* This method was generated by MyBatis Generator. * This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_take_stash.status * This method returns the value of the database column sys_take_stash.status
* *
* @return the value of sys_take_stash.status * @return the value of sys_take_stash.status
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Integer getStatus() { public Integer getStatus() {
return status; return status;
@ -444,7 +510,7 @@ public class TakeStash {
* *
* @param status the value for sys_take_stash.status * @param status the value for sys_take_stash.status
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setStatus(Integer status) { public void setStatus(Integer status) {
this.status = status; this.status = status;
@ -456,7 +522,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.profit_and_loss_by_close * @return the value of sys_take_stash.profit_and_loss_by_close
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Double getProfitAndLossByClose() { public Double getProfitAndLossByClose() {
return profitAndLossByClose; return profitAndLossByClose;
@ -468,7 +534,7 @@ public class TakeStash {
* *
* @param profitAndLossByClose the value for sys_take_stash.profit_and_loss_by_close * @param profitAndLossByClose the value for sys_take_stash.profit_and_loss_by_close
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setProfitAndLossByClose(Double profitAndLossByClose) { public void setProfitAndLossByClose(Double profitAndLossByClose) {
this.profitAndLossByClose = profitAndLossByClose; this.profitAndLossByClose = profitAndLossByClose;
@ -480,7 +546,7 @@ public class TakeStash {
* *
* @return the value of sys_take_stash.trading_margin * @return the value of sys_take_stash.trading_margin
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public Double getTradingMargin() { public Double getTradingMargin() {
return tradingMargin; return tradingMargin;
@ -492,7 +558,7 @@ public class TakeStash {
* *
* @param tradingMargin the value for sys_take_stash.trading_margin * @param tradingMargin the value for sys_take_stash.trading_margin
* *
* @mbg.generated Mon Jul 17 14:31:17 CST 2023 * @mbg.generated Fri Jul 21 14:51:28 CST 2023
*/ */
public void setTradingMargin(Double tradingMargin) { public void setTradingMargin(Double tradingMargin) {
this.tradingMargin = tradingMargin; this.tradingMargin = tradingMargin;

@ -130,6 +130,9 @@ public interface TrainingMapper {
"WHERE NOW() >= start_time AND NOW() <= end_time AND status <> 'ONGOING'") "WHERE NOW() >= start_time AND NOW() <= end_time AND status <> 'ONGOING'")
void updateTrainingStatusToInProgress(); void updateTrainingStatusToInProgress();
@Select("select training_id from sys_training where status=1") @Select("select training_id from sys_training where status='ONGOING'")
List<String> selectProceedTraining(); List<String> selectProceedTraining();
@Select("select training_id from sys_training where status= 'FINISHED'")
List<String> selectTrainingIdByStatus();
} }

@ -1,8 +1,12 @@
package com.sztzjy.forex.trading_trading.service; package com.sztzjy.forex.trading_trading.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sztzjy.forex.trading_trading.entity.PendingOrder; import com.sztzjy.forex.trading_trading.entity.PendingOrder;
import com.sztzjy.forex.trading_trading.entity.PendingOrderExample; import com.sztzjy.forex.trading_trading.entity.PendingOrderExample;
import com.sztzjy.forex.trading_trading.entity.TakeStash;
import com.sztzjy.forex.trading_trading.mappers.PendingOrderMapper; import com.sztzjy.forex.trading_trading.mappers.PendingOrderMapper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -17,15 +21,18 @@ public class PendingOrderService {
pendingOrderMapper.insert(pendingOrder); pendingOrderMapper.insert(pendingOrder);
} }
public List<PendingOrder> selectByTrainingIdAndStatusAndMemberId(PendingOrder pendingOrder){ public PageInfo<PendingOrder> selectByTrainingIdAndStatusAndMemberId(PendingOrder pendingOrder, Integer pageNum,Integer pageSize){
PageHelper.startPage(pageNum, pageSize);
PendingOrderExample pendingOrderExample = new PendingOrderExample(); PendingOrderExample pendingOrderExample = new PendingOrderExample();
PendingOrderExample.Criteria criteria = pendingOrderExample.createCriteria(); PendingOrderExample.Criteria criteria = pendingOrderExample.createCriteria();
criteria.andMemberIdEqualTo(pendingOrder.getMemberId()).andTrainingIdEqualTo(pendingOrder.getTrainingId()).andStatusEqualTo(pendingOrder.getStatus()); criteria.andMemberIdEqualTo(pendingOrder.getMemberId()).andTrainingIdEqualTo(pendingOrder.getTrainingId()).andStatusEqualTo(pendingOrder.getStatus());
List<PendingOrder> pendingOrders = pendingOrderMapper.selectByExample(pendingOrderExample); List<PendingOrder> pendingOrders = pendingOrderMapper.selectByExample(pendingOrderExample);
return pendingOrders; PageInfo<PendingOrder> pageInfo = new PageInfo<>(pendingOrders);
return pageInfo;
} }
public void cancelOrder(String pendingOrderId){ public void cancelOrder(String pendingOrderId){
pendingOrderMapper.deleteByPrimaryKey(pendingOrderId); pendingOrderMapper.deleteByPrimaryKey(pendingOrderId);
} }
} }

@ -2,12 +2,17 @@ package com.sztzjy.forex.trading_trading.service;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess; import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess;
import com.sztzjy.forex.trading_trading.common.mql5API.Mql5API; import com.sztzjy.forex.trading_trading.common.mql5API.Mql5API;
import com.sztzjy.forex.trading_trading.controller.PendingOrderController;
import com.sztzjy.forex.trading_trading.controller.TakeStashController; import com.sztzjy.forex.trading_trading.controller.TakeStashController;
import com.sztzjy.forex.trading_trading.controller.TradingController;
import com.sztzjy.forex.trading_trading.entity.ForexMarketData; import com.sztzjy.forex.trading_trading.entity.ForexMarketData;
import com.sztzjy.forex.trading_trading.entity.mql5Entity.ForexData; import com.sztzjy.forex.trading_trading.entity.mql5Entity.ForexData;
import com.sztzjy.forex.trading_trading.mappers.TrainingMapper; import com.sztzjy.forex.trading_trading.mappers.TrainingMapper;
import com.sztzjy.forex.trading_trading.util.BigDecimalUtils;
import com.sztzjy.forex.trading_trading.util.ForexMarketDateUtil;
import com.sztzjy.forex.trading_trading.util.RedisUtil; import com.sztzjy.forex.trading_trading.util.RedisUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A; import org.checkerframework.checker.units.qual.A;
@ -17,6 +22,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; import java.util.*;
@ -44,40 +51,49 @@ public class ScheduledTask {
@Autowired @Autowired
TakeStashController takeStashController; TakeStashController takeStashController;
@Autowired
ForexMarketDateUtil forexMarketDateUtil;
@Autowired
PendingOrderController pendingOrderController;
@Autowired
TradingController tradingController;
@Autowired
BigDecimalUtils bigDecimalUtils;
@Scheduled(cron = "0 * * * * *") // 修改实训状态 每分钟执行一次 @Scheduled(cron = "0 * * * * *") // 修改实训状态 每分钟执行一次
public void updateTrainingStatus() { public void updateTrainingStatus() {
trainingMapper.updateTrainingStatusToInProgress(); trainingMapper.updateTrainingStatusToInProgress();
trainingMapper.updateTrainingStatusToEnd(); trainingMapper.updateTrainingStatusToEnd();
} }
Boolean flag=false; //项目启动保证insertForexMarketData先执行 暂用
//每两分钟执行一次 真实的数据插入 //每两分钟执行一次 真实的数据插入
@PostConstruct
@Scheduled(cron = "0 */2 * * * ?") @Scheduled(cron = "0 */2 * * * ?")
public void insertForexMarketData() { public void insertForexMarketData() {
if(!timerEnable){ // if(!timerEnable){
return; // return;
} // }
//TODO getMarketQuotation方法获取的数据有空指针待解决
Mql5API api = new Mql5API(); Mql5API api = new Mql5API();
List<ForexData> forexData = api.getMarketQuotation(); List<ForexData> forexData = api.getMarketQuotation();
List<ForexMarketData> forexMarketDataList = ForexMarketData.copyToForexData(forexData); List<ForexMarketData> forexMarketDataList = ForexMarketData.copyToForexData(forexData);
forexMarketDataService.insertAll(forexMarketDataList); forexMarketDataService.insertAll(forexMarketDataList);
redisUtil.set("ForexDateList", forexMarketDataList); redisUtil.set("ForexDateList", forexMarketDataList);
flag=true;
} }
//每16秒执行一次 根据真实汇率数据生成模拟汇率数据 //每16秒执行一次 根据真实汇率数据生成模拟汇率数据
@Scheduled(cron = "0/16 * * * * ?") @Scheduled(cron = "0/16 * * * * ?")
public void insertSimulatedForexMarketData() { public void insertSimulatedForexMarketData() {
if(!timerEnable){ // if(!timerEnable){
return; // return;
} // }
if (flag==false){
return;
}
//获取batchId相同的最后入库的数据 //获取batchId相同的最后入库的数据
List<ForexMarketData> forexMarketDataList = forexMarketDataService.selectLastForexMarketData(); List<ForexMarketData> forexMarketDataList=redisUtil.get("ForexDateList");
// forexMarketDataList = forexMarketDataService.selectLastForexMarketData();
if(forexMarketDataList==null|| forexMarketDataList.size()==0){ if(forexMarketDataList==null|| forexMarketDataList.size()==0){
return; return;
} }
@ -85,11 +101,13 @@ public class ScheduledTask {
Random random = new Random(); Random random = new Random();
List<ForexMarketData> forexMarketData = new ArrayList<>(); List<ForexMarketData> forexMarketData = new ArrayList<>();
String batchId = IdUtil.simpleUUID(); String batchId = IdUtil.simpleUUID();
DecimalFormat decimalFormat = new DecimalFormat("#0.######"); // 格式化为六位小数
for (ForexMarketData data : forexMarketDataList) { for (ForexMarketData data : forexMarketDataList) {
Double buyPic = modifyDecimal(data.getBuyPic(), random);
Double openPriDouble = Double.valueOf(data.getOpenPri());
String diffAmo = bigDecimalUtils.sub(String.valueOf(buyPic), data.getOpenPri()).toString();
ForexMarketData resultData = new ForexMarketData( ForexMarketData resultData = new ForexMarketData(
modifyDecimal(data.getBuyPic(), random), buyPic,
modifyDecimal(data.getClosePri(), random), data.getClosePri(),
data.getCode(), data.getCode(),
data.getColor(), data.getColor(),
data.getCurrency(), data.getCurrency(),
@ -99,14 +117,14 @@ public class ScheduledTask {
data.getLowPic(), data.getLowPic(),
data.getOpenPri(), data.getOpenPri(),
data.getRanges(), data.getRanges(),
data.getSellPic(), String.valueOf(modifyDecimal(Double.parseDouble(data.getSellPic()), random)),
data.getYesPic(), data.getYesPic(),
String.valueOf(modifyDecimal(Double.parseDouble(data.getDiffAmo()), random)), diffAmo,
String.valueOf(modifyDecimal(Double.parseDouble(decimalFormat.format(Double.parseDouble(data.getDiffPer().replace("%",""))/100)), random)), data.getDiffPer(),
batchId); batchId);
forexMarketData.add(resultData); forexMarketData.add(resultData);
} }
forexMarketDataService.insertAllByMarketData(forexMarketData); // forexMarketDataService.insertAllByMarketData(forexMarketData);
redisUtil.set("ForexDateList", forexMarketData); redisUtil.set("ForexDateList", forexMarketData);
log.info("--------插入模拟汇率数据成功------"); log.info("--------插入模拟汇率数据成功------");
}catch (Exception e) { }catch (Exception e) {
@ -144,6 +162,7 @@ public class ScheduledTask {
} }
//error
//监听止损止盈 根据code获取当前买卖价格 如果价格高于/低于止损止盈 则按照止损止盈的值进行平仓 //监听止损止盈 根据code获取当前买卖价格 如果价格高于/低于止损止盈 则按照止损止盈的值进行平仓
//查询实训表中状态为1的所有实训并获取ID 获取持仓表中所有状态为0 且止损和止盈不为空的所有数据 获取当前价位如果 //查询实训表中状态为1的所有实训并获取ID 获取持仓表中所有状态为0 且止损和止盈不为空的所有数据 获取当前价位如果
@Scheduled(cron = "0 */2 * * * ?") @Scheduled(cron = "0 */2 * * * ?")
@ -229,4 +248,37 @@ public class ScheduledTask {
} }
//挂单自动开仓(到期自动撤单) 定时方法
@Scheduled(cron = "0 */2 * * * ?")
public void OpenPendingOrder() {
Set<String> pendingOrderSet = redisUtil.keys("pengingOrder*");
List<ForexMarketData> forexDateList = redisUtil.get("ForexDateList");
Map<String, ForexMarketData> forexMarketDateMap = forexMarketDateUtil.getForexMarketDateMap(forexDateList);
for (String key : pendingOrderSet) {
Map<Object, Object> pengingOrderMap = redisUtil.hmget(key);
Boolean expire = pendingOrderController.isExpire(pengingOrderMap, key); //判断是否到期
if (expire) {
continue;
}
//判断是否开仓
Boolean isPpen = pendingOrderController.isOpenTakeStash(pengingOrderMap,forexMarketDateMap);
if(isPpen){
continue;
}
JSONObject jsonObject = pendingOrderController.pengingKeyReturnJSONObject(pengingOrderMap);
tradingController.getMarketQuotation(jsonObject);
}
}
//自动清空实例到期的所有redisKey
@Scheduled(cron = "0 */2 * * * ?")
public void clearRedisKeyByTrainingId(){
List<String> trainingIds=trainingMapper.selectTrainingIdByStatus();
for (int i = 0; i < trainingIds.size(); i++) {
redisUtil.del("trainingId_"+trainingIds+"*");
}
}
} }

@ -1,6 +1,8 @@
package com.sztzjy.forex.trading_trading.service; package com.sztzjy.forex.trading_trading.service;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sztzjy.forex.trading_trading.entity.TakeStash; import com.sztzjy.forex.trading_trading.entity.TakeStash;
import com.sztzjy.forex.trading_trading.entity.TakeStashExample; import com.sztzjy.forex.trading_trading.entity.TakeStashExample;
import com.sztzjy.forex.trading_trading.mappers.TakeStashMapper; import com.sztzjy.forex.trading_trading.mappers.TakeStashMapper;
@ -19,12 +21,14 @@ public class TakeStashService {
takeStashMapper.insert(takeStash); takeStashMapper.insert(takeStash);
} }
public List<TakeStash> findTakeStashByTrainingIdAndMemberIdAndStatus(String trainingId, String memberId, Integer status) { public PageInfo<TakeStash> findTakeStashByTrainingIdAndMemberIdAndStatus(String trainingId, String memberId, Integer status,Integer pageNum,Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
TakeStashExample example=new TakeStashExample(); TakeStashExample example=new TakeStashExample();
TakeStashExample.Criteria criteria = example.createCriteria(); TakeStashExample.Criteria criteria = example.createCriteria();
criteria.andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId).andStatusEqualTo(status); criteria.andMemberIdEqualTo(memberId).andTrainingIdEqualTo(trainingId).andStatusEqualTo(status);
List<TakeStash> takeStashes = takeStashMapper.selectByExample(example); List<TakeStash> takeStashes = takeStashMapper.selectByExample(example);
return takeStashes; PageInfo<TakeStash> pageInfo = new PageInfo<>(takeStashes);
return pageInfo;
} }
public List<TakeStash> selectAllByMemberIdAndStatus(String memberId, Integer status) { public List<TakeStash> selectAllByMemberIdAndStatus(String memberId, Integer status) {

@ -0,0 +1,287 @@
package com.sztzjy.forex.trading_trading.util;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
@Component
public class BigDecimalUtils {
//默认除法运算精度
private static final int DEF_DIV_SCALE = 5;
public double add(double v1, double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.add(b2).doubleValue();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public BigDecimal add(String v1, String v2) {
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.add(b2);
}
/**
*
*
* @param v1
* @param v2
* @param scale scale
* @return
* @throws IllegalAccessException
*/
public String add(String v1, String v2, int scale) throws IllegalAccessException {
if (scale < 0) {
throw new IllegalAccessException("The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.add(b2).setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public Double sub(Double v1, Double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.subtract(b2).doubleValue();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public BigDecimal sub(String v1, String v2) {
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.subtract(b2);
}
/**
*
*
* @param v1
* @param v2
* @param scale scale
* @return
* @throws IllegalAccessException
*/
public String sub(String v1, String v2, int scale) throws IllegalAccessException {
if (scale < 0) {
throw new IllegalAccessException("The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.subtract(b2).setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public Double mul(double v1, double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.multiply(b2).doubleValue();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public BigDecimal mul(String v1, String v2) {
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.multiply(b2);
}
/**
*
*
* @param v1
* @param v2
* @param scale scale
* @return
*/
public double mul(double v1, double v2, int scale) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return round(b1.multiply(b2).doubleValue(), scale);
}
/**
*
*
* @param v1
* @param v2
* @param scale scale
* @return
*/
public String mul(String v1, String v2, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.multiply(b2).setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
}
/**
*
* 10
*
* @param v1
* @param v2
* @return
*/
public Double div(double v1, double v2) {
return div(v1, v2, DEF_DIV_SCALE);
}
/**
* scale
*
*
* @param v1
* @param v2
* @param scale
* @return
*/
public double div(double v1, double v2, int scale) {
if (scale < 0) {
throw new IllegalArgumentException("The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
/**
* scale
*
*
* @param v1
* @param v2
* @param scale
* @return
*/
public String div(String v1, String v2, int scale) {
if (scale < 0) {
throw new IllegalArgumentException("The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v1);
return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).toString();
}
/**
*
*
* @param v
* @param scale
* @return
*/
public double round(double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException("The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(Double.toString(v));
return b.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
/**
*
*
* @param v
* @param scale
* @return
*/
public String round(String v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(v);
return b.setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
}
/**
*
*
* @param v1
* @param v2
* @param scale
* @return
*/
public String remainder(String v1, String v2, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
return b1.remainder(b2).setScale(scale, BigDecimal.ROUND_HALF_UP).toString();
}
/**
* BigDecimal
*
* @param v1
* @param v2
* @param scale
* @return
*/
public BigDecimal remainder(BigDecimal v1, BigDecimal v2, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
return v1.remainder(v2).setScale(scale, BigDecimal.ROUND_HALF_UP);
}
/**
*
*
* @param v1
* @param v2
* @return v1 v2 true false
*/
public boolean compare(String v1, String v2) {
BigDecimal b1 = new BigDecimal(v1);
BigDecimal b2 = new BigDecimal(v2);
int bj = b1.compareTo(b2);
boolean res;
if (bj > 0)
res = true;
else
res = false;
return res;
}
}

@ -0,0 +1,3 @@
FROM openjdk:18
EXPOSE 8801
ENTRYPOINT ["java","-jar","/foreignExchangeTrading.jar"]

@ -5,7 +5,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
<id column="stash_id" jdbcType="VARCHAR" property="stashId" /> <id column="stash_id" jdbcType="VARCHAR" property="stashId" />
<result column="member_id" jdbcType="VARCHAR" property="memberId" /> <result column="member_id" jdbcType="VARCHAR" property="memberId" />
@ -16,9 +16,11 @@
<result column="buy_sell_type" jdbcType="VARCHAR" property="buySellType" /> <result column="buy_sell_type" jdbcType="VARCHAR" property="buySellType" />
<result column="volume_transaction" jdbcType="DOUBLE" property="volumeTransaction" /> <result column="volume_transaction" jdbcType="DOUBLE" property="volumeTransaction" />
<result column="price_transaction" jdbcType="DOUBLE" property="priceTransaction" /> <result column="price_transaction" jdbcType="DOUBLE" property="priceTransaction" />
<result column="price_transaction_close" jdbcType="DOUBLE" property="priceTransactionClose" />
<result column="stop_loss" jdbcType="DOUBLE" property="stopLoss" /> <result column="stop_loss" jdbcType="DOUBLE" property="stopLoss" />
<result column="stop_win" jdbcType="DOUBLE" property="stopWin" /> <result column="stop_win" jdbcType="DOUBLE" property="stopWin" />
<result column="time_transaction" jdbcType="TIMESTAMP" property="timeTransaction" /> <result column="time_transaction" jdbcType="TIMESTAMP" property="timeTransaction" />
<result column="time_transaction_close" jdbcType="TIMESTAMP" property="timeTransactionClose" />
<result column="status" jdbcType="INTEGER" property="status" /> <result column="status" jdbcType="INTEGER" property="status" />
<result column="profit_and_loss_by_close" jdbcType="DOUBLE" property="profitAndLossByClose" /> <result column="profit_and_loss_by_close" jdbcType="DOUBLE" property="profitAndLossByClose" />
<result column="trading_margin" jdbcType="DOUBLE" property="tradingMargin" /> <result column="trading_margin" jdbcType="DOUBLE" property="tradingMargin" />
@ -27,7 +29,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
<where> <where>
<foreach collection="oredCriteria" item="criteria" separator="or"> <foreach collection="oredCriteria" item="criteria" separator="or">
@ -61,7 +63,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
<where> <where>
<foreach collection="example.oredCriteria" item="criteria" separator="or"> <foreach collection="example.oredCriteria" item="criteria" separator="or">
@ -95,17 +97,17 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
stash_id, member_id, training_id, trading_code, currency_name, order_number, buy_sell_type, stash_id, member_id, training_id, trading_code, currency_name, order_number, buy_sell_type,
volume_transaction, price_transaction, stop_loss, stop_win, time_transaction, status, volume_transaction, price_transaction, price_transaction_close, stop_loss, stop_win,
profit_and_loss_by_close, trading_margin time_transaction, time_transaction_close, status, profit_and_loss_by_close, trading_margin
</sql> </sql>
<select id="selectByExample" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStashExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStashExample" resultMap="BaseResultMap">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
select select
<if test="distinct"> <if test="distinct">
@ -124,9 +126,9 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from sys_take_stash from sys_take_stash
where stash_id = #{stashId,jdbcType=VARCHAR} where stash_id = #{stashId,jdbcType=VARCHAR}
@ -135,7 +137,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
delete from sys_take_stash delete from sys_take_stash
where stash_id = #{stashId,jdbcType=VARCHAR} where stash_id = #{stashId,jdbcType=VARCHAR}
@ -144,7 +146,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
delete from sys_take_stash delete from sys_take_stash
<if test="_parameter != null"> <if test="_parameter != null">
@ -155,26 +157,28 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
insert into sys_take_stash (stash_id, member_id, training_id, insert into sys_take_stash (stash_id, member_id, training_id,
trading_code, currency_name, order_number, trading_code, currency_name, order_number,
buy_sell_type, volume_transaction, price_transaction, buy_sell_type, volume_transaction, price_transaction,
stop_loss, stop_win, time_transaction, price_transaction_close, stop_loss, stop_win,
status, profit_and_loss_by_close, trading_margin time_transaction, time_transaction_close,
) status, profit_and_loss_by_close, trading_margin
values (#{stashId,jdbcType=VARCHAR}, #{memberId,jdbcType=VARCHAR}, #{trainingId,jdbcType=VARCHAR}, )
#{tradingCode,jdbcType=VARCHAR}, #{currencyName,jdbcType=VARCHAR}, #{orderNumber,jdbcType=VARCHAR}, values (#{stashId,jdbcType=VARCHAR}, #{memberId,jdbcType=VARCHAR}, #{trainingId,jdbcType=VARCHAR},
#{buySellType,jdbcType=VARCHAR}, #{volumeTransaction,jdbcType=DOUBLE}, #{priceTransaction,jdbcType=DOUBLE}, #{tradingCode,jdbcType=VARCHAR}, #{currencyName,jdbcType=VARCHAR}, #{orderNumber,jdbcType=VARCHAR},
#{stopLoss,jdbcType=DOUBLE}, #{stopWin,jdbcType=DOUBLE}, #{timeTransaction,jdbcType=TIMESTAMP}, #{buySellType,jdbcType=VARCHAR}, #{volumeTransaction,jdbcType=DOUBLE}, #{priceTransaction,jdbcType=DOUBLE},
#{status,jdbcType=INTEGER}, #{profitAndLossByClose,jdbcType=DOUBLE}, #{tradingMargin,jdbcType=DOUBLE} #{priceTransactionClose,jdbcType=DOUBLE}, #{stopLoss,jdbcType=DOUBLE}, #{stopWin,jdbcType=DOUBLE},
) #{timeTransaction,jdbcType=TIMESTAMP}, #{timeTransactionClose,jdbcType=TIMESTAMP},
#{status,jdbcType=INTEGER}, #{profitAndLossByClose,jdbcType=DOUBLE}, #{tradingMargin,jdbcType=DOUBLE}
)
</insert> </insert>
<insert id="insertSelective" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStash"> <insert id="insertSelective" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStash">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
insert into sys_take_stash insert into sys_take_stash
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -205,6 +209,9 @@
<if test="priceTransaction != null"> <if test="priceTransaction != null">
price_transaction, price_transaction,
</if> </if>
<if test="priceTransactionClose != null">
price_transaction_close,
</if>
<if test="stopLoss != null"> <if test="stopLoss != null">
stop_loss, stop_loss,
</if> </if>
@ -214,6 +221,9 @@
<if test="timeTransaction != null"> <if test="timeTransaction != null">
time_transaction, time_transaction,
</if> </if>
<if test="timeTransactionClose != null">
time_transaction_close,
</if>
<if test="status != null"> <if test="status != null">
status, status,
</if> </if>
@ -252,6 +262,9 @@
<if test="priceTransaction != null"> <if test="priceTransaction != null">
#{priceTransaction,jdbcType=DOUBLE}, #{priceTransaction,jdbcType=DOUBLE},
</if> </if>
<if test="priceTransactionClose != null">
#{priceTransactionClose,jdbcType=DOUBLE},
</if>
<if test="stopLoss != null"> <if test="stopLoss != null">
#{stopLoss,jdbcType=DOUBLE}, #{stopLoss,jdbcType=DOUBLE},
</if> </if>
@ -261,6 +274,9 @@
<if test="timeTransaction != null"> <if test="timeTransaction != null">
#{timeTransaction,jdbcType=TIMESTAMP}, #{timeTransaction,jdbcType=TIMESTAMP},
</if> </if>
<if test="timeTransactionClose != null">
#{timeTransactionClose,jdbcType=TIMESTAMP},
</if>
<if test="status != null"> <if test="status != null">
#{status,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
</if> </if>
@ -276,7 +292,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
select count(*) from sys_take_stash select count(*) from sys_take_stash
<if test="_parameter != null"> <if test="_parameter != null">
@ -287,7 +303,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
update sys_take_stash update sys_take_stash
<set> <set>
@ -318,6 +334,9 @@
<if test="record.priceTransaction != null"> <if test="record.priceTransaction != null">
price_transaction = #{record.priceTransaction,jdbcType=DOUBLE}, price_transaction = #{record.priceTransaction,jdbcType=DOUBLE},
</if> </if>
<if test="record.priceTransactionClose != null">
price_transaction_close = #{record.priceTransactionClose,jdbcType=DOUBLE},
</if>
<if test="record.stopLoss != null"> <if test="record.stopLoss != null">
stop_loss = #{record.stopLoss,jdbcType=DOUBLE}, stop_loss = #{record.stopLoss,jdbcType=DOUBLE},
</if> </if>
@ -327,6 +346,9 @@
<if test="record.timeTransaction != null"> <if test="record.timeTransaction != null">
time_transaction = #{record.timeTransaction,jdbcType=TIMESTAMP}, time_transaction = #{record.timeTransaction,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.timeTransactionClose != null">
time_transaction_close = #{record.timeTransactionClose,jdbcType=TIMESTAMP},
</if>
<if test="record.status != null"> <if test="record.status != null">
status = #{record.status,jdbcType=INTEGER}, status = #{record.status,jdbcType=INTEGER},
</if> </if>
@ -345,24 +367,26 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
update sys_take_stash update sys_take_stash
set stash_id = #{record.stashId,jdbcType=VARCHAR}, set stash_id = #{record.stashId,jdbcType=VARCHAR},
member_id = #{record.memberId,jdbcType=VARCHAR}, member_id = #{record.memberId,jdbcType=VARCHAR},
training_id = #{record.trainingId,jdbcType=VARCHAR}, training_id = #{record.trainingId,jdbcType=VARCHAR},
trading_code = #{record.tradingCode,jdbcType=VARCHAR}, trading_code = #{record.tradingCode,jdbcType=VARCHAR},
currency_name = #{record.currencyName,jdbcType=VARCHAR}, currency_name = #{record.currencyName,jdbcType=VARCHAR},
order_number = #{record.orderNumber,jdbcType=VARCHAR}, order_number = #{record.orderNumber,jdbcType=VARCHAR},
buy_sell_type = #{record.buySellType,jdbcType=VARCHAR}, buy_sell_type = #{record.buySellType,jdbcType=VARCHAR},
volume_transaction = #{record.volumeTransaction,jdbcType=DOUBLE}, volume_transaction = #{record.volumeTransaction,jdbcType=DOUBLE},
price_transaction = #{record.priceTransaction,jdbcType=DOUBLE}, price_transaction = #{record.priceTransaction,jdbcType=DOUBLE},
stop_loss = #{record.stopLoss,jdbcType=DOUBLE}, price_transaction_close = #{record.priceTransactionClose,jdbcType=DOUBLE},
stop_win = #{record.stopWin,jdbcType=DOUBLE}, stop_loss = #{record.stopLoss,jdbcType=DOUBLE},
time_transaction = #{record.timeTransaction,jdbcType=TIMESTAMP}, stop_win = #{record.stopWin,jdbcType=DOUBLE},
status = #{record.status,jdbcType=INTEGER}, time_transaction = #{record.timeTransaction,jdbcType=TIMESTAMP},
profit_and_loss_by_close = #{record.profitAndLossByClose,jdbcType=DOUBLE}, time_transaction_close = #{record.timeTransactionClose,jdbcType=TIMESTAMP},
trading_margin = #{record.tradingMargin,jdbcType=DOUBLE} status = #{record.status,jdbcType=INTEGER},
profit_and_loss_by_close = #{record.profitAndLossByClose,jdbcType=DOUBLE},
trading_margin = #{record.tradingMargin,jdbcType=DOUBLE}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -371,7 +395,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify. This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023. This element was generated on Fri Jul 21 14:51:28 CST 2023.
--> -->
update sys_take_stash update sys_take_stash
<set> <set>
@ -399,6 +423,9 @@
<if test="priceTransaction != null"> <if test="priceTransaction != null">
price_transaction = #{priceTransaction,jdbcType=DOUBLE}, price_transaction = #{priceTransaction,jdbcType=DOUBLE},
</if> </if>
<if test="priceTransactionClose != null">
price_transaction_close = #{priceTransactionClose,jdbcType=DOUBLE},
</if>
<if test="stopLoss != null"> <if test="stopLoss != null">
stop_loss = #{stopLoss,jdbcType=DOUBLE}, stop_loss = #{stopLoss,jdbcType=DOUBLE},
</if> </if>
@ -408,6 +435,9 @@
<if test="timeTransaction != null"> <if test="timeTransaction != null">
time_transaction = #{timeTransaction,jdbcType=TIMESTAMP}, time_transaction = #{timeTransaction,jdbcType=TIMESTAMP},
</if> </if>
<if test="timeTransactionClose != null">
time_transaction_close = #{timeTransactionClose,jdbcType=TIMESTAMP},
</if>
<if test="status != null"> <if test="status != null">
status = #{status,jdbcType=INTEGER}, status = #{status,jdbcType=INTEGER},
</if> </if>
@ -420,6 +450,31 @@
</set> </set>
where stash_id = #{stashId,jdbcType=VARCHAR} where stash_id = #{stashId,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStash">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jul 21 14:51:28 CST 2023.
-->
update sys_take_stash
set member_id = #{memberId,jdbcType=VARCHAR},
training_id = #{trainingId,jdbcType=VARCHAR},
trading_code = #{tradingCode,jdbcType=VARCHAR},
currency_name = #{currencyName,jdbcType=VARCHAR},
order_number = #{orderNumber,jdbcType=VARCHAR},
buy_sell_type = #{buySellType,jdbcType=VARCHAR},
volume_transaction = #{volumeTransaction,jdbcType=DOUBLE},
price_transaction = #{priceTransaction,jdbcType=DOUBLE},
price_transaction_close = #{priceTransactionClose,jdbcType=DOUBLE},
stop_loss = #{stopLoss,jdbcType=DOUBLE},
stop_win = #{stopWin,jdbcType=DOUBLE},
time_transaction = #{timeTransaction,jdbcType=TIMESTAMP},
time_transaction_close = #{timeTransactionClose,jdbcType=TIMESTAMP},
status = #{status,jdbcType=INTEGER},
profit_and_loss_by_close = #{profitAndLossByClose,jdbcType=DOUBLE},
trading_margin = #{tradingMargin,jdbcType=DOUBLE}
where stash_id = #{stashId,jdbcType=VARCHAR}
</update>
<update id="updateWinLossByPrimaryKey" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStash"> <update id="updateWinLossByPrimaryKey" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStash">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
@ -452,11 +507,17 @@
<if test="priceTransaction != null"> <if test="priceTransaction != null">
price_transaction = #{priceTransaction,jdbcType=DOUBLE}, price_transaction = #{priceTransaction,jdbcType=DOUBLE},
</if> </if>
stop_loss = #{stopLoss,jdbcType=DOUBLE}, <if test="priceTransactionClose != null">
stop_win = #{stopWin,jdbcType=DOUBLE}, price_transaction_close = #{priceTransactionClose,jdbcType=DOUBLE},
</if>
stop_loss = #{stopLoss,jdbcType=DOUBLE},
stop_win = #{stopWin,jdbcType=DOUBLE},
<if test="timeTransaction != null"> <if test="timeTransaction != null">
time_transaction = #{timeTransaction,jdbcType=TIMESTAMP}, time_transaction = #{timeTransaction,jdbcType=TIMESTAMP},
</if> </if>
<if test="timeTransactionClose != null">
time_transaction_close = #{timeTransactionClose,jdbcType=TIMESTAMP},
</if>
<if test="status != null"> <if test="status != null">
status = #{status,jdbcType=INTEGER}, status = #{status,jdbcType=INTEGER},
</if> </if>
@ -469,27 +530,4 @@
</set> </set>
where stash_id = #{stashId,jdbcType=VARCHAR} where stash_id = #{stashId,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.sztzjy.forex.trading_trading.entity.TakeStash">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Jul 17 14:31:17 CST 2023.
-->
update sys_take_stash
set member_id = #{memberId,jdbcType=VARCHAR},
training_id = #{trainingId,jdbcType=VARCHAR},
trading_code = #{tradingCode,jdbcType=VARCHAR},
currency_name = #{currencyName,jdbcType=VARCHAR},
order_number = #{orderNumber,jdbcType=VARCHAR},
buy_sell_type = #{buySellType,jdbcType=VARCHAR},
volume_transaction = #{volumeTransaction,jdbcType=DOUBLE},
price_transaction = #{priceTransaction,jdbcType=DOUBLE},
stop_loss = #{stopLoss,jdbcType=DOUBLE},
stop_win = #{stopWin,jdbcType=DOUBLE},
time_transaction = #{timeTransaction,jdbcType=TIMESTAMP},
status = #{status,jdbcType=INTEGER},
profit_and_loss_by_close = #{profitAndLossByClose,jdbcType=DOUBLE},
trading_margin = #{tradingMargin,jdbcType=DOUBLE}
where stash_id = #{stashId,jdbcType=VARCHAR}
</update>
</mapper> </mapper>
Loading…
Cancel
Save