Compare commits
79 Commits
twelvedata
...
huy-featur
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd06493b9c | ||
|
|
476645109d | ||
|
|
66eccce4cb | ||
|
|
5ab279daa6 | ||
|
|
be24a57d2d | ||
|
|
aa796cf853 | ||
|
|
9a06979f07 | ||
|
|
d1f9600361 | ||
|
|
fcab660024 | ||
|
|
ad95848c2c | ||
|
|
90a26823f0 | ||
|
|
c72c0ff4cd | ||
|
|
85094c22b2 | ||
|
|
59684cccfc | ||
|
|
57690ecb5e | ||
|
|
8cf511f1b7 | ||
|
|
f612b5128e | ||
|
|
07a69f29b9 | ||
|
|
3e1ff24bb6 | ||
|
|
b26d3962c4 | ||
|
|
d085d8de12 | ||
|
|
0476ad100b | ||
|
|
f87df03715 | ||
|
|
fc59d1f47c | ||
|
|
6fdc13a72d | ||
|
|
6b5623dc33 | ||
|
|
4a22fc0a95 | ||
|
|
563dae1c45 | ||
|
|
fa02ebf03b | ||
|
|
0f5f25f744 | ||
|
|
615aae7e1d | ||
|
|
c89345329d | ||
|
|
f18521d190 | ||
|
|
e84c212bf0 | ||
|
|
1ff1797b0b | ||
|
|
89c0fe0321 | ||
|
|
b6052a46ff | ||
|
|
d40c30bcb5 | ||
|
|
5b16f1f2c9 | ||
|
|
b8d4e0d3f2 | ||
|
|
c19277e390 | ||
|
|
514875878f | ||
|
|
4257541342 | ||
|
|
441adac15a | ||
|
|
ba29ab98c7 | ||
|
|
94ec73874b | ||
|
|
549345719a | ||
|
|
3870400411 | ||
|
|
94d2936ffb | ||
|
|
59e4aa9e1a | ||
|
|
bae645e3c6 | ||
|
|
94d9aea2c8 | ||
|
|
5ae9762d45 | ||
|
|
ece52491dd | ||
|
|
6235d41711 | ||
|
|
c865eccaf4 | ||
|
|
136020a497 | ||
|
|
d7da59aca1 | ||
|
|
8427bed427 | ||
|
|
269f02b79d | ||
|
|
7cc456bcd8 | ||
|
|
be05d403af | ||
|
|
4a29bf6659 | ||
|
|
5b2eb8519a | ||
|
|
2e4449bd64 | ||
|
|
b321fd9d4e | ||
|
|
2f9e54bf4f | ||
| 3bb354bbc6 | |||
| a403cba964 | |||
|
|
99bde81670 | ||
|
|
bae941828e | ||
|
|
2f86571578 | ||
|
|
d491bef735 | ||
|
|
74c64eb7d4 | ||
|
|
f50b6b5519 | ||
| 2446d89b30 | |||
|
|
33a68eb7e8 | ||
|
|
7b0a08150d | ||
|
|
146e9d9bc0 |
@@ -2,7 +2,12 @@ stages:
|
||||
# 构建
|
||||
- build
|
||||
- dockerize
|
||||
- webhook
|
||||
- deploy
|
||||
|
||||
variables:
|
||||
company_name: juyoutech
|
||||
project_name: germany_stock
|
||||
service_name: market
|
||||
|
||||
build:
|
||||
image: maven:3.6.3-openjdk-8
|
||||
@@ -48,28 +53,36 @@ dockerize:
|
||||
- main
|
||||
- develop
|
||||
script:
|
||||
- echo ">>>>>>Start Building Image<<<<<<"
|
||||
- ls
|
||||
- ls target
|
||||
- echo $DOCKER_PASSWORD
|
||||
- echo $CI_PIPELINE_ID
|
||||
- docker build -t juyoutech/india_stock_market:latest .
|
||||
- docker tag juyoutech/india_stock_market:latest juyoutech/india_stock_market:$CI_PIPELINE_ID
|
||||
- docker tag juyoutech/india_stock_market:latest juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
||||
- docker login -u juyoutech -p dckr_pat_8rg23IBA2kZMOCX4IJKApb8m5l8
|
||||
- docker push juyoutech/india_stock_market:latest
|
||||
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
||||
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
||||
webhook:
|
||||
stage: webhook
|
||||
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
||||
- pwd
|
||||
- ls -lah
|
||||
- echo $DOCKER_PASSWORD | docker login -u ${company_name} --password-stdin
|
||||
- docker build -t ${company_name}/${project_name}_${service_name} .
|
||||
|
||||
- docker push ${company_name}/${project_name}_${service_name}
|
||||
|
||||
- docker tag ${company_name}/${project_name}_${service_name} ${company_name}/${project_name}_${service_name}:$CI_PIPELINE_ID
|
||||
- docker push ${company_name}/${project_name}_${service_name}:$CI_PIPELINE_ID
|
||||
|
||||
- docker tag ${company_name}/${project_name}_${service_name} ${company_name}/${project_name}_${service_name}:$CI_COMMIT_BRANCH
|
||||
- docker push ${company_name}/${project_name}_${service_name}:$CI_COMMIT_BRANCH
|
||||
|
||||
- echo ${company_name}/${project_name}_${service_name}:$CI_COMMIT_BRANCH
|
||||
|
||||
deploy-dev:
|
||||
stage: deploy
|
||||
only:
|
||||
- develop
|
||||
script:
|
||||
- echo ">>>>>>Start Deploy<<<<<<"
|
||||
- echo "Deploying application..."
|
||||
- ls
|
||||
- apt-get update
|
||||
- apt-get install -y curl
|
||||
- curl --max-time 30 http://149.88.86.7:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=deploy-test.sh
|
||||
- echo ">>>>>>Start Deploy Finish<<<<<<"
|
||||
- apk update
|
||||
- apk add curl
|
||||
- |
|
||||
curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"namespace":"dgdev", "deployment_name":"germany-stock-market"}' \
|
||||
https://updater-dgdev.moneytj.com/restart-deployment
|
||||
- echo "Application successfully deployed."
|
||||
|
||||
|
||||
|
||||
12
pom.xml
12
pom.xml
@@ -89,6 +89,12 @@
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20240303</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
@@ -185,6 +191,12 @@
|
||||
<version>30.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -29,6 +29,10 @@ public class QMoneyStockPO extends EntityPathBase<MoneyStockPO> {
|
||||
|
||||
public final StringPath moneyScId = createString("moneyScId");
|
||||
|
||||
public final StringPath nseIndiaChartId = createString("nseIndiaChartId");
|
||||
|
||||
public final StringPath nseIndiaId = createString("nseIndiaId");
|
||||
|
||||
public final DateTimePath<java.util.Date> saveTime = createDateTime("saveTime", java.util.Date.class);
|
||||
|
||||
public final StringPath selfDispId = createString("selfDispId");
|
||||
@@ -39,6 +43,8 @@ public class QMoneyStockPO extends EntityPathBase<MoneyStockPO> {
|
||||
|
||||
public final StringPath stockType = createString("stockType");
|
||||
|
||||
public final BooleanPath useFromBseindia = createBoolean("useFromBseindia");
|
||||
|
||||
public QMoneyStockPO(String variable) {
|
||||
super(MoneyStockPO.class, forVariable(variable));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import static com.querydsl.core.types.PathMetadataFactory.*;
|
||||
|
||||
import com.querydsl.core.types.dsl.*;
|
||||
|
||||
import com.querydsl.core.types.PathMetadata;
|
||||
import javax.annotation.Generated;
|
||||
import com.querydsl.core.types.Path;
|
||||
|
||||
|
||||
/**
|
||||
* QOptionalStockPO is a Querydsl query type for OptionalStockPO
|
||||
*/
|
||||
@Generated("com.querydsl.codegen.EntitySerializer")
|
||||
public class QOptionalStockPO extends EntityPathBase<OptionalStockPO> {
|
||||
|
||||
private static final long serialVersionUID = 1161631810L;
|
||||
|
||||
public static final QOptionalStockPO optionalStockPO = new QOptionalStockPO("optionalStockPO");
|
||||
|
||||
public final StringPath company = createString("company");
|
||||
|
||||
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
||||
|
||||
public final StringPath symbol = createString("symbol");
|
||||
|
||||
public QOptionalStockPO(String variable) {
|
||||
super(OptionalStockPO.class, forVariable(variable));
|
||||
}
|
||||
|
||||
public QOptionalStockPO(Path<? extends OptionalStockPO> path) {
|
||||
super(path.getType(), path.getMetadata());
|
||||
}
|
||||
|
||||
public QOptionalStockPO(PathMetadata metadata) {
|
||||
super(OptionalStockPO.class, metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public class QStockIpoPO extends EntityPathBase<StockIpoPO> {
|
||||
|
||||
public final DateTimePath<java.util.Date> createDate = createDateTime("createDate", java.util.Date.class);
|
||||
|
||||
public final StringPath exchangeType = createString("exchangeType");
|
||||
|
||||
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
||||
|
||||
public final NumberPath<Integer> isList = createNumber("isList", Integer.class);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import static com.querydsl.core.types.PathMetadataFactory.*;
|
||||
|
||||
import com.querydsl.core.types.dsl.*;
|
||||
|
||||
import com.querydsl.core.types.PathMetadata;
|
||||
import javax.annotation.Generated;
|
||||
import com.querydsl.core.types.Path;
|
||||
|
||||
|
||||
/**
|
||||
* QStockTempPO is a Querydsl query type for StockTempPO
|
||||
*/
|
||||
@Generated("com.querydsl.codegen.EntitySerializer")
|
||||
public class QStockTempPO extends EntityPathBase<StockTempPO> {
|
||||
|
||||
private static final long serialVersionUID = 1973569078L;
|
||||
|
||||
public static final QStockTempPO stockTempPO = new QStockTempPO("stockTempPO");
|
||||
|
||||
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
||||
|
||||
public final StringPath stockGid = createString("stockGid");
|
||||
|
||||
public final StringPath stockLogo = createString("stockLogo");
|
||||
|
||||
public final StringPath stockType = createString("stockType");
|
||||
|
||||
public QStockTempPO(String variable) {
|
||||
super(StockTempPO.class, forVariable(variable));
|
||||
}
|
||||
|
||||
public QStockTempPO(Path<? extends StockTempPO> path) {
|
||||
super(path.getType(), path.getMetadata());
|
||||
}
|
||||
|
||||
public QStockTempPO(PathMetadata metadata) {
|
||||
super(StockTempPO.class, metadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.stock.market.domain.basic.convert;
|
||||
|
||||
import cn.qutaojing.common.domain.convert.SimpleEntityPOConvert;
|
||||
import cn.qutaojing.common.utils.SpringUtils;
|
||||
import cn.stock.market.domain.basic.entity.OptionalStock;
|
||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Lazy
|
||||
public class OptionalStockConvert extends SimpleEntityPOConvert<OptionalStock, OptionalStockPO> {
|
||||
public static OptionalStockConvert of() {
|
||||
return SpringUtils.getBean(OptionalStockConvert.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.stock.market.domain.basic.convert;
|
||||
|
||||
import cn.qutaojing.common.domain.convert.SimpleEntityPOConvert;
|
||||
import cn.qutaojing.common.utils.SpringUtils;
|
||||
import cn.stock.market.domain.basic.entity.Stock;
|
||||
import cn.stock.market.domain.basic.entity.StockTemp;
|
||||
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* StockConvert
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@Component
|
||||
@Lazy
|
||||
public class StockTempConvert extends SimpleEntityPOConvert<StockTemp, StockTempPO> {
|
||||
public static StockTempConvert of() {
|
||||
return SpringUtils.getBean(StockTempConvert.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.stock.market.domain.basic.entity;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@EqualsAndHashCode(
|
||||
callSuper = false
|
||||
)
|
||||
public class OptionalStock extends OptionalStockPO {
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.stock.market.domain.basic.entity;
|
||||
|
||||
import cn.qutaojing.common.utils.Beans;
|
||||
import cn.stock.market.dto.command.StockCreateCommand;
|
||||
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* Stock
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@EqualsAndHashCode(
|
||||
callSuper = false
|
||||
)
|
||||
public class StockTemp extends StockTempPO {
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.stock.market.domain.basic.repository;
|
||||
|
||||
import cn.qutaojing.common.domain.convert.IEntityPOConvert;
|
||||
import cn.qutaojing.common.domain.respostory.SimplePoConvertEntityRepository;
|
||||
import cn.stock.market.domain.basic.convert.OptionalStockConvert;
|
||||
import cn.stock.market.domain.basic.entity.OptionalStock;
|
||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
||||
import cn.stock.market.infrastructure.db.repo.OptionalStockRepo;
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor(
|
||||
onConstructor = @__(@Autowired)
|
||||
)
|
||||
public class OptionalStockRepository extends SimplePoConvertEntityRepository<OptionalStock, OptionalStockPO, Integer> {
|
||||
final OptionalStockRepo repo;
|
||||
|
||||
final OptionalStockConvert convert;
|
||||
|
||||
@Override
|
||||
public GenericJpaRepository<OptionalStockPO, Integer> repo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityPOConvert<OptionalStock, OptionalStockPO> convert() {
|
||||
return convert;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.stock.market.domain.basic.repository;
|
||||
|
||||
import cn.qutaojing.common.domain.convert.IEntityPOConvert;
|
||||
import cn.qutaojing.common.domain.respostory.LocalCacheBean;
|
||||
import cn.qutaojing.common.domain.respostory.LocalCacheRepository;
|
||||
import cn.qutaojing.common.jpa.ConditionBuilder;
|
||||
import cn.qutaojing.common.utils.SpringUtils;
|
||||
import cn.stock.market.domain.basic.convert.StockConvert;
|
||||
import cn.stock.market.domain.basic.convert.StockTempConvert;
|
||||
import cn.stock.market.domain.basic.entity.Stock;
|
||||
import cn.stock.market.domain.basic.entity.StockTemp;
|
||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||
import cn.stock.market.infrastructure.db.po.QStockTempPO;
|
||||
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||
import cn.stock.market.infrastructure.db.repo.StockRepo;
|
||||
import cn.stock.market.infrastructure.db.repo.StockTempRepo;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* StockRepository
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@Repository
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class StockTempRepository extends LocalCacheRepository<StockTemp, StockTempPO, Integer> {
|
||||
final StockTempRepo repo;
|
||||
final StockTempConvert convert;
|
||||
final static QStockTempPO q = QStockTempPO.stockTempPO;
|
||||
|
||||
public List<StockTemp> findAllForCheck() {
|
||||
return findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericJpaRepository<StockTempPO, Integer> repo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityPOConvert<StockTemp, StockTempPO> convert() {
|
||||
return convert;
|
||||
}
|
||||
|
||||
public static StockTempRepository of() {
|
||||
return SpringUtils.getBean(StockTempRepository.class);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -247,34 +249,112 @@ public class StockService {
|
||||
String result = "";
|
||||
try {
|
||||
// 使用Jsoup连接到网页
|
||||
Document doc = Jsoup.connect("https://www.business-standard.com/markets/news")
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||
.header("Referer", "https://www.business-standard.com/")
|
||||
.header("Accept-Language", "en-US,en;q=0.9")
|
||||
.get();
|
||||
result = doc.html().substring(doc.html().indexOf("<div class=\"shortvideoimg\" style=\"position:relative\">"),doc.html().lastIndexOf("<div class=\"shortvideoimg\" style=\"position:relative\">")+1200);
|
||||
// Document doc = Jsoup.connect("https://www.business-standard.com/markets/news")
|
||||
// .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||
// .header("Referer", "https://www.business-standard.com/")
|
||||
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||
// .get();
|
||||
String url = "https://www.business-standard.com/markets/news";
|
||||
// Document doc = Jsoup.connect(url)
|
||||
// .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
||||
// .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||
// .header("Accept-Language", "en-US,en;q=0.5")
|
||||
// .header("Connection", "keep-alive")
|
||||
// .referrer("https://www.google.com")
|
||||
// .ignoreHttpErrors(true)
|
||||
// .timeout(10000)
|
||||
// .get();
|
||||
String doGetNews = HttpClientRequest.doGetNews(url);
|
||||
// result = doc.html().substring(doc.html().indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">"),doc.html().lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">")+500);
|
||||
// Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// for (Element divElement : divElements) {
|
||||
// sb.append(divElement.outerHtml()).append("\n");
|
||||
// }
|
||||
// result = sb.toString();
|
||||
result = extractNewsFromHtml(doGetNews);
|
||||
} catch (Exception e) {
|
||||
return e.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String extractNewsFromHtml(String rawHtml) {
|
||||
Document doc = Jsoup.parse(rawHtml);
|
||||
|
||||
// Optional: extract raw block around <div class="listingstyle_shortvideoimg__0TWuX shortvideoimg">
|
||||
int start = rawHtml.indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">");
|
||||
int end = rawHtml.lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">") + 500;
|
||||
String result = (start != -1 && end > start) ? rawHtml.substring(start, end) : "";
|
||||
|
||||
// Extract article list using CSS selector
|
||||
Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Element divElement : divElements) {
|
||||
sb.append(divElement.outerHtml()).append("\n");
|
||||
}
|
||||
|
||||
// If you only want the div content:
|
||||
result = sb.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> getNewsInfo(String url) {
|
||||
// String result = "";
|
||||
// List<String> list = new ArrayList<>();
|
||||
// try {
|
||||
// // 使用Jsoup连接到网页
|
||||
//// Document doc = Jsoup.connect(url)
|
||||
//// .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||
//// .header("Referer", "https://www.business-standard.com/")
|
||||
//// .header("Accept-Language", "en-US,en;q=0.9")
|
||||
//// .get();
|
||||
// Document doc = Jsoup.connect(url)
|
||||
// .referrer("https://www.business-standard.com/")
|
||||
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||
// .userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1")
|
||||
// .timeout(5000) // timeout 5 seconds
|
||||
// .get();
|
||||
// result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
||||
// list.add(result);
|
||||
// list.add(doc.html().substring(doc.html().indexOf("og:title") + 19, doc.html().indexOf("<meta property=\"og:url") - 5));
|
||||
// } catch (Exception e) {
|
||||
// list.add(e.toString());
|
||||
// return list;
|
||||
// }
|
||||
// return list;
|
||||
String result = "";
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
// 使用Jsoup连接到网页
|
||||
Document doc = Jsoup.connect(url)
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||
.header("Referer", "https://www.business-standard.com/")
|
||||
.header("Accept-Language", "en-US,en;q=0.9")
|
||||
.get();
|
||||
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
||||
// Step 1: Get raw HTML via HttpClient
|
||||
String rawHtml = HttpClientRequest.doGetNews(url);
|
||||
|
||||
// Step 2: Parse HTML with Jsoup
|
||||
Document doc = Jsoup.parse(rawHtml);
|
||||
|
||||
// Step 3: Extract content manually (like original)
|
||||
int startIdx = rawHtml.indexOf("articleBody") + 14;
|
||||
int endIdx = rawHtml.indexOf(",\"author\":") - 1;
|
||||
|
||||
if (startIdx > 0 && endIdx > startIdx) {
|
||||
result = rawHtml.substring(startIdx, endIdx);
|
||||
} else {
|
||||
result = "[articleBody not found]";
|
||||
}
|
||||
list.add(result);
|
||||
list.add(doc.html().substring(doc.html().indexOf("og:title") + 19, doc.html().indexOf("<meta property=\"og:url") - 5));
|
||||
|
||||
// Step 4: Extract og:title
|
||||
int titleStart = rawHtml.indexOf("og:title") + 19;
|
||||
int titleEnd = rawHtml.indexOf("<meta property=\"og:url") - 5;
|
||||
|
||||
if (titleStart > 0 && titleEnd > titleStart) {
|
||||
list.add(rawHtml.substring(titleStart, titleEnd));
|
||||
} else {
|
||||
list.add("[title not found]");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
list.add(e.toString());
|
||||
return list;
|
||||
list.add("[Error] " + e.getMessage());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -974,7 +1054,7 @@ public class StockService {
|
||||
String exchange = "bse";
|
||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||
String coCode = "20558";
|
||||
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
||||
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
||||
IndiaStockVO market = objToVo(object);
|
||||
market.setName("BSESENSEX指数");
|
||||
vo1.setIndexVo(market);
|
||||
@@ -1004,7 +1084,7 @@ public class StockService {
|
||||
String exchange = "nse";
|
||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||
String coCode = "20559";
|
||||
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
||||
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
|
||||
IndiaStockVO market = objToVo(object);
|
||||
market.setName("NIFTY50指数");
|
||||
vo1.setIndexVo(market);
|
||||
@@ -1034,23 +1114,23 @@ public class StockService {
|
||||
}
|
||||
private IndiaStockVO objToVo(JSONObject object){
|
||||
IndiaStockVO market = new IndiaStockVO();
|
||||
if(object.containsKey("prev_close")){
|
||||
market.setClose(object.getString("prev_close"));
|
||||
if(object.containsKey("priceprevclose")){
|
||||
market.setClose(object.getString("priceprevclose"));
|
||||
}
|
||||
if(object.containsKey("price")){
|
||||
market.setNowPrice(object.getString("price"));
|
||||
if(object.containsKey("pricecurrent")){
|
||||
market.setNowPrice(object.getString("pricecurrent"));
|
||||
}
|
||||
if(object.containsKey("perchg")){
|
||||
market.setRate(object.getString("perchg"));
|
||||
if(object.containsKey("pricepercentchange")){
|
||||
market.setRate(object.getString("pricepercentchange"));
|
||||
}
|
||||
if(object.containsKey("high_price")){
|
||||
market.setHigh(object.getString("high_price"));
|
||||
if(object.containsKey("HIGH")){
|
||||
market.setHigh(object.getString("HIGH"));
|
||||
}
|
||||
if(object.containsKey("low_price")){
|
||||
market.setLow(object.getString("low_price"));
|
||||
if(object.containsKey("LOW")){
|
||||
market.setLow(object.getString("LOW"));
|
||||
}
|
||||
if(object.containsKey("open_price")){
|
||||
market.setOpen(object.getString("open_price"));
|
||||
if(object.containsKey("OPEN")){
|
||||
market.setOpen(object.getString("OPEN"));
|
||||
}
|
||||
return market;
|
||||
// stockListVO.setName(jsonObject.getString("companyname"));
|
||||
|
||||
18
src/main/java/cn/stock/market/dto/OptionalStockResponse.java
Normal file
18
src/main/java/cn/stock/market/dto/OptionalStockResponse.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package cn.stock.market.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class OptionalStockResponse {
|
||||
private String message;
|
||||
private Integer code;
|
||||
private DataResponse data = new DataResponse();
|
||||
|
||||
@Data
|
||||
public static class DataResponse {
|
||||
private String symbol;
|
||||
private String company;
|
||||
private Double pricecurrent;
|
||||
private Float pricepercentchange;
|
||||
}
|
||||
}
|
||||
28
src/main/java/cn/stock/market/dto/model/Symbol.java
Normal file
28
src/main/java/cn/stock/market/dto/model/Symbol.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package cn.stock.market.dto.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Symbol {
|
||||
private String symbol;
|
||||
private String description;
|
||||
private String stockGid;
|
||||
private String type;
|
||||
private String exchange;
|
||||
private String currencyCode;
|
||||
private String currencyLogoid;
|
||||
private String logoid;
|
||||
private String providerId;
|
||||
private String sourceLogoid;
|
||||
private String sourceId;
|
||||
private String country;
|
||||
private boolean isPrimaryListing;
|
||||
private List<String> typespecs;
|
||||
|
||||
// Getters and setters
|
||||
// Bạn có thể dùng Lombok nếu muốn ngắn gọn hơn
|
||||
// Hoặc generate getter/setter trong IDE
|
||||
|
||||
}
|
||||
48
src/main/java/cn/stock/market/dto/query/StockChartDto.java
Normal file
48
src/main/java/cn/stock/market/dto/query/StockChartDto.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package cn.stock.market.dto.query;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class StockChartDto {
|
||||
private Long timestamp;
|
||||
private double open;
|
||||
private double high;
|
||||
private double low;
|
||||
private double close;
|
||||
private double volume;
|
||||
|
||||
public StockChartDto(Long date, double open, double high, double low, double close, double volume) {
|
||||
this.timestamp = date;
|
||||
this.open = open;
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
this.close = close;
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public double getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public double getOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public double getHigh() {
|
||||
return high;
|
||||
}
|
||||
|
||||
public double getLow() {
|
||||
return low;
|
||||
}
|
||||
|
||||
public double getClose() {
|
||||
return close;
|
||||
}
|
||||
}
|
||||
@@ -187,18 +187,17 @@ public class TodayApis {
|
||||
|
||||
//获取详情
|
||||
public static JSONObject getStockDetail(String exchange,String coCode){
|
||||
String url = String.format("https://marketapi.intoday.in/widget/stockdetail/pullview?co_code=%s&exchange=%s",coCode,exchange);
|
||||
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/%s",exchange);
|
||||
String str = get(url);
|
||||
JSONObject object = JSON.parseObject(str);
|
||||
boolean bool = false;
|
||||
if(object.containsKey("success")){
|
||||
bool = object.getBoolean("success");
|
||||
if(object.containsKey("code")){
|
||||
bool = object.getInteger("code") == 200;
|
||||
}
|
||||
if(!bool){
|
||||
return new JSONObject();
|
||||
}
|
||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||
JSONObject entity = JSON.parseObject(jsonArray.get(0).toString());
|
||||
JSONObject entity = JSON.parseObject(object.getString("data"));
|
||||
return entity;
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,14 @@ public class MoneyStockPO {
|
||||
* 展示表示 */
|
||||
String selfDispId;
|
||||
|
||||
/**
|
||||
* NSE India的id */
|
||||
String nseIndiaId;
|
||||
|
||||
/**
|
||||
* NSE India Chart的id */
|
||||
String nseIndiaChartId;
|
||||
|
||||
/**
|
||||
* 自有self_url */
|
||||
String selfUrl;
|
||||
@@ -75,4 +83,6 @@ public class MoneyStockPO {
|
||||
/**
|
||||
* 是否展示 0是 1否 */
|
||||
Integer isShow;
|
||||
|
||||
Boolean useFromBseindia = false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(
|
||||
name = "optional_stock"
|
||||
)
|
||||
public class OptionalStockPO {
|
||||
@Id
|
||||
@GeneratedValue(
|
||||
strategy = javax.persistence.GenerationType.IDENTITY
|
||||
)
|
||||
Integer id;
|
||||
|
||||
String symbol;
|
||||
|
||||
String company;
|
||||
}
|
||||
@@ -61,11 +61,11 @@ public class StockIpoPO {
|
||||
|
||||
/**
|
||||
* 是否显示【1 显示,2 不显示】 */
|
||||
Integer isShow;
|
||||
Integer isShow = 1;
|
||||
|
||||
/**
|
||||
* 是否上市【1 未上市,2 已上市】 */
|
||||
Integer isList;
|
||||
Integer isList = 1;
|
||||
|
||||
Date createDate;
|
||||
|
||||
@@ -79,6 +79,8 @@ public class StockIpoPO {
|
||||
* 申请总额 */
|
||||
String apply;
|
||||
|
||||
String exchangeType;
|
||||
|
||||
/**
|
||||
* 市盈率 */
|
||||
BigDecimal peRatio;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* StockPO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "stockTemp")
|
||||
public class StockTempPO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
String stockType;
|
||||
|
||||
String stockGid;
|
||||
|
||||
String stockLogo;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
public interface OptionalStockRepo extends GenericJpaRepository<OptionalStockPO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
/**
|
||||
* StockRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
public interface StockTempRepo extends GenericJpaRepository<StockTempPO, Integer> {
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import cn.stock.market.domain.basic.repository.StockRepository;
|
||||
import cn.stock.market.domain.basic.service.StockService;
|
||||
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
|
||||
import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
|
||||
import cn.stock.market.utils.DateTimeUtil;
|
||||
import cn.stock.market.utils.Utils;
|
||||
import com.ag.utils.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -25,6 +26,8 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -118,8 +121,16 @@ public class InvestingTask {
|
||||
newsList.forEach( n -> {
|
||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
||||
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||
// String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
||||
String imgUrl = extractImgSrc(n);
|
||||
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||
// Extract the date and time using regex
|
||||
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
|
||||
Matcher matcher = pattern.matcher(n);
|
||||
String time = "";
|
||||
if (matcher.find()) {
|
||||
time = DateTimeUtil.formatDateTimeFor24H(matcher.group(1).trim(),"dd MMM yyyy | hh:mm a");
|
||||
}
|
||||
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
@@ -140,4 +151,22 @@ public class InvestingTask {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String extractImgSrc(String htmlData) {
|
||||
String searchString = "<noscript>";
|
||||
int startPos = htmlData.indexOf(searchString);
|
||||
|
||||
if (startPos != -1) {
|
||||
String startTag = "src=";
|
||||
startPos = htmlData.indexOf(startTag, startPos) + startTag.length() + 1;
|
||||
|
||||
int endPos = htmlData.indexOf("?", startPos);
|
||||
|
||||
if (endPos != -1) {
|
||||
return htmlData.substring(startPos, endPos);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,15 +115,15 @@ public class MoneyScraper {
|
||||
if (ulElement != null) {
|
||||
for (Element aElement : ulElement.select("a")) {
|
||||
String exchangeValue = aElement.text().trim();
|
||||
if ("BSE".equals(exchangeValue) || "NSE".equals(exchangeValue)) {
|
||||
if ("BSE".equals(exchangeValue.toUpperCase()) || "NSE".equals(exchangeValue.toUpperCase())) {
|
||||
log.info(Thread.currentThread().getName() + ",the stock url: " + url +
|
||||
", the exchange Value: " + exchangeValue);
|
||||
MoneyStock build = MoneyStock.builder().stockName(name).stockType(exchangeValue.toLowerCase(Locale.ROOT))
|
||||
MoneyStock build = MoneyStock.builder().stockName(name).stockType(exchangeValue.toUpperCase(Locale.ROOT))
|
||||
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
|
||||
.selfUrl(url)
|
||||
.selfDispId(extractDispId(url))
|
||||
.moneyScId(companyCodeId).saveTime(new Date()).build();
|
||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(name), QMoneyStockPO.moneyStockPO.stockType.eq(exchangeValue.toLowerCase(Locale.ROOT)));
|
||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(name), QMoneyStockPO.moneyStockPO.stockType.upper().eq(exchangeValue.toUpperCase(Locale.ROOT)));
|
||||
if (CollectionUtil.isEmpty(all)) {
|
||||
moneyStockRepository.save(build);
|
||||
}
|
||||
@@ -264,15 +264,15 @@ public class MoneyScraper {
|
||||
for (Element aElement : ulElement.select("a")) {
|
||||
String exchangeValue = aElement.text().trim();
|
||||
|
||||
if ("BSE".equals(exchangeValue) || "NSE".equals(exchangeValue)) {
|
||||
if ("BSE".equals(exchangeValue.toUpperCase(Locale.ROOT)) || "NSE".equals(exchangeValue.toUpperCase(Locale.ROOT))) {
|
||||
log.info(Thread.currentThread().getName()+",stockName: " + textContent + ", self_link: " + linkAttribute +
|
||||
", the exchange Value: " + exchangeValue);
|
||||
MoneyStock build = MoneyStock.builder().stockName(textContent).stockType(exchangeValue.toLowerCase(Locale.ROOT))
|
||||
MoneyStock build = MoneyStock.builder().stockName(textContent).stockType(exchangeValue.toUpperCase(Locale.ROOT))
|
||||
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
|
||||
.selfUrl(linkAttribute)
|
||||
.selfDispId(extractDispId(linkAttribute))
|
||||
.moneyScId(companyCodeId).saveTime(new Date()).build();
|
||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(textContent), QMoneyStockPO.moneyStockPO.stockType.eq(exchangeValue.toLowerCase(Locale.ROOT)));
|
||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(textContent), QMoneyStockPO.moneyStockPO.stockType.upper().eq(exchangeValue.toUpperCase(Locale.ROOT)));
|
||||
if(CollectionUtil.isEmpty(all)){
|
||||
moneyStockRepository.save(build);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
package cn.stock.market.infrastructure.job;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.stock.market.domain.basic.entity.BtodayStock;
|
||||
import cn.stock.market.domain.basic.entity.MoneyStock;
|
||||
import cn.stock.market.domain.basic.entity.StockIpo;
|
||||
import cn.stock.market.domain.basic.repository.BtodayStockRepository;
|
||||
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
||||
import cn.stock.market.domain.basic.repository.StockIpoRepository;
|
||||
import cn.stock.market.dto.StockIpoDTO;
|
||||
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
||||
import cn.stock.market.infrastructure.db.po.QStockIpoPO;
|
||||
import cn.stock.market.infrastructure.db.po.StockIpoPO;
|
||||
import cn.stock.market.infrastructure.db.repo.BtodayStockRepo;
|
||||
import com.alibaba.druid.sql.visitor.functions.Now;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -31,14 +37,11 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -54,6 +57,10 @@ public class Scraper {
|
||||
private StockIpoRepository stockIpoRepository;
|
||||
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(5);
|
||||
@Autowired
|
||||
private MoneyStockRepository moneyStockRepository;
|
||||
|
||||
private boolean times = false;
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 1 */2 * ?")
|
||||
@@ -104,14 +111,16 @@ public class Scraper {
|
||||
|
||||
|
||||
@Scheduled(cron = "0 0 18 * * ?")
|
||||
// @PostConstruct
|
||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||
public void getMoneyControllerNewIPOSchedule() {
|
||||
log.info("定时任务执行获取新股ipo的方法开始执行");
|
||||
// 目标 URL
|
||||
String url = "https://www.moneycontrol.com/ipo/open-upcoming-ipos";
|
||||
List<String> urls = Arrays.asList("https://www.moneycontrol.com/ipo/upcoming-ipos/", "https://www.moneycontrol.com/ipo/open-ipos/");
|
||||
// 创建 HttpClient 实例
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
// 创建 HttpGet 请求
|
||||
for (String url : urls) {
|
||||
HttpGet request = new HttpGet(url);
|
||||
try {
|
||||
// 执行请求
|
||||
@@ -136,11 +145,18 @@ public class Scraper {
|
||||
JSONObject jsonObject = JSONObject.parseObject(jsonDataStr);
|
||||
log.info("获取到新股的json信息:"+jsonObject.toJSONString());
|
||||
|
||||
|
||||
|
||||
JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
||||
JSONObject ipoTableData = pageProps.getJSONObject("ipoTableData");
|
||||
|
||||
|
||||
|
||||
// 解析 openData 和 upcomingData
|
||||
JSONArray openData = ipoTableData.getJSONArray("openData");
|
||||
// if (openData.isEmpty()){
|
||||
// openData = ipoTableData.getJSONArray("openUpcomingData");
|
||||
// }
|
||||
JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData");
|
||||
List<StockIpo> listStockIpoList = new ArrayList<>();
|
||||
for (int i = 0; i < openData.size(); i++) {
|
||||
@@ -153,8 +169,7 @@ public class Scraper {
|
||||
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
|
||||
Integer totalNumber = 0;
|
||||
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(0))){
|
||||
Integer issue_size = entry.getInteger("issue_size");
|
||||
BigDecimal issueSize = new BigDecimal(issue_size);
|
||||
BigDecimal issueSize = new BigDecimal(entry.getLong("issue_size"));
|
||||
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
|
||||
totalNumber = totalNumberBigDecimal.intValue();
|
||||
}
|
||||
@@ -163,7 +178,28 @@ public class Scraper {
|
||||
stockIpo.setCreateDate(new Date());
|
||||
stockIpo.setUpdateDate(new Date());
|
||||
stockIpo.setSourceType("3");
|
||||
listStockIpoList.add(stockIpo);
|
||||
|
||||
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
||||
continue;
|
||||
}
|
||||
String codeDetail = entry.getString("url").substring(entry.getString("url").lastIndexOf('/') + 1);;
|
||||
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), codeDetail);
|
||||
|
||||
for (String exchange : exchanges) {
|
||||
StockIpo ipo = new StockIpo();
|
||||
ipo.setStockCode(stockIpo.getStockCode());
|
||||
ipo.setStockName(stockIpo.getStockName());
|
||||
ipo.setStockPrice(stockIpo.getStockPrice());
|
||||
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
||||
ipo.setListingDate(stockIpo.getListingDate());
|
||||
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
||||
ipo.setApply(stockIpo.getApply());
|
||||
ipo.setCreateDate(stockIpo.getCreateDate());
|
||||
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
||||
ipo.setExchangeType(exchange);
|
||||
ipo.setSourceType("3");
|
||||
listStockIpoList.add(ipo);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < upcomingData.size(); i++) {
|
||||
@@ -186,11 +222,37 @@ public class Scraper {
|
||||
stockIpo.setCreateDate(new Date());
|
||||
stockIpo.setUpdateDate(new Date());
|
||||
stockIpo.setSourceType("3");
|
||||
listStockIpoList.add(stockIpo);
|
||||
|
||||
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), stockIpo.getStockCode());
|
||||
|
||||
for (String exchange : exchanges) {
|
||||
StockIpo ipo = new StockIpo();
|
||||
ipo.setStockCode(stockIpo.getStockCode());
|
||||
ipo.setStockName(stockIpo.getStockName());
|
||||
ipo.setStockPrice(stockIpo.getStockPrice());
|
||||
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
||||
ipo.setListingDate(stockIpo.getListingDate());
|
||||
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
||||
ipo.setApply(stockIpo.getApply());
|
||||
ipo.setCreateDate(stockIpo.getCreateDate());
|
||||
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
||||
ipo.setExchangeType(exchange);
|
||||
ipo.setSourceType("3");
|
||||
listStockIpoList.add(ipo);
|
||||
}
|
||||
}
|
||||
|
||||
// stockIpoRepository.saveAll(listStockIpoList);
|
||||
|
||||
if (!listStockIpoList.isEmpty())
|
||||
{
|
||||
listStockIpoList = listStockIpoList.stream().filter(a -> StringUtils.isNotBlank(a.getStockName())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode);
|
||||
if(CollectionUtil.isNotEmpty(scIdList)){
|
||||
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
|
||||
@@ -198,13 +260,27 @@ public class Scraper {
|
||||
.map(StockIpo::getStockCode)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
listStockIpoList = listStockIpoList.stream()
|
||||
.filter(stockIpos -> !existingStockScIds.contains(stockIpos.getStockCode())).filter(stockIpo -> StringUtils.isNotBlank(stockIpo.getStockName()))
|
||||
.collect(Collectors.toList());
|
||||
for (StockIpo stockIpo : listStockIpoList) {
|
||||
StockIpo existIpo = existStockIpoList.stream().filter(a -> a.getStockCode().equals(stockIpo.getStockCode()) && (a.getExchangeType() == null || a.getExchangeType().isEmpty() || a.getExchangeType().toLowerCase().trim().equals(stockIpo.getExchangeType().toLowerCase().trim()))).findFirst().orElse(null);
|
||||
if (existIpo != null) {
|
||||
if (existIpo.getExchangeType() == null || existIpo.getExchangeType().isEmpty()){
|
||||
existIpo.setExchangeType(stockIpo.getExchangeType());
|
||||
}
|
||||
stockIpo.setId(existIpo.getId());
|
||||
if (existIpo.getStockPrice() != null){
|
||||
stockIpo.setStockPrice(existIpo.getStockPrice());
|
||||
stockIpo.setApply(existIpo.getApply());
|
||||
}
|
||||
}
|
||||
}
|
||||
// listStockIpoList = listStockIpoList.stream()
|
||||
// .filter(stockIpos -> !existingStockScIds.contains(stockIpos.getStockCode())).filter(stockIpo -> StringUtils.isNotBlank(stockIpo.getStockName()))
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
//保存全部的新股
|
||||
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
||||
stockIpoRepository.saveAll(listStockIpoList);
|
||||
|
||||
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
||||
}else {
|
||||
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
||||
@@ -222,7 +298,39 @@ public class Scraper {
|
||||
} catch (IOException e) {
|
||||
log.error("获取新股接口发生异常",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 19 * * ?")
|
||||
@PostConstruct
|
||||
@RequestMapping("/addMoneyStock")
|
||||
public void addMoneyStock() {
|
||||
log.info("定时任务执行获取新股ipo的方法开始执行");
|
||||
|
||||
List<StockIpo> stockIpoList;
|
||||
|
||||
if(!times){
|
||||
stockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.listingDate.isNotNull()
|
||||
.and(QStockIpoPO.stockIpoPO.listingDate.loe(DateTime.now()))
|
||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotNull())
|
||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotEmpty())
|
||||
); // first time run
|
||||
|
||||
times = true;
|
||||
}
|
||||
else {
|
||||
stockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.listingDate.isNotNull()
|
||||
.and(QStockIpoPO.stockIpoPO.listingDate.loe(DateTime.now())
|
||||
.and(QStockIpoPO.stockIpoPO.listingDate.goe(DateUtil.offsetDay(DateTime.now(), -3))))
|
||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotNull())
|
||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotEmpty())
|
||||
); // from second run
|
||||
}
|
||||
|
||||
List<MoneyStock> moneyStockList = convertToMoneyStock(stockIpoList);
|
||||
moneyStockRepository.saveAll(moneyStockList);
|
||||
}
|
||||
|
||||
|
||||
@@ -236,12 +344,6 @@ public class Scraper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void processSubMap(Map<String, String> sefUrlList) {
|
||||
for (Map.Entry<String, String> entry : sefUrlList.entrySet()) {
|
||||
String companyName = entry.getKey();
|
||||
@@ -378,4 +480,135 @@ public class Scraper {
|
||||
log.info("Getting web detail URL: " + url + "...");
|
||||
return Jsoup.connect(url).ignoreContentType(true).execute().body();
|
||||
}
|
||||
|
||||
public List<String> getIpoExchange(String stockName, String stockCode) {
|
||||
List<String> exchanges = new ArrayList<>();
|
||||
String url = "https://www.moneycontrol.com/ipo/{stockName}-{stockCode}-ipodetail";
|
||||
url = url.replace("{stockName}", stockName.toLowerCase().replace(" ", "-")).replace("{stockCode}", stockCode.toLowerCase());
|
||||
|
||||
org.apache.http.client.HttpClient client = HttpClients.createDefault();
|
||||
HttpGet request = new HttpGet(url);
|
||||
try {
|
||||
org.apache.http.HttpResponse response = client.execute(request);
|
||||
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
Document doc = Jsoup.parse(responseBody);
|
||||
|
||||
Element scriptTag = doc.selectFirst("script#__NEXT_DATA__");
|
||||
|
||||
if (scriptTag != null) {
|
||||
String jsonDataStr = scriptTag.html();
|
||||
|
||||
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(jsonDataStr);
|
||||
log.info("获取到新股的json信息:" + jsonObject.toJSONString());
|
||||
|
||||
com.alibaba.fastjson.JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
||||
com.alibaba.fastjson.JSONObject overview = pageProps.getJSONObject("ipoDetails").getJSONObject("ipoDetails").getJSONObject("overview");
|
||||
|
||||
String exchangeStr = overview.getString("listing_on");
|
||||
|
||||
if (exchangeStr != null && !exchangeStr.isEmpty() && !exchangeStr.equals("null")) {
|
||||
exchanges.addAll(new ArrayList<>(Arrays.asList(exchangeStr.split(","))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
}
|
||||
|
||||
if (exchanges.isEmpty()) {
|
||||
exchanges.add("");
|
||||
}
|
||||
|
||||
return exchanges;
|
||||
}
|
||||
|
||||
public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
||||
// Lấy danh sách tất cả stockCode và exchangeType từ stockIpoList
|
||||
Set<String> stockCodes = stockIpoList.stream().map(StockIpo::getStockCode).collect(Collectors.toSet());
|
||||
// Set<String> exchangeTypes = stockIpoList.stream().map(StockIpo::getExchangeType).collect(Collectors.toSet());
|
||||
Set<String> exchangeTypes = stockIpoList.stream().map(stockIpo -> stockIpo.getExchangeType().toUpperCase()).collect(Collectors.toSet());
|
||||
|
||||
// Lấy tất cả các MoneyStock tồn tại trong database với stockCode và exchangeType trong stockIpoList
|
||||
List<MoneyStock> existingMoneyStocks = moneyStockRepository.findAll(
|
||||
QMoneyStockPO.moneyStockPO.moneyScId.in(stockCodes)
|
||||
.and(QMoneyStockPO.moneyStockPO.stockType.upper().in(exchangeTypes))
|
||||
);
|
||||
|
||||
// Lưu các stockCode và exchangeType đã tồn tại
|
||||
Set<String> existingKeys = existingMoneyStocks.stream()
|
||||
.map(ms -> ms.getMoneyScId() + ms.getStockType().toUpperCase())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// Chỉ giữ những StockIpo chưa tồn tại
|
||||
return stockIpoList.stream()
|
||||
.filter(stockIpo -> !existingKeys.contains(stockIpo.getStockCode() + stockIpo.getExchangeType().toUpperCase()))
|
||||
.map(this::convert)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
||||
// return stockIpoList.stream()
|
||||
// .filter(stockIpo -> !moneyStockRepository.exists(
|
||||
// QMoneyStockPO.moneyStockPO.stockType.eq(stockIpo.getExchangeType())
|
||||
// .and(QMoneyStockPO.moneyStockPO.moneyScId.eq(stockIpo.getStockCode()))
|
||||
// )) // Chỉ giữ những StockIpo chưa tồn tại
|
||||
// .map(this::convert)
|
||||
// .collect(Collectors.toList());
|
||||
// }
|
||||
|
||||
private MoneyStock convert(StockIpo stockIpo) {
|
||||
MoneyStock moneyStock = new MoneyStock();
|
||||
|
||||
moneyStock.setStockName(stockIpo.getStockName());
|
||||
moneyStock.setMoneyScId(stockIpo.getStockCode());
|
||||
moneyStock.setSelfDispId(stockIpo.getStockCode());
|
||||
moneyStock.setStockType(stockIpo.getExchangeType().toUpperCase());
|
||||
moneyStock.setSaveTime(DateTime.now());
|
||||
moneyStock.setNseIndiaId(getNSEId(stockIpo));
|
||||
|
||||
return moneyStock;
|
||||
}
|
||||
|
||||
private String getNSEId(StockIpo stockIpo){
|
||||
String url = "https://priceapi.moneycontrol.com/pricefeed/" + stockIpo.getExchangeType().toLowerCase() + "/equitycash/" + stockIpo.getStockCode();
|
||||
// 创建 HttpClient 实例
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
// 创建 HttpGet 请求
|
||||
HttpGet request = new HttpGet(url);
|
||||
try {
|
||||
// 执行请求
|
||||
HttpResponse response = client.execute(request);
|
||||
|
||||
// 检查请求是否成功
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
// 获取响应体
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
|
||||
if (responseBody != null) {
|
||||
// 获取 JSON 数据
|
||||
|
||||
// 将 JSON 字符串解析为 Java JSONObject
|
||||
JSONObject jsonObject = JSONObject.parseObject(responseBody);
|
||||
log.info("获取到新股的json信息:" + jsonObject.toJSONString());
|
||||
|
||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||
|
||||
if(stockIpo.getExchangeType().toUpperCase(Locale.ROOT).equals("NSE")){
|
||||
return jsonData.getString("NSEID");
|
||||
}
|
||||
else if(stockIpo.getExchangeType().toUpperCase(Locale.ROOT).equals("BSE")){
|
||||
return jsonData.getString("BSEID");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
log.info(e.getMessage());
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package cn.stock.market.infrastructure.job;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.stock.market.domain.basic.entity.Stock;
|
||||
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 okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
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";
|
||||
|
||||
public StockNewTask(StockTempRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
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");
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
symbol.setTypespecs(typespecsList);
|
||||
|
||||
allSymbols.add(symbol);
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
@@ -186,6 +188,25 @@ public class DateTimeUtil {
|
||||
}
|
||||
|
||||
|
||||
public static String formatDateTimeFor24H(String inputDateTime,String inputFormatStr){
|
||||
String outputDateTime = "";
|
||||
// 1. 解析日期时间
|
||||
SimpleDateFormat inputFormat = new SimpleDateFormat(inputFormatStr, Locale.ENGLISH);
|
||||
Date date = null;
|
||||
try {
|
||||
date = inputFormat.parse(inputDateTime);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (date != null) {
|
||||
// 2. 转换为24小时制
|
||||
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
outputDateTime = outputFormat.format(date);
|
||||
}
|
||||
return outputDateTime;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
parseToDateByMinute(10);
|
||||
}
|
||||
|
||||
@@ -265,6 +265,56 @@ public class HttpClientRequest {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String doGetNews(String url) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
CloseableHttpResponse response = null;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
httpClient = HttpClients.createDefault();
|
||||
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
|
||||
// Spoof real browser headers
|
||||
httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
||||
httpGet.setHeader("Accept-Language", "en-US,en;q=0.9,vi;q=0.8,ug;q=0.7,fr;q=0.6");
|
||||
httpGet.setHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1");
|
||||
httpGet.setHeader("Priority", "u=0, i");
|
||||
httpGet.setHeader("Sec-Fetch-Dest", "document");
|
||||
httpGet.setHeader("Sec-Fetch-Mode", "navigate");
|
||||
httpGet.setHeader("Sec-Fetch-Site", "none");
|
||||
httpGet.setHeader("Sec-Fetch-User", "?1");
|
||||
httpGet.setHeader("Upgrade-Insecure-Requests", "1");
|
||||
|
||||
// Set cookies exactly like in curl
|
||||
httpGet.setHeader("Cookie", "userUid=1747102033185-d570fba9-62fd-40be-93ca-ed08b4de57d4; _sid=MTc0NzEwMjAzMzE4Ni4ycTU%3D; _scor_uid=135c13065ff84620b5318b489af93e87; _gcl_au=1.1.249135292.1747102036; _ga=GA1.1.1031614211.1747102037; WZRK_G=28895afb56ff48dda59fe8de0af746bf; FCNEC=%5B%5B%22AKsRol8sHYeSYz_FYPkInYXN3P4ZDPfVKbsRfILfDuOMLhDtkTuoCJP5MlvT9gIbOe7IlDfY8ZeHszhwdVtAoKF1gWv0pLAq5EqpLpse8CEm_ZNv-bUSs6zEyqpOkeKWFI_Ei6VfNAvnZAO8PcXdF8_ncsaO902X7g%3D%3D%22%5D%5D; _ga_KRGL1M61LX=GS2.1.s1747105135$o2$g0$t1747105135$j60$l0$h0");
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(10000)
|
||||
.setSocketTimeout(15000)
|
||||
.setConnectionRequestTimeout(10000)
|
||||
.build();
|
||||
httpGet.setConfig(requestConfig);
|
||||
|
||||
response = httpClient.execute(httpGet);
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (response != null) response.close();
|
||||
if (httpClient != null) httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse";
|
||||
String str = doGet(url);
|
||||
|
||||
181
src/main/java/cn/stock/market/utils/NseIndiaRequest.java
Normal file
181
src/main/java/cn/stock/market/utils/NseIndiaRequest.java
Normal file
@@ -0,0 +1,181 @@
|
||||
package cn.stock.market.utils;
|
||||
|
||||
import cn.stock.market.dto.StockHistoryRequest;
|
||||
import cn.stock.market.dto.StockHistoryResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class NseIndiaRequest {
|
||||
private static final String NSE_INDIA_URL = "https://www.nseindia.com";
|
||||
private static final String NSE_INDIA_CHART_URL = "https://charting.nseindia.com";
|
||||
private static final OkHttpClient client;
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
static {
|
||||
client = new OkHttpClient.Builder()
|
||||
.cookieJar(new CookieJar() {
|
||||
private final Map<String, List<Cookie>> cookieStore = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
|
||||
cookieStore.put(url.host(), cookies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cookie> loadForRequest(HttpUrl url) {
|
||||
List<Cookie> cookies = cookieStore.get(url.host());
|
||||
return cookies != null ? cookies : new ArrayList<Cookie>();
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Request createRequest(String url) {
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header("accept", "application/json, text/plain, */*")
|
||||
.header("accept-language", "en-US,en;q=0.9")
|
||||
.header("cache-control", "no-cache")
|
||||
.header("pragma", "no-cache")
|
||||
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
|
||||
.build();
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
private static void initCookie(String url) {
|
||||
Request request = createRequest(url);
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("Failed to fetch initial cookies");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to initialize cookies", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Integer getCode(String symbol) {
|
||||
Request request = createRequest(NSE_INDIA_CHART_URL + "//Charts/GetEQMasters").newBuilder()
|
||||
.addHeader("referer", NSE_INDIA_CHART_URL)
|
||||
.addHeader("origin", NSE_INDIA_CHART_URL)
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("Failed to get EQ code");
|
||||
}
|
||||
|
||||
String result = response.body().string();
|
||||
|
||||
String regex = "(\\d+)\\|" + symbol + "\\|.*";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(result);
|
||||
|
||||
if (matcher.find()) {
|
||||
return Integer.valueOf(matcher.group(1));
|
||||
}
|
||||
throw new IOException("No data found");
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to get EQ code", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static JSONObject stockByJYSFromHttp(String stockType, String symbol, String nseIndiaId) {
|
||||
initCookie(NSE_INDIA_URL);
|
||||
|
||||
String url = NSE_INDIA_URL + "/api/quote-equity?symbol=" + nseIndiaId;
|
||||
Request request = createRequest(url).newBuilder()
|
||||
.addHeader("referer", NSE_INDIA_URL)
|
||||
.addHeader("origin", NSE_INDIA_URL)
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("Request failed with code: " + response.code());
|
||||
}
|
||||
|
||||
JSONObject jsonData = JSONObject.parseObject(response.body().string());
|
||||
JSONObject data =jsonData.getJSONObject("priceInfo");
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("pricepercentchange",data.getString("pChange"));
|
||||
json.put("stockType",stockType);
|
||||
json.put("pricechange",data.getString("change"));
|
||||
json.put("pricecurrent",data.getString("lastPrice"));
|
||||
json.put("priceprevclose",data.getString("previousClose"));
|
||||
json.put("PREVDATE","");
|
||||
json.put("VOL",jsonData.getJSONObject("preOpenMarket").getString("totalTradedVolume"));
|
||||
json.put("dataSourceType","3");
|
||||
json.put("symbol",symbol);
|
||||
json.put("BSEID",symbol);
|
||||
json.put("NSEID",symbol);
|
||||
json.put("LTH",data.getString("upperCP"));
|
||||
json.put("LTL",data.getString("lowerCP"));
|
||||
json.put("OPN",data.getString("open"));
|
||||
|
||||
return json;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to fetch data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static StockHistoryResponse stockKLineFromHttp(StockHistoryRequest stockHistoryRequest, String resolution) {
|
||||
initCookie(NSE_INDIA_CHART_URL);
|
||||
|
||||
Integer code = getCode(stockHistoryRequest.getSymbol());
|
||||
|
||||
int interval = 1;
|
||||
if (StringUtils.equals("H", resolution)) {
|
||||
resolution = "I";
|
||||
interval = 60;
|
||||
}
|
||||
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("chartPeriod", resolution);
|
||||
body.put("chartStart", 0);
|
||||
body.put("exch", "N");
|
||||
body.put("fromDate", 0);
|
||||
body.put("instrType", "C");
|
||||
body.put("scripCode", code);
|
||||
body.put("timeInterval", interval);
|
||||
body.put("toDate", stockHistoryRequest.getTo() + 18000);
|
||||
body.put("ulToken", code);
|
||||
|
||||
String payload;
|
||||
try {
|
||||
payload = objectMapper.writeValueAsString(body);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to serialize body", e);
|
||||
}
|
||||
|
||||
RequestBody requestBody = RequestBody.create(
|
||||
MediaType.get("application/json; charset=utf-8"),
|
||||
payload
|
||||
);
|
||||
|
||||
Request request = createRequest(NSE_INDIA_CHART_URL + "//Charts/symbolhistoricaldata/").newBuilder()
|
||||
.addHeader("referer", NSE_INDIA_CHART_URL)
|
||||
.addHeader("origin", NSE_INDIA_CHART_URL)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("Request failed with code: " + response.code());
|
||||
}
|
||||
|
||||
StockHistoryResponse result = objectMapper.readValue(response.body().string(), StockHistoryResponse.class);
|
||||
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to fetch data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -159,6 +160,19 @@ public class BTodayStockController {
|
||||
|
||||
String forObject = restTemplate.getForObject(apiUrl, String.class);
|
||||
JSONObject jsonObject = JSON.parseObject(forObject);
|
||||
JSONArray arryData = jsonObject.getJSONArray("data");
|
||||
if (arryData != null&&arryData.size()>0) {
|
||||
try {
|
||||
JSONObject jsonObject1 = arryData.getJSONObject(0);
|
||||
String price = jsonObject1.getString("price");
|
||||
double priceValue = Double.parseDouble(price);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
jsonObject1.put("price", df.format(priceValue));
|
||||
} catch (NumberFormatException e) {
|
||||
// Handle the case where price is not a valid double
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
jsonObject.put("id",btodayStock.getId());
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,13 +26,14 @@ public class MoneyProxyApiControl {
|
||||
|
||||
@GetMapping({"/market/api/proxy/queryStockMoneyProxy","/api/proxy/queryStockMoneyProxy"})
|
||||
public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){
|
||||
log.info("queryStockByMoneyIdAndExchangeType");
|
||||
return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType);
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) {
|
||||
try {
|
||||
String url = "https://priceapi.moneycontrol.com/pricefeed/"+exchangeType+"/equitycash/" + scId ;
|
||||
String url = "https://moneycontrol.titanrwa.org/pricefeed/"+exchangeType+"/equitycash/" + scId ;
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
@@ -53,7 +54,8 @@ public class MoneyProxyApiControl {
|
||||
log.error("HTTP request failed with response code: " + responseCode);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("stockByMoneyIdAndExchangeTypeFromHttp",e);
|
||||
e.printStackTrace();
|
||||
log.error("stockByMoneyIdAndExchangeTypeFromHttp failed {}",e.getMessage());
|
||||
}
|
||||
return new JSONObject();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package cn.stock.market.web;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -12,6 +14,7 @@ import cn.qutaojing.common.jpa.ConditionBuilder;
|
||||
import cn.stock.market.domain.basic.entity.SiteNews;
|
||||
import cn.stock.market.domain.basic.repository.SiteNewsRepository;
|
||||
import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
|
||||
import cn.stock.market.infrastructure.job.InvestingTask;
|
||||
import cn.stock.market.web.annotations.EncryptFilter;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@@ -169,15 +172,22 @@ public class StockApiController {
|
||||
|
||||
@RequestMapping({"test.do"})
|
||||
@ResponseBody
|
||||
public ServerResponse test(@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum) {
|
||||
public ServerResponse test(/*@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum*/) {
|
||||
String news = stockService.getNews();
|
||||
List<String> newsList = Arrays.asList(news.split("<a href="));
|
||||
newsList = newsList.subList(1, newsList.size());
|
||||
newsList.forEach( n -> {
|
||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
||||
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||
String imgUrl = InvestingTask.extractImgSrc(n);
|
||||
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||
// Extract the date and time using regex
|
||||
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
|
||||
Matcher matcher = pattern.matcher(n);
|
||||
String time = "";
|
||||
if (matcher.find()) {
|
||||
time = matcher.group(1).trim();
|
||||
}
|
||||
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
@@ -238,7 +248,7 @@ public class StockApiController {
|
||||
@ResponseBody
|
||||
public ServerResponse getIndiaIndexByToday() {
|
||||
String INDEX_CODE = "TODAY_INDEX";
|
||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,60000, (string) -> {
|
||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||
return this.stockService.getIndexByBtoday();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ spring:
|
||||
show-sql: true
|
||||
# Redis配置
|
||||
redis:
|
||||
host: 43.132.212.180
|
||||
password: ruTZ9J3gaDhknJ
|
||||
port: 36379
|
||||
host: 43.153.142.41
|
||||
password: a5v8b86P4mVzFlUqJV
|
||||
port: 30001
|
||||
database: 1
|
||||
lettuce:
|
||||
pool:
|
||||
@@ -17,9 +17,9 @@ spring:
|
||||
datasource:
|
||||
stock-market:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8
|
||||
url: jdbc:mysql://43.153.142.41:30000/india_stock?useUnicode=true&characterEncoding=utf-8
|
||||
username: root
|
||||
password: 33BsUUcnXRYgwtIND
|
||||
password: uNejHIFQGJOUtYTmE
|
||||
maxActive: 500
|
||||
testWhileIdle: true
|
||||
validationQuery: SELECT 1
|
||||
|
||||
Reference in New Issue
Block a user