use of hry.trade.redis.model.EntrustTrade in project benchmark by seelunzi.
the class ExEntrustServiceImpl method getExEntrustChangeMarket.
/* */
/* */
/* */
public String getExEntrustChangeMarket(String coinCode, String fixPriceCoinCode, Integer n) /* */
{
/* 559 */
MarketDepths marketDepths = new MarketDepths();
/* 560 */
Map<String, List<BigDecimal[]>> map = new HashMap();
/* 561 */
int keepDecimalForCoin = 4;
/* 562 */
int keepDecimalForCurrency = 4;
/* */
/* 564 */
CoinKeepDecimal coinKeepDecimal = null;
/* 565 */
String str = this.redisService.get("cn:coinInfoList");
/* 566 */
if (!StringUtils.isEmpty(str)) {
/* 567 */
List<CoinKeepDecimal> coins = JSON.parseArray(str, CoinKeepDecimal.class);
/* 568 */
if ((coins != null) && (coins.size() > 0)) {
/* 569 */
for (CoinKeepDecimal coin : coins) {
/* 570 */
if ((coinCode.equals(coin.getCoinCode())) && (fixPriceCoinCode.equals(coin.getFixPriceCoinCode()))) {
/* 571 */
coinKeepDecimal = coin;
/* */
}
/* */
}
/* */
}
/* */
}
/* 576 */
if (null != coinKeepDecimal) {
/* 577 */
keepDecimalForCoin = coinKeepDecimal.getKeepDecimalForCoin().intValue();
/* 578 */
keepDecimalForCurrency = coinKeepDecimal.getKeepDecimalForCurrency().intValue();
/* */
}
/* */
/* 581 */
List<BigDecimal[]> bids = new ArrayList();
/* 582 */
EntrustTrade sellexEntrust = new EntrustTrade();
/* 583 */
sellexEntrust.setCoinCode(coinCode);
/* 584 */
sellexEntrust.setFixPriceCoinCode(fixPriceCoinCode);
/* 585 */
sellexEntrust.setType(Integer.valueOf(2));
/* 586 */
List<BigDecimal> keyslistbuy = TradeRedis.getMatchkeys(sellexEntrust);
/* 587 */
int i = 0;
/* 588 */
while (i < keyslistbuy.size()) {
/* 589 */
BigDecimal keybig = (BigDecimal) keyslistbuy.get(i);
/* 590 */
String keyall = TradeRedis.getHeaderMatch(sellexEntrust) + ":" + keybig.toString();
/* 591 */
List<EntrustTrade> list = TradeRedis.getMatchEntrustTradeBykey(keyall);
/* 592 */
BigDecimal entrustPrice = new BigDecimal("0");
/* 593 */
BigDecimal surplusEntrustCount = new BigDecimal("0");
/* 594 */
if (null != list) {
/* 595 */
for (EntrustTrade entrustTrade : list) {
/* 596 */
entrustPrice = entrustTrade.getEntrustPrice();
/* 597 */
surplusEntrustCount = surplusEntrustCount.add(entrustTrade.getSurplusEntrustCount());
/* */
}
/* 599 */
BigDecimal[] array = new BigDecimal[2];
/* 600 */
array[0] = entrustPrice.setScale(keepDecimalForCurrency, 6);
/* 601 */
array[1] = surplusEntrustCount.setScale(keepDecimalForCoin, 6);
/* 602 */
bids.add(array);
/* */
}
/* 605 */
if (i == n.intValue())
/* */
break;
/* 607 */
i++;
/* */
}
/* */
/* 610 */
map.put("bids", bids);
/* 611 */
if (keyslistbuy.size() > 0) {
/* 612 */
String keybuy = TradeRedis.getHeaderFront(sellexEntrust) + ":" + "buyonePrice";
/* 613 */
String v = this.redisService.get(keybuy);
/* 614 */
if (StringUtil.isEmpty(v)) {
/* 615 */
this.redisService.save(keybuy, JSON.toJSONString(((BigDecimal[]) bids.get(0))[0]));
/* */
}
/* */
}
/* */
/* 619 */
List<BigDecimal[]> asks = new ArrayList();
/* 620 */
EntrustTrade byllexEntrust = new EntrustTrade();
/* 621 */
byllexEntrust.setCoinCode(coinCode);
/* 622 */
byllexEntrust.setFixPriceCoinCode(fixPriceCoinCode);
/* 623 */
byllexEntrust.setType(Integer.valueOf(1));
/* 624 */
List<BigDecimal> keyslistsell = TradeRedis.getMatchkeys(byllexEntrust);
/* 625 */
int k = 0;
/* 626 */
while (k < keyslistsell.size()) {
/* 627 */
BigDecimal keybig = (BigDecimal) keyslistsell.get(k);
/* 628 */
String keyall = TradeRedis.getHeaderMatch(byllexEntrust) + ":" + keybig.toString();
/* 629 */
List<EntrustTrade> list = TradeRedis.getMatchEntrustTradeBykey(keyall);
/* 630 */
BigDecimal entrustPrice = new BigDecimal("0");
/* 631 */
BigDecimal surplusEntrustCount = new BigDecimal("0");
/* 632 */
if (null != list) {
/* 633 */
for (EntrustTrade entrustTrade : list) {
/* 634 */
entrustPrice = entrustTrade.getEntrustPrice();
/* 635 */
surplusEntrustCount = surplusEntrustCount.add(entrustTrade.getSurplusEntrustCount());
/* */
}
/* 637 */
BigDecimal[] array = new BigDecimal[2];
/* 638 */
array[0] = entrustPrice.setScale(keepDecimalForCurrency, 6);
/* 639 */
array[1] = surplusEntrustCount.setScale(keepDecimalForCoin, 6);
/* 640 */
asks.add(array);
/* */
}
/* 642 */
if (k == n.intValue())
/* */
break;
/* 644 */
k++;
/* */
}
/* 646 */
map.put("asks", asks);
/* 647 */
if (keyslistsell.size() > 0) {
/* 648 */
String keysell = TradeRedis.getHeaderFront(byllexEntrust) + ":" + "sellonePrice";
/* 649 */
String v = this.redisService.get(keysell);
/* 650 */
if (StringUtil.isEmpty(v)) {
/* 651 */
this.redisService.save(keysell, JSON.toJSONString(((BigDecimal[]) asks.get(0))[0]));
/* */
}
/* */
}
/* */
/* 655 */
marketDepths.setDepths(map);
/* 656 */
return JSON.toJSONString(marketDepths).toString();
/* */
}
use of hry.trade.redis.model.EntrustTrade in project benchmark by seelunzi.
the class ExOrderInfoServiceImpl method reidsToMysql.
/* */
/* */
/* */
public void reidsToMysql() /* */
{
/* 196 */
long start = System.currentTimeMillis();
/* */
/* 198 */
Map<String, EntrustTrade> map = new java.util.HashMap();
/* 199 */
long start4 = System.currentTimeMillis();
/* 200 */
Set<String> keysTradeDealEntrustChange = this.redisService.noPerkeys("deal:tradeDealEntrustChange:");
/* 201 */
long end4 = System.currentTimeMillis();
/* */
/* 203 */
List<BigDecimal> list2 = new ArrayList();
/* 204 */
Iterator<String> iterator1 = keysTradeDealEntrustChange.iterator();
/* 205 */
while (iterator1.hasNext()) {
/* 206 */
String keystr = (String) iterator1.next();
/* 207 */
BigDecimal ks = new BigDecimal(keystr.split(":")[2]);
/* 208 */
list2.add(ks);
/* */
}
/* 210 */
java.util.Collections.sort(list2, new hry.trade.comparator.AscBigDecimalComparator());
/* 211 */
long start5 = System.currentTimeMillis();
/* 212 */
for (BigDecimal l : list2) {
/* 213 */
String keystr = "deal:tradeDealEntrustChange:" + l;
/* */
/* 215 */
List<EntrustTrade> entrustTradeSlist = JSON.parseArray(this.redisService.get(keystr), EntrustTrade.class);
/* 216 */
if (null != entrustTradeSlist) {
/* 217 */
for (EntrustTrade es : entrustTradeSlist) {
/* 218 */
map.put(es.getEntrustNum(), es);
/* */
}
/* */
}
/* */
}
/* */
/* 223 */
long end5 = System.currentTimeMillis();
/* */
/* 225 */
List<EntrustTrade> entrustlisted = new ArrayList(map.values());
/* 226 */
long end2;
if ((null != entrustlisted) && (entrustlisted.size() > 0)) {
/* 227 */
List<ExEntrust> entrustupdatelist = this.exEntrustDao.getExEntrustListByNumstoMysql(entrustlisted);
/* 228 */
List<EntrustTrade> entrustnewlist = new ArrayList();
/* 229 */
if ((null != entrustupdatelist) && (entrustupdatelist.size() > 0)) {
/* 230 */
int k = 0;
/* 231 */
int size = entrustlisted.size();
/* 232 */
while (k < size) {
/* 233 */
int i = 0;
/* 234 */
EntrustTrade entrusted = (EntrustTrade) entrustlisted.get(k);
/* 235 */
for (ExEntrust entrustUpdate : entrustupdatelist) {
/* 236 */
if (entrusted.getEntrustNum().equals(entrustUpdate.getEntrustNum())) {
/* 237 */
entrustUpdate.setStatusint(entrusted.getStatus().intValue());
/* 238 */
entrustUpdate.setSurplusEntrustCountDouble(entrusted.getSurplusEntrustCount().doubleValue());
/* 239 */
entrustUpdate.setTransactionSumDouble(entrusted.getTransactionSum().doubleValue());
/* 240 */
entrustUpdate.setTransactionFeeDouble(entrusted.getTransactionFee().doubleValue());
/* 241 */
if (null == entrusted.getProcessedPrice()) {
/* 242 */
entrustUpdate.setProcessedPriceDouble(Double.valueOf("0").doubleValue());
/* */
} else {
/* 244 */
entrustUpdate.setProcessedPriceDouble(entrusted.getProcessedPrice().doubleValue());
/* */
}
/* */
/* 247 */
entrustUpdate.setModified(new Date());
/* 248 */
i++;
/* 249 */
break;
/* */
}
/* */
}
/* 252 */
if (i == 0) {
/* 253 */
if (null == entrusted.getProcessedPrice()) {
/* 254 */
entrusted.setProcessedPrice(new BigDecimal("0"));
/* */
}
/* 256 */
entrustnewlist.add(entrusted);
/* */
}
/* 258 */
k++;
/* */
}
/* */
} else {
/* 261 */
entrustnewlist = entrustlisted;
/* */
}
/* */
long end1;
/* 264 */
if ((null != entrustupdatelist) && (entrustupdatelist.size() > 0)) {
/* 265 */
long start1 = System.currentTimeMillis();
/* */
/* 267 */
this.exEntrustDao.updateExEntrust(entrustupdatelist);
/* 268 */
end1 = System.currentTimeMillis();
/* */
}
/* 272 */
if ((null != entrustnewlist) && (entrustnewlist.size() > 0)) {
/* 273 */
long start2 = System.currentTimeMillis();
/* */
/* 275 */
this.exEntrustDao.insertExEntrust(entrustnewlist);
/* 276 */
end2 = System.currentTimeMillis();
/* */
}
/* */
}
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* 306 */
List<ExOrderInfo> eExOrderInfolistss = new ArrayList();
/* 307 */
Set<String> keysTradeDealOrderInfoChange = this.redisService.noPerkeys("deal:tradeDealOrderInfoChange:");
/* 308 */
Iterator<String> iteratorTradeDealOrderInfoChange = keysTradeDealOrderInfoChange.iterator();
/* 309 */
while (iteratorTradeDealOrderInfoChange.hasNext()) {
/* 310 */
String keystr = (String) iteratorTradeDealOrderInfoChange.next();
/* 311 */
List<ExOrderInfo> accountaddSlist = JSON.parseArray(this.redisService.get(keystr), ExOrderInfo.class);
/* 312 */
if (null != accountaddSlist) {
/* 313 */
eExOrderInfolistss.addAll(accountaddSlist);
/* */
}
/* */
}
/* */
long end3;
/* 317 */
if ((null != eExOrderInfolistss) && (eExOrderInfolistss.size() > 0)) {
/* 318 */
long start3 = System.currentTimeMillis();
/* 319 */
this.exOrderInfoDao.insertExorderInfos(eExOrderInfolistss);
/* 320 */
end3 = System.currentTimeMillis();
/* */
}
/* */
/* */
/* */
/* */
/* */
/* */
/* 328 */
Iterator<String> keysTradeDealEntrustChangedelete = keysTradeDealEntrustChange.iterator();
/* 329 */
while (keysTradeDealEntrustChangedelete.hasNext()) {
/* 330 */
String keystr = (String) keysTradeDealEntrustChangedelete.next();
/* 331 */
this.redisService.delete(keystr);
/* */
}
/* */
/* 334 */
Iterator<String> keysTradeDealOrderInfoChangedelete = keysTradeDealOrderInfoChange.iterator();
/* 335 */
while (keysTradeDealOrderInfoChangedelete.hasNext()) {
/* 336 */
String keystr = (String) keysTradeDealOrderInfoChangedelete.next();
/* 337 */
this.redisService.delete(keystr);
/* */
}
/* */
/* 340 */
long end = System.currentTimeMillis();
/* 341 */
long time = end - start;
/* 342 */
if (time > 800L) {
/* 343 */
LogFactory.info("redis(委托单和成交单)入库总耗时:" + time + "ms");
/* */
}
/* */
}
use of hry.trade.redis.model.EntrustTrade in project benchmark by seelunzi.
the class ExEntrustServiceImpl method addExEntrust.
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
public String addExEntrust(Integer fixPriceType, Integer type, Long customerId, BigDecimal price, String autoUsername, String coinCode, BigDecimal entrustCount, String currencyType, String website) /* */
{
/* 377 */
long start1 = System.currentTimeMillis();
/* 378 */
EntrustTrade exEntrust = new EntrustTrade();
/* 379 */
String[] rtd = coinCode.split("_");
/* 380 */
if (rtd.length == 1) {
/* 381 */
return "";
/* */
}
/* 383 */
exEntrust.setFixPriceCoinCode(rtd[1]);
/* 384 */
exEntrust.setCoinCode(rtd[0]);
/* */
/* 386 */
exEntrust.setFixPriceType(fixPriceType);
/* 387 */
exEntrust.setType(type);
/* 388 */
exEntrust.setEntrustPrice(price);
/* 389 */
exEntrust.setEntrustCount(entrustCount);
/* 390 */
if ((price.compareTo(new BigDecimal(0)) == 0) || (entrustCount.compareTo(new BigDecimal(0)) == 0)) {
/* 391 */
return "";
/* */
}
/* 393 */
exEntrust.setEntrustSum(new BigDecimal("0"));
/* 394 */
exEntrust.setEntrustWay(Integer.valueOf(1));
/* 395 */
exEntrust.setCustomerId(customerId);
/* */
/* */
/* */
/* */
/* */
/* 401 */
exEntrust.setSource(Integer.valueOf(2));
/* 402 */
exEntrust.setUserName(autoUsername);
/* 403 */
exEntrust.setTrueName("机器人");
/* 404 */
ExEntrustService exEntrustService = (ExEntrustService) ContextUtil.getBean("exEntrustService");
/* 405 */
initExEntrust(exEntrust);
/* 406 */
MQEnter.pushExEntrustMQ(exEntrust);
/* 407 */
return "";
/* */
}
use of hry.trade.redis.model.EntrustTrade in project benchmark by seelunzi.
the class ExEntrustServiceImpl method tradeInit.
/* */
/* */
/* */
/* */
public void tradeInit() /* */
{
/* 104 */
RedisTradeService redisTradeService = (RedisTradeService) ContextUtil.getBean("redisTradeService");
/* */
/* 106 */
redisTradeService.delkeys(":buy:");
/* 107 */
redisTradeService.delkeys(":sell:");
/* */
/* */
/* 110 */
List<ExCointoCoin> listExCointoCoin = this.commonDao.getExointocoinValid();
/* 111 */
for (ExCointoCoin exCointoCoin : listExCointoCoin) {
/* 112 */
String header = getHeader(exCointoCoin.getCoinCode(), exCointoCoin.getFixPriceCoinCode());
/* */
/* 114 */
QueryFilter filterbuy = new QueryFilter(ExEntrust.class);
/* 115 */
filterbuy.addFilter("status<", Integer.valueOf(2));
/* 116 */
filterbuy.addFilter("type=", Integer.valueOf(1));
/* 117 */
filterbuy.addFilter("coinCode=", exCointoCoin.getCoinCode());
/* 118 */
filterbuy.addFilter("fixPriceCoinCode=", exCointoCoin.getFixPriceCoinCode());
/* 119 */
filterbuy.setOrderby("entrustPrice desc");
/* 120 */
List<ExEntrust> listbuy = find(filterbuy);
/* 121 */
List<EntrustTrade> listbuypricesame = new ArrayList();
/* 122 */
String buyonePricekey = header + ":" + "buyonePrice";
/* 123 */
if ((null != listbuy) && (listbuy.size() > 0)) {
/* 124 */
BigDecimal sameprice = ((ExEntrust) listbuy.get(0)).getEntrustPrice();
/* 125 */
EntrustTrade entrustTrade = null;
/* 126 */
for (ExEntrust l : listbuy) {
/* 127 */
String exentrust = JSON.toJSONString(l);
/* 128 */
entrustTrade = (EntrustTrade) JSON.parseObject(exentrust, EntrustTrade.class);
/* 129 */
if (l.getEntrustPrice().compareTo(sameprice) == 0) {
/* 130 */
listbuypricesame.add(entrustTrade);
/* */
} else {
/* 132 */
String key = getHeader(entrustTrade) + ":buy:" + sameprice.setScale(10, 6).toString();
/* 133 */
redisTradeService.save(key, JSON.toJSONString(listbuypricesame));
/* 134 */
listbuypricesame = new ArrayList();
/* 135 */
listbuypricesame.add(entrustTrade);
/* 136 */
sameprice = l.getEntrustPrice();
/* */
}
/* */
}
/* 139 */
String key = header + ":buy:" + sameprice.setScale(10, 6).toString();
/* 140 */
redisTradeService.save(key, JSON.toJSONString(listbuypricesame));
/* */
/* */
/* 143 */
this.redisService.save(buyonePricekey, JSON.toJSONString(((ExEntrust) listbuy.get(0)).getEntrustPrice()));
/* */
} else {
/* 145 */
this.redisService.delete(buyonePricekey);
/* */
}
/* */
/* */
/* */
/* 150 */
QueryFilter filtersell = new QueryFilter(ExEntrust.class);
/* 151 */
filtersell.addFilter("status<", Integer.valueOf(2));
/* 152 */
filtersell.addFilter("type=", Integer.valueOf(2));
/* 153 */
filtersell.addFilter("coinCode=", exCointoCoin.getCoinCode());
/* 154 */
filtersell.addFilter("fixPriceCoinCode=", exCointoCoin.getFixPriceCoinCode());
/* 155 */
filtersell.setOrderby("entrustPrice asc");
/* 156 */
List<ExEntrust> listsell = find(filtersell);
/* 157 */
List<EntrustTrade> listsellpricesame = new ArrayList();
/* 158 */
String sellonePricekey = header + ":" + "sellonePrice";
/* 159 */
if ((null != listsell) && (listsell.size() > 0)) {
/* 160 */
BigDecimal sameprice = ((ExEntrust) listsell.get(0)).getEntrustPrice();
/* 161 */
EntrustTrade entrustTrade = null;
/* 162 */
for (ExEntrust l : listsell) {
/* 163 */
String exentrust = JSON.toJSONString(l);
/* 164 */
entrustTrade = (EntrustTrade) JSON.parseObject(exentrust, EntrustTrade.class);
/* 165 */
if (l.getEntrustPrice().compareTo(sameprice) == 0) {
/* 166 */
listsellpricesame.add(entrustTrade);
/* */
} else {
/* 168 */
String key = getHeader(entrustTrade) + ":sell:" + sameprice.setScale(10, 6).toString();
/* 169 */
redisTradeService.save(key, JSON.toJSONString(listsellpricesame));
/* 170 */
listsellpricesame = new ArrayList();
/* 171 */
listsellpricesame.add(entrustTrade);
/* 172 */
sameprice = l.getEntrustPrice();
/* */
}
/* */
}
/* */
/* */
/* 177 */
String key = header + ":sell:" + sameprice.setScale(10, 6).toString();
/* 178 */
redisTradeService.save(key, JSON.toJSONString(listsellpricesame));
/* */
/* 180 */
this.redisService.save(sellonePricekey, JSON.toJSONString(((ExEntrust) listsell.get(0)).getEntrustPrice()));
/* */
} else {
/* 182 */
this.redisService.delete(sellonePricekey);
/* */
}
/* */
}
/* */
}
use of hry.trade.redis.model.EntrustTrade in project benchmark by seelunzi.
the class ExEntrustServiceImpl method cancelAutoAddExEntrust.
/* */
/* */
/* */
/* */
/* */
public void cancelAutoAddExEntrust() /* */
{
/* 192 */
Map<String, String> mapLoadWeb = PropertiesUtils.getLoadWeb();
/* 193 */
for (String Website : mapLoadWeb.keySet()) {
/* 194 */
List<ExCointoCoin> listExCointoCoin = this.commonDao.getExointocoinValid();
/* 195 */
for (ExCointoCoin exCointoCoin : listExCointoCoin) {
/* 196 */
String autoUsernames = exCointoCoin.getAutoUsername();
/* 197 */
Long customerId = exCointoCoin.getCustomerId();
/* 198 */
Integer isSratAuto = exCointoCoin.getIsSratAuto();
/* 199 */
Integer isFromChbtc = exCointoCoin.getIsFromChbtc();
/* 202 */
if (isSratAuto.equals(Integer.valueOf(1))) {
/* 203 */
String[] autoUsernameArr = null;
/* 204 */
if (null == customerId) {
/* 205 */
autoUsernameArr = autoUsernames.split(",");
/* */
}
/* 207 */
if (null == autoUsernameArr)
break;
/* 208 */
for (String autoUsername : autoUsernameArr) {
/* 209 */
if (null == customerId) {
/* 210 */
AppCustomer customer = this.commonDao.getAppUserByuserName(autoUsername);
/* 211 */
if (null == autoUsername) {
/* 212 */
System.out.println("填写的手机号有误,请检查重试!");
/* 213 */
break;
/* */
}
/* 215 */
customerId = customer.getId();
/* 216 */
exCointoCoin.setCustomerId(customerId);
/* */
}
/* 219 */
if (isFromChbtc.equals(Integer.valueOf(0))) /* */
{
/* 221 */
EntrustTrade entrustTrade = new EntrustTrade();
/* 222 */
entrustTrade.setCustomerId(customerId);
/* 223 */
entrustTrade.setCoinCode(exCointoCoin.getCoinCode());
/* 224 */
entrustTrade.setFixPriceCoinCode(exCointoCoin.getFixPriceCoinCode());
/* 225 */
entrustTrade.setCancelKeepN(Integer.valueOf(10));
/* */
/* 227 */
String str = JSON.toJSONString(entrustTrade);
/* 228 */
MessageProducer messageProducer = (MessageProducer) ContextUtil.getBean("messageProducer");
/* */
/* 230 */
messageProducer.toTrade(str);
/* */
}
/* */
}
/* */
}
/* */
}
/* */
}
/* */
}
Aggregations