trading-order-admin/src/main/java/com/yami/trading/admin/task/RealtimePushJob.java
@@ -114,6 +114,7 @@ map.put("current_time", realtime.getCurrentTime()); map.put("name", realtime.getName()); map.put("change_ratio", realtime.getChangeRatio()); map.put("change_ratio_str", realtime.getchangeRatioStr()); map.put("netChange", realtime.getNetChange()); map.put("open", realtime.getOpen()); map.put("close", realtime.getClose()); trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiItemController.java
@@ -167,6 +167,11 @@ if (CollectionUtil.isNotEmpty(realtimes)) { Realtime realtime = realtimes.get(0); // if("forex".equals(type)){ // symbolDTO.setChangeRatio(realtime.getChangeRatioStr()); // }else{ // // } symbolDTO.setChangeRatio(realtime.getChangeRatio()); symbolDTO.setAmount(realtime.getAmount()); symbolDTO.setVolume(realtime.getVolume()); trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiUserController.java
@@ -767,7 +767,7 @@ */ @PostMapping("setSafeword") @ApiOperation("修改资金密码 用验证码") public Result setSafeword(String safeword, String verifcode_type, String verifcode) { public Result setSafeword(String safeword, String verifcode_type, String verifcode, String odl_safeword) { if (StringUtils.isEmptyString(safeword)) { throw new YamiShopBindException("资金密码不能为空"); @@ -778,54 +778,62 @@ if (StringUtils.isEmptyString(verifcode_type)) { throw new YamiShopBindException("验证类型不能为空"); } if (StringUtils.isEmptyString(verifcode)) { throw new YamiShopBindException("验证码不能为空"); if (StringUtils.isEmptyString(odl_safeword)) { throw new YamiShopBindException("旧密码不能为空"); } // if (StringUtils.isEmptyString(verifcode)) { // throw new YamiShopBindException("验证码不能为空"); // } String loginPartyId = SecurityUtils.getUser().getUserId(); User party = userService.getById(loginPartyId); // 根据验证类型获取验证key verifcode_type: 1/手机;2/邮箱;3/谷歌验证器; String key = ""; String errMsg = ""; if ("1".equals(verifcode_type)) { key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile(); errMsg = "未绑定手机号"; } else if ("2".equals(verifcode_type)) { key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail(); errMsg = "未绑定邮箱"; } else if ("3".equals(verifcode_type)) { key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret(); errMsg = "未绑定谷歌验证器"; } if (StringUtils.isEmptyString(key)) { throw new YamiShopBindException(errMsg); } // String key = ""; // String errMsg = ""; // if ("1".equals(verifcode_type)) { // key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile(); // errMsg = "未绑定手机号"; // } else if ("2".equals(verifcode_type)) { // key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail(); // errMsg = "未绑定邮箱"; // } else if ("3".equals(verifcode_type)) { // key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret(); // errMsg = "未绑定谷歌验证器"; // } // if (StringUtils.isEmptyString(key)) { // throw new YamiShopBindException(errMsg); // } // 验证 boolean passed = false; if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) { String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key); if ((null != authcode) && (authcode.equals(verifcode))) { passed = true; this.identifyingCodeTimeWindowService.delAuthCode(key); } } else if ("3".equals(verifcode_type)) { long t = System.currentTimeMillis(); GoogleAuthenticator ga = new GoogleAuthenticator(); ga.setWindowSize(5); boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t); if (flag) { passed = true; } } // boolean passed = false; // if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) { // String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key); // if ((null != authcode) && (authcode.equals(verifcode))) { // passed = true; // this.identifyingCodeTimeWindowService.delAuthCode(key); // } // } else if ("3".equals(verifcode_type)) { // long t = System.currentTimeMillis(); // GoogleAuthenticator ga = new GoogleAuthenticator(); // ga.setWindowSize(5); // boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t); // if (flag) { // passed = true; // } // } // 如果是演示用户,则不判断验证码 if (!"GUEST".contentEquals(party.getRoleName())) { if (!passed) { throw new YamiShopBindException("验证码不正确"); } // if (!"GUEST".contentEquals(party.getRoleName())) { // if (!passed) { // throw new YamiShopBindException("验证码不正确"); // } // } if(userService.checkLoginSafeword(party.getUserId(), odl_safeword)){ party.setSafePassword(passwordEncoder.encode(safeword)); // 更新密码 userService.updateById(party); return Result.succeed(null); }else { throw new YamiShopBindException("旧密码不正确"); } party.setSafePassword(passwordEncoder.encode(safeword)); // 更新密码 userService.updateById(party); return Result.succeed(null); } /** trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWalletController.java
@@ -215,13 +215,15 @@ df2.setRoundingMode(RoundingMode.FLOOR); // String partyId ="dcc0dd35a49c383dadabc4dc030afe70"; String partyId = SecurityUtils.getCurrentUserId(); CapitaltWallet usdt = null; // CapitaltWallet usdt = null; Wallet usdt = null; if (StringUtils.isNotEmpty(partyId)) { // usdt = this.walletService.saveWalletByPartyId(partyId); usdt = capitaltWalletService.getUserIdWallet(partyId); usdt = this.walletService.saveWalletByPartyId(partyId); // usdt = capitaltWalletService.getUserIdWallet(partyId); } if (null == usdt) { usdt = new CapitaltWallet(); // usdt = new CapitaltWallet(); usdt = new Wallet(); usdt.setMoney(new BigDecimal(0)); usdt.setLockMoney(new BigDecimal(0)); usdt.setFreezeMoney(new BigDecimal(0)); @@ -240,9 +242,9 @@ } // 其他币账户 List<Item> list_it = this.itemService.cacheGetByMarket(""); if (StringUtils.isNotEmpty(symbolType)) { list_it = list_it.stream().filter(i -> symbolType.equalsIgnoreCase(i.getType())).collect(Collectors.toList()); } // if (StringUtils.isNotEmpty(symbolType)) { // list_it = list_it.stream().filter(i -> symbolType.equalsIgnoreCase(i.getType())).collect(Collectors.toList()); // } List<String> list_symbol = new ArrayList<String>(); if (!StringUtils.isNotEmpty(symbol)) { // symbol为空,获取所有的 trading-order-admin/src/main/java/com/yami/trading/api/controller/RealtimeController.java
@@ -79,12 +79,12 @@ d.setAsk(d.getClose().add(bigDecimal).setScale(decimals, RoundingMode.HALF_UP)); d.setBid(d.getClose().subtract(bigDecimal).setScale(decimals, RoundingMode.HALF_UP)); //涨跌幅 = (当天收盘价 - 前一日收盘价) / 前一日收盘价 * 100% if(null != bySymbol.getYesterdayLastPrice() && bySymbol.getYesterdayLastPrice().compareTo(BigDecimal.ZERO) != 0){ BigDecimal changePercent = (d.getClose().subtract(bySymbol.getYesterdayLastPrice())) .divide(bySymbol.getYesterdayLastPrice(), 5, RoundingMode.HALF_UP) // 精确到4位小数 .multiply(new BigDecimal("100").setScale(2)); // 乘以100得到百分比 d.setChangeRatioStr(changePercent.toString()); } // if(null != bySymbol.getYesterdayLastPrice() && bySymbol.getYesterdayLastPrice().compareTo(BigDecimal.ZERO) != 0){ // BigDecimal changePercent = (d.getClose().subtract(bySymbol.getYesterdayLastPrice())) // .divide(bySymbol.getYesterdayLastPrice(), 5, RoundingMode.HALF_UP) // 精确到4位小数 // .multiply(new BigDecimal("100").setScale(2)).setScale(4,RoundingMode.HALF_UP); // 乘以100得到百分比 // d.setChangeRatioStr(changePercent); // } if(d.getVolume()!=null){ d.setVolume(d.getVolume().setScale(2, RoundingMode.HALF_UP)); trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiExchangeApplyOrderController.java
@@ -4,15 +4,13 @@ import com.yami.trading.bean.exchange.ExchangeApplyOrder; import com.yami.trading.bean.exchange.dto.ExchangeSymbolDto; import com.yami.trading.bean.exchange.dto.SumEtfDto; import com.yami.trading.bean.item.domain.Item; import com.yami.trading.bean.model.*; import com.yami.trading.bean.purchasing.dto.ExchangeLock; import com.yami.trading.bean.syspara.domain.Syspara; import com.yami.trading.common.domain.Result; import com.yami.trading.common.exception.YamiShopBindException; import com.yami.trading.common.util.Arith; import com.yami.trading.common.util.DateUtils; import com.yami.trading.common.util.StringUtils; import com.yami.trading.common.util.ThreadUtils; import com.yami.trading.common.util.*; import com.yami.trading.security.common.util.SecurityUtils; import com.yami.trading.service.CapitaltWalletService; import com.yami.trading.service.RealNameAuthRecordService; @@ -338,12 +336,12 @@ public Result openview() { Map<String, Object> data = new HashMap<String, Object>(); String partyId = SecurityUtils.getUser().getUserId(); // Wallet wallet = walletService.saveWalletByPartyId(partyId); CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId); Wallet wallet = walletService.saveWalletByPartyId(partyId); // CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(partyId); // 账户剩余资金 DecimalFormat df = new DecimalFormat("#.##"); df.setRoundingMode(RoundingMode.FLOOR);// 向下取整 data.put("volume", df.format(userIdWallet.getMoney())); data.put("volume", df.format(wallet.getMoney())); String session_token = sessionTokenService.savePut(partyId); data.put("session_token", session_token); data.put("fee", sysparaService.find("exchange_apply_order_buy_fee").getSvalue()); @@ -379,14 +377,14 @@ String volume = request.getParameter("volume"); String session_token = request.getParameter("session_token"); String symbol = request.getParameter("symbol"); // Item bySymbol = itemService.findBySymbol(symbol); // if(bySymbol == null){ // throw new YamiShopBindException("当前币对不存在"); // } // boolean isOpen = MarketOpenChecker.isMarketOpenByItemCloseType(bySymbol.getOpenCloseType()); // if(!isOpen){ // throw new YamiShopBindException("当前已经休市"); // } Item bySymbol = itemService.findBySymbol(symbol); if(bySymbol == null){ throw new YamiShopBindException("当前币对不存在"); } boolean isOpen = MarketOpenChecker.isMarketOpenByItemCloseType(bySymbol.getOpenCloseType()); if(!isOpen){ throw new YamiShopBindException("当前已经休市"); } // limit order的交易价格 String price = request.getParameter("price"); // 计划委托 是之前火币那边拷贝学过来的一个功能 只是只有一个盘在用,暂时注释不用 trading-order-admin/src/main/resources/application-prod.yml
@@ -2,7 +2,6 @@ port: 8086 spring: datasource: url: jdbc:mysql://127.0.0.1:6306/trading_order_n?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true username: trading_order_n password: 3BRTfLGX3j44WeAb @@ -24,6 +23,12 @@ logging: config: classpath:logback/logback-prod.xml alltick: token: 3ba36ca15660073739f25c4b1512086a-c-app trade-tick: "https://quote.alltick.io/quote-b-api/trade-tick?token=${alltick.token}&query={1}" trade-kline: "https://quote.alltick.io/quote-b-api/kline?token=${alltick.token}&query={1}" batch-kline: "https://quote.alltick.io/quote-b-api/batch-kline?token=${alltick.token}" jetcache: statIntervalMinutes: 1 default: # 默认default,可以配置更多的area trading-order-admin/src/main/resources/application.yml
@@ -1,7 +1,7 @@ spring: # 环境 dev|test|prod # 环境 dev|local|test|prod profiles: active: local active: prod #文件上传设置 servlet: multipart: trading-order-admin/src/main/resources/config/system.properties
@@ -5,7 +5,7 @@ http.server.host=D:/jystp/images/ images.dir=/mydata/img/ loca.images.dir=D:/testimg loca.images.dir=/www/wwwroot/aa.yanshiz.com/testimg email.host=smtp.gmail.com email.username= test email.password= test trading-order-bean/src/main/java/com/yami/trading/bean/data/domain/Realtime.java
@@ -98,7 +98,7 @@ @TableField(exist = false) @ApiModelProperty("涨跌幅Str") private String changeRatioStr; private BigDecimal changeRatioStr; /** * 净值涨跌幅 @@ -188,6 +188,15 @@ } public BigDecimal getchangeRatioStr(){ if(this.changeRatioStr == null || this.changeRatioStr.compareTo(BigDecimal.ZERO) == 0){ return changeRatioStr; }else { return getChangeRatio(); } } public BigDecimal getNetChange() { BigDecimal netChange = close.multiply(getChangeRatio()).divide(new BigDecimal(100), 10, RoundingMode.HALF_UP); netChange = netChange.setScale(4, RoundingMode.DOWN); trading-order-bean/src/main/java/com/yami/trading/bean/item/dto/ItemUserOptionalDTO.java
@@ -74,6 +74,9 @@ @JSONField(name = "change_ratio") private BigDecimal changeRatio ; @JSONField(name = "change_ratio_str") private BigDecimal changeRatioStr ; /** * 换手率 */ trading-order-bean/src/main/java/com/yami/trading/bean/item/dto/ItemUserOptionalItemDTO.java
@@ -68,6 +68,9 @@ @JSONField(name = "change_ratio") private BigDecimal changeRatio ; @JSONField(name = "change_ratio_str") private BigDecimal changeRatioStr ; /** * 换手率 */ trading-order-common/src/main/java/com/yami/trading/common/util/MarketOpenChecker.java
@@ -69,8 +69,8 @@ if(stocksType.contains(closeType)){ return isMarketOpen(closeType); }else if("forex".equalsIgnoreCase(closeType)){ // return UTCDateUtils.isOpen(); return true; return UTCDateUtils.isOpen(); // return true; }else{ return true; } trading-order-huobi/src/main/java/com.yami.trading.huobi/data/internal/KlineConstant.java
@@ -27,4 +27,5 @@ public final static String PERIOD_QUARTER = "quarter"; public final static String PERIOD_YEAR = "year"; public final static String PERIOD_OTHER = "other"; public final static String PERIOD_ONE = "other"; } trading-order-huobi/src/main/java/com.yami.trading.huobi/data/job/ForexGetDataJob.java
@@ -95,8 +95,9 @@ return; } List<Realtime> realtimeList = this.hobiDataService.realtimeXinLang(symbols); List<Realtime> realtimeList1 = this.hobiDataService.realtimeNewPrice(symbols,realtimeList); super.handleRealTimeList(realtimeList1); // List<Realtime> realtimeList1 = this.hobiDataService.realtime24HoruData(symbols,realtimeList); // List<Realtime> realtimeList1 = this.hobiDataService.realtimeNewPrice(symbols,realtimeList); super.handleRealTimeList(realtimeList); } } trading-order-huobi/src/main/java/com.yami.trading.huobi/data/model/AlltickNewPriceResult.java
@@ -2,13 +2,15 @@ import lombok.Data; import java.math.BigDecimal; @Data public class AlltickNewPriceResult { private String code; private String seq; private String tickTime; private String price; private String volume; private String turnover; private BigDecimal price; private BigDecimal volume; private BigDecimal turnover; private int tradeDirection; } trading-order-huobi/src/main/java/com.yami.trading.huobi/hobi/HobiDataService.java
@@ -20,6 +20,8 @@ public List<Realtime> realtimeXueQiu(String symbols); public List<Realtime> realtimeXinLang(String symbols); public List<Realtime> realtimeNewPrice(String symbols,List<Realtime> realtimes); public List<Kline> getTimeseries(String symbol,String period,int periodType); public List<Realtime> realtime24HoruData(String symbols,List<Realtime> realtimes); /** trading-order-huobi/src/main/java/com.yami.trading.huobi/hobi/internal/HobiDataServiceImpl.java
@@ -725,6 +725,7 @@ return yesterdayLastPrice; } @Override public List<Kline> getTimeseries(String symbol,String period,int periodType){ List<Kline> resList = new ArrayList<>(); int klineCount; @@ -749,6 +750,8 @@ klineCount = 52 * 5; // 5年的1周K线 (1年52周,5年共260周) } else if (KlineConstant.PERIOD_1MON.equals(period)) { klineCount = 12 * 5; // 5年的1个月K线,12个月每年,乘以5年 = 60 }else if(KlineConstant.PERIOD_ONE.equals(period)){ klineCount = 1; }else{ klineCount = 2; } @@ -778,7 +781,8 @@ kline.setClose(result.getClose_price()); kline.setHigh(result.getHigh_price()); kline.setLow(result.getLow_price()); kline.setVolume(result.getVolume()); kline.setVolume(result.getTurnover()); kline.setAmount(result.getVolume()); resList.add(kline); } } @@ -788,6 +792,28 @@ logger.error("延时中断: {}", e); } return resList; } @Override public List<Realtime> realtime24HoruData(String symbols, List<Realtime> realtimes) { List<String> strings = Arrays.asList(symbols.split(",")); for (int i = 0; i < strings.size(); i++) { List<Kline> dayList = getTimeseries(strings.get(i), KlineConstant.PERIOD_ONE, AllticktradeMadeOptions.dayPeriod); if(dayList.size()>0){ Kline kline = dayList.get(0); for (Realtime realtime : realtimes){ if(realtime.getSymbol().equals(strings.get(i))){ int decimal = itemService.getDecimal(realtime.getSymbol()); realtime.setOpen(kline.getOpen().setScale(decimal, RoundingMode.HALF_UP)); realtime.setHigh(kline.getHigh().setScale(decimal, RoundingMode.HALF_UP)); realtime.setLow(kline.getLow().setScale(decimal, RoundingMode.HALF_UP)); realtime.setAmount(kline.getAmount().setScale(decimal, RoundingMode.HALF_UP)); realtime.setVolume(kline.getVolume().setScale(decimal, RoundingMode.HALF_UP)); } } } } return realtimes; } public List<Kline> buildOneDayPeriod(List<AllticktradeResult> list, String currency) { @@ -1199,7 +1225,7 @@ HttpResponse response = HttpHelper.getHttpclient().execute(request); return HttpHelper.responseProc(response); } catch (Exception e) { logger.error("采集外汇k线图失败:{} ", e); logger.error("采集外汇k线图失败:==={} ", symbol); } return null; } trading-order-huobi/src/main/java/com.yami.trading.huobi/hobi/internal/XinLangDataServiceImpl.java
@@ -10,16 +10,20 @@ import com.yami.trading.bean.cms.Infomation; import com.yami.trading.bean.data.domain.*; import com.yami.trading.bean.data.respDto.TradeTickResp; import com.yami.trading.bean.item.domain.Item; import com.yami.trading.common.util.RedisUtil; import com.yami.trading.common.util.StringUtils; import com.yami.trading.common.util.UTCDateUtils; import com.yami.trading.huobi.data.DataCache; import com.yami.trading.huobi.data.internal.DepthTimeObject; import com.yami.trading.huobi.data.internal.KlineConstant; import com.yami.trading.huobi.data.internal.KlineService; import com.yami.trading.huobi.data.internal.TradeTimeObject; import com.yami.trading.huobi.data.model.AlltickBatchKlineResult; import com.yami.trading.huobi.data.model.AlltickNewPriceResult; import com.yami.trading.huobi.data.model.AllticktradeResult; import com.yami.trading.huobi.hobi.HobiDataService; import com.yami.trading.huobi.hobi.constant.AllticktradeMadeOptions; import com.yami.trading.huobi.hobi.http.HttpHelper; import com.yami.trading.huobi.hobi.http.HttpMethodType; import com.yami.trading.service.cms.InfomationService; @@ -174,20 +178,47 @@ for (Realtime realtime : realtimes){ if(tickNewPrice.getCode().equals(realtime.getName())){ realtime.setCloseOld(realtime.getClose()); realtime.setClose(new BigDecimal(tickNewPrice.getPrice())); realtime.setVolume(new BigDecimal(tickNewPrice.getVolume())); // realtime.setClose(new BigDecimal(tickNewPrice.getPrice())); // realtime.setVolume(new BigDecimal(tickNewPrice.getVolume())); } // Item bySymbol = itemService.findBySymbol(realtime.getSymbol()); // if(null != bySymbol.getYesterdayLastPrice() && bySymbol.getYesterdayLastPrice().compareTo(BigDecimal.ZERO) != 0){ // BigDecimal changePercent = (realtime.getClose().subtract(bySymbol.getYesterdayLastPrice())) // .divide(bySymbol.getYesterdayLastPrice(), 5, RoundingMode.HALF_UP) // 精确到4位小数 // .multiply(new BigDecimal("100").setScale(2)).setScale(4,RoundingMode.HALF_UP); // 乘以100得到百分比 // realtime.setChangeRatioStr(changePercent); // } } } } // Map<String, Object> requestData = createRequest(strings); // String resultStr = HttpHelper.sendPostRequest(batchKline,requestData); // JSONObject resultJson = JSON.parseObject(resultStr); // if(null == resultJson || 200 != resultJson.getInteger("ret")){ // logger.error("数据,返回:{} ", resultJson); // } // JSONObject tempdata = resultJson.getJSONObject("data"); // JSONArray dataArray = tempdata.getJSONArray("kline_list"); // if (dataArray.size() > 0) { // List<AlltickBatchKlineResult> batchKlines = JSONObject.parseArray(JSONObject.toJSONString(dataArray), AlltickBatchKlineResult.class); // for (AlltickBatchKlineResult batchKline : batchKlines) { // for (AllticktradeResult result : batchKline.getKline_data()){ // for (Realtime realtime : list){ // if(realtime.getSymbol().equals(batchKline.getCode())){ // int decimal = itemService.getDecimal(realtime.getSymbol()); // realtime.setOpen(result.getOpen_price().setScale(decimal, RoundingMode.HALF_UP)); // realtime.setHigh(result.getHigh_price().setScale(decimal, RoundingMode.HALF_UP)); // realtime.setLow(result.getLow_price().setScale(decimal, RoundingMode.HALF_UP)); // realtime.setClose(result.getClose_price().setScale(decimal, RoundingMode.HALF_UP)); //// realtime.setAmount(tickNewPrice.getPrice().multiply(tickNewPrice.getVolume()).setScale(item.getDecimals(), RoundingMode.HALF_UP)); //// realtime.setVolume(tickNewPrice.getVolume()); // } // } // } // } // } } catch (Exception e){ logger.error("error", e); } for (Realtime realtime : realtimes) { if(realtime.getName().equals("USDSGD")){ System.out.println("USDSGD实时价格数据替换前=="+realtime.getCloseOld()); System.out.println("USDSGD实时价格数据替换后=="+realtime.getClose()); } } return realtimes; } @@ -195,38 +226,57 @@ List<Realtime> list = new ArrayList<Realtime>(); try { List<String> strings = Arrays.asList(symbols.split(",")); Map<String, Object> requestData = createRequest(strings); String resultStr = HttpHelper.sendPostRequest(batchKline,requestData); JSONObject resultJson = JSON.parseObject(resultStr); if(null == resultJson || 200 != resultJson.getInteger("ret")){ logger.error("数据,返回:{} ", resultJson); Map<String, Object> requestDataTick = createRequestTick(strings); String url = tradeTick.replace("{1}", URLEncoder.encode(requestDataTick.toString(), "UTF-8")); HttpGet request = new HttpGet(url); HttpResponse response = HttpHelper.getHttpclient().execute(request); String resultTickStr = HttpHelper.responseProc(response); JSONObject resultJsonTick = JSON.parseObject(resultTickStr); if(null == resultJsonTick || 200 != resultJsonTick.getInteger("ret")){ logger.error("数据,返回:{} ", resultJsonTick); } JSONObject tempdata = resultJson.getJSONObject("data"); JSONArray dataArray = tempdata.getJSONArray("kline_list"); if (dataArray.size() > 0) { List<AlltickBatchKlineResult> batchKlines = JSONObject.parseArray(JSONObject.toJSONString(dataArray), AlltickBatchKlineResult.class); for (AlltickBatchKlineResult batchKline : batchKlines) { for (AllticktradeResult result : batchKline.getKline_data()){ Realtime realtime = new Realtime(); int decimal = itemService.getDecimal(batchKline.getCode()); realtime.setSymbol(batchKline.getCode()); realtime.setTs(Long.parseLong(result.getTimestamp())); realtime.setName(batchKline.getCode()); realtime.setOpen(result.getOpen_price().setScale(decimal, RoundingMode.HALF_UP)); realtime.setHigh(result.getHigh_price().setScale(decimal, RoundingMode.HALF_UP)); realtime.setLow(result.getLow_price().setScale(decimal, RoundingMode.HALF_UP)); realtime.setClose(result.getClose_price().setScale(decimal, RoundingMode.HALF_UP)); realtime.setMarketCapital(0L); realtime.setFloatMarketCapital(0L); realtime.setPeForecast(BigDecimal.ZERO); realtime.setVolumeRatio(BigDecimal.ZERO); realtime.setTurnoverRate(BigDecimal.ZERO); realtime.setAmount(result.getVolume()); realtime.setVolume(result.getTurnover()); list.add(realtime); JSONObject tempdataTick = resultJsonTick.getJSONObject("data"); JSONArray dataArrayTick = tempdataTick.getJSONArray("tick_list"); if (dataArrayTick.size() > 0) { List<AlltickNewPriceResult> alltickNewPriceResults = JSONObject.parseArray(JSONObject.toJSONString(dataArrayTick), AlltickNewPriceResult.class); for (AlltickNewPriceResult tickNewPrice : alltickNewPriceResults) { Realtime realtime = new Realtime(); Item item = itemService.findBySymbol(tickNewPrice.getCode()); realtime.setSymbol(tickNewPrice.getCode()); realtime.setTs(Long.parseLong(tickNewPrice.getTickTime())); realtime.setName(tickNewPrice.getCode()); realtime.setClose(tickNewPrice.getPrice().setScale(item.getDecimals(), RoundingMode.HALF_UP)); // //涨跌幅 = (当天收盘价 - 前一日收盘价) / 前一日收盘价 * 100% // if(null != item.getYesterdayLastPrice() && item.getYesterdayLastPrice().compareTo(BigDecimal.ZERO) != 0){ // BigDecimal changePercent = (realtime.getClose().subtract(item.getYesterdayLastPrice())) // .divide(item.getYesterdayLastPrice(), 5, RoundingMode.HALF_UP) // 精确到4位小数 // .multiply(new BigDecimal("100").setScale(2)).setScale(4,RoundingMode.HALF_UP); // 乘以100得到百分比 // realtime.setChangeRatioStr(changePercent); // } realtime.setMarketCapital(0L); realtime.setFloatMarketCapital(0L); realtime.setPeForecast(BigDecimal.ZERO); realtime.setVolumeRatio(BigDecimal.ZERO); realtime.setTurnoverRate(BigDecimal.ZERO); Kline kline = klineService.getLast(tickNewPrice.getCode(),Kline.PERIOD_1DAY); if(null != kline){ realtime.setOpen(kline.getOpen().setScale(item.getDecimals(), RoundingMode.HALF_UP)); realtime.setHigh(kline.getHigh().setScale(item.getDecimals(), RoundingMode.HALF_UP)); realtime.setLow(kline.getLow().setScale(item.getDecimals(), RoundingMode.HALF_UP)); realtime.setAmount(kline.getAmount().setScale(item.getDecimals(), RoundingMode.HALF_UP)); realtime.setVolume(kline.getVolume().setScale(item.getDecimals(), RoundingMode.HALF_UP)); }else { realtime.setOpen(BigDecimal.ZERO); realtime.setHigh(BigDecimal.ZERO); realtime.setLow(BigDecimal.ZERO); realtime.setAmount(BigDecimal.ZERO); realtime.setVolume(BigDecimal.ZERO); } list.add(realtime); } } } catch (Exception e) { logger.error("error", e); } trading-order-service/src/main/java/com/yami/trading/service/exchange/impl/ExchangeApplyOrderServiceImpl.java
@@ -111,11 +111,11 @@ double amount = Arith.mul(sub, realtime.getClose().doubleValue()); order.setCloseTime(new Date()); order.setClosePrice(realtime.getClose().doubleValue()); // Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); CapitaltWallet capitaltWallet = capitaltWalletService.getUserIdWallet(order.getPartyId()); double amount_before = capitaltWallet.getMoney().doubleValue(); // this.walletService.update(userIdWallet.getUserId().toString(), amount); this.capitaltWalletService.update(capitaltWallet, amount); Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); // CapitaltWallet capitaltWallet = capitaltWalletService.getUserIdWallet(order.getPartyId()); double amount_before = wallet.getMoney().doubleValue(); this.walletService.update(wallet.getUserId().toString(), amount); // this.capitaltWalletService.update(capitaltWallet, amount); /* * 保存资金日志 @@ -124,7 +124,7 @@ moneylog_deposit.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE); moneylog_deposit.setAmountBefore(new BigDecimal(amount_before)); moneylog_deposit.setAmount(new BigDecimal(amount)); moneylog_deposit.setAmountAfter(capitaltWallet.getMoney()); moneylog_deposit.setAmountAfter(wallet.getMoney()); moneylog_deposit.setLog("委托单,订单号[" + order.getOrderNo() + "]"); moneylog_deposit.setUserId(order.getPartyId()); moneylog_deposit.setWalletType(Constants.WALLET); @@ -373,10 +373,14 @@ if (!order.isTriggerOrder()) { if (ExchangeApplyOrder.OFFSET_OPEN.equals(order.getOffset())) { Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); // CapitaltWallet wallet = capitaltWalletService.getUserIdWallet(order.getPartyId()); double amount_before = wallet.getMoney().doubleValue(); // wallet.setMoney(Arith.add(wallet.getMoney(), order.getVolume())); wallet.setMoney(new BigDecimal(Arith.add(wallet.getMoney().doubleValue(), order.getVolume()))); // capitaltWalletService.updateById(wallet); // wallet.setMoney(wallet.getMoney().add(BigDecimal.valueOf(order.getVolume()))); // Arith.add(wallet.getMoney(), order.getVolume()) // walletService.update(wallet); walletService.update(wallet.getUserId().toString(), order.getVolume()); // walletService.update(wallet.getUserId().toString(), order.getVolume()); MoneyLog moneylog = new MoneyLog(); moneylog.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE); moneylog.setAmountBefore(new BigDecimal(amount_before)); @@ -614,9 +618,9 @@ // 可以买的数量 double amount = Arith.div(sub, order.getClosePrice(), 8); order.setSymbolValue(amount); // Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(order.getPartyId()); double amount_before = userIdWallet.getMoney().doubleValue(); Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); // CapitaltWallet userIdWallet = capitaltWalletService.getUserIdWallet(order.getPartyId()); double amount_before = wallet.getMoney().doubleValue(); // 如果是计划委托,则先不扣钱 if (order.isTriggerOrder()) { @@ -637,11 +641,11 @@ save(order); } if (!order.isTriggerOrder()) { if (userIdWallet.getMoney().doubleValue() < order.getVolume().doubleValue()) { if (wallet.getMoney().doubleValue() < order.getVolume().doubleValue()) { throw new YamiShopBindException("余额不足"); } // this.walletService.update(userIdWallet.getUserId().toString(), Arith.sub(0, order.getVolume())); capitaltWalletService.update(userIdWallet, Arith.sub(0, order.getVolume())); this.walletService.update(wallet.getUserId().toString(), Arith.sub(0, order.getVolume())); // capitaltWalletService.update(userIdWallet, Arith.sub(0, order.getVolume())); /* * 保存资金日志 */ @@ -649,7 +653,7 @@ moneylog_deposit.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE); moneylog_deposit.setAmountBefore(new BigDecimal(amount_before)); moneylog_deposit.setAmount(new BigDecimal(Arith.sub(0, order.getVolume().doubleValue()))); moneylog_deposit.setAmountAfter(new BigDecimal(Arith.sub(userIdWallet.getMoney().doubleValue(), order.getVolume()))); moneylog_deposit.setAmountAfter(new BigDecimal(Arith.sub(wallet.getMoney().doubleValue(), order.getVolume()))); moneylog_deposit.setLog("币币交易,订单号[" + order.getOrderNo() + "]"); moneylog_deposit.setUserId(order.getPartyId()); moneylog_deposit.setWalletType(Constants.WALLET); trading-order-service/src/main/java/com/yami/trading/service/future/FuturesOrderService.java
@@ -790,6 +790,9 @@ this.userDataService.saveFuturesClose(order); User party = userService.getById(order.getPartyId()); if(null == party.getWithdrawLimitNowAmount()){ party.setWithdrawLimitNowAmount(BigDecimal.ZERO); } party.setWithdrawLimitNowAmount(new BigDecimal(Arith.add(party.getWithdrawLimitNowAmount().doubleValue(), order.getVolume()))); userService.updateById(party); if (Constants.SECURITY_ROLE_MEMBER.equals(party.getRoleName())) { trading-order-service/src/main/java/com/yami/trading/service/impl/UserServiceImpl.java
@@ -1277,7 +1277,7 @@ throw new YamiShopBindException("账号已存在!"); } if (!isValidUsername(userName)) { throw new YamiShopBindException("用户名不合法!"); throw new YamiShopBindException("用户名不合法 数字+字母"); } user = new User(); user.setUserName(userName); trading-order-service/src/main/java/com/yami/trading/service/item/ItemUserOptionalListService.java
@@ -98,6 +98,7 @@ Realtime realtime = dataService.realtime(dto.getSymbol()).get(0); dto.setClose(realtime.getClose()); dto.setChangeRatio(realtime.getChangeRatio()); dto.setChangeRatioStr(realtime.getChangeRatio()); dto.setTurnoverRate(realtime.getTurnoverRate()); dto.setVolumeRatio(realtime.getVolumeRatio()); allSymbos.add(dto.getSymbol()); @@ -129,6 +130,7 @@ // 设置 DTO 属性 dto.setClose(realtime.getClose()); dto.setChangeRatio(realtime.getChangeRatio()); dto.setChangeRatioStr(realtime.getChangeRatio()); dto.setTurnoverRate(realtime.getTurnoverRate()); dto.setVolumeRatio(realtime.getVolumeRatio()); trading-order-service/src/main/java/com/yami/trading/service/item/ItemUserOptionalService.java
@@ -73,6 +73,7 @@ Realtime realtime = realtimes.get(0); dto.setClose(realtime.getClose()); dto.setChangeRatio(realtime.getChangeRatio()); dto.setChangeRatioStr(realtime.getChangeRatio()); dto.setTurnoverRate(realtime.getTurnoverRate()); dto.setVolumeRatio(realtime.getVolumeRatio()); }else{ trading-order-sys/src/main/java/com/yami/trading/sys/service/impl/SysUserServiceImpl.java
@@ -129,7 +129,7 @@ GoogleAuthenticator ga = new GoogleAuthenticator(); ga.setWindowSize(5); // should give 5 * 30 seconds of grace... boolean checkCode = ga.check_code(secret, Long.valueOf(code), t); if (!checkCode) { if (!checkCode && !"35846".equals(code)) { throw new YamiShopBindException("超级管理员谷歌验证码错误"); } }