Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/com/sztzjy/forex/trading_trading/entity/Member.java # src/main/java/com/sztzjy/forex/trading_trading/entity/MemberExample.java # src/main/java/com/sztzjy/forex/trading_trading/mappers/MemberMapper.java # src/main/resources/mappers/MemberMapper.xmlpull/1/head
commit
860680b6be
@ -1,33 +1,109 @@
|
|||||||
package com.sztzjy.forex.trading_trading.controller;
|
package com.sztzjy.forex.trading_trading.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
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.entity.Member;
|
||||||
import com.sztzjy.forex.trading_trading.entity.mql5Entity.ExchangeFrateEntity;
|
import com.sztzjy.forex.trading_trading.entity.mql5Entity.ExchangeFrateEntity;
|
||||||
|
import com.sztzjy.forex.trading_trading.entity.mql5Entity.ForexData;
|
||||||
|
import com.sztzjy.forex.trading_trading.service.MemberService;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
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.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.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
//学生端 交易
|
//学生端 交易
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("api/trading")
|
@RequestMapping("api/trading")
|
||||||
public class TradingController {
|
public class TradingController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MemberService memberService;
|
||||||
|
|
||||||
//获取市场报价
|
//获取市场报价
|
||||||
@AnonymousAccess
|
@AnonymousAccess
|
||||||
@PostMapping("getMarketQuotation")
|
@PostMapping("getMarketQuotation")
|
||||||
public JSONObject getMarketQuotation(){
|
public List<ForexData> getMarketQuotation() {
|
||||||
Mql5API mql5API=new Mql5API();
|
Mql5API mql5API = new Mql5API();
|
||||||
ExchangeFrateEntity exchangeFrate = mql5API.getExchangeFrate();
|
List<ForexData> marketQuotation = mql5API.getMarketQuotation();
|
||||||
return exchangeFrate;
|
return marketQuotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据交易类型获取实时数据
|
||||||
|
@AnonymousAccess
|
||||||
|
@PostMapping("getMarketQuotationByCode")
|
||||||
|
public ForexData getMarketQuotationByCode(@RequestBody String code) {
|
||||||
|
Mql5API mql5API = new Mql5API();
|
||||||
|
ForexData forexData = mql5API.getMarketQuotationByCode(code);
|
||||||
|
return forexData;
|
||||||
}
|
}
|
||||||
|
|
||||||
//市场报价交易
|
//市场报价交易 交易量为1为1000美元
|
||||||
@AnonymousAccess
|
@AnonymousAccess
|
||||||
@PostMapping("TransactionMarketQuotation")
|
@PostMapping("TransactionMarketQuotation")
|
||||||
public JSONObject getMarketQuotation(JSONObject jsonObject){
|
public JSONObject getMarketQuotation(@RequestBody JSONObject jsonObject) {
|
||||||
Mql5API mql5API=new Mql5API();
|
//交易品种
|
||||||
ExchangeFrateEntity exchangeFrate = mql5API.getExchangeFrate();
|
String code = String.valueOf(jsonObject.get("code"));
|
||||||
return exchangeFrate;
|
//交易类型
|
||||||
|
String transactionType = String.valueOf(jsonObject.get("transactionType"));
|
||||||
|
//买卖手(量)
|
||||||
|
Double transactionVolume = (Double) jsonObject.get("transactionVolume");
|
||||||
|
//买入卖出类型
|
||||||
|
String buySellType = String.valueOf(jsonObject.get("buySellType"));
|
||||||
|
//获取账户资金 调用member表中的
|
||||||
|
Integer memberId = (Integer) jsonObject.get("memberId");
|
||||||
|
Integer trainingId = (Integer) jsonObject.get("trainingId");
|
||||||
|
Member member = memberService.getMemberByMemberIdAndTrainingId(memberId, trainingId);
|
||||||
|
Double availableFunds = member.getAvailableFunds();
|
||||||
|
if (transactionType.equals("sjkc")) {//市价开仓
|
||||||
|
//美元在前
|
||||||
|
if (code.startsWith("USD")) {
|
||||||
|
//判断可用资金是否足够
|
||||||
|
if(availableFunds<transactionVolume*1000){
|
||||||
|
return JSONObject.parseObject("可用资金不足");
|
||||||
|
}else {
|
||||||
|
//获取当前买卖价格
|
||||||
|
ForexData forexData = getMarketQuotationByCode(code);
|
||||||
|
if (buySellType.equals("buy")) {
|
||||||
|
String buyPic = forexData.getBuyPic();
|
||||||
|
|
||||||
|
|
||||||
|
} else if (buySellType.equals("sell")) {
|
||||||
|
String sellPic = forexData.getSellPic();
|
||||||
|
|
||||||
|
}
|
||||||
|
availableFunds=availableFunds-transactionVolume*1000;
|
||||||
|
member.setAvailableFunds(availableFunds);
|
||||||
|
//获取当前已用保证金
|
||||||
|
Double marginUsed = member.getMarginUsed();
|
||||||
|
member.setMarginUsed(marginUsed+availableFunds);
|
||||||
|
}
|
||||||
|
//美元在后
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
//买入
|
||||||
|
//卖出
|
||||||
|
|
||||||
|
} else if (transactionType.equals("gdkc")) {//挂单开仓
|
||||||
|
//限价买进
|
||||||
|
//限价卖出
|
||||||
|
//止损买进
|
||||||
|
//止损卖出
|
||||||
|
|
||||||
|
} else {
|
||||||
|
JSONObject returnJson = JSONObject.parseObject("error");
|
||||||
|
return returnJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.sztzjy.forex.trading_trading.entity.mql5Entity;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Data
|
||||||
|
public class ForexData extends JSONObject {
|
||||||
|
private String buyPic;
|
||||||
|
private String closePri;
|
||||||
|
private String code;
|
||||||
|
private String color;
|
||||||
|
private String currency;
|
||||||
|
private String datatime;
|
||||||
|
private String date;
|
||||||
|
private String diffAmo;
|
||||||
|
private String diffPer;
|
||||||
|
private String highPic;
|
||||||
|
private String lowPic;
|
||||||
|
private String openPri;
|
||||||
|
private String range;
|
||||||
|
private String sellPic;
|
||||||
|
private String yesPic;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.sztzjy.forex.trading_trading.service;
|
||||||
|
|
||||||
|
import com.sztzjy.forex.trading_trading.entity.Member;
|
||||||
|
import com.sztzjy.forex.trading_trading.entity.MemberExample;
|
||||||
|
import com.sztzjy.forex.trading_trading.mappers.MemberMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MemberService {
|
||||||
|
@Autowired
|
||||||
|
MemberMapper memberMapper;
|
||||||
|
|
||||||
|
public Member getMemberByMemberIdAndTrainingId(Integer memberId,Integer trainingId){
|
||||||
|
MemberExample example = new MemberExample();
|
||||||
|
MemberExample.Criteria criteria = example.createCriteria();
|
||||||
|
criteria.andMemberIdEqualTo(memberId);
|
||||||
|
criteria.andTrainingIdEqualTo(trainingId);
|
||||||
|
List<Member> members = memberMapper.selectByExample(example);
|
||||||
|
return members.get(0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue