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());
|
||||
log.info("StockMarketLaunch RUNNING....");
|
||||
|
||||
// String marketDomain = env.getProperty("market.domain");
|
||||
// if(StringUtils.isNotBlank(marketDomain)) {
|
||||
// log.info("发现marketDomain: {}", marketDomain);
|
||||
// SiteSetting siteSetting = SiteSettingRepository.of().get();
|
||||
// if(siteSetting == null) {
|
||||
// log.info("找不到siteSetting信息, 无法设置");
|
||||
// } else {
|
||||
// log.info("设置前: {}", JSON.toJSONString(siteSetting));
|
||||
// boolean flag = siteSetting.checkAndAddIfNoExists(marketDomain);
|
||||
// if(! flag) {
|
||||
// SiteSettingRepository.of().saveAndFlush(siteSetting);
|
||||
// log.info("已经设置: {}....", JSON.toJSONString(siteSetting));
|
||||
// } else {
|
||||
// log.info("包含, 跳过....");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
String marketDomain = env.getProperty("market.domain");
|
||||
if(StringUtils.isNotBlank(marketDomain)) {
|
||||
log.info("发现marketDomain: {}", marketDomain);
|
||||
SiteSetting siteSetting = SiteSettingRepository.of().get();
|
||||
if(siteSetting == null) {
|
||||
log.info("找不到siteSetting信息, 无法设置");
|
||||
} else {
|
||||
log.info("设置前: {}", JSON.toJSONString(siteSetting));
|
||||
boolean flag = siteSetting.checkAndAddIfNoExists(marketDomain);
|
||||
if(! flag) {
|
||||
SiteSettingRepository.of().saveAndFlush(siteSetting);
|
||||
log.info("已经设置: {}....", JSON.toJSONString(siteSetting));
|
||||
} else {
|
||||
log.info("包含, 跳过....");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Bean
|
||||
|
||||
@@ -55,6 +55,11 @@ public class StockRepository extends LocalCacheRepository<Stock, StockPO, Intege
|
||||
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() {
|
||||
Map<String, Stock> map = cacheList()
|
||||
.stream().collect(Collectors.toMap(Stock::getStockName, val -> val, (u, v) -> u));
|
||||
|
||||
@@ -13,11 +13,9 @@ import cn.hutool.core.text.StrFormatter;
|
||||
import cn.stock.market.dto.model.*;
|
||||
import cn.stock.market.infrastructure.api.EttechchartsApis;
|
||||
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.investing.IndiaIndexVo;
|
||||
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.investing.*;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
|
||||
import cn.stock.market.utils.*;
|
||||
import com.ag.utils.CollectionUtils;
|
||||
@@ -1048,70 +1046,33 @@ public class StockService {
|
||||
return ServerResponse.createBySuccess(indexVoList);
|
||||
}
|
||||
|
||||
public ServerResponse getIndexByBtoday(){
|
||||
List<IndiaIndexVo> indexVoList = new ArrayList<>();
|
||||
try {
|
||||
String exchange = "bse";
|
||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||
String coCode = "20558";
|
||||
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
||||
IndiaStockVO market = objToVo(object);
|
||||
market.setName("BSESENSEX指数");
|
||||
public ServerResponse getIndexByBtoday() throws Exception {
|
||||
List<StockIndex> list = HomeApiIndex.fetchStockIndices();
|
||||
|
||||
List<IndiaIndexNewVo> indexVoList = new ArrayList<>();
|
||||
|
||||
for (StockIndex stockIndex : list) {
|
||||
IndiaIndexNewVo vo1 = new IndiaIndexNewVo();
|
||||
IndiaStockVO market = new IndiaStockVO();
|
||||
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);
|
||||
|
||||
//获取k线图 1D 当天的数据
|
||||
String format = "S";
|
||||
String durationType = "D";
|
||||
String duration = "1";
|
||||
List kine = TodayApis.getStockKline(exchange,coCode,format,durationType,duration);
|
||||
vo1.setKLine(kine);
|
||||
List<ChartCandle> kLines = HomeApiIndex.fetchChartData(stockIndex.getId(), 419);
|
||||
// List kline = HomeApiIndex.convertToJsonList(kLines);
|
||||
vo1.setKLine(kLines);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
private IndiaStockVO objToVo(JSONObject object){
|
||||
IndiaStockVO market = new IndiaStockVO();
|
||||
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() {
|
||||
log.info("英文股票新闻数据同步开始");
|
||||
try {
|
||||
|
||||
@@ -16,7 +16,7 @@ public class RealTimeTask {
|
||||
|
||||
/*每天9点定时删除股票k线数据*/
|
||||
@Transactional
|
||||
@Scheduled(cron = "0 00 9 * * MON-FRI")
|
||||
// @Scheduled(cron = "0 00 9 * * MON-FRI")
|
||||
public void deleteStockCode() {
|
||||
log.info("每天9点定时删除股票k线数据");
|
||||
repo.deleteStockCode();
|
||||
@@ -24,7 +24,7 @@ public class RealTimeTask {
|
||||
|
||||
/*每天0点定时删除期货k线数据*/
|
||||
@Transactional
|
||||
@Scheduled(cron = "0 00 0 * * MON-FRI")
|
||||
// @Scheduled(cron = "0 00 0 * * MON-FRI")
|
||||
public void deleteStockFuturesCode() {
|
||||
log.info("每天0点定时删除期货k线数据");
|
||||
repo.deleteStockFuturesCode();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class Scraper {
|
||||
private boolean times = false;
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 1 */2 * ?")
|
||||
// @Scheduled(cron = "0 0 1 */2 * ?")
|
||||
@RequestMapping("/testScraperGetBusinessToday")
|
||||
public void schedule() {
|
||||
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
|
||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||
public void getMoneyControllerNewIPOSchedule() {
|
||||
@@ -303,7 +303,7 @@ public class Scraper {
|
||||
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 19 * * ?")
|
||||
// @Scheduled(cron = "0 0 19 * * ?")
|
||||
@PostConstruct
|
||||
@RequestMapping("/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.StockTempRepository;
|
||||
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.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StockNewTask {
|
||||
final StockTempRepository repository;
|
||||
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 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) {
|
||||
this.repository = repository;
|
||||
}
|
||||
@Autowired
|
||||
StockRepository stockRepository;
|
||||
|
||||
@PostConstruct
|
||||
public void test() throws Exception {
|
||||
List<Symbol> allSymbols = new ArrayList<>();
|
||||
int start = 0;
|
||||
int symbolsRemaining;
|
||||
|
||||
do {
|
||||
int finalStart = start;
|
||||
if(start > 0){
|
||||
finalStart = start + 1;
|
||||
}
|
||||
// @PostConstruct
|
||||
@Scheduled(cron = "0 01 22 * * ?")
|
||||
public void syncStock() throws Exception {
|
||||
|
||||
String url = BASE_URL + String.format(PARAMS, finalStart);
|
||||
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();
|
||||
int limit = 20000;
|
||||
List<String> exchanges = Arrays.asList("BER", "DUS", "HAM", "HAN", "MUN", "SWB", "FWB", "XETR");
|
||||
Map<String, Stock> stockGidMap = stockRepository.cacheGidMap();
|
||||
for (String exchange : exchanges) {
|
||||
List<Stock> newStocks = new ArrayList<>();
|
||||
int start = 0;
|
||||
int symbolsRemaining;
|
||||
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()) {
|
||||
throw new RuntimeException("Unexpected response code: " + response.code());
|
||||
}
|
||||
if (!response.isSuccessful()) {
|
||||
throw new RuntimeException("Unexpected response code: " + response.code());
|
||||
}
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject json = new JSONObject(responseBody);
|
||||
JSONArray symbols = json.getJSONArray("symbols");
|
||||
symbolsRemaining = json.getInt("symbols_remaining");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject json = new JSONObject(responseBody);
|
||||
JSONArray symbols = json.getJSONArray("symbols");
|
||||
symbolsRemaining = json.getInt("symbols_remaining");
|
||||
|
||||
for (int i = 0; i < symbols.length(); i++) {
|
||||
JSONObject s = symbols.getJSONObject(i);
|
||||
Symbol symbol = new Symbol();
|
||||
|
||||
symbol.setSymbol(s.optString("symbol"));
|
||||
symbol.setDescription(s.optString("description"));
|
||||
symbol.setType(s.optString("type"));
|
||||
symbol.setExchange(s.optString("exchange"));
|
||||
symbol.setCurrencyCode(s.optString("currency_code"));
|
||||
symbol.setCurrencyLogoid(s.optString("currency-logoid"));
|
||||
symbol.setLogoid(s.optString("logoid"));
|
||||
symbol.setProviderId(s.optString("provider_id"));
|
||||
symbol.setSourceLogoid("https://s3-symbol-logo.tradingview.com/" + s.optString("source_logoid") + "--big.svg");
|
||||
symbol.setSourceId(s.optString("source_id"));
|
||||
symbol.setCountry(s.optString("country"));
|
||||
symbol.setPrimaryListing(s.optBoolean("is_primary_listing", false));
|
||||
symbol.setStockGid(symbol.getExchange() + ":" + symbol.getSymbol());
|
||||
// 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));
|
||||
for (int i = 0; i < symbols.length(); i++) {
|
||||
JSONObject s = symbols.getJSONObject(i);
|
||||
if (s.optString("type").equals("stock") && !stockGidMap.containsKey(s.optString("exchange") + ":" + s.getString("symbol"))) {
|
||||
Stock stock = new Stock();
|
||||
stock.setStockGid(s.optString("exchange") + ":" +s.getString("symbol"));
|
||||
stock.setStockCode(stock.getStockGid());
|
||||
stock.setStockSpell(s.optString("symbol"));
|
||||
stock.setStockName(s.optString("description"));
|
||||
stock.setStockSymbol(s.optString("symbol"));
|
||||
stock.setStockType(s.optString("exchange"));
|
||||
stock.setIsLock(0);
|
||||
stock.setIsShow(0);
|
||||
stock.setAddTime(new Date());
|
||||
stock.setStockState(0);
|
||||
stock.setStockPlate("https://s3-symbol-logo.tradingview.com/" + s.optString("source_logoid") + "--big.svg");
|
||||
newStocks.add(stock);
|
||||
stockGidMap.put(s.optString("exchange") + ":" + s.getString("symbol"), stock);
|
||||
}
|
||||
}
|
||||
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();
|
||||
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);
|
||||
} while (symbolsRemaining > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class StockTask {
|
||||
}
|
||||
|
||||
/*同步股票列表*/
|
||||
@Scheduled(cron = "0 0 6 * * ?")
|
||||
// @Scheduled(cron = "0 0 6 * * ?")
|
||||
public void syncAFutureStockList() {
|
||||
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
|
||||
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() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
Config config = SpringUtils.getBean(Config.class);
|
||||
|
||||
@@ -249,8 +249,12 @@ public class StockApiController {
|
||||
public ServerResponse getIndiaIndexByToday() {
|
||||
String INDEX_CODE = "TODAY_INDEX";
|
||||
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"})
|
||||
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
|
||||
|
||||
@@ -5,7 +5,7 @@ spring:
|
||||
redis:
|
||||
host: 43.153.142.41
|
||||
password: a5v8b86P4mVzFlUqJV
|
||||
port: 30001
|
||||
port: 30041
|
||||
database: 1
|
||||
lettuce:
|
||||
pool:
|
||||
@@ -17,7 +17,7 @@ spring:
|
||||
datasource:
|
||||
stock-market:
|
||||
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
|
||||
password: uNejHIFQGJOUtYTmE
|
||||
maxActive: 500
|
||||
|
||||
Reference in New Issue
Block a user