udpate
This commit is contained in:
@@ -13,6 +13,7 @@ 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;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StockNewTask {
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
private static final String BASE_URL = "https://symbol-search.tradingview.com/symbol_search/v3/";
|
||||
@@ -33,7 +35,7 @@ public class StockNewTask {
|
||||
StockRepository stockRepository;
|
||||
|
||||
|
||||
// @PostConstruct
|
||||
@PostConstruct
|
||||
@Scheduled(cron = "0 01 22 * * ?")
|
||||
public void syncStock() throws Exception {
|
||||
|
||||
@@ -85,15 +87,21 @@ public class StockNewTask {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Thread.sleep(500);
|
||||
|
||||
start += symbols.length();
|
||||
System.out.println("Fetched: " + symbols.length() + ", Remaining: " + symbolsRemaining);
|
||||
if (!newStocks.isEmpty()) {
|
||||
stockRepository.saveAll(newStocks);
|
||||
try {
|
||||
if (!newStocks.isEmpty()) {
|
||||
stockRepository.saveAll(newStocks);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
log.error("Insert stock failed: {}", e.getMessage());
|
||||
}
|
||||
|
||||
if (start >= limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user