Compare commits
6 Commits
huy-featur
...
huy-featur
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ef7b46038 | ||
|
|
9785a391a2 | ||
|
|
5b3504f32a | ||
|
|
f67af0d3e9 | ||
|
|
af21d583d9 | ||
|
|
3255012fba |
@@ -41,23 +41,23 @@ public class StockMarketLaunch implements CommandLineRunner {
|
|||||||
MDC.put(MdcUtil.TRACE_ID, MdcUtil.getTraceId());
|
MDC.put(MdcUtil.TRACE_ID, MdcUtil.getTraceId());
|
||||||
log.info("StockMarketLaunch RUNNING....");
|
log.info("StockMarketLaunch RUNNING....");
|
||||||
|
|
||||||
// String marketDomain = env.getProperty("market.domain");
|
String marketDomain = env.getProperty("market.domain");
|
||||||
// if(StringUtils.isNotBlank(marketDomain)) {
|
if(StringUtils.isNotBlank(marketDomain)) {
|
||||||
// log.info("发现marketDomain: {}", marketDomain);
|
log.info("发现marketDomain: {}", marketDomain);
|
||||||
// SiteSetting siteSetting = SiteSettingRepository.of().get();
|
SiteSetting siteSetting = SiteSettingRepository.of().get();
|
||||||
// if(siteSetting == null) {
|
if(siteSetting == null) {
|
||||||
// log.info("找不到siteSetting信息, 无法设置");
|
log.info("找不到siteSetting信息, 无法设置");
|
||||||
// } else {
|
} else {
|
||||||
// log.info("设置前: {}", JSON.toJSONString(siteSetting));
|
log.info("设置前: {}", JSON.toJSONString(siteSetting));
|
||||||
// boolean flag = siteSetting.checkAndAddIfNoExists(marketDomain);
|
boolean flag = siteSetting.checkAndAddIfNoExists(marketDomain);
|
||||||
// if(! flag) {
|
if(! flag) {
|
||||||
// SiteSettingRepository.of().saveAndFlush(siteSetting);
|
SiteSettingRepository.of().saveAndFlush(siteSetting);
|
||||||
// log.info("已经设置: {}....", JSON.toJSONString(siteSetting));
|
log.info("已经设置: {}....", JSON.toJSONString(siteSetting));
|
||||||
// } else {
|
} else {
|
||||||
// log.info("包含, 跳过....");
|
log.info("包含, 跳过....");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Bean
|
// @Bean
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ public class StockRepository extends LocalCacheRepository<Stock, StockPO, Intege
|
|||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Stock> cacheGidMap() {
|
||||||
|
Map<String, Stock> map = cacheList().stream().collect(Collectors.toMap(Stock::getStockGid, val -> val, (u, v) -> u));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Stock> cacheNameMap() {
|
public Map<String, Stock> cacheNameMap() {
|
||||||
Map<String, Stock> map = cacheList()
|
Map<String, Stock> map = cacheList()
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ import cn.hutool.core.text.StrFormatter;
|
|||||||
import cn.stock.market.dto.model.*;
|
import cn.stock.market.dto.model.*;
|
||||||
import cn.stock.market.infrastructure.api.EttechchartsApis;
|
import cn.stock.market.infrastructure.api.EttechchartsApis;
|
||||||
import cn.stock.market.infrastructure.api.GrowwInApis;
|
import cn.stock.market.infrastructure.api.GrowwInApis;
|
||||||
|
import cn.stock.market.infrastructure.api.HomeApiIndex;
|
||||||
import cn.stock.market.infrastructure.api.TodayApis;
|
import cn.stock.market.infrastructure.api.TodayApis;
|
||||||
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo;
|
import cn.stock.market.infrastructure.api.investing.*;
|
||||||
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
|
|
||||||
import cn.stock.market.infrastructure.api.investing.InvestingApis;
|
|
||||||
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
|
|
||||||
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
|
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
|
||||||
import cn.stock.market.utils.*;
|
import cn.stock.market.utils.*;
|
||||||
import com.ag.utils.CollectionUtils;
|
import com.ag.utils.CollectionUtils;
|
||||||
@@ -1048,70 +1046,33 @@ public class StockService {
|
|||||||
return ServerResponse.createBySuccess(indexVoList);
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerResponse getIndexByBtoday(){
|
public ServerResponse getIndexByBtoday() throws Exception {
|
||||||
List<IndiaIndexVo> indexVoList = new ArrayList<>();
|
List<StockIndex> list = HomeApiIndex.fetchStockIndices();
|
||||||
try {
|
|
||||||
String exchange = "bse";
|
List<IndiaIndexNewVo> indexVoList = new ArrayList<>();
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
|
||||||
String coCode = "20558";
|
for (StockIndex stockIndex : list) {
|
||||||
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
IndiaIndexNewVo vo1 = new IndiaIndexNewVo();
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
market.setName("BSESENSEX指数");
|
market.setClose(String.valueOf(stockIndex.getClose()));
|
||||||
|
market.setHigh(String.valueOf(stockIndex.getHigh()));
|
||||||
|
market.setLow(String.valueOf(stockIndex.getLow()));
|
||||||
|
market.setName(stockIndex.getName());
|
||||||
|
market.setNowPrice(String.valueOf(stockIndex.getClose()));
|
||||||
|
market.setOpen(String.valueOf(stockIndex.getOpen()));
|
||||||
|
market.setRate(String.valueOf(stockIndex.getPercentChange()));
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
//获取k线图 1D 当天的数据
|
List<ChartCandle> kLines = HomeApiIndex.fetchChartData(stockIndex.getId(), 419);
|
||||||
String format = "S";
|
// List kline = HomeApiIndex.convertToJsonList(kLines);
|
||||||
String durationType = "D";
|
vo1.setKLine(kLines);
|
||||||
String duration = "1";
|
|
||||||
List kine = TodayApis.getStockKline(exchange,coCode,format,durationType,duration);
|
|
||||||
vo1.setKLine(kine);
|
|
||||||
indexVoList.add(vo1);
|
indexVoList.add(vo1);
|
||||||
}catch (Exception e){
|
|
||||||
log.error("BToday获取BSESENSEX指数数据异常,异常信息。。。。", e);
|
|
||||||
try {
|
|
||||||
GrowwInApis.requestSenSexData(indexVoList);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
log.error("GrowwIn获取BSESENSEX指数数据异常,异常信息。。。。", e1);
|
|
||||||
try{
|
|
||||||
EttechchartsApis.requestSensexData(indexVoList);
|
|
||||||
} catch (Exception e2) {
|
|
||||||
log.error("Ettechcharts获取BSESENSEX指数数据异常,异常信息。。。。", e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
String exchange = "nse";
|
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
|
||||||
String coCode = "20559";
|
|
||||||
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
|
|
||||||
IndiaStockVO market = objToVo(object);
|
|
||||||
market.setName("NIFTY50指数");
|
|
||||||
vo1.setIndexVo(market);
|
|
||||||
|
|
||||||
//获取k线图 1D 当天的数据
|
|
||||||
String format = "S";
|
|
||||||
String durationType = "D";
|
|
||||||
String duration = "1";
|
|
||||||
List kine = TodayApis.getStockKline(exchange,coCode,format,durationType,duration);
|
|
||||||
vo1.setKLine(kine);
|
|
||||||
indexVoList.add(vo1);
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error("BToday获取NIFTY50指数数据异常,异常信息。。。。", e);
|
|
||||||
try {
|
|
||||||
GrowwInApis.requestNifty50Data(indexVoList);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
log.error("GrowwIn获取NIFTY50指数数据异常,异常信息。。。。", e1);
|
|
||||||
try{
|
|
||||||
EttechchartsApis.requestNifty50Data(indexVoList);
|
|
||||||
} catch (Exception e2) {
|
|
||||||
log.error("Ettechcharts获取NIFTY50指数数据异常,异常信息。。。。", e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ServerResponse.createBySuccess(indexVoList);
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndiaStockVO objToVo(JSONObject object){
|
private IndiaStockVO objToVo(JSONObject object){
|
||||||
IndiaStockVO market = new IndiaStockVO();
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
if(object.containsKey("priceprevclose")){
|
if(object.containsKey("priceprevclose")){
|
||||||
|
|||||||
11
src/main/java/cn/stock/market/dto/model/ChartCandle.java
Normal file
11
src/main/java/cn/stock/market/dto/model/ChartCandle.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package cn.stock.market.dto.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChartCandle {
|
||||||
|
private String upd_date;
|
||||||
|
private Double price;
|
||||||
|
|
||||||
|
// Getters & Setters (hoặc @Data nếu dùng Lombok)
|
||||||
|
}
|
||||||
31
src/main/java/cn/stock/market/dto/model/StockIndex.java
Normal file
31
src/main/java/cn/stock/market/dto/model/StockIndex.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package cn.stock.market.dto.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StockIndex {
|
||||||
|
private String id;
|
||||||
|
private String symbol;
|
||||||
|
private String name;
|
||||||
|
private String exchange;
|
||||||
|
private String micCode;
|
||||||
|
private String datetime;
|
||||||
|
private long timestamp;
|
||||||
|
private Double open;
|
||||||
|
private Double high;
|
||||||
|
private Double low;
|
||||||
|
private Double close;
|
||||||
|
private Long volume;
|
||||||
|
private Double previousClose;
|
||||||
|
private Double change;
|
||||||
|
private Double percentChange;
|
||||||
|
private Long averageVolume;
|
||||||
|
private Boolean isMarketOpen;
|
||||||
|
private Long marketCap;
|
||||||
|
private String fiftyTwoWeek;
|
||||||
|
private Integer icon;
|
||||||
|
|
||||||
|
// Getters & setters (hoặc dùng @Data nếu có Lombok)
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package cn.stock.market.infrastructure.api;
|
||||||
|
import cn.stock.market.dto.model.ChartCandle;
|
||||||
|
import cn.stock.market.dto.model.StockIndex;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HomeApiIndex {
|
||||||
|
private static final OkHttpClient client = new OkHttpClient();
|
||||||
|
private static final String API_URL = "https://apinode-dgdev.moneytj.com/api/ger-market/stocks/query-list?symbols=XETR:DAX,XETR:MDAX,XETR:SDXP,XETR:HDAX";
|
||||||
|
private static final String BASE_URL = "https://apinode-dgdev.moneytj.com/api/ger-market/chart";
|
||||||
|
|
||||||
|
public static List<StockIndex> fetchStockIndices() throws Exception {
|
||||||
|
List<StockIndex> result = new ArrayList<>();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(API_URL)
|
||||||
|
.addHeader("User-Agent", "Mozilla/5.0")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new RuntimeException("HTTP error code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
String body = response.body().string();
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
JSONArray data = json.getJSONArray("data");
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length(); i++) {
|
||||||
|
JSONObject obj = data.getJSONObject(i);
|
||||||
|
StockIndex index = new StockIndex();
|
||||||
|
|
||||||
|
index.setId(obj.optString("id"));
|
||||||
|
index.setSymbol(obj.optString("symbol"));
|
||||||
|
index.setName(obj.optString("name"));
|
||||||
|
index.setExchange(obj.optString("exchange"));
|
||||||
|
index.setMicCode(obj.optString("mic_code"));
|
||||||
|
index.setDatetime(obj.optString("datetime"));
|
||||||
|
index.setTimestamp(obj.optLong("timestamp"));
|
||||||
|
index.setOpen(getDoubleOrNull(obj, "open"));
|
||||||
|
index.setHigh(getDoubleOrNull(obj, "high"));
|
||||||
|
index.setLow(getDoubleOrNull(obj, "low"));
|
||||||
|
index.setClose(getDoubleOrNull(obj, "close"));
|
||||||
|
index.setVolume(getLongOrNull(obj, "volume"));
|
||||||
|
index.setPreviousClose(getDoubleOrNull(obj, "previous_close"));
|
||||||
|
index.setChange(getDoubleOrNull(obj, "change"));
|
||||||
|
index.setPercentChange(getDoubleOrNull(obj, "percent_change"));
|
||||||
|
index.setAverageVolume(getLongOrNull(obj, "average_volume"));
|
||||||
|
index.setIsMarketOpen(obj.optBoolean("is_market_open"));
|
||||||
|
index.setMarketCap(getLongOrNull(obj, "market_cap"));
|
||||||
|
index.setFiftyTwoWeek(obj.optString("fifty_two_week", null));
|
||||||
|
index.setIcon(obj.optInt("icon", 0));
|
||||||
|
|
||||||
|
result.add(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ChartCandle> fetchChartData(String symbol, int amount) throws Exception {
|
||||||
|
List<ChartCandle> result = new ArrayList<>();
|
||||||
|
|
||||||
|
String url = BASE_URL + "?symbol=" + symbol + "&interval=D&amount=" + amount;
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("User-Agent", "Mozilla/5.0")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new RuntimeException("HTTP error code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
String body = response.body().string();
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
JSONArray data = json.getJSONArray("data");
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length(); i++) {
|
||||||
|
JSONObject obj = data.getJSONObject(i);
|
||||||
|
ChartCandle candle = new ChartCandle();
|
||||||
|
|
||||||
|
long ts = obj.optLong("time");
|
||||||
|
String formattedTime = convertToGermanTime(ts);
|
||||||
|
|
||||||
|
candle.setUpd_date(formattedTime);
|
||||||
|
candle.setPrice(getDoubleOrNull(obj, "close"));
|
||||||
|
|
||||||
|
result.add(candle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static List<JSONObject> convertToJsonList(List<ChartCandle> candles) {
|
||||||
|
// List<JSONObject> result = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (ChartCandle c : candles) {
|
||||||
|
// JSONObject obj = new JSONObject();
|
||||||
|
// String formattedTime = convertToGermanTime(c.getTime());
|
||||||
|
// obj.put("upd_date", formattedTime);
|
||||||
|
// obj.put("price", c.getClose());
|
||||||
|
// result.add(obj);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static String convertToGermanTime(long epochSeconds) {
|
||||||
|
ZoneId germanyZone = ZoneId.of("Europe/Berlin");
|
||||||
|
Instant instant = Instant.ofEpochSecond(epochSeconds);
|
||||||
|
ZonedDateTime zonedDateTime = instant.atZone(germanyZone);
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||||
|
return formatter.format(zonedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to safely parse nullable numbers
|
||||||
|
private static Double getDoubleOrNull(JSONObject obj, String key) {
|
||||||
|
return obj.isNull(key) ? null : obj.optDouble(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Long getLongOrNull(JSONObject obj, String key) {
|
||||||
|
return obj.isNull(key) ? null : obj.optLong(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.stock.market.infrastructure.api.investing;
|
||||||
|
|
||||||
|
import cn.stock.market.dto.model.ChartCandle;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel(value = "指数信息")
|
||||||
|
public class IndiaIndexNewVo {
|
||||||
|
@ApiModelProperty(value = "指数详情")
|
||||||
|
private IndiaStockVO indexVo;
|
||||||
|
@ApiModelProperty(value = "指数k线")
|
||||||
|
private List<ChartCandle> kLine;
|
||||||
|
}
|
||||||
@@ -110,7 +110,7 @@ public class InvestingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*新闻接口*/
|
/*新闻接口*/
|
||||||
@Scheduled(cron = "0 0 0/3 * * ?")
|
// @Scheduled(cron = "0 0 0/3 * * ?")
|
||||||
public void saveStockNews() {
|
public void saveStockNews() {
|
||||||
log.info("英文股票新闻数据同步开始");
|
log.info("英文股票新闻数据同步开始");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class RealTimeTask {
|
|||||||
|
|
||||||
/*每天9点定时删除股票k线数据*/
|
/*每天9点定时删除股票k线数据*/
|
||||||
@Transactional
|
@Transactional
|
||||||
@Scheduled(cron = "0 00 9 * * MON-FRI")
|
// @Scheduled(cron = "0 00 9 * * MON-FRI")
|
||||||
public void deleteStockCode() {
|
public void deleteStockCode() {
|
||||||
log.info("每天9点定时删除股票k线数据");
|
log.info("每天9点定时删除股票k线数据");
|
||||||
repo.deleteStockCode();
|
repo.deleteStockCode();
|
||||||
@@ -24,7 +24,7 @@ public class RealTimeTask {
|
|||||||
|
|
||||||
/*每天0点定时删除期货k线数据*/
|
/*每天0点定时删除期货k线数据*/
|
||||||
@Transactional
|
@Transactional
|
||||||
@Scheduled(cron = "0 00 0 * * MON-FRI")
|
// @Scheduled(cron = "0 00 0 * * MON-FRI")
|
||||||
public void deleteStockFuturesCode() {
|
public void deleteStockFuturesCode() {
|
||||||
log.info("每天0点定时删除期货k线数据");
|
log.info("每天0点定时删除期货k线数据");
|
||||||
repo.deleteStockFuturesCode();
|
repo.deleteStockFuturesCode();
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class Scraper {
|
|||||||
private boolean times = false;
|
private boolean times = false;
|
||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 1 */2 * ?")
|
// @Scheduled(cron = "0 0 1 */2 * ?")
|
||||||
@RequestMapping("/testScraperGetBusinessToday")
|
@RequestMapping("/testScraperGetBusinessToday")
|
||||||
public void schedule() {
|
public void schedule() {
|
||||||
String BASE_URL = "https://akm-img-a-in.tosshub.com/businesstoday/resource/market-widgets/prod/company-master-23-01-2023.json";
|
String BASE_URL = "https://akm-img-a-in.tosshub.com/businesstoday/resource/market-widgets/prod/company-master-23-01-2023.json";
|
||||||
@@ -110,7 +110,7 @@ public class Scraper {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 18 * * ?")
|
// @Scheduled(cron = "0 0 18 * * ?")
|
||||||
// @PostConstruct
|
// @PostConstruct
|
||||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||||
public void getMoneyControllerNewIPOSchedule() {
|
public void getMoneyControllerNewIPOSchedule() {
|
||||||
@@ -303,7 +303,7 @@ public class Scraper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 19 * * ?")
|
// @Scheduled(cron = "0 0 19 * * ?")
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@RequestMapping("/addMoneyStock")
|
@RequestMapping("/addMoneyStock")
|
||||||
public void addMoneyStock() {
|
public void addMoneyStock() {
|
||||||
|
|||||||
@@ -12,112 +12,101 @@ import cn.stock.market.domain.basic.entity.StockTemp;
|
|||||||
import cn.stock.market.domain.basic.repository.StockRepository;
|
import cn.stock.market.domain.basic.repository.StockRepository;
|
||||||
import cn.stock.market.domain.basic.repository.StockTempRepository;
|
import cn.stock.market.domain.basic.repository.StockTempRepository;
|
||||||
import cn.stock.market.dto.model.Symbol;
|
import cn.stock.market.dto.model.Symbol;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class StockNewTask {
|
public class StockNewTask {
|
||||||
final StockTempRepository repository;
|
|
||||||
private static final OkHttpClient client = new OkHttpClient();
|
private static final OkHttpClient client = new OkHttpClient();
|
||||||
private static final String BASE_URL = "https://symbol-search.tradingview.com/symbol_search/v3/";
|
private static final String BASE_URL = "https://symbol-search.tradingview.com/symbol_search/v3/";
|
||||||
private static final String PARAMS = "?start=%d&hl=1&country=DE&lang=en&search_type=stocks&domain=production&sort_by_country=US&promo=true&exchange=XETR";
|
private static final String PARAMS = "?start={start}&hl=1&country=DE&lang=en&search_type=stocks&domain=production&sort_by_country=US&promo=true&exchange={exchange}";
|
||||||
|
|
||||||
public StockNewTask(StockTempRepository repository) {
|
@Autowired
|
||||||
this.repository = repository;
|
StockRepository stockRepository;
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void test() throws Exception {
|
|
||||||
List<Symbol> allSymbols = new ArrayList<>();
|
|
||||||
int start = 0;
|
|
||||||
int symbolsRemaining;
|
|
||||||
|
|
||||||
do {
|
// @PostConstruct
|
||||||
int finalStart = start;
|
@Scheduled(cron = "0 01 22 * * ?")
|
||||||
if(start > 0){
|
public void syncStock() throws Exception {
|
||||||
finalStart = start + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String url = BASE_URL + String.format(PARAMS, finalStart);
|
int limit = 20000;
|
||||||
Request request = new Request.Builder()
|
List<String> exchanges = Arrays.asList("BER", "DUS", "HAM", "HAN", "MUN", "SWB", "FWB", "XETR");
|
||||||
.url(url)
|
Map<String, Stock> stockGidMap = stockRepository.cacheGidMap();
|
||||||
.addHeader("Origin", "https://www.tradingview.com")
|
for (String exchange : exchanges) {
|
||||||
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
List<Stock> newStocks = new ArrayList<>();
|
||||||
.addHeader("Accept", "application/json, text/plain, */*")
|
int start = 0;
|
||||||
.addHeader("Referer", "https://www.tradingview.com/")
|
int symbolsRemaining;
|
||||||
.build();
|
do {
|
||||||
|
int finalStart = start;
|
||||||
|
if(start > 0){
|
||||||
|
finalStart = start + 1;
|
||||||
|
}
|
||||||
|
String url = BASE_URL + PARAMS.replace("{start}", String.valueOf(finalStart)).replace("{exchange}", exchange);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("Origin", "https://www.tradingview.com")
|
||||||
|
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||||
|
.addHeader("Accept", "application/json, text/plain, */*")
|
||||||
|
.addHeader("Referer", "https://www.tradingview.com/")
|
||||||
|
.build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
throw new RuntimeException("Unexpected response code: " + response.code());
|
throw new RuntimeException("Unexpected response code: " + response.code());
|
||||||
}
|
}
|
||||||
|
|
||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
JSONObject json = new JSONObject(responseBody);
|
JSONObject json = new JSONObject(responseBody);
|
||||||
JSONArray symbols = json.getJSONArray("symbols");
|
JSONArray symbols = json.getJSONArray("symbols");
|
||||||
symbolsRemaining = json.getInt("symbols_remaining");
|
symbolsRemaining = json.getInt("symbols_remaining");
|
||||||
|
|
||||||
for (int i = 0; i < symbols.length(); i++) {
|
for (int i = 0; i < symbols.length(); i++) {
|
||||||
JSONObject s = symbols.getJSONObject(i);
|
JSONObject s = symbols.getJSONObject(i);
|
||||||
Symbol symbol = new Symbol();
|
if (s.optString("type").equals("stock") && !stockGidMap.containsKey(s.optString("exchange") + ":" + s.getString("symbol"))) {
|
||||||
|
Stock stock = new Stock();
|
||||||
symbol.setSymbol(s.optString("symbol"));
|
stock.setStockGid(s.optString("exchange") + ":" +s.getString("symbol"));
|
||||||
symbol.setDescription(s.optString("description"));
|
stock.setStockCode(stock.getStockGid());
|
||||||
symbol.setType(s.optString("type"));
|
stock.setStockSpell(s.optString("symbol"));
|
||||||
symbol.setExchange(s.optString("exchange"));
|
stock.setStockName(s.optString("description"));
|
||||||
symbol.setCurrencyCode(s.optString("currency_code"));
|
stock.setStockSymbol(s.optString("symbol"));
|
||||||
symbol.setCurrencyLogoid(s.optString("currency-logoid"));
|
stock.setStockType(s.optString("exchange"));
|
||||||
symbol.setLogoid(s.optString("logoid"));
|
stock.setIsLock(0);
|
||||||
symbol.setProviderId(s.optString("provider_id"));
|
stock.setIsShow(0);
|
||||||
symbol.setSourceLogoid("https://s3-symbol-logo.tradingview.com/" + s.optString("source_logoid") + "--big.svg");
|
stock.setAddTime(new Date());
|
||||||
symbol.setSourceId(s.optString("source_id"));
|
stock.setStockState(0);
|
||||||
symbol.setCountry(s.optString("country"));
|
stock.setStockPlate("https://s3-symbol-logo.tradingview.com/" + s.optString("source_logoid") + "--big.svg");
|
||||||
symbol.setPrimaryListing(s.optBoolean("is_primary_listing", false));
|
newStocks.add(stock);
|
||||||
symbol.setStockGid(symbol.getExchange() + ":" + symbol.getSymbol());
|
stockGidMap.put(s.optString("exchange") + ":" + s.getString("symbol"), stock);
|
||||||
// typespecs array
|
|
||||||
JSONArray typespecsArr = s.optJSONArray("typespecs");
|
|
||||||
List<String> typespecsList = new ArrayList<>();
|
|
||||||
if (typespecsArr != null) {
|
|
||||||
for (int j = 0; j < typespecsArr.length(); j++) {
|
|
||||||
typespecsList.add(typespecsArr.getString(j));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
symbol.setTypespecs(typespecsList);
|
Thread.sleep(500);
|
||||||
|
|
||||||
allSymbols.add(symbol);
|
start += symbols.length();
|
||||||
}
|
System.out.println("Fetched: " + symbols.length() + ", Remaining: " + symbolsRemaining);
|
||||||
|
try {
|
||||||
|
if (!newStocks.isEmpty()) {
|
||||||
|
stockRepository.saveAll(newStocks);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("Insert stock failed: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
Thread.sleep(1000);
|
if (start >= limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
start += symbols.length();
|
} while (symbolsRemaining > 0);
|
||||||
System.out.println("Fetched: " + symbols.length() + ", Remaining: " + symbolsRemaining);
|
|
||||||
|
|
||||||
} while (symbolsRemaining > 0);
|
|
||||||
|
|
||||||
// Output test
|
|
||||||
for (int i = 0; i < Math.min(5, allSymbols.size()); i++) {
|
|
||||||
Symbol s = allSymbols.get(i);
|
|
||||||
System.out.println(s.getSymbol() + " - " + s.getDescription());
|
|
||||||
}
|
|
||||||
// Lúc này bạn có thể insert vào DB hoặc return từ service
|
|
||||||
|
|
||||||
allSymbols = allSymbols.stream().filter(x -> x.getType().equals("stock")).collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<StockTemp> stockTemps = repository.findAllForCheck();
|
|
||||||
|
|
||||||
if(stockTemps != null && !stockTemps.isEmpty()){
|
|
||||||
for (Symbol symbol : allSymbols) {
|
|
||||||
if((symbol.getSymbol() + ":" + symbol.getExchange()).contains())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
repository.of().saveAll(stockTemps);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class StockTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*同步股票列表*/
|
/*同步股票列表*/
|
||||||
@Scheduled(cron = "0 0 6 * * ?")
|
// @Scheduled(cron = "0 0 6 * * ?")
|
||||||
public void syncAFutureStockList() {
|
public void syncAFutureStockList() {
|
||||||
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
|
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
|
||||||
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||||
@@ -154,7 +154,7 @@ public class StockTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*同步股票列表*/
|
/*同步股票列表*/
|
||||||
@Scheduled(cron = "0 0 6 * * ?")
|
// @Scheduled(cron = "0 0 6 * * ?")
|
||||||
public void syncAStockList() {
|
public void syncAStockList() {
|
||||||
MdcUtil.setTraceIdIfAbsent();
|
MdcUtil.setTraceIdIfAbsent();
|
||||||
Config config = SpringUtils.getBean(Config.class);
|
Config config = SpringUtils.getBean(Config.class);
|
||||||
|
|||||||
@@ -249,8 +249,12 @@ public class StockApiController {
|
|||||||
public ServerResponse getIndiaIndexByToday() {
|
public ServerResponse getIndiaIndexByToday() {
|
||||||
String INDEX_CODE = "TODAY_INDEX";
|
String INDEX_CODE = "TODAY_INDEX";
|
||||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||||
return this.stockService.getIndexByBtoday();
|
try {
|
||||||
});
|
return this.stockService.getIndexByBtoday();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@RequestMapping({"getIndiaIndexByEttech.do"})
|
@RequestMapping({"getIndiaIndexByEttech.do"})
|
||||||
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
|
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ spring:
|
|||||||
redis:
|
redis:
|
||||||
host: 43.153.142.41
|
host: 43.153.142.41
|
||||||
password: a5v8b86P4mVzFlUqJV
|
password: a5v8b86P4mVzFlUqJV
|
||||||
port: 30001
|
port: 30041
|
||||||
database: 1
|
database: 1
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -17,7 +17,7 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
stock-market:
|
stock-market:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://43.153.142.41:30000/india_stock?useUnicode=true&characterEncoding=utf-8
|
url: jdbc:mysql://43.153.142.41:30040/germany_stock?useUnicode=true&characterEncoding=utf-8
|
||||||
username: root
|
username: root
|
||||||
password: uNejHIFQGJOUtYTmE
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
|
|||||||
Reference in New Issue
Block a user