|
|
|
@ -21,8 +21,10 @@ import com.blockchain.server.currency.redis.MarketLegalCache; |
|
|
|
|
import com.blockchain.server.currency.service.CurrencyMarketService; |
|
|
|
|
import com.blockchain.server.currency.service.CurrencyPairService; |
|
|
|
|
import com.blockchain.server.currency.websocket.WebSocketSendMsgUtils; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.redisson.api.RedissonClient; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.BeansException; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.messaging.simp.SimpMessagingTemplate; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -32,6 +34,7 @@ import java.util.*; |
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
public class CurrencyMarketServiceImpl implements CurrencyMarketService { |
|
|
|
|
|
|
|
|
@ -95,6 +98,7 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public CurrencyMarketDTO save(String coinName, String unitName, BigDecimal amount, BigDecimal total, Long timestamp, String tradingType) { |
|
|
|
|
try { |
|
|
|
|
String currencyPair = coinName + "-" + unitName; |
|
|
|
|
//检测币对是否合法
|
|
|
|
|
checkCurrency(currencyPair); |
|
|
|
@ -113,6 +117,11 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService { |
|
|
|
|
setMarketCache(dto); |
|
|
|
|
|
|
|
|
|
return dto; |
|
|
|
|
} catch (BeansException e) { |
|
|
|
|
log.error("CurrencyMarketServiceImpl.save: save error, coinName={}, unitName={}, amount={}, total={}, timestamp={}, tradingType={}", |
|
|
|
|
coinName, unitName, amount, total, timestamp, tradingType); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -122,6 +131,9 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService { |
|
|
|
|
//获取一天的K线行情
|
|
|
|
|
SortedMap<String, CurrencyMarketKDTO> map = getOneDayMarketK(currencyPair, |
|
|
|
|
MarketKTypeEnums.ONEDAY.getTimeType(), MarketKTypeEnums.ONEDAY.getTimeNumber()); |
|
|
|
|
if (map == null || map.isEmpty()) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
CurrencyMarketDTO dto = getMarketInfo(currencyPair, map); |
|
|
|
|
return dto; |
|
|
|
|
} |
|
|
|
@ -432,9 +444,9 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService { |
|
|
|
|
ktype.getTimeType(), ktype.getTimeNumber()); |
|
|
|
|
if (lock) { |
|
|
|
|
SortedMap<String, CurrencyMarketKDTO> map = marketKCache.getMarketKListCache(dto.getCurrencyPair(), ktype.getTimeType(), ktype.getTimeNumber()); |
|
|
|
|
if (map == null) |
|
|
|
|
if (map == null || map.isEmpty()) |
|
|
|
|
map = selectMarketK(dto.getCurrencyPair(), ktype.getTimeType(), ktype.getTimeNumber()); |
|
|
|
|
if (map == null) continue; |
|
|
|
|
if (map == null || map.isEmpty()) continue; |
|
|
|
|
Long timestamp = (dto.getTimestamp() / (ktype.getTimeNumber() * MarketKEnums.valueOf(ktype.getTimeType()).getSecond())) * ktype.getTimeNumber() * MarketKEnums.valueOf(ktype.getTimeType()).getSecond(); |
|
|
|
|
CurrencyMarketKDTO kdto = map.get(timestamp.toString()); |
|
|
|
|
if (kdto == null) { |
|
|
|
@ -608,7 +620,7 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService { |
|
|
|
|
*/ |
|
|
|
|
private SortedMap<String, CurrencyMarketKDTO> getOneDayMarketK(String currencyPair, String timeType, Integer timeNumber) { |
|
|
|
|
SortedMap<String, CurrencyMarketKDTO> map = marketKCache.getMarketKListCache(currencyPair, timeType, timeNumber); |
|
|
|
|
if (map == null) { |
|
|
|
|
if (map == null || map.isEmpty()) { |
|
|
|
|
boolean lock = marketKCache.tryFairLock(redissonClient, currencyPair, |
|
|
|
|
timeType, timeNumber); |
|
|
|
|
if (lock) { |
|
|
|
|