Merge branches 'cpv' and 'feature/撮合交易' of https://gitee.com/chonggaoxiao/new_excoin into cpv
# Conflicts:
# src/main/java/com/xcong/excoin/modules/blackchain/service/UsdtEthService.java
# src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java
# src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
# src/main/java/com/xcong/excoin/processor/DefaultCoinProcessor.java
# src/main/java/com/xcong/excoin/quartz/job/KLineGeneratorJob.java
# src/main/java/com/xcong/excoin/quartz/job/NotionalPoolingJob.java
# src/main/resources/application-prod.yml
# src/main/resources/mapper/member/MemberAuthenticationDao.xml
7 files added
29 files modified
| | |
| | | |
| | | public static final String EXCHANGE_A = "biue-exchange-A"; |
| | | |
| | | |
| | | public static final String EXCHANGE_USDT_UPDATE = "exchange_usdt_update"; |
| | | |
| | | public static final String QUEUE_USDT_UPDATE = "queue_usdt_update"; |
| | | |
| | | public static final String ROUTING_KEY_USDT_UPDATE = "routing_key_usdt_update"; |
| | | |
| | | public static final String EXCHANGE_USDT_ADDRESS = "exchange_usdt_address"; |
| | | |
| | | public static final String QUEUE_USDT_ADDRESS= "queue_usdt_address"; |
| | | |
| | | public static final String ROUTING_KEY_USDT_ADDRESS = "routing_key_usdt_address"; |
| | | |
| | | |
| | | /** |
| | | * 撮合交易 |
| | | */ |
| | |
| | | |
| | | public static final String ROUTING_KEY_ROC = "roc-transfer-routingKey"; |
| | | |
| | | public static final String EXCHANGE_ROC_ORDER_SUBMIT = "roc-exchange-order-submit"; |
| | | |
| | | public static final String QUEUE_ROC_ORDER_SUBMIT = "roc-order-queue-submit"; |
| | | |
| | | public static final String ROUTING_KEY_ROC_ORDER_SUBMIT = "roc-order-routingKey-submit"; |
| | | |
| | | public static final String EXCHANGE_ROC_ORDER_CANCEL = "roc-exchange-order-cancel"; |
| | | |
| | | public static final String QUEUE_ROC_ORDER_CANCEL = "roc-order-queue-cancel"; |
| | | |
| | | public static final String ROUTING_KEY_ROC_ORDER_CANCEL = "roc-order-routingKey-cancel"; |
| | | |
| | | |
| | | @Resource |
| | | private ConnectionFactory connectionFactory; |
| | |
| | | return BindingBuilder.bind(testQueue()).to(defaultExchange()).with(ROUTING_KEY_TEST); |
| | | } |
| | | |
| | | // 交易订单 |
| | | @Bean |
| | | public DirectExchange orderSubmitExchange() { |
| | | return new DirectExchange(EXCHANGE_ROC_ORDER_SUBMIT); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | public Queue ordereSubmitQueue() { |
| | | return new Queue(QUEUE_ROC_ORDER_SUBMIT, true); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding bindingSubmitOrder() { |
| | | return BindingBuilder.bind(ordereSubmitQueue()).to(orderSubmitExchange()).with(ROUTING_KEY_ROC_ORDER_SUBMIT); |
| | | } |
| | | |
| | | // 交易订单 |
| | | @Bean |
| | | public DirectExchange orderCancelExchange() { |
| | | return new DirectExchange(EXCHANGE_ROC_ORDER_CANCEL); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | public Queue ordereCancelQueue() { |
| | | return new Queue(QUEUE_ROC_ORDER_CANCEL, true); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding bindingCancelOrder() { |
| | | return BindingBuilder.bind(ordereCancelQueue()).to(orderCancelExchange()).with(ROUTING_KEY_ROC_ORDER_CANCEL); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | public DirectExchange usdtUpdateExchange() { |
| | | return new DirectExchange(EXCHANGE_USDT_UPDATE); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | public Queue usdtUpdateQueue() { |
| | | return new Queue(QUEUE_USDT_UPDATE, true); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding usdtUpdatebinding() { |
| | | return BindingBuilder.bind(usdtUpdateQueue()).to(usdtUpdateExchange()).with(ROUTING_KEY_USDT_UPDATE); |
| | | } |
| | | |
| | | @Bean |
| | | public DirectExchange usdtAddressExchange() { |
| | | return new DirectExchange(EXCHANGE_USDT_ADDRESS); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | public Queue usdtAddressQueue() { |
| | | return new Queue(QUEUE_USDT_ADDRESS, true); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding usdtAddressbinding() { |
| | | return BindingBuilder.bind(usdtAddressQueue()).to(usdtAddressExchange()).with(ROUTING_KEY_USDT_ADDRESS); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 交换器A 可以继续添加交换器B C |
New file |
| | |
| | | package com.xcong.excoin.modules.blackchain.model; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * 充值扫块dto |
| | | */ |
| | | @Data |
| | | public class EthUsdtChargeDto { |
| | | |
| | | private String address; |
| | | private String hash; |
| | | private BigDecimal balance; |
| | | |
| | | public EthUsdtChargeDto() { |
| | | } |
| | | |
| | | public EthUsdtChargeDto(String address, String hash, BigDecimal balance) { |
| | | this.address = address; |
| | | this.hash = hash; |
| | | this.balance = balance; |
| | | } |
| | | } |
| | |
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.CompletableFuture;
|
| | | import java.util.concurrent.ExecutionException;
|
| | |
|
| | | import org.web3j.abi.FunctionEncoder;
|
| | |
| | |
|
| | | // log.debug("transfer hexValue:" + hexValue);
|
| | |
|
| | | EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
|
| | |
|
| | | CompletableFuture<EthSendTransaction> ethSendTransactionCompletableFuture = web3j.ethSendRawTransaction(hexValue).sendAsync();
|
| | | EthSendTransaction ethSendTransaction = ethSendTransactionCompletableFuture.get();
|
| | | //return "hash";
|
| | |
|
| | | if (ethSendTransaction.hasError()) {
|
| | | // log.info("transfer error:", ethSendTransaction.getError().getMessage());
|
| | |
| | | BigInteger nonce = ethGetTransactionCount.getTransactionCount();
|
| | | BigInteger value = Convert.toWei(amount, Convert.Unit.ETHER).toBigInteger();
|
| | | RawTransaction rawTransaction = RawTransaction.createEtherTransaction(nonce,
|
| | | Convert.toWei("50", Convert.Unit.GWEI).toBigInteger(),
|
| | | Convert.toWei("70", Convert.Unit.GWEI).toBigInteger(),
|
| | | Convert.toWei("60000", Convert.Unit.WEI).toBigInteger(), toAddress, value);
|
| | | byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
|
| | | String hexValue = Numeric.toHexString(signedMessage);
|
| | |
| | | public TransferEventResponse apply(Log log) { |
| | | EventValuesWithLog eventValues = extractEventParametersWithLog(TRANSFER_EVENT, log); |
| | | TransferEventResponse typedResponse = new TransferEventResponse(); |
| | | System.out.println(eventValues); |
| | | if(eventValues!=null){ |
| | | typedResponse.log = log; |
| | | typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue(); |
| | |
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.xcong.excoin.modules.blackchain.service.*;
|
| | | import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | |
| | | MemberDao memberDao;
|
| | | @Resource
|
| | | MemberCoinAddressDao memberMapper;
|
| | |
|
| | | @Resource
|
| | | private UsdtUpdateProducer usdtUpdateProducer;
|
| | |
|
| | | @Override
|
| | | public Result findBlockAddress(String symbol) {
|
| | |
| | | coinAddress.setLabel(uuid);
|
| | | memberMapper.insert(coinAddress);
|
| | | }
|
| | | // 发送新增的地址到监听集合
|
| | | usdtUpdateProducer.sendAddressMsg(address);
|
| | | }
|
| | | break;
|
| | | case "CPV":
|
| | |
| | | package com.xcong.excoin.modules.blackchain.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.modules.blackchain.model.EthUsdtChargeDto; |
| | | import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao; |
| | | import com.xcong.excoin.rabbit.producer.UsdtUpdateProducer; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.web3j.crypto.Credentials; |
| | | import org.web3j.protocol.Web3j; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class UsdtErc20UpdateService { |
| | | |
| | | @Resource |
| | | private UsdtUpdateProducer usdtUpdateProducer; |
| | | |
| | | @Resource |
| | | private MemberCoinAddressDao coinWalletDao; |
| | | |
| | | public final static List<String> ALL_ADDRESS_LIST = new ArrayList<>(); |
| | | |
| | | public final static String USDT_BLOCK_NUM = "USDT_BLOCK_NUM"; |
| | | public final static String USDT_BLOCK_NUM_GOLDEN = "USDT_BLOCK_NUM_GOLDEN"; |
| | | |
| | | private final static BigInteger DIVIDE_USDT = new BigInteger("1000000"); |
| | | private final static BigDecimal DIVIDE_USDT = new BigDecimal("1000000"); |
| | | |
| | | private static Web3j web3; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | |
| | | public void updateUsdt(){ |
| | | // 首先查询所有的钱包地址 |
| | | List<String> tdCoinWallets = coinWalletDao.selectAllSymbolAddress(CoinTypeEnum.USDT.toString(),"ERC20"); |
| | | if(tdCoinWallets!=null){ |
| | | ALL_ADDRESS_LIST.addAll(tdCoinWallets); |
| | | } |
| | | // 获取最新区块 |
| | | String string = redisUtils.getString(USDT_BLOCK_NUM); |
| | | String string = redisUtils.getString(USDT_BLOCK_NUM_GOLDEN); |
| | | if(string==null){ |
| | | string = "11014249"; |
| | | } |
| | | BigInteger blockNum = new BigInteger(string); |
| | | Credentials credentials = Credentials.create(privateKey); |
| | | EthUsdtContract contract = EthUsdtContract.load(contractAddr, web3, credentials, getStaticGasProvider()); |
| | | EthFilter filter = getFilter(new BigInteger("10943021")); |
| | | EthUsdtContract contract = EthUsdtContract.load(contractAddr, getInstance(), credentials, getStaticGasProvider()); |
| | | EthFilter filter = getFilter(blockNum); |
| | | Map<String,BigInteger> map = new HashMap<String,BigInteger>(); |
| | | map.put("blockNum",blockNum); |
| | | contract.transferEventFlowable(filter).subscribe(e->{ |
| | | if(e!=null){ |
| | | if(e!=null && StringUtils.isNotBlank(e.to) && e.log.getBlockNumber()!=null){ |
| | | String transactionHash = e.log.getTransactionHash(); |
| | | BigInteger blockNumber1 = e.log.getBlockNumber(); |
| | | String toAddress = e.to; |
| | | BigInteger tokenBalance = e.tokens; |
| | | // 金额 |
| | | BigInteger divide = tokenBalance.divide(DIVIDE_USDT); |
| | | // 发送消息队列 TODO |
| | | |
| | | if(ALL_ADDRESS_LIST.contains(toAddress)){ |
| | | System.out.println("存在本地的地址:"+toAddress); |
| | | // 金额 |
| | | BigDecimal divide = new BigDecimal(tokenBalance.toString()).divide(DIVIDE_USDT); |
| | | // 发送消息队列 |
| | | EthUsdtChargeDto dto = new EthUsdtChargeDto(toAddress,transactionHash,divide); |
| | | usdtUpdateProducer.sendMsg(JSONObject.toJSONString(dto)); |
| | | } |
| | | if(map.get("blockNum").compareTo(blockNumber1)!=0){ |
| | | redisUtils.set(USDT_BLOCK_NUM_GOLDEN,blockNumber1.toString()); |
| | | map.put("blockNum",blockNumber1); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | private static EthFilter getFilter(BigInteger startBlock) { |
| | | if (startBlock != null) { |
| | |
| | | return new EthFilter(DefaultBlockParameterName.EARLIEST, |
| | | DefaultBlockParameterName.LATEST, contractAddr); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | BigDecimal usdt = ethService.tokenGetBalance(address); |
| | | log.info("地址:{}, 金额:{}", address, usdt); |
| | | //log.info("地址:{}, 金额:{}", address, usdt); |
| | | if (usdt != null && usdt.compareTo(LIMIT) > 0) { |
| | | usdt = usdt.subtract(new BigDecimal("0.01")); |
| | | |
| | | // 查询eth是否足够 |
| | | BigDecimal eth = EthService.getEthBlance(address); |
| | | log.info("地址:{}, ETH:{}", address, eth); |
| | | //log.info("地址:{}, ETH:{}", address, eth); |
| | | if (eth != null && eth.compareTo(FEE) >= 0) { |
| | | MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectBlockAddressWithTag(memberId, CoinTypeEnum.USDT.name(), "ERC20"); |
| | | if (memberCoinAddressEntity == null) { |
| | |
| | | import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
|
| | | import com.xcong.excoin.modules.symbols.constants.SymbolsConstats;
|
| | | import org.springframework.validation.annotation.Validated;
|
| | | import org.springframework.web.bind.annotation.GetMapping;
|
| | | 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.RestController;
|
| | | import org.springframework.web.bind.annotation.*;
|
| | |
|
| | | import com.xcong.excoin.common.response.Result;
|
| | | import com.xcong.excoin.modules.coin.parameter.dto.CancelEntrustWalletCoinOrderDto;
|
| | |
| | | @Api(value = "币币交易接口", tags = "币币交易接口")
|
| | | @RestController
|
| | | @RequestMapping(value = "/api/orderCoin")
|
| | | @CrossOrigin("*")
|
| | | public class OrderCoinController {
|
| | |
|
| | | @Resource
|
| | |
| | | package com.xcong.excoin.modules.coin.dao;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | |
| | | public interface OrderCoinDealDao extends BaseMapper<OrderCoinsDealEntity>{
|
| | |
|
| | | List<OrderCoinsDealEntity> selectAllWalletCoinOrder(@Param("memberId")Long memberId);
|
| | | |
| | | BigDecimal sumTodayBuyAmount(@Param("memberId")Long memberId, @Param("symbol") String symbol);
|
| | | BigDecimal sumTodayEntrustCntBuyAmount(@Param("memberId")Long memberId, @Param("symbol") String symbol);
|
| | | List<OrderCoinsDealEntity> selectCoinOrderDealByOrderId(@Param("orderId")Long orderId);
|
| | |
|
| | | List<OrderCoinsDealEntity> selectAllWalletCoinOrderBySymbol(@Param("memberId")Long memberId,@Param("symbol")String symbol);
|
| | | List<OrderCoinsDealEntity> selectAllCoinDealsOrderBySymbol(@Param("symbol")String symbol);
|
| | |
|
| | |
| | | package com.xcong.excoin.modules.coin.dao;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.ibatis.annotations.Param;
|
| | |
| | | List<OrderCoinsEntity> selectAllEntrustingCoinOrderList(List<String> list);
|
| | |
|
| | | List<OrderCoinsEntity> selectCoinOrderOnTrade(List<String> list);
|
| | |
|
| | | void updateDeal(@Param("id") Long id, @Param("dealCnt")BigDecimal dealCnt,@Param("dealAmount")BigDecimal dealAmount);
|
| | | }
|
| | |
| | | package com.xcong.excoin.modules.coin.service; |
| | | |
| | | import com.xcong.excoin.modules.blackchain.model.EthUsdtChargeDto; |
| | | import com.xcong.excoin.modules.blackchain.model.RocTransferDetail; |
| | | |
| | | public interface BlockCoinService { |
| | |
| | | |
| | | public void updateRoc(RocTransferDetail transferDetail); |
| | | |
| | | void updateEthUsdtNew(EthUsdtChargeDto ethUsdtChargeDto); |
| | | |
| | | } |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), newBalance, balance, 0); |
| | | |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance,null); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance, null); |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.USDT.name(), 1, 1); |
| | | |
| | |
| | | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.ETH.name(), null, balance,null); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.ETH.name(), null, balance, null); |
| | | |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.ETH.name(), 1, 1); |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance,null); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance, null); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance,null); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance, null); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.BTC.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | if (memberCoinAddressEntity != null) { |
| | | memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(), amount, BigDecimal.ZERO, 0); |
| | | // 添加冲币记录 |
| | | String orderNo = insertCoinCharge(EosService.ACCOUNT, memberId, amount, CoinTypeEnum.EOS.name(), memo, BigDecimal.ZERO,null); |
| | | String orderNo = insertCoinCharge(EosService.ACCOUNT, memberId, amount, CoinTypeEnum.EOS.name(), memo, BigDecimal.ZERO, null); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.EOS.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | if (memberCoinAddressEntity != null) { |
| | | memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(), amount, BigDecimal.ZERO, 0); |
| | | // 添加冲币记录 |
| | | String orderNo = insertCoinCharge(XrpService.ACCOUNT, memberId, amount, CoinTypeEnum.XRP.name(), memo, BigDecimal.ZERO,null); |
| | | String orderNo = insertCoinCharge(XrpService.ACCOUNT, memberId, amount, CoinTypeEnum.XRP.name(), memo, BigDecimal.ZERO, null); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.XRP.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(), amount, BigDecimal.ZERO, 0); |
| | | // 添加冲币记录 |
| | | String orderNo = insertCoinCharge(address, memberId, amount, CoinTypeEnum.USDT.name(), "TRC20", BigDecimal.ZERO,transactionId); |
| | | String orderNo = insertCoinCharge(address, memberId, amount, CoinTypeEnum.USDT.name(), "TRC20", BigDecimal.ZERO, transactionId); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.USDT.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | String address = transferDetail.getAddress(); |
| | | BigDecimal balance = transferDetail.getBalance(); |
| | | String symbol = transferDetail.getSymbol(); |
| | | if(org.apache.commons.lang.StringUtils.isBlank(address) || org.apache.commons.lang.StringUtils.isBlank(symbol) || balance ==null ){ |
| | | if (org.apache.commons.lang.StringUtils.isBlank(address) || org.apache.commons.lang.StringUtils.isBlank(symbol) || balance == null) { |
| | | return; |
| | | } |
| | | |
| | | if(balance.compareTo(new BigDecimal("0.0001"))<=0){ |
| | | if (balance.compareTo(new BigDecimal("0.0001")) <= 0) { |
| | | return; |
| | | } |
| | | |
| | | MemberCoinAddressEntity memberCoinAddress = memberCoinAddressDao.selectCoinAddressByAddressAndSymbol(address, symbol); |
| | | if(memberCoinAddress==null){ |
| | | if (memberCoinAddress == null) { |
| | | return; |
| | | } |
| | | Long memberId = memberCoinAddress.getMemberId(); |
| | | // 查询钱包 并更新 |
| | | MemberWalletCoinEntity walletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.CPV.name()); |
| | | if (walletCoinEntity == null) { |
| | | // 创建一个钱包 |
| | | // 创建一个钱包 |
| | | // 创建这个钱包 |
| | | walletCoinEntity = new MemberWalletCoinEntity(); |
| | | walletCoinEntity.setAvailableBalance(BigDecimal.ZERO); |
| | |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), balance, BigDecimal.ZERO, 0); |
| | | |
| | | String orderNo = insertCoinCharge(address, memberId, balance, CoinTypeEnum.CPV.name(), "", BigDecimal.ZERO,null); |
| | | String orderNo = insertCoinCharge(address, memberId, balance, CoinTypeEnum.CPV.name(), "", BigDecimal.ZERO, null); |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", balance, CoinTypeEnum.CPV.name(), 1, 1); |
| | | |
| | | try{ |
| | | try { |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = balance.toPlainString() + CoinTypeEnum.CPV.name(); |
| | | String amount = balance.toPlainString() + "ROC"; |
| | | Sms106Send.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } else { |
| | | SubMailSend.sendRechargeMail(member.getEmail(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | //e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void updateEthUsdtNew(EthUsdtChargeDto ethUsdtChargeDto) { |
| | | String address = ethUsdtChargeDto.getAddress(); |
| | | String hash = ethUsdtChargeDto.getHash(); |
| | | // hash没有用过 |
| | | Map<String,Object> param = new HashMap<>(); |
| | | param.put("hash",hash); |
| | | param.put("address",address); |
| | | List<MemberCoinChargeEntity> memberCoinChargeEntities = memberCoinChargeDao.selectByMap(param); |
| | | if(CollectionUtils.isNotEmpty(memberCoinChargeEntities)){ |
| | | return; |
| | | } |
| | | MemberCoinAddressEntity coinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbol(address, CoinTypeEnum.USDT.toString()); |
| | | if (coinAddressEntity == null) { |
| | | return; |
| | | } |
| | | Long memberId = coinAddressEntity.getMemberId(); |
| | | BigDecimal balance = ethUsdtChargeDto.getBalance(); |
| | | if (balance != null && balance.compareTo(new BigDecimal("0.1")) > 0) { |
| | | balance = balance.setScale(8, RoundingMode.CEILING); |
| | | BigDecimal early = BigDecimal.ZERO; |
| | | |
| | | MemberWalletCoinEntity walletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); |
| | | if (walletCoinEntity == null) { |
| | | return; |
| | | } |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), newBalance, balance, 0); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance, ethUsdtChargeDto.getHash()); |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.USDT.name(), 1, 1); |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = newBalance.toPlainString() + "USDT-ERC20"; |
| | | Sms106Send.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } else { |
| | | SubMailSend.sendRechargeMail(member.getEmail(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | private String generateNo() { |
| | |
| | | return String.valueOf(timestamp).substring(2) + random; |
| | | } |
| | | |
| | | public String insertCoinCharge(String address, Long memberId, BigDecimal newBalance, String symbol, String tag, BigDecimal lastAmount,String hash) { |
| | | public String insertCoinCharge(String address, Long memberId, BigDecimal newBalance, String symbol, String tag, BigDecimal lastAmount, String hash) { |
| | | MemberCoinChargeEntity memberCoinChargeEntity = new MemberCoinChargeEntity(); |
| | | memberCoinChargeEntity.setAddress(address); |
| | | memberCoinChargeEntity.setMemberId(memberId); |
| | |
| | | import com.xcong.excoin.modules.platform.entity.PlatformSymbolsCoinEntity;
|
| | |
|
| | | import com.xcong.excoin.modules.symbols.constants.SymbolsConstats;
|
| | | import com.xcong.excoin.rabbit.producer.OrderSubmitProducer;
|
| | | import com.xcong.excoin.trade.CoinTrader;
|
| | | import com.xcong.excoin.trade.CoinTraderFactory;
|
| | | import com.xcong.excoin.trade.ExchangeTrade;
|
| | |
| | |
|
| | | @Resource
|
| | | private MemberDao memberDao;
|
| | |
|
| | | @Resource
|
| | | private OrderSubmitProducer orderSubmitProducer;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | // memberWalletCoinDao.updateById(walletCoin);
|
| | | memberWalletCoinDao.updateWalletBalance(walletCoin.getId(),amount.negate(),amount.negate(),amount);
|
| | | }
|
| | | // 加入到撮合
|
| | | CoinTrader trader = factory.getTrader(symbol);
|
| | | trader.trade(order);
|
| | | // 加入到撮合 TODO 通过消息队列发送到交易撮合
|
| | | //CoinTrader trader = factory.getTrader(symbol);
|
| | | //trader.trade(order);
|
| | | order.setSymbol(symbol);
|
| | | orderSubmitProducer.sendMsg(JSONObject.toJSONString(order));
|
| | | return Result.ok(MessageSourceUtils.getString("order_service_0011"));
|
| | | }
|
| | |
|
| | |
| | | if (ObjectUtil.isNotEmpty(orderCoinsEntity) && orderCoinsEntity.getMemberId().equals(memberId) ) {
|
| | | // 如果是撮合交易单
|
| | | if (SymbolsConstats.EXCHANGE_SYMBOLS.contains(orderCoinsEntity.getSymbol())) {
|
| | | return this.cancelEntrustWalletCoinOrderForMatch(orderId);
|
| | | orderSubmitProducer.sendCancelMsg(orderId);
|
| | | // return this.cancelEntrustWalletCoinOrderForMatch(orderId);
|
| | | return Result.ok(MessageSourceUtils.getString("order_service_0013"));
|
| | | }
|
| | | if (orderCoinsEntity.getOrderStatus() == OrderCoinsEntity.ORDERSTATUS_CANCEL || orderCoinsEntity.getOrderStatus()==OrderCoinsEntity.ORDERSTATUS_DONE) {
|
| | | return Result.fail(MessageSourceUtils.getString("order_service_0012"));
|
| | |
| | | @Transactional
|
| | | public Result cancelEntrustWalletCoinOrderForMatch(String orderId) {
|
| | | //获取用户ID
|
| | | Long memberId = LoginUserUtils.getAppLoginUser().getId();
|
| | | OrderCoinsEntity orderCoinsEntity = orderCoinsDao.selectById(orderId);
|
| | | if(orderCoinsEntity==null){
|
| | | return Result.ok("");
|
| | | }
|
| | | Long memberId = orderCoinsEntity.getMemberId();
|
| | | // 取消撮合订单的单
|
| | | CoinTrader trader = factory.getTrader(orderCoinsEntity.getSymbol());
|
| | | trader.cancelOrder(orderCoinsEntity);
|
| | | if (ObjectUtil.isNotEmpty(orderCoinsEntity) && orderCoinsEntity.getMemberId().equals(memberId)) {
|
| | | if (ObjectUtil.isNotEmpty(orderCoinsEntity) ) {
|
| | | if (orderCoinsEntity.getOrderStatus() == OrderCoinsEntity.ORDERSTATUS_CANCEL || orderCoinsEntity.getOrderStatus()==OrderCoinsEntity.ORDERSTATUS_DONE) {
|
| | | return Result.fail(MessageSourceUtils.getString("order_service_0012"));
|
| | | }
|
| | |
| | | detail.setDealPrice(orderCoinsEntity.getDealPrice());
|
| | | detail.setDealAmount(orderCoinsEntity.getDealAmount());
|
| | | detail.setFeeAmount(orderCoinsEntity.getFeeAmount());
|
| | | orderCoinDealDao.insert(detail);
|
| | |
|
| | | if (OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
|
| | | //如果是限价买入,撤单将USDT账户冻结金额返回
|
| | | String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
|
| | |
| | | if (ObjectUtil.isNotEmpty(walletCoin)) {
|
| | | //手续费 = 开仓价*数量*手续费率
|
| | | //返还金额=开仓价*未成交数量+手续费
|
| | |
|
| | | // 这里根据成交的单计算
|
| | | List<OrderCoinsDealEntity> orderCoinsDealEntities = orderCoinDealDao.selectCoinOrderDealByOrderId(Long.valueOf(orderId));
|
| | | BigDecimal dealAmount = BigDecimal.ZERO;
|
| | | if(CollectionUtils.isNotEmpty(orderCoinsDealEntities)){
|
| | | for (OrderCoinsDealEntity orderCoinsDealEntity : orderCoinsDealEntities) {
|
| | | dealAmount = dealAmount.add(orderCoinsDealEntity.getDealAmount());
|
| | | }
|
| | | }
|
| | | // 市价的按成交额退款
|
| | | BigDecimal returnBalance = orderCoinsEntity.getEntrustAmount().subtract(orderCoinsEntity.getDealAmount());
|
| | | BigDecimal returnBalance = orderCoinsEntity.getEntrustAmount().subtract(dealAmount);
|
| | |
|
| | | // 需要退回的手续费
|
| | | BigDecimal returnFee = BigDecimal.ZERO;
|
| | | if (returnBalance.compareTo(orderCoinsEntity.getEntrustAmount()) == 0) {
|
| | | returnFee = orderCoinsEntity.getFeeAmount();
|
| | | } else {
|
| | | // 按比例退回
|
| | | BigDecimal needFee = orderCoinsEntity.getDealAmount().divide(orderCoinsEntity.getEntrustAmount(), 8, BigDecimal.ROUND_DOWN).multiply(orderCoinsEntity.getFeeAmount());
|
| | | BigDecimal needFee = orderCoinsEntity.getFeeAmount().multiply(dealAmount.divide(orderCoinsEntity.getEntrustAmount(), 8, BigDecimal.ROUND_DOWN));
|
| | | returnFee = orderCoinsEntity.getFeeAmount().subtract(needFee);
|
| | | }
|
| | | BigDecimal avi = returnBalance.add(returnFee);
|
| | | memberWalletCoinDao.updateWalletBalance(walletCoin.getId(),avi,null,returnBalance.negate());
|
| | | walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance).add(returnFee));
|
| | | walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance));
|
| | | memberWalletCoinDao.updateById(walletCoin);
|
| | | //memberWalletCoinDao.updateById(walletCoin);
|
| | | // 流水记录
|
| | | MemberAccountFlowEntity record = new MemberAccountFlowEntity();
|
| | | record.setSource(MemberAccountFlowEntity.SOURCE_CANCEL);
|
| | |
| | | return Result.ok(MessageSourceUtils.getString("order_service_0013"));
|
| | | }
|
| | | }
|
| | | orderCoinDealDao.insert(detail);
|
| | | }
|
| | | return Result.fail(MessageSourceUtils.getString("order_service_0043"));
|
| | | }
|
| | |
| | | }
|
| | | Long memberId = buyOrderCoinsEntity.getMemberId();
|
| | | if (buyOrderCoinsEntity != null) {
|
| | | List<OrderCoinsDealEntity> orderCoinsDealEntities = orderCoinDealDao.selectCoinOrderDealByOrderId(buyOrderId);
|
| | | // 比较剩余的量
|
| | | BigDecimal dealAmount = buyOrderCoinsEntity.getDealAmount();
|
| | | BigDecimal dealAmount = BigDecimal.ZERO;
|
| | | BigDecimal dealCnt = BigDecimal.ZERO;
|
| | | if(CollectionUtils.isNotEmpty(orderCoinsDealEntities)){
|
| | | for (OrderCoinsDealEntity orderCoinsDealEntity : orderCoinsDealEntities) {
|
| | | dealAmount=dealAmount.add(orderCoinsDealEntity.getDealAmount());
|
| | | dealCnt = dealCnt.add(orderCoinsDealEntity.getSymbolCnt());
|
| | | }
|
| | | }
|
| | |
|
| | | // 单的总金额
|
| | | BigDecimal entrustAmount = buyOrderCoinsEntity.getEntrustAmount();
|
| | | BigDecimal add = dealAmount.add(buyTurnover);
|
| | | BigDecimal closingPrice = buyTurnover.multiply(new BigDecimal("0.002"));
|
| | |
|
| | | //成交量
|
| | | BigDecimal dealCnt = buyOrderCoinsEntity.getDealCnt().add(amount);
|
| | | //成交总量
|
| | | dealCnt = dealCnt.add(amount);
|
| | | // 创建一个完成的单
|
| | | OrderCoinsDealEntity detail = new OrderCoinsDealEntity();
|
| | | detail.setMemberId(buyOrderCoinsEntity.getMemberId());
|
| | |
| | | memberWalletCoinDao.updateWalletBalance(coinsEntity.getId(),subtract,subtract,subtract.negate());
|
| | | }
|
| | | } else {
|
| | | OrderCoinsEntity update = new OrderCoinsEntity();
|
| | | update.setId(buyOrderId);
|
| | | update.setDealAmount(add);
|
| | | update.setDealCnt(buyOrderCoinsEntity.getDealCnt().add(amount));
|
| | | update.setUpdateTime(new Date());
|
| | | orderCoinsDao.updateById(update);
|
| | | // 更新买单
|
| | | orderCoinsDao.updateDeal(buyOrderId,amount,buyTurnover);
|
| | | }
|
| | | }
|
| | | // 卖单
|
| | |
| | |
|
| | | List<MemberCoinAddressEntity> selectAllBlockAddressBySymbol(@Param("symbol") String symbol);
|
| | |
|
| | | List<String> selectAllSymbolAddress(@Param("symbol")String symbol,@Param("tag") String tag);
|
| | |
|
| | | }
|
| | |
| | | |
| | | public Result findKlineDetails(KlineDetailDto klineDetailDto); |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | // 存储昨日K线 |
| | | if("day".equals(rangeUnit)){ |
| | | redisUtils.set("CPV/USDT",kLine); |
| | | System.out.println("存储日K线"); |
| | | kLine.setOpen(kLine.getClose()); |
| | | kLine.setLow(kLine.getClose()); |
| | | kLine.setHigh(kLine.getClose()); |
| | | redisUtils.set("ROC/USDT",kLine); |
| | | } |
| | | } |
| | | |
| | |
| | | list = (List) data; |
| | | } |
| | | list.add(kLine); |
| | | redisUtils.set(key, list); |
| | | int size = list.size(); |
| | | if(size>500){ |
| | | list = list.subList(size-500,size); |
| | | } |
| | | List lines = new ArrayList(); |
| | | if(CollectionUtils.isNotEmpty(list)){ |
| | | for(Object object:list){ |
| | | lines.add(object); |
| | | } |
| | | } |
| | | redisUtils.set(key, lines); |
| | | // mongoTemplate.insert(kLine,"exchange_kline_"+symbol+"_"+kLine.getPeriod()); |
| | | } |
| | | |
| | |
| | | |
| | | return totalVolume; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("1"); |
| | | list.add("2"); |
| | | list.add("3"); |
| | | list.add("4"); |
| | | list.add("5"); |
| | | list=list.subList(2,5); |
| | | System.out.println(list); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * ETH_USDT 同步 |
| | | */ |
| | | @Scheduled(cron = "0 0/10 * * * ? ") |
| | | public void ethUsdtUpdate() { |
| | | blockCoinService.updateEthUsdt(); |
| | | } |
| | | //@Scheduled(cron = "0 0/10 * * * ? ") |
| | | // public void ethUsdtUpdate() { |
| | | // blockCoinService.updateEthUsdt(); |
| | | // } |
| | | |
| | | /** |
| | | * eth 同步 |
| | |
| | | /** |
| | | * BTC_USDT 同步 |
| | | */ |
| | | @Scheduled(cron = "0 2/10 * * * ? ") |
| | | //@Scheduled(cron = "0 2/10 * * * ? ") |
| | | public void btcUsdtUpdate() { |
| | | blockCoinService.updateBtcUsdt(); |
| | | } |
| | |
| | | /** |
| | | * ETH_USDT 同步 |
| | | */ |
| | | @Scheduled(cron = "0 0/5 * * * ? ") |
| | | //Scheduled(cron = "0 0/5 * * * ? ") |
| | | public void rocUpdate() { |
| | | blockCoinService.updateEthUsdt(); |
| | | // blockCoinService.updateEthUsdt(); |
| | | } |
| | | } |
| | |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "trade", havingValue = "true") |
| | | @ConditionalOnProperty(prefix = "app", name = "exchange-trade", havingValue = "true") |
| | | public class CoinTradeInitJob { |
| | | |
| | | @Resource |
| | |
| | | // 创建K线生成器 |
| | | CoinProcessor processor = new DefaultCoinProcessor(symbol, "USDT"); |
| | | processor.setMarketService(marketService); |
| | | processor.setRedisUtils(redisUtils); |
| | | //processor.setExchangeRate(exchangeRate); |
| | | processor.initializeThumb(); |
| | | //processor.initializeUsdRate(); |
| | |
| | | import com.xcong.excoin.modules.coin.service.OrderCoinService; |
| | | import com.xcong.excoin.processor.CoinProcessorFactory; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | @ConditionalOnProperty(prefix = "app", name = "exchange-trade", havingValue = "true") |
| | | public class KLineGeneratorJob { |
| | | @Resource |
| | | private CoinProcessorFactory processorFactory; |
| | | |
| | | |
| | | /** |
| | | * 每分钟定时器,处理分钟K线 |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 2/8 * * * ? ") |
| | | public void usdtEthPoolCheck() { |
| | | log.info("USDTETH归集结果扫描开始"); |
| | | usdtEthService.usdtEthPoolCheck(); |
| | | } |
| | | // @Scheduled(cron = "0 2/8 * * * ? ") |
| | | // public void usdtEthPoolCheck() { |
| | | // log.info("USDTETH归集结果扫描开始"); |
| | | // usdtEthService.usdtEthPoolCheck(); |
| | | // } |
| | | |
| | | @Scheduled(cron = "0 2/30 * * * ? ") |
| | | public void poolEth() { |
New file |
| | |
| | | package com.xcong.excoin.quartz.job; |
| | | |
| | | import com.xcong.excoin.modules.blackchain.service.UsdtErc20UpdateService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 开启撮合交易 |
| | | * |
| | | * @author wzy |
| | | * @date 2020-05-28 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") |
| | | public class UsdtErc20InitJob { |
| | | |
| | | |
| | | @Resource |
| | | private UsdtErc20UpdateService usdtErc20UpdateService; |
| | | |
| | | @PostConstruct |
| | | public void initCoinTrade() { |
| | | System.out.println("开启USDT同步"); |
| | | usdtErc20UpdateService.updateUsdt(); |
| | | } |
| | | } |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-05-25 |
| | | **/ |
| | | * websocket 只能后台撮合交易那台开启 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "exchange-trade", havingValue = "true") |
| | | public class ExchangeConsumer { |
| | | |
| | | @Resource |
| | |
| | | orderCoinService.handleOrder(exchangeTrades); |
| | | } |
| | | |
| | | /** |
| | | * 更新最新K线 |
| | | * @param content |
| | | */ |
| | | // @RabbitListener(queues = RabbitMqConfig.QUEUE_TRADE_PLATE) |
| | | // public void newKling(String content) { |
| | | // log.info("#---->{}#", content); |
| | | // // 最新K线的币种 |
| | | // String key = "NEW_KINE_{}"; |
| | | // key = StrUtil.format(key, content); |
| | | // Object o = redisUtils.get(key); |
| | | // Map<String, Candlestick> currentKlineMap = (Map<String, Candlestick>)o; |
| | | // // 推送最新K线 |
| | | // Set<Map.Entry<String, Candlestick>> entries = currentKlineMap.entrySet(); |
| | | // for(Map.Entry<String, Candlestick> map : entries){ |
| | | // tradePlateSendWebSocket.sendMessageKline(content,map.getKey(),JSONObject.toJSONString(map.getValue()),null); |
| | | // } |
| | | // |
| | | // } |
| | | } |
| | |
| | | * @author helius |
| | | */ |
| | | @Component |
| | | @Deprecated |
| | | @ConditionalOnProperty(prefix = "app", name = "newest-price-update-job-contract", havingValue = "true") |
| | | public class OperateOrderPriceConsumer { |
| | | |
New file |
| | |
| | | package com.xcong.excoin.rabbit.consumer; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.configurations.RabbitMqConfig; |
| | | import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity; |
| | | import com.xcong.excoin.modules.coin.service.OrderCoinService; |
| | | import com.xcong.excoin.trade.CoinTrader; |
| | | import com.xcong.excoin.trade.CoinTraderFactory; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 提交买卖单进入撮合系统 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "exchange-trade", havingValue = "true") |
| | | public class OrderSubmitConsumer { |
| | | |
| | | @Resource |
| | | private CoinTraderFactory factory; |
| | | |
| | | @Resource |
| | | private OrderCoinService orderCoinService; |
| | | |
| | | @RabbitListener(queues = RabbitMqConfig.QUEUE_ROC_ORDER_SUBMIT) |
| | | public void doSomething(String content) { |
| | | log.info("#提交的订单---->{}#", content); |
| | | OrderCoinsEntity coinsEntity = JSONObject.parseObject(content, OrderCoinsEntity.class); |
| | | String symbol = coinsEntity.getSymbol(); |
| | | CoinTrader trader = factory.getTrader(symbol); |
| | | trader.trade(coinsEntity); |
| | | } |
| | | |
| | | /** |
| | | * 取消订单 |
| | | * @param content |
| | | */ |
| | | @RabbitListener(queues = RabbitMqConfig.QUEUE_ROC_ORDER_CANCEL) |
| | | public void doCancel(String content) { |
| | | log.info("#取消的订单---->{}#", content); |
| | | orderCoinService.cancelEntrustWalletCoinOrderForMatch(content); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * 用户修改止损止盈价格、提价限价委托、下单爆仓价等消息 |
| | | * 后台打包开启 APP 不开启 |
| | | * @author helius |
| | | * ROC币种同步 |
| | | */ |
| | | @Component |
| | | //@ConditionalOnProperty(prefix = "app", name = "newest-price-update-job-contract", havingValue = "true") |
| | | @ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") |
| | | public class RocBlockUpdateConsumer { |
| | | |
| | | @Resource |
New file |
| | |
| | | package com.xcong.excoin.rabbit.consumer; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.configurations.RabbitMqConfig; |
| | | import com.xcong.excoin.modules.blackchain.model.EthUsdtChargeDto; |
| | | import com.xcong.excoin.modules.blackchain.service.UsdtErc20UpdateService; |
| | | import com.xcong.excoin.modules.coin.service.BlockCoinService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-05-25 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") |
| | | public class UsdtUpdateConsumer { |
| | | |
| | | |
| | | @Resource |
| | | private BlockCoinService blockCoinService; |
| | | |
| | | |
| | | @RabbitListener(queues = RabbitMqConfig.QUEUE_USDT_UPDATE) |
| | | public void doSomething(String content) { |
| | | log.info("#USDT同步---->{}#", content); |
| | | EthUsdtChargeDto ethUsdtChargeDto = JSONObject.parseObject(content, EthUsdtChargeDto.class); |
| | | // 更新这个用户的余额 |
| | | blockCoinService.updateEthUsdtNew(ethUsdtChargeDto); |
| | | } |
| | | |
| | | @RabbitListener(queues = RabbitMqConfig.QUEUE_USDT_ADDRESS) |
| | | public void addUsdtAddress(String content) { |
| | | if(!UsdtErc20UpdateService.ALL_ADDRESS_LIST.contains(content)){ |
| | | log.info("#添加新地址---->{}#", content); |
| | | UsdtErc20UpdateService.ALL_ADDRESS_LIST.add(content); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @Deprecated |
| | | @ConditionalOnProperty(prefix = "app", name = "rabbit-consumer", havingValue = "true") |
| | | public class WebsocketPriceConsumer { |
| | | |
| | |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "newest-price-update-job-contract", havingValue = "true") |
| | | @Deprecated |
| | | public class OrderProducerInit { |
| | | |
| | | @Resource |
New file |
| | |
| | | package com.xcong.excoin.rabbit.producer; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.xcong.excoin.configurations.RabbitMqConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.rabbit.connection.CorrelationData; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-05-25 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | public class OrderSubmitProducer implements RabbitTemplate.ConfirmCallback { |
| | | |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | @Autowired |
| | | public OrderSubmitProducer(RabbitTemplate rabbitTemplate) { |
| | | this.rabbitTemplate = rabbitTemplate; |
| | | rabbitTemplate.setConfirmCallback(this); |
| | | } |
| | | |
| | | public void sendMsg(String content) { |
| | | CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID()); |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ROC_ORDER_SUBMIT, RabbitMqConfig.ROUTING_KEY_ROC_ORDER_SUBMIT, content, correlationData); |
| | | } |
| | | |
| | | public void sendCancelMsg(String content) { |
| | | CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID()); |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ROC_ORDER_CANCEL, RabbitMqConfig.ROUTING_KEY_ROC_ORDER_CANCEL, content, correlationData); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void confirm(CorrelationData correlationData, boolean ack, String cause) { |
| | | log.info("#----->{}#", correlationData); |
| | | if (ack) { |
| | | log.info("success"); |
| | | } else { |
| | | log.info("--->{}", cause); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.excoin.rabbit.producer; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.xcong.excoin.configurations.RabbitMqConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.amqp.rabbit.connection.CorrelationData; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-05-25 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | public class UsdtUpdateProducer implements RabbitTemplate.ConfirmCallback { |
| | | |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | @Autowired |
| | | public UsdtUpdateProducer(RabbitTemplate rabbitTemplate) { |
| | | this.rabbitTemplate = rabbitTemplate; |
| | | rabbitTemplate.setConfirmCallback(this); |
| | | } |
| | | |
| | | public void sendMsg(String content) { |
| | | CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID()); |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_USDT_UPDATE, RabbitMqConfig.ROUTING_KEY_USDT_UPDATE, content, correlationData); |
| | | } |
| | | |
| | | public void sendAddressMsg(String content) { |
| | | CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID()); |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_USDT_ADDRESS, RabbitMqConfig.ROUTING_KEY_USDT_ADDRESS, content, correlationData); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void confirm(CorrelationData correlationData, boolean ack, String cause) { |
| | | log.info("#----->{}#", correlationData); |
| | | if (ack) { |
| | | log.info("success"); |
| | | } else { |
| | | log.info("--->{}", cause); |
| | | } |
| | | } |
| | | } |
| | |
| | | @OnOpen |
| | | public void onOpen(Session session) { |
| | | onlineCount.incrementAndGet(); // 在线数加1 |
| | | log.info("有新连接加入:{},当前在线人数为:{}", session.getId(), onlineCount.get()); |
| | | // log.info("有新连接加入:{},当前在线人数为:{}", session.getId(), onlineCount.get()); |
| | | } |
| | | |
| | | /** |
| | |
| | | map.remove(session.getId()); |
| | | } |
| | | } |
| | | log.info("有一连接关闭:{},当前在线人数为:{}", session.getId(), onlineCount.get()); |
| | | //log.info("有一连接关闭:{},当前在线人数为:{}", session.getId(), onlineCount.get()); |
| | | } |
| | | |
| | | /** |
| | |
| | | result.setRep(sub); |
| | | if (o != null) { |
| | | List<Candlestick> list = (List<Candlestick>) o; |
| | | |
| | | if(list!=null && list.size()>300){ |
| | | int size = list.size(); |
| | | list = list.subList(size-300,size); |
| | | } |
| | | CandlestickModel model = null; |
| | | for (Candlestick candlestick : list) { |
| | | CandlestickModel model = new CandlestickModel(); |
| | | model = new CandlestickModel(); |
| | | model.setAmount(candlestick.getAmount()); |
| | | model.setClose(candlestick.getClose()); |
| | | model.setCount(candlestick.getCount()); |
| | |
| | | |
| | | @OnError |
| | | public void onError(Session session, Throwable error) { |
| | | log.error("发生错误"); |
| | | error.printStackTrace(); |
| | | // log.error("发生错误"); |
| | | //error.printStackTrace(); |
| | | } |
| | | |
| | | /** |
New file |
| | |
| | | server: |
| | | port: 8888 |
| | | servlet: |
| | | context-path: / |
| | | |
| | | spring: |
| | | profiles: |
| | | active: dev |
| | | datasource: |
| | | url: jdbc:mysql://rm-bp1i2g5rg5dubo9s40o.mysql.rds.aliyuncs.com:3306/db_roc?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8 |
| | | username: roc_user |
| | | password: roc123pasd!@ |
| | | driver-class-name: com.mysql.jdbc.Driver |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | druid: |
| | | initial-size: ${spring_datasource_druid_initial_size:10} |
| | | max-active: ${spring_datasource_druid_max_active:20} |
| | | min-idle: ${spring_datasource_druid_min_idle:3} |
| | | #配置获取连接等待超时的时间 |
| | | max-wait: 60000 |
| | | pool-prepared-statements: true |
| | | max-pool-prepared-statement-per-connection-size: 20 |
| | | validation-query: SELECT 'x' |
| | | test-on-borrow: true |
| | | test-on-return: true |
| | | test-while-idle: true |
| | | #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 |
| | | time-between-eviction-runs-millis: 60000 |
| | | #配置一个连接在池中最小生存的时间,单位是毫秒 |
| | | min-evictable-idle-time-millis: 300000 |
| | | #spring.datasource.druid.max-evguide.ftlictable-idle-time-millis= |
| | | filters: stat,wall |
| | | stat-view-servlet: |
| | | # 默认true 内置监控页面首页/druid/index.html |
| | | enabled: true |
| | | url-pattern: /druid/* |
| | | # 允许清空统计数据 |
| | | reset-enable: true |
| | | login-username: root |
| | | login-password: 123456 |
| | | # IP白名单 多个逗号分隔 |
| | | allow: ${spring_datasource_stat_view_servlet_allow:} |
| | | # IP黑名单 |
| | | deny: ${spring_datasource_stat_view_servlet_deny:} |
| | | ## 国际化配置 |
| | | messages: |
| | | basename: i18n/messages |
| | | ## redis配置 |
| | | redis: |
| | | ## Redis数据库索引(默认为0) |
| | | database: 1 |
| | | ## Redis服务器地址 |
| | | host: 47.114.114.219 |
| | | ## Redis服务器连接端口 |
| | | port: 6379 |
| | | ## Redis服务器连接密码(默认为空) |
| | | password: biyi123 |
| | | jedis: |
| | | pool: |
| | | ## 连接池最大连接数(使用负值表示没有限制) |
| | | #spring.redis.pool.max-active=8 |
| | | max-active: 300 |
| | | ## 连接池最大阻塞等待时间(使用负值表示没有限制) |
| | | #spring.redis.pool.max-wait=-1 |
| | | max-wait: -1 |
| | | ## 连接池中的最大空闲连接 |
| | | #spring.redis.pool.max-idle=8 |
| | | max-idle: 100 |
| | | ## 连接池中的最小空闲连接 |
| | | #spring.redis.pool.min-idle=0 |
| | | min-idle: 8 |
| | | ## 连接超时时间(毫秒) |
| | | timeout: 30000 |
| | | rabbitmq: |
| | | host: 47.114.114.219 |
| | | port: 5672 |
| | | username: roc_user |
| | | password: roc123456 |
| | | publisher-confirm-type: correlated |
| | | |
| | | |
| | | #custom: |
| | | # rabbitmq: |
| | | # host: 120.27.238.55 |
| | | # port: 5672 |
| | | # username: ct_rabbit |
| | | # password: 123456 |
| | | |
| | | mybatis-plus: |
| | | mapper-locations: classpath:mapper/**/*.xml |
| | | |
| | | |
| | | app: |
| | | debug: false |
| | | redis_expire: 3000 |
| | | kline-update-job: false |
| | | newest-price-update-job: false |
| | | exchange-trade: false |
| | | day-line: false |
| | | other-job: false |
| | | loop-job: false |
| | | rabbit-consumer: false |
| | | block-job: false |
| | | |
| | | aliyun: |
| | | oss: |
| | | end-point: https://oss-cn-hangzhou.aliyuncs.com |
| | | bucket-name: https://excoin.oss-cn-hangzhou.aliyuncs.com |
| | | access-key-id: LTAI4GBuydqbJ5bTsDP97Lpd |
| | | access-key-secret: vbCjQtPxABWjqtUlQfzjlA0qAY96fh |
| | | |
| | | rsa: |
| | | public_key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCf8UFZK54AiK4PRu7tNd+Z8qZ77o/QXCnk25DRmygVpOEu5mGNSAvfnWmKp2pEV2RljeXq3Rid/+LQkonaebMJeXKSF0yxL/VgyeT8JaQ5gNbOrdfdlc+mFkXJyzyJt8YkvApEdPRNSU2ENBn7mgRfD0BYPM4vZ6/rv+de38FJwIDAQAB |
| | | private_key: MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIJ/xQVkrngCIrg9G7u0135nypnvuj9BcKeTbkNGbKBWk4S7mYY1IC9+daYqnakRXZGWN5erdGJ3/4tCSidp5swl5cpIXTLEv9WDJ5PwlpDmA1s6t192Vz6YWRcnLPIm3xiS8CkR09E1JTYQ0GfuaBF8PQFg8zi9nr+u/517fwUnAgMBAAECgYBhPt9NvpI4wbanvnndLczr2GJkxfzvSE+vwLCJF4C5FusFHVsxZINggQcg1V75bwRgCiXRMyYefreCSdrCditS43PzTOmE4RRrpxLlm8oubJc0C98LQ2qlN9AsUqL5IHpVGgbHDyWAwjc1GBID6nwXKpxq1/VodFqhahG9D5EZsQJBALnkb+5VTxQbiyQI4Uc9NIvAyVcNY1OisbvY6tvNgdBbJkADgAb78M1HWxxYjUqsvzggNHc7cWqWBHMgpnJaqm8CQQCztze4D7uAk7OC9MJHY5eE980J8Kk+GEZKxz4LahzU6V6dcb9GFac3wEtgilj/tOAn9y0/Q8sm9vvCIbMDzgzJAkEAqRYcqhF26LdVDOX25DHMBgLKISDQZFbsjA13M4/usHL4i+mjHrc0BcUOHu59NpuDI65HitzLAUSLr5zXSdUmiQJAW77wOg4GCejdXsB3IhzMsHwU97sdm26nC+vVV9xvJZ6Rx8zW+f9543NOx9U5BCmhuaVtOvvwDU9PTVcI3atmSQJAXAIJ5gGdtXx0DXiX4VvzNFHqgaqHMGvXyjNVkU2FYQbSAd2A6app4uRO+BkZu9dSjh14m+oXMnV2HzAN2rRnjA== |
| | |
| | | select * from member_coin_address
|
| | | where symbol=#{symbol}
|
| | | </select>
|
| | |
|
| | | <select id="selectAllSymbolAddress" resultType="string" parameterType="map">
|
| | | select address from member_coin_address where symbol =#{symbol}
|
| | | <if test="tag!=null and tag !=''">
|
| | | and tag = #{tag}
|
| | | </if>
|
| | | </select>
|
| | | </mapper> |
| | |
| | | order by create_time desc
|
| | | </select>
|
| | |
|
| | | <select id="sumTodayBuyAmount" resultType="java.math.BigDecimal">
|
| | | select sum(symbol_cnt) from coins_order_deal
|
| | | where member_id = #{memberId} and symbol=#{symbol}
|
| | | and order_type =1
|
| | | and order_status=3
|
| | | and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d')
|
| | | </select>
|
| | | <select id="sumTodayEntrustCntBuyAmount" resultType="java.math.BigDecimal">
|
| | | select sum(entrust_cnt) from coins_order
|
| | | where member_id = #{memberId} and symbol=#{symbol}
|
| | | and order_type =1
|
| | | and order_status=1
|
| | | and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d')
|
| | | </select>
|
| | |
|
| | | <select id="selectCoinOrderDealByOrderId" resultType="com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity">
|
| | | select * from coins_order_deal where order_id = #{orderId}
|
| | | order by create_time desc
|
| | | </select>
|
| | |
|
| | |
|
| | | <select id="selectOrderCoinDealByTime" resultType="com.xcong.excoin.trade.ExchangeTrade">
|
| | | SELECT
|
| | | symbol symbol,
|
| | |
| | | </foreach>
|
| | | </if>
|
| | | </select>
|
| | |
|
| | | <update id="updateDeal" parameterType="map">
|
| | | update coins_order
|
| | | <set>
|
| | | <if test="dealCnt!=null">
|
| | | deal_cnt = deal_cnt+#{dealCnt},
|
| | | </if>
|
| | | <if test="dealAmount!=null">
|
| | | deal_amount = deal_amount+#{dealAmount},
|
| | | </if>
|
| | | </set>
|
| | | where id = #{id}
|
| | | </update>
|
| | | </mapper>
|