Compare commits

172 Commits

Author SHA1 Message Date
vu-tran
5aef88988e update orders index 2025-08-11 18:44:47 +07:00
vu-tran
02d7b9d027 Merge branch 'develop_red' of gitlab.main99.com:germany/ger-market-java into develop_red 2025-08-11 18:36:23 +07:00
vu-tran
d1fb4bded8 update index 2025-08-11 18:32:16 +07:00
dd5eeede7d feat: add support for fetching recent trading day chart data and optimize caching for index retrieval 2025-08-11 07:29:26 +08:00
vu-tran
f3dd600189 update time for response news 2025-08-11 00:36:45 +07:00
vu-tran
7caaccb580 update get news 2025-08-05 15:51:59 +07:00
7deabedfa3 feat: add BME stock types to top active codes filter 2025-08-01 22:47:42 +08:00
vpckiet
721317de0a Merge branch 'feature/update_top_list' into 'develop_red'
stock top list

See merge request germany/ger-market-java!4
2025-07-25 03:07:25 +00:00
Congkiet4695
88bfdfa7fa stock top list 2025-07-25 10:06:38 +07:00
vpckiet
51bcd72051 Merge branch 'feature/stock_type_filter' into 'develop_red'
update filter type stock top list

See merge request germany/ger-market-java!3
2025-07-24 03:28:23 +00:00
Congkiet4695
769b35046e update filter type stock top list 2025-07-24 10:26:47 +07:00
trannhanvu88
368f4f2f9f Edit .gitlab-ci.yml 2025-07-23 07:11:17 +00:00
trannhanvu88
4053683339 Edit .gitlab-ci.yml 2025-07-23 05:30:29 +00:00
VoGiaHuy2058
9fd87aaf89 done sync us stock and change env 2025-07-23 10:19:05 +07:00
vu-tran
ccda6cba45 update get gainer and loser 2025-07-09 08:56:49 +07:00
vu-tran
22303b5460 update 2025-07-04 18:38:26 +07:00
vu-tran
992108c6e4 update top gainer and loser 2025-07-04 17:31:09 +07:00
vu-tran
a086f33541 update top gainer and loser 2025-07-04 17:30:59 +07:00
vu-tran
d864aee7e1 update 2025-07-04 14:01:05 +07:00
vu-tran
fc74d7c33f update news 2025-07-04 13:41:21 +07:00
VuTran
309516c40b update url 2025-06-30 15:48:37 +07:00
VuTran
20875fbead update index name 2025-06-30 15:34:47 +07:00
VuTran
2e6474035b remove scheduler sync stock from tradingview 2025-06-30 11:10:13 +07:00
vu-tran
4db963b0e5 update top active 2025-06-27 17:14:48 +07:00
vu-tran
401983255a update index 2025-06-27 14:07:53 +07:00
vu-tran
2d36e8264f update chart 2025-06-20 11:04:18 +07:00
vu-tran
580d4321bb update sort by time 2025-06-19 14:43:23 +07:00
vu-tran
6f2c8652e2 Merge branch 'develop' of gitlab.main99.com:germany/ger-market-java into develop 2025-06-19 14:14:34 +07:00
vu-tran
e423e3fc19 get germany news 2025-06-19 14:14:13 +07:00
vpckiet
d237c51176 Merge branch 'feature/update_get_germany_stock' into 'develop'
update get germany stock

See merge request germany/ger-market-java!1
2025-06-19 03:00:22 +00:00
vpckiet
97bc0ea694 update get germany stock 2025-06-19 09:59:08 +07:00
VoGiaHuy2058
8ef7b46038 done home page 2025-06-18 22:41:58 +07:00
VoGiaHuy2058
9785a391a2 home-page 2025-06-18 17:51:36 +07:00
vu-tran
5b3504f32a update 2025-06-18 15:38:15 +07:00
vu-tran
f67af0d3e9 udpate 2025-06-18 14:22:40 +07:00
vu-tran
af21d583d9 update new stock 2025-06-18 13:35:15 +07:00
VoGiaHuy2058
cd06493b9c done requuiement 2025-06-18 10:37:12 +07:00
vu-tran
3255012fba turn off india stock task 2025-06-18 10:35:08 +07:00
VoGiaHuy2058
476645109d done for stockTemp repository 2025-06-18 07:52:49 +07:00
VoGiaHuy2058
66eccce4cb apply new daily stock 2025-06-17 17:33:18 +07:00
owen l
5ab279daa6 Update .gitlab-ci.yml file 2025-06-17 06:34:34 +00:00
vpckiet
be24a57d2d Merge branch 'feature/update_money_stock' into 'develop'
update money ipo

See merge request india/india_market_java!63
2025-06-02 06:55:25 +00:00
vpckiet
aa796cf853 update money ipo 2025-06-02 13:51:29 +07:00
vpckiet
9a06979f07 Merge branch 'feature/update_ipo' into 'develop'
update money ipo check

See merge request india/india_market_java!61
2025-05-22 07:33:13 +00:00
vpckiet
d1f9600361 update money ipo check 2025-05-22 14:32:35 +07:00
vpckiet
fcab660024 Merge branch 'feature/update_ipo' into 'develop'
update ipo check

See merge request india/india_market_java!60
2025-05-22 07:01:22 +00:00
vpckiet
ad95848c2c update ipo check 2025-05-22 14:00:18 +07:00
vu-tran
90a26823f0 update news 2025-05-13 10:10:42 +07:00
VoGiaHuy2058
c72c0ff4cd Revert "fix cron"
This reverts commit 85094c22b2.
2025-05-12 18:53:06 +07:00
VoGiaHuy2058
85094c22b2 fix cron 2025-05-12 18:44:16 +07:00
mush_ball
59684cccfc Edit .gitlab-ci.yml 2025-04-28 10:45:30 +00:00
vu-tran
57690ecb5e update logs 2025-04-28 17:38:16 +07:00
vu-tran
8cf511f1b7 update ipo 2025-04-24 13:41:59 +07:00
vu-tran
f612b5128e update issue size to long 2025-02-10 09:54:10 +07:00
vu-tran
07a69f29b9 update get data open ipo 2025-02-10 09:37:39 +07:00
vu-tran
3e1ff24bb6 update link ipo 2025-01-15 11:27:40 +07:00
vu-tran
b26d3962c4 update crawl ipo 2024-12-11 14:23:08 +07:00
vu-tran
d085d8de12 update crawl ipo 2024-12-11 12:39:15 +07:00
vpckiet
0476ad100b Merge branch 'bug/update_bse' into 'develop'
fix bug

See merge request india/india_market_java!55
2024-12-10 17:03:43 +00:00
Congkiet4695
f87df03715 fix bug 2024-12-11 00:01:57 +07:00
vpckiet
fc59d1f47c Merge branch 'bug/update_symbol' into 'develop'
fix bug chart day

See merge request india/india_market_java!54
2024-12-10 14:57:04 +00:00
vpckiet
6fdc13a72d fix bug chart day 2024-12-10 21:56:23 +07:00
vpckiet
6b5623dc33 Merge branch 'bug/update_symbol' into 'develop'
fix bug get chart

See merge request india/india_market_java!53
2024-12-10 13:15:40 +00:00
vpckiet
4a22fc0a95 fix bug get chart 2024-12-10 20:14:42 +07:00
vpckiet
563dae1c45 Merge branch 'feature/update_bseindia_detail' into 'develop'
update chart

See merge request india/india_market_java!52
2024-12-10 12:55:38 +00:00
vpckiet
fa02ebf03b update chart 2024-12-10 19:54:45 +07:00
vpckiet
0f5f25f744 Merge branch 'feature/update_bseindia_detail' into 'develop'
update get detail from bseindia

See merge request india/india_market_java!51
2024-12-10 09:38:33 +00:00
vpckiet
615aae7e1d update get detail from bseindia 2024-12-10 16:37:54 +07:00
vu-tran
c89345329d uncomment scheduler 2024-11-12 11:13:22 +07:00
vpckiet
f18521d190 Merge branch 'bug/nse_type' into 'develop'
fix bug

See merge request india/india_market_java!50
2024-10-28 10:40:50 +00:00
vpckiet
e84c212bf0 fix bug 2024-10-28 17:40:04 +07:00
vogiahuy2058
1ff1797b0b done new logic to add moneystock 2024-10-24 14:10:42 +07:00
vogiahuy2058
89c0fe0321 change cron 2024-10-23 16:39:41 +07:00
vogiahuy2058
b6052a46ff done save exchange type and save money stock 2024-10-23 16:35:59 +07:00
vpckiet
d40c30bcb5 Merge branch 'bug/crawl_news' into 'develop'
update crawl

See merge request india/india_market_java!48
2024-10-21 09:19:14 +00:00
vpckiet
5b16f1f2c9 update crawl 2024-10-21 16:14:22 +07:00
vpckiet
b8d4e0d3f2 Merge branch 'bug/update_kline_format' into 'develop'
update

See merge request india/india_market_java!46
2024-10-10 03:50:50 +00:00
vpckiet
c19277e390 update 2024-10-10 10:50:01 +07:00
vpckiet
514875878f Merge branch 'bug/update_kline_format' into 'develop'
fix bug kline

See merge request india/india_market_java!45
2024-10-10 01:47:17 +00:00
vpckiet
4257541342 fix bug kline 2024-10-09 17:18:26 +07:00
quangnguyen202
441adac15a Merge branch 'feature/optional-stock' into 'develop'
Add api for optional stock

See merge request india/india_market_java!44
2024-10-01 07:07:59 +00:00
quangnguyen202
ba29ab98c7 Add api for optional stock 2024-10-01 14:06:24 +07:00
Gavin g
94ec73874b Merge branch 'feature/kline-alternate-source' into 'develop'
Add alternate source

See merge request india/india_market_java!43
2024-09-26 09:57:06 +00:00
quangnguyen202
549345719a Add alternate source 2024-09-26 16:51:41 +07:00
gavin
3870400411 修改切换备用数据源的判断条件 2024-09-19 15:59:12 +08:00
Gavin g
94d2936ffb Merge branch 'feature/stock-kline-nseindia' into 'develop'
Add alternal source

See merge request india/india_market_java!42
2024-09-19 07:37:45 +00:00
quangnguyen202
59e4aa9e1a Add alternal source 2024-09-19 14:33:22 +07:00
gavin
bae645e3c6 修复官方查询时名称写死的问题 2024-09-12 14:15:31 +08:00
gavin
94d9aea2c8 指定股票更换详情测试代码 2024-09-10 13:11:01 +08:00
gavin
5ae9762d45 指定股票更换详情测试代码 2024-09-09 14:59:38 +08:00
quangnguyen202
ece52491dd Merge branch 'refactor/optimization' into 'develop'
Optimize

See merge request india/india_market_java!38
2024-09-09 06:54:16 +00:00
quangnguyen202
6235d41711 Optimize 2024-09-06 11:17:41 +07:00
vpckiet
c865eccaf4 Merge branch 'refactor/optimization' into 'develop'
Optimize code

See merge request india/india_market_java!37
2024-09-06 01:53:33 +00:00
quangnguyen202
136020a497 Update 2024-09-05 16:30:46 +07:00
quangnguyen202
d7da59aca1 Optimize code 2024-09-05 15:59:13 +07:00
gavin
8427bed427 指定股票更换详情测试代码 2024-09-04 12:52:17 +08:00
gavin
269f02b79d 指定股票更换详情测试代码 2024-09-04 11:56:04 +08:00
gavin
7cc456bcd8 同步手动更新代码 2024-09-02 15:32:50 +08:00
vpckiet
be05d403af Merge branch 'bug/craw_img_news' into 'develop'
update crawl img news

See merge request india/india_market_java!33
2024-09-02 06:47:52 +00:00
Congkiet4695
4a29bf6659 update crawl img news 2024-09-02 13:46:22 +07:00
gavin
5b2eb8519a 大盘缓存数据改为6秒 2024-07-26 15:04:56 +08:00
gavin
2e4449bd64 大盘数据更换moneycontrol 数据源 2024-07-26 14:53:50 +08:00
Thanh Nguyen
b321fd9d4e Update automatic-deployment link 2024-07-23 09:39:48 +07:00
gavin
2f9e54bf4f 更改数据库连接
更新新闻时间格式为24小时制
2024-07-12 15:33:25 +08:00
3bb354bbc6 Merge remote-tracking branch 'origin/develop' into develop 2024-07-08 12:38:26 +08:00
a403cba964 fix: 时间字段错乱 2024-07-08 12:38:13 +08:00
Achilles
99bde81670 Merge remote-tracking branch 'origin/develop' into develop 2024-06-28 17:00:04 +08:00
Achilles
bae941828e 代码优化和优化 2024-06-28 16:59:58 +08:00
gs
2f86571578 价格问题处理 2024-06-25 18:00:21 +08:00
gs
d491bef735 新闻时间处理 2024-06-25 17:45:15 +08:00
gs
74c64eb7d4 Merge remote-tracking branch 'origin/develop' into develop
# Conflicts:
#	src/main/java/cn/stock/market/web/StockApiController.java
2024-06-20 16:55:50 +08:00
gs
f50b6b5519 新闻时间处理 2024-06-20 16:54:56 +08:00
2446d89b30 fix: 时间字段错乱 2024-06-20 16:33:38 +08:00
gs
33a68eb7e8 新闻处理 2024-06-20 14:50:15 +08:00
gs
7b0a08150d Merge remote-tracking branch 'origin/develop' into develop
# Conflicts:
#	src/main/java/cn/stock/market/domain/basic/service/StockService.java
2024-06-20 14:47:53 +08:00
gs
146e9d9bc0 新闻处理 2024-06-20 14:47:04 +08:00
william
59a0480be0 Merge branch 'main' into 'develop'
# Conflicts:
#   docker-entrypoint.sh
2024-05-06 12:33:09 +00:00
william
5fe3200ea1 fix bug 2024-05-06 12:31:40 +00:00
vercel
943c6c77e4 fix: 新闻抓取优化 2024-05-05 13:53:46 +08:00
william
b2e93f646c 1 2024-05-01 11:57:12 +08:00
william
9af156cd4a 1 2024-05-01 11:53:13 +08:00
william
8660354dc1 fix bug 2024-05-01 01:35:02 +08:00
william
ed924d85ae Merge branch 'main' of gitlab.main99.com:india/india_market_java 2024-05-01 01:30:32 +08:00
william
b7f0793d88 修复错误 2024-05-01 01:30:27 +08:00
Administrator
4e9810e074 Merge branch 'develop' into 'main'
Merge branch 'main' into 'develop'

See merge request india/india_market_java!25
2024-04-30 16:37:43 +00:00
Administrator
d2e186cae6 Merge branch 'main' into 'develop'
Main

See merge request india/india_market_java!24
2024-04-30 16:19:23 +00:00
william
d8862710a1 兼容路径错误问题 2024-05-01 00:17:46 +08:00
william
efae848b4f 修复环境变量 2024-04-30 21:47:07 +08:00
william
0cec277282 修改命名 2024-04-29 23:35:09 +08:00
Administrator
f6cc52bb9c 更改docker镜像的名称 2024-04-29 10:23:45 +00:00
guoshuai
45fe49a398 Merge branch 'develop' into 'main'
fix:优化money股票K线图1w和1m

See merge request india/india_market_java!23
2024-04-29 07:16:55 +00:00
xiaoliuhu
e0007aa6cc fix:优化money股票K线图1w和1m 2024-04-29 14:10:48 +08:00
william
3982de78be 1 2024-04-27 09:00:47 +08:00
william
d24ce12179 1 2024-04-27 08:58:06 +08:00
william
7524952c46 docker镜像构建 2024-04-27 08:46:05 +08:00
guoshuai
40555fcd64 Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!22
2024-04-25 11:54:10 +00:00
xiaoliuhu
30d95acdcf fix:优化money股票K线图 2024-04-25 10:09:59 +08:00
xiaoliuhu
c340bba073 fix:优化money股票K线图1H和1D只返回当天数据 2024-04-24 22:21:04 +08:00
guoshuai
4a3b75e0c6 Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!21
2024-04-24 14:14:25 +00:00
xiaoliuhu
33c83af353 fix:优化money股票K线图1H和1D只返回当天数据 2024-04-24 22:11:49 +08:00
xiaoliuhu
11130a9eda fix:优化money股票K线图1H和1D只返回当天数据 2024-04-24 21:50:28 +08:00
xiaoliuhu
5a95d6be9a 优化money股票K线图1H和1D只返回当天数据 2024-04-24 21:24:03 +08:00
xiaoliuhu
e680bee42b fix:优化money股票K线图1H和1D只返回当天数据 2024-04-24 21:18:39 +08:00
xiaoliuhu
fbc7815365 fix:修改economictimes获取指数详情bug 2024-04-20 21:32:52 +08:00
xiaoliuhu
37bb619e24 fix:修改economictimes获取指数详情bug 2024-04-20 21:28:18 +08:00
xiaoliuhu
a7e6cc0b05 fix:拓展可自定义时间缓存接口,app指数接口增加缓存1分钟 2024-04-20 19:20:05 +08:00
xiaoliuhu
ece782497f fix:app指数接口增加economictimes数据源兜底 2024-04-20 19:11:47 +08:00
zhangjian
4b25467bd2 日志打印优化 2024-04-20 17:16:43 +08:00
zhangjian
5b3cc7e156 印度--获取指定指数信息接口getIndiaIndexByToday.do: BToday添加兜底数据源Growwin 2024-04-20 17:01:59 +08:00
zhangjian
55c9865845 money股票推荐getTopGainer和 getTopLoser接口根据股票名称去重 2024-04-20 14:26:15 +08:00
zhangjian
07d3b0623e money股票推荐相关getTopActives接口根据股票名称去重 2024-04-20 10:33:50 +08:00
guoshuai
85fe98cc29 Merge branch 'develop' into 'main'
hotfix: 脏数据情况下的一个股票处理

See merge request india/india_market_java!20
2024-03-26 11:21:53 +00:00
guoshuai
9d6413bc43 Merge branch 'develop' into 'main'
hotfix:价格优化

See merge request india/india_market_java!19
2024-03-21 09:42:50 +00:00
guoshuai
8c472d2973 Merge branch 'develop' into 'main'
代码优化

See merge request india/india_market_java!18
2024-03-18 10:19:06 +00:00
rplees
1d945f126e Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!17
2024-03-15 06:07:14 +00:00
rplees
19cb36b33a Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!16
2024-02-23 09:52:23 +00:00
rplees
a977f7c5fe Merge branch 'develop' into 'main'
新闻定时任务新增日志信息

See merge request india/india_market_java!15
2024-02-16 10:39:43 +00:00
rplees
f7bf2cb0eb Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!14
2024-02-16 10:13:14 +00:00
guoshuai
de44d54ece Merge branch 'develop' into 'main'
代码返回参数优化

See merge request india/india_market_java!13
2024-02-15 15:47:04 +00:00
guoshuai
ff2896a0fd Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!12
2024-02-15 15:04:45 +00:00
rplees
877154c1cc Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!11
2024-02-12 14:11:14 +00:00
rplees
96c23943ab Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!10
2024-02-08 12:35:11 +00:00
rplees
930e1e79cf Merge branch 'develop' into 'main'
新股修改的时间获取

See merge request india/india_market_java!9
2024-02-06 07:42:08 +00:00
rplees
6c429ba58f Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!8
2024-02-02 07:12:48 +00:00
rplees
277ee7dfe4 Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!7
2024-01-24 06:27:47 +00:00
rplees
933dadca3c Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!6
2024-01-14 15:09:09 +00:00
li deng
a9704b62ae Merge branch 'dengli2024/1/11' into 'main'
新闻定时任务

See merge request india/india_market_java!5
2024-01-11 10:16:49 +00:00
dengli
ef392a7fe7 新闻定时任务 2024-01-11 18:04:32 +08:00
rplees
e98b6d0463 Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!4
2024-01-09 12:35:18 +00:00
rplees
0a0c969e28 Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!3
2024-01-04 07:45:15 +00:00
rplees
2087d8914b Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!2
2024-01-03 12:00:31 +00:00
rplees
42a40b9ff8 Merge branch 'develop' into 'main'
Develop

See merge request india/india_market_java!1
2023-12-31 11:13:55 +00:00
61 changed files with 3364 additions and 524 deletions

View File

@@ -1,7 +1,13 @@
stages: stages:
# 构建 # 构建
- build - build
- webhook - dockerize
- deploy
variables:
company_name: juyoutech
project_name: germany_stock
service_name: market
build: build:
image: maven:3.6.3-openjdk-8 image: maven:3.6.3-openjdk-8
@@ -9,6 +15,7 @@ build:
only: only:
- main - main
- develop - develop
- develop_red
before_script: before_script:
- echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" - echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -37,16 +44,45 @@ build:
- mvn clean install -Dmaven.test.skip=true - mvn clean install -Dmaven.test.skip=true
- ls - ls
- echo ">>>>>>Finish Building<<<<<<" - echo ">>>>>>Finish Building<<<<<<"
webhook: dockerize:
stage: webhook stage: dockerize
tags:
- hk2
dependencies:
- build
only: only:
- main
- develop - develop
- develop_red
script: script:
- echo ">>>>>>Start Deploy<<<<<<" - 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_red
script:
- echo "Deploying application..."
- ls - ls
- apt-get update - apk update
- apt-get install -y curl - apk add 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 - apk add curl openssh sshpass
- echo ">>>>>>Start Deploy Finish<<<<<<" - |
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no ubuntu@"$SSH_HOST" "./deploy_service.sh market $CI_PIPELINE_ID"
- echo "Application successfully deployed."

17
Dockerfile Normal file
View File

@@ -0,0 +1,17 @@
FROM openjdk:8
RUN echo "deb http://archive.debian.org/debian/ stretch main contrib non-free" > /etc/apt/sources.list \
&& echo "deb-src http://archive.debian.org/debian/ stretch main contrib non-free" >> /etc/apt/sources.list \
&& echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/10no-check-valid
RUN apt-get update
#RUN apt-get install -y iputils-ping dnsutils vim net-tools --allow-unauthenticated
WORKDIR /app
COPY target/india_market_java.jar /app/app.jar
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
CMD ["docker-entrypoint.sh"]

21
docker-entrypoint.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
export JAVA_OPTS="$JAVA_OPTS -XX:-OmitStackTraceInFastThrow \
-Dspring.redis.host=$REDIS_HOST \
-Dspring.redis.password=$REDIS_PASS \
-Dmarket.domain=$MARKET_HOST \
-Dspring.redis.port=$REDIS_PORT \
-Dspring.datasource.stock-market.url=jdbc:mysql://$MYSQL_HOST:$MYSQL_PORT/$MYSQL_DB?useUnicode=true&autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=true \
-Dspring.datasource.stock-market.username=$MYSQL_USER \
-Dspring.datasource.stock-market.password=$MYSQL_PASSWORD \
-Dspring.datasource.stock.url=jdbc:mysql://$MYSQL_HOST:$MYSQL_PORT/$MYSQL_DB?useUnicode=true&autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=true \
-Dspring.datasource.stock.username=$MYSQL_USER \
-Dspring.datasource.stock.password=$MYSQL_PASSWORD"
echo 'param:'$@
echo 'JAVA_OPTS:'$JAVA_OPTS
java $JAVA_OPTS -jar /app/app.jar $@
tail -f /dev/null

12
pom.xml
View File

@@ -89,6 +89,12 @@
<version>4.1.0</version> <version>4.1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
</dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
@@ -185,6 +191,12 @@
<version>30.1-jre</version> <version>30.1-jre</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@@ -29,6 +29,10 @@ public class QMoneyStockPO extends EntityPathBase<MoneyStockPO> {
public final StringPath moneyScId = createString("moneyScId"); 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 DateTimePath<java.util.Date> saveTime = createDateTime("saveTime", java.util.Date.class);
public final StringPath selfDispId = createString("selfDispId"); public final StringPath selfDispId = createString("selfDispId");
@@ -39,6 +43,8 @@ public class QMoneyStockPO extends EntityPathBase<MoneyStockPO> {
public final StringPath stockType = createString("stockType"); public final StringPath stockType = createString("stockType");
public final BooleanPath useFromBseindia = createBoolean("useFromBseindia");
public QMoneyStockPO(String variable) { public QMoneyStockPO(String variable) {
super(MoneyStockPO.class, forVariable(variable)); super(MoneyStockPO.class, forVariable(variable));
} }

View File

@@ -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);
}
}

View File

@@ -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 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> id = createNumber("id", Integer.class);
public final NumberPath<Integer> isList = createNumber("isList", Integer.class); public final NumberPath<Integer> isList = createNumber("isList", Integer.class);

View File

@@ -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);
}
}

View File

@@ -20,6 +20,12 @@ import cn.stock.market.domain.basic.entity.SiteSetting;
import cn.stock.market.domain.basic.repository.SiteSettingRepository; import cn.stock.market.domain.basic.repository.SiteSettingRepository;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.TimeZone;
@SpringBootApplication(exclude = { @SpringBootApplication(exclude = {
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
RedisAutoConfiguration.class, RedisAutoConfiguration.class,
@@ -31,6 +37,11 @@ public class StockMarketLaunch implements CommandLineRunner {
public static void main(String[] args) { public static void main(String[] args) {
HttpGlobalConfig.setTimeout(45000); HttpGlobalConfig.setTimeout(45000);
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Madrid"));
log.info("JVM ZoneId: {}", ZoneId.systemDefault());
log.info("Sample: now={}, madrid={}",
new Date(),
ZonedDateTime.now(ZoneId.of("Europe/Madrid")));
SpringApplication.run(StockMarketLaunch.class, args); SpringApplication.run(StockMarketLaunch.class, args);
} }

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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;
}
}

View File

@@ -54,6 +54,11 @@ public class StockRepository extends LocalCacheRepository<Stock, StockPO, Intege
return map; return map;
} }
public Map<String, Stock> cacheGidMap() {
Map<String, Stock> map = cacheList().stream().collect(Collectors.toMap(Stock::getStockGid, val -> val, (u, v) -> u));
return map;
}
public Map<String, Stock> cacheNameMap() { public Map<String, Stock> cacheNameMap() {
Map<String, Stock> map = cacheList() Map<String, Stock> map = cacheList()

View File

@@ -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);
}
}

View File

@@ -1,28 +1,21 @@
package cn.stock.market.domain.basic.service; package cn.stock.market.domain.basic.service;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.net.ssl.X509TrustManager;
import javax.persistence.EntityExistsException; import javax.persistence.EntityExistsException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.sound.midi.Soundbank;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.StrFormatter; import cn.hutool.core.text.StrFormatter;
import cn.stock.market.dto.model.*; import cn.stock.market.dto.model.*;
import cn.stock.market.infrastructure.api.EttechchartsApis;
import cn.stock.market.infrastructure.api.GrowwInApis;
import cn.stock.market.infrastructure.api.HomeApiIndex;
import cn.stock.market.infrastructure.api.TodayApis; import cn.stock.market.infrastructure.api.TodayApis;
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo; import cn.stock.market.infrastructure.api.investing.*;
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
import cn.stock.market.infrastructure.api.investing.InvestingApis;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO; import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
import cn.stock.market.utils.*; import cn.stock.market.utils.*;
import com.ag.utils.CollectionUtils; import com.ag.utils.CollectionUtils;
@@ -30,18 +23,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Request.Builder; import okhttp3.Request.Builder;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import cn.stock.market.infrastructure.db.po.QStockPO; import cn.stock.market.infrastructure.db.po.QStockPO;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@@ -70,11 +54,6 @@ import cn.stock.market.infrastructure.api.sina.vo.MarketVO;
import cn.stock.market.infrastructure.api.sina.vo.MarketVOResult; import cn.stock.market.infrastructure.api.sina.vo.MarketVOResult;
import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO; import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO;
import cn.stock.market.infrastructure.api.sina.vo.k.echarts.EchartsDataVO; import cn.stock.market.infrastructure.api.sina.vo.k.echarts.EchartsDataVO;
import cn.stock.market.utils.GetPyByChinese;
import cn.stock.market.utils.HttpClientRequest;
import cn.stock.market.utils.PropertiesUtil;
import cn.stock.market.utils.ServerResponse;
import cn.stock.market.utils.Utils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@@ -268,34 +247,112 @@ public class StockService {
String result = ""; String result = "";
try { try {
// 使用Jsoup连接到网页 // 使用Jsoup连接到网页
Document doc = Jsoup.connect("https://www.business-standard.com/markets/news") // 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("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("Referer", "https://www.business-standard.com/")
.header("Accept-Language", "en-US,en;q=0.9") // .header("Accept-Language", "en-US,en;q=0.9")
.get(); // .get();
result = doc.html().substring(doc.html().indexOf("<div class=\"short-video-img\">"),doc.html().lastIndexOf("<div class=\"short-video-img\">")+500); 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) { } catch (Exception e) {
return e.toString(); return e.toString();
} }
return result; 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) { 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 = ""; String result = "";
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
try { try {
// 使用Jsoup连接到网页 // Step 1: Get raw HTML via HttpClient
Document doc = Jsoup.connect(url) String rawHtml = HttpClientRequest.doGetNews(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/") // Step 2: Parse HTML with Jsoup
.header("Accept-Language", "en-US,en;q=0.9") Document doc = Jsoup.parse(rawHtml);
.get();
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1); // 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(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) { } catch (Exception e) {
list.add(e.toString()); list.add("[Error] " + e.getMessage());
return list;
} }
return list; return list;
} }
@@ -989,69 +1046,67 @@ public class StockService {
return ServerResponse.createBySuccess(indexVoList); return ServerResponse.createBySuccess(indexVoList);
} }
public ServerResponse getIndexByBtoday(){ public ServerResponse getIndexByBtoday() throws Exception {
List<IndiaIndexVo> indexVoList = new ArrayList<>(); List<StockIndex> list = HomeApiIndex.fetchStockIndices();
try {
String exchange = "bse"; List<IndiaIndexNewVo> indexVoList = new ArrayList<>();
IndiaIndexVo vo1 = new IndiaIndexVo();
String coCode = "20558"; for (StockIndex stockIndex : list) {
JSONObject object = TodayApis.getStockDetail(exchange, coCode); IndiaIndexNewVo vo1 = new IndiaIndexNewVo();
IndiaStockVO market = objToVo(object); IndiaStockVO market = new IndiaStockVO();
market.setName("BSESENSEX指数"); market.setClose(String.valueOf(stockIndex.getClose()));
market.setHigh(String.valueOf(stockIndex.getHigh()));
market.setLow(String.valueOf(stockIndex.getLow()));
market.setName(stockIndex.getName());
market.setNowPrice(String.valueOf(stockIndex.getClose()));
market.setOpen(String.valueOf(stockIndex.getOpen()));
market.setRate(String.valueOf(stockIndex.getPercentChange()));
vo1.setIndexVo(market); vo1.setIndexVo(market);
//获取k线图 1D 当天的数据 // 只获取最近交易日的K线数据智能跳过周末优化性能和网络传输
String format = "S"; List<ChartCandle> kLines = HomeApiIndex.fetchTodayAndYesterdayChartData(stockIndex.getId());
String durationType = "D"; vo1.setKLine(kLines);
String duration = "1";
List kine = TodayApis.getStockKline(exchange,coCode,format,durationType,duration);
vo1.setKLine(kine);
indexVoList.add(vo1); indexVoList.add(vo1);
}catch (Exception e){ List<String> order = Arrays.asList(
log.info("获取NIFTY50指数数据异常异常信息{}。。。。",e.getMessage()); "IBEX 35 Index",
"DAX Index",
"Dow Jones Industrial Average",
"S&P 500 Index"
);
Map<String, Integer> orderMap = new HashMap<>();
for (int i = 0; i < order.size(); i++) {
orderMap.put(order.get(i), i);
}
indexVoList.sort(Comparator.comparingInt(o -> orderMap.getOrDefault(o.getIndexVo().getName(), Integer.MAX_VALUE)));
} }
try {
String exchange = "nse";
IndiaIndexVo vo1 = new IndiaIndexVo();
String coCode = "20559";
JSONObject object = TodayApis.getStockDetail(exchange, 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.info("获取NIFTY50指数数据异常异常信息{}。。。。",e.getMessage());
}
return ServerResponse.createBySuccess(indexVoList); return ServerResponse.createBySuccess(indexVoList);
} }
private IndiaStockVO objToVo(JSONObject object){ private IndiaStockVO objToVo(JSONObject object){
IndiaStockVO market = new IndiaStockVO(); IndiaStockVO market = new IndiaStockVO();
if(object.containsKey("prev_close")){ if(object.containsKey("priceprevclose")){
market.setClose(object.getString("prev_close")); market.setClose(object.getString("priceprevclose"));
} }
if(object.containsKey("price")){ if(object.containsKey("pricecurrent")){
market.setNowPrice(object.getString("price")); market.setNowPrice(object.getString("pricecurrent"));
} }
if(object.containsKey("perchg")){ if(object.containsKey("pricepercentchange")){
market.setRate(object.getString("perchg")); market.setRate(object.getString("pricepercentchange"));
} }
if(object.containsKey("high_price")){ if(object.containsKey("HIGH")){
market.setHigh(object.getString("high_price")); market.setHigh(object.getString("HIGH"));
} }
if(object.containsKey("low_price")){ if(object.containsKey("LOW")){
market.setLow(object.getString("low_price")); market.setLow(object.getString("LOW"));
} }
if(object.containsKey("open_price")){ if(object.containsKey("OPEN")){
market.setOpen(object.getString("open_price")); market.setOpen(object.getString("OPEN"));
} }
return market; return market;
// stockListVO.setName(jsonObject.getString("companyname")); // stockListVO.setName(jsonObject.getString("companyname"));
@@ -1069,4 +1124,48 @@ public class StockService {
} }
public ServerResponse getEttechcharts(){
List<IndiaIndexVo> indexVoList = new ArrayList<>();
try {
//获取详情
String indexid = "2365";
String exchange = "47";
String keyName = "sensex";
IndiaIndexVo vo1 = new IndiaIndexVo();
JSONObject object = EttechchartsApis.getStockDetail(indexid, exchange,keyName);
IndiaStockVO market = EttechchartsApis.ettechchartsObjToVo(object);
market.setName("BSESENSEX指数");
vo1.setIndexVo(market);
//获取k线图 1min 当天的数据 分钟
String scripcode = "SENSEX";
List kine = EttechchartsApis.getStockKline(scripcode,exchange);
vo1.setKLine(kine);
indexVoList.add(vo1);
}catch (Exception e){
log.info("获取BSESENSEX指数数据异常异常信息{}。。。。",e.getMessage());
}
try {
//获取详情
String indexid = "2369";
String exchangeid = "50";
String keyName = "nifty";
IndiaIndexVo vo1 = new IndiaIndexVo();
JSONObject object = EttechchartsApis.getStockDetail(indexid, exchangeid,keyName);
IndiaStockVO market = EttechchartsApis.ettechchartsObjToVo(object);
market.setName("NIFTY50指数");
vo1.setIndexVo(market);
//获取k线图 1min 当天的数据 分钟
String scripcode = "NSE+Index";
List kine = EttechchartsApis.getStockKline(scripcode,exchangeid);
vo1.setKLine(kine);
indexVoList.add(vo1);
}catch (Exception e){
log.info("获取NIFTY50指数数据异常异常信息{}。。。。",e.getMessage());
}
return ServerResponse.createBySuccess(indexVoList);
}
} }

View 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;
}
}

View File

@@ -0,0 +1,10 @@
package cn.stock.market.dto;
import lombok.Data;
import java.util.List;
@Data
public class RawStockApiResponse {
private List<StockDataDto> data;
}

View File

@@ -0,0 +1,13 @@
package cn.stock.market.dto;
import lombok.Data;
@Data
public class StockDataDto {
private long time;
private double open;
private double close;
private double max;
private double min;
private long volume;
}

View File

@@ -0,0 +1,31 @@
package cn.stock.market.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class StockQuoteData {
private String id;
private String symbol;
private String name;
private String exchange;
private String mic_code;
private String datetime;
private long timestamp;
private double open;
private double high;
private double low;
private double close;
private long volume;
private double previous_close;
private double change;
private double percent_change;
private double average_volume;
@JsonProperty("is_market_open")
private boolean market_open;
private Long market_cap;
private Object fifty_two_week;
private int icon;
}

View File

@@ -0,0 +1,13 @@
package cn.stock.market.dto;
import lombok.Data;
import java.util.List;
@Data
public class StockQuoteResponse {
private List<StockQuoteData> data;
private boolean success;
private String message;
private int status;
}

View File

@@ -0,0 +1,13 @@
package cn.stock.market.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class TradingViewData {
private String s; // symbol
private List<Object> d; // data array
}

View File

@@ -0,0 +1,13 @@
package cn.stock.market.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class TradingViewResponse {
private int totalCount;
private List<TradingViewData> data;
}

View 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)
}

View 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)
}

View 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
}

View 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;
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,233 @@
package cn.stock.market.infrastructure.api;
import cn.stock.market.dto.TodayStockDTO;
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo;
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 数据来源网站:<a href="https://groww.in/indices/nifty">...</a>, <a href="https://groww.in/indices/sp-bse-sensex">...</a>
*
* @auther jnerh
*/
public class GrowwInApis {
public static final String INDEX_DETAIL_URL = "https://groww.in/v1/api/stocks_data/v1/accord_points/exchange/%s/segment/CASH/latest_indices_ohlc/%s";
public static final String INDEX_KLINE_URL = "https://groww.in/v1/api/charting_service/v2/chart/delayed/exchange/%s/segment/CASH/%s/daily?intervalInMinutes=%s&minimal=true";
public static void requestSenSexData(List<IndiaIndexVo> indexVoList) {
IndiaIndexVo vo1 = new IndiaIndexVo();
JSONObject object = GrowwInApis.getSenSexDetail();
IndiaStockVO market = GrowwInApis.objToVo(object);
market.setName("BSESENSEX指数");
vo1.setIndexVo(market);
List kine = GrowwInApis.getSenSexKline();
vo1.setKLine(kine);
indexVoList.add(vo1);
}
public static void requestNifty50Data(List<IndiaIndexVo> indexVoList) {
IndiaIndexVo vo1 = new IndiaIndexVo();
JSONObject object = GrowwInApis.getNifty50Detail();
IndiaStockVO market = GrowwInApis.objToVo(object);
market.setName("NIFTY50指数");
vo1.setIndexVo(market);
List kine = GrowwInApis.getNifty50Kline();
vo1.setKLine(kine);
indexVoList.add(vo1);
}
/**
* 获取Nifty50指数详情
*/
public static JSONObject getIndexDetail(String exchange, String type) {
String url = String.format(INDEX_DETAIL_URL, exchange, type);
String str = get(url);
return JSON.parseObject(str);
}
/**
* 获取k线图
*/
public static List getIndexKline(String exchange, String type, String intervalInMinutes) {
String url = String.format(INDEX_KLINE_URL, exchange, type, intervalInMinutes);
String str = get(url);
JSONObject object = JSON.parseObject(str);
return getList(object.getString("candles"));
}
/**
* 获取Nifty50指数详情
*/
public static JSONObject getSenSexDetail() {
return getIndexDetail("BSE", "1");
}
/**
* 获取k线图
*/
public static List getSenSexKline() {
return getIndexKline("BSE", "1", "1");
}
/**
* 获取Nifty50指数详情
*/
public static JSONObject getNifty50Detail() {
return getIndexDetail("NSE", "NIFTY");
}
/**
* 获取k线图
*/
public static List getNifty50Kline() {
return getIndexKline("NSE", "NIFTY", "5");
}
static String get(String url) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
String result = "";
try {
httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Referer", "https://groww.in/indices/nifty");
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0");
httpGet.setHeader("X-App-Id", "growwWeb");
httpGet.setHeader("X-Device-Id", "fd4815a2-49e4-570a-931a-0316d4d8a52d");
httpGet.setHeader("X-Device-Type", "desktop");
httpGet.setHeader("X-Platform", "web");
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
httpGet.setConfig(requestConfig);
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != response) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
public static IndiaStockVO objToVo(JSONObject object) {
IndiaStockVO market = new IndiaStockVO();
if (object.containsKey("close")) {
market.setClose(object.getString("close"));
}
if (object.containsKey("value")) {
market.setNowPrice(object.getString("value"));
}
if (object.containsKey("dayChangePerc")) {
market.setRate(object.getString("dayChangePerc"));
}
if (object.containsKey("high")) {
market.setHigh(object.getString("high"));
}
if (object.containsKey("low")) {
market.setLow(object.getString("low"));
}
if (object.containsKey("open")) {
market.setOpen(object.getString("open"));
}
return market;
}
private static List getList(String json) {
List<JSONObject> dataObject = new ArrayList<>();
JSONArray jsonArray = JSON.parseArray(json);
for (Object obj : jsonArray) {
JSONObject entity = new JSONObject();
JSONArray jsonArray1 = JSON.parseArray(obj.toString());
entity.put("upd_date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(JSON.parseArray(obj.toString()).getLong(0) * 1000)).replace(" ", "T"));
entity.put("price", jsonArray1.getBigDecimal(1));
dataObject.add(entity);
}
return dataObject;
}
private static TodayStockDTO todayStockDTO(JSONObject jsonObject) {
TodayStockDTO dto = new TodayStockDTO();
if (jsonObject.containsKey("exchange")) {
dto.setStockType(jsonObject.getString("exchange"));
} else {
dto.setStockType("");
}
if (jsonObject.containsKey("lname")) {
dto.setStockName(jsonObject.getString("lname"));
} else {
dto.setStockName("");
}
if (jsonObject.containsKey("high_price")) {
dto.setHighPrice(jsonObject.getString("highPrice"));
} else {
dto.setHighPrice("0.00");
}
if (jsonObject.containsKey("low_price")) {
dto.setLowPrice(jsonObject.getString("low_price"));
} else {
dto.setLowPrice("0.00");
}
if (jsonObject.containsKey("price")) {
dto.setLastPrice(jsonObject.getString("price"));
} else {
dto.setLastPrice("0.00");
}
if (jsonObject.containsKey("close_price")) {
dto.setPrevClosePrice(jsonObject.getString("close_price"));
} else {
dto.setPrevClosePrice("0.00");
}
if (jsonObject.containsKey("netchg")) {
dto.setChange(jsonObject.getString("netchg"));
} else {
dto.setChange("0.00");
}
if (jsonObject.containsKey("perchg")) {
dto.setChangePercent(jsonObject.getString("perchg"));
} else {
dto.setChangePercent("0.00");
}
return dto;
}
public static void main(String[] args) {
System.out.println(getNifty50Detail());
System.out.println(getNifty50Kline());
}
}

View File

@@ -0,0 +1,228 @@
package cn.stock.market.infrastructure.api;
import cn.qutaojing.common.utils.SpringUtils;
import cn.stock.market.dto.model.ChartCandle;
import cn.stock.market.dto.model.StockIndex;
import cn.stock.market.web.config.Config;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class HomeApiIndex {
private static final OkHttpClient client = new OkHttpClient();
static Config config = SpringUtils.getBean(Config.class);
private static final String API_URL = config.getStockUrlPrefix() + "/api/ger-market/stocks/query-list?symbols=IBC:BME,DAX,^DJI:NASDAQ,^SPX:NASDAQ";
private static final String BASE_URL = config.getStockUrlPrefix() + "/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"));
if (index.getSymbol().equals("DAX")) {
index.setName("DAX Index");
}else if (index.getSymbol().equals("MDAX")) {
index.setName("MDAX Index");
}else if (index.getSymbol().equals("IBC:BME")) {
index.setName("IBEX 35 Index");
} else if (index.getSymbol().equals("SDXP")) {
index.setName("SDAX Index");
}else {
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 {
return fetchChartDataWithDateFilter(symbol, amount, false);
}
/**
* 获取最近的交易日K线数据支持跨周末
* @param symbol 股票代码
* @return 最近交易日的K线数据
*/
public static List<ChartCandle> fetchTodayAndYesterdayChartData(String symbol) throws Exception {
return fetchChartDataWithDateFilter(symbol, 168, true); // 获取7天数据确保包含交易日
}
/**
* 获取图表数据,支持日期过滤
* @param symbol 股票代码
* @param amount 数据量
* @param filterRecentDays 是否只返回最近交易日的数据
*/
private static List<ChartCandle> fetchChartDataWithDateFilter(String symbol, int amount, boolean filterRecentDays) throws Exception {
List<ChartCandle> result = new ArrayList<>();
String url = BASE_URL + "?symbol=" + symbol + "&interval=H&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");
if (filterRecentDays) {
// 获取最近的交易日期
Set<LocalDate> recentTradingDays = getRecentTradingDays();
for (int i = 0; i < data.length(); i++) {
JSONObject obj = data.getJSONObject(i);
long ts = obj.optLong("time");
ZonedDateTime zonedDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.of("Europe/Berlin"));
LocalDate dataDate = zonedDateTime.toLocalDate();
// 只保留最近交易日的数据
if (recentTradingDays.contains(dataDate)) {
ChartCandle candle = new ChartCandle();
String formattedTime = convertToGermanTime(ts);
candle.setUpd_date(formattedTime);
candle.setPrice(getDoubleOrNull(obj, "close"));
result.add(candle);
}
}
} else {
// 不过滤,返回所有数据
for (int i = 0; i < data.length(); i++) {
JSONObject obj = data.getJSONObject(i);
long ts = obj.optLong("time");
String formattedTime = convertToGermanTime(ts);
ChartCandle candle = new ChartCandle();
candle.setUpd_date(formattedTime);
candle.setPrice(getDoubleOrNull(obj, "close"));
result.add(candle);
}
}
return result;
}
/**
* 获取最近的交易日期(排除周末)
* @return 最近两个交易日的日期集合
*/
public static Set<LocalDate> getRecentTradingDays() {
Set<LocalDate> tradingDays = new HashSet<>();
ZoneId germanyZone = ZoneId.of("Europe/Berlin");
LocalDate current = LocalDate.now(germanyZone);
int foundDays = 0;
int daysBack = 0;
// 向前查找最近的两个交易日
while (foundDays < 2 && daysBack < 10) { // 最多向前查找10天
LocalDate checkDate = current.minusDays(daysBack);
// 排除周末(周六=6, 周日=7
if (checkDate.getDayOfWeek() != DayOfWeek.SATURDAY &&
checkDate.getDayOfWeek() != DayOfWeek.SUNDAY) {
tradingDays.add(checkDate);
foundDays++;
}
daysBack++;
}
return tradingDays;
}
// 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);
}
}

View File

@@ -187,18 +187,17 @@ public class TodayApis {
//获取详情 //获取详情
public static JSONObject getStockDetail(String exchange,String coCode){ 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); String str = get(url);
JSONObject object = JSON.parseObject(str); JSONObject object = JSON.parseObject(str);
boolean bool = false; boolean bool = false;
if(object.containsKey("success")){ if(object.containsKey("code")){
bool = object.getBoolean("success"); bool = object.getInteger("code") == 200;
} }
if(!bool){ if(!bool){
return new JSONObject(); return new JSONObject();
} }
JSONArray jsonArray = JSON.parseArray(object.getString("data")); JSONObject entity = JSON.parseObject(object.getString("data"));
JSONObject entity = JSON.parseObject(jsonArray.get(0).toString());
return entity; return entity;
} }

View File

@@ -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;
}

View File

@@ -56,6 +56,14 @@ public class MoneyStockPO {
* 展示表示 */ * 展示表示 */
String selfDispId; String selfDispId;
/**
* NSE India的id */
String nseIndiaId;
/**
* NSE India Chart的id */
String nseIndiaChartId;
/** /**
* 自有self_url */ * 自有self_url */
String selfUrl; String selfUrl;
@@ -75,4 +83,6 @@ public class MoneyStockPO {
/** /**
* 是否展示 0是 1否 */ * 是否展示 0是 1否 */
Integer isShow; Integer isShow;
Boolean useFromBseindia = false;
} }

View File

@@ -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;
}

View File

@@ -8,6 +8,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
@@ -75,6 +76,7 @@ public class SiteNewsPO {
/** /**
* 显示时间 */ * 显示时间 */
@ApiModelProperty("显示时间") @ApiModelProperty("显示时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Europe/Madrid")
Date showTime; Date showTime;
/** /**

View File

@@ -61,11 +61,11 @@ public class StockIpoPO {
/** /**
* 是否显示【1 显示2 不显示】 */ * 是否显示【1 显示2 不显示】 */
Integer isShow; Integer isShow = 1;
/** /**
* 是否上市【1 未上市2 已上市】 */ * 是否上市【1 未上市2 已上市】 */
Integer isList; Integer isList = 1;
Date createDate; Date createDate;
@@ -79,6 +79,8 @@ public class StockIpoPO {
* 申请总额 */ * 申请总额 */
String apply; String apply;
String exchangeType;
/** /**
* 市盈率 */ * 市盈率 */
BigDecimal peRatio; BigDecimal peRatio;

View File

@@ -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;
}

View File

@@ -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> {
}

View File

@@ -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> {
}

View File

@@ -7,6 +7,7 @@ import cn.stock.market.domain.basic.repository.StockRepository;
import cn.stock.market.domain.basic.service.StockService; import cn.stock.market.domain.basic.service.StockService;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis; import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.infrastructure.db.po.QSiteNewsPO; import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
import cn.stock.market.utils.DateTimeUtil;
import cn.stock.market.utils.Utils; import cn.stock.market.utils.Utils;
import com.ag.utils.CollectionUtils; import com.ag.utils.CollectionUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
@@ -15,25 +16,45 @@ import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.time.LocalDateTime;
import java.util.Date; import java.time.ZoneId;
import java.util.List; import java.time.ZonedDateTime;
import java.util.Map; import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j @Slf4j
@Component @Component
@RestController
@RequestMapping("/api/market/investing")
public class InvestingTask { public class InvestingTask {
@Autowired @Autowired
StockService stockService; StockService stockService;
@Autowired @Autowired
SiteNewsRepository newsRepository; SiteNewsRepository newsRepository;
@Autowired
RestTemplate restTemplate;
// @Scheduled(cron = "0 0 6 * * ?") // @Scheduled(cron = "0 0 6 * * ?")
public void syncIndiaData(){ public void syncIndiaData(){
@@ -107,7 +128,7 @@ public class InvestingTask {
} }
/*新闻接口*/ /*新闻接口*/
@Scheduled(cron = "0 0 0/3 * * ?") // @Scheduled(cron = "0 0 0/3 * * ?")
public void saveStockNews() { public void saveStockNews() {
log.info("英文股票新闻数据同步开始"); log.info("英文股票新闻数据同步开始");
try { try {
@@ -118,8 +139,16 @@ public class InvestingTask {
newsList.forEach( n -> { newsList.forEach( n -> {
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2); String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_")); String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?")); // 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 = 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 siteNews = new SiteNews();
siteNews.setAddTime(new Date()); siteNews.setAddTime(new Date());
@@ -140,4 +169,251 @@ 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;
}
/*德国新闻接口*/
// @Scheduled(cron = "0 0 0/3 * * ?")
public void saveGerNews() {
log.info("德国股票新闻数据同步开始");
int savedCount = 0;
int totalCount = 0;
try {
// API URL for getting news list
String newsListUrl = "https://api.boerse-frankfurt.de/v1/data/category_news?newsType=ALL&lang=de&offset=0&limit=50";
// Headers for the API request
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json, text/plain, */*");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8,ug;q=0.7,fr;q=0.6");
headers.add("origin", "https://www.boerse-frankfurt.de");
headers.add("priority", "u=1, i");
headers.add("referer", "https://www.boerse-frankfurt.de/");
headers.add("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<>(headers);
// Get news list
ResponseEntity<String> response = restTemplate.exchange(
newsListUrl,
HttpMethod.GET,
entity,
String.class
);
if (response.getStatusCode().value() == 200 && response.getBody() != null) {
JSONObject newsListResponse = JSON.parseObject(response.getBody());
JSONArray newsData = newsListResponse.getJSONArray("data");
if (newsData != null && newsData.size() > 0) {
totalCount = newsData.size();
log.info("Found {} German news items to process", totalCount);
for (int i = 0; i < newsData.size(); i++) {
try {
JSONObject newsItem = newsData.getJSONObject(i);
String newsId = newsItem.getString("id");
String headline = newsItem.getString("headline");
String time = newsItem.getString("time");
String source = newsItem.getString("source");
String teaserText = newsItem.getString("teaserText");
String teaserImageUrl = newsItem.getString("teaserImageUrl");
// Check if news already exists
List<SiteNews> existingNews = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(newsId));
if (existingNews.size() == 0) {
// Get news detail
String newsDetailUrl = "https://api.boerse-frankfurt.de/v1/data/news?id=" + newsId + "&lang=de";
HttpEntity<String> detailEntity = new HttpEntity<>(headers);
ResponseEntity<String> detailResponse = restTemplate.exchange(
newsDetailUrl,
HttpMethod.GET,
detailEntity,
String.class
);
if (detailResponse.getStatusCode().value() == 200 && detailResponse.getBody() != null) {
JSONObject newsDetail = JSON.parseObject(detailResponse.getBody());
String body = newsDetail.getString("body");
// Create SiteNews entity
SiteNews siteNews = new SiteNews();
siteNews.setAddTime(new Date());
siteNews.setSourceId(newsId);
siteNews.setTitle(headline);
siteNews.setSourceName(source);
siteNews.setDescription(teaserText != null ? teaserText : "");
siteNews.setImgurl(teaserImageUrl);
siteNews.setContent(body != null ? body : "");
siteNews.setStatus(1);
siteNews.setType(1); // Set as financial news type
siteNews.setViews(0);
// Parse and set show time
if (time != null && !time.isEmpty()) {
try {
// Parse ISO 8601 format: "2025-06-19T08:37:58+02:00"
// Remove timezone offset and convert to standard format
String timeStr = time.replace("+02:00", "").replace("T", " ");
siteNews.setShowTime(DateTimeUtil.strToDate(timeStr, "yyyy-MM-dd HH:mm:ss"));
} catch (Exception e) {
log.warn("Failed to parse time for news {}: {}", newsId, time);
siteNews.setShowTime(new Date());
}
} else {
siteNews.setShowTime(new Date());
}
try {
newsRepository.save(siteNews);
savedCount++;
log.info("Saved German news [{}/{}]: {}", savedCount, totalCount, headline);
} catch (Exception e) {
log.warn("Failed to save German news {}: {}", newsId, e.getMessage());
}
} else {
log.warn("Failed to get news detail for {}: HTTP {}", newsId, detailResponse.getStatusCode());
}
} else {
log.debug("News {} already exists, skipping", newsId);
}
} catch (Exception e) {
log.warn("Error processing news item {}: {}", i, e.getMessage());
}
}
} else {
log.warn("No news data found in API response");
}
} else {
log.error("Failed to get news list: HTTP {}", response.getStatusCode());
}
log.info("德国股票新闻数据同步完成,处理了 {} 条新闻,保存了 {} 条新闻", totalCount, savedCount);
} catch (Exception e) {
log.error("德国新闻数据同步异常,异常信息: {}", e.getMessage(), e);
}
}
@Scheduled(cron = "0 0 0/3 * * ?")
// @PostConstruct
public void getCincoDiasNews() {
String baseUrl = "https://cincodias.elpais.com";
try {
List<SiteNews> results = new ArrayList<>();
String listUrl = baseUrl + "/ultimas-noticias/";
Document doc = Jsoup.connect(listUrl)
.userAgent("Mozilla/5.0")
.get();
Elements articles = doc.select("article.c");
for (Element article : articles) {
// Title and Link
Element aTag = article.selectFirst("h2.c_t a");
String title = aTag != null ? aTag.text().trim() : null;
String link = aTag != null ? aTag.absUrl("href") : null;
// Author
Element authorTag = article.selectFirst("a.c_a_a");
String author = authorTag != null ? authorTag.text().trim() : null;
Element figure = article.selectFirst("figure.c_m a img");
String imageUrl = null;
if (figure != null) {
imageUrl = figure.attr("src");
}
// Date
Date publishedDate = null;
try {
Element timeTag = article.selectFirst("time");
if (timeTag != null) {
String datetimeAttr = timeTag.attr("datetime");
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
ZonedDateTime zonedDateTime = ZonedDateTime.parse(datetimeAttr, formatter);
publishedDate = Date.from(zonedDateTime.toInstant());
}
} catch (Exception e) {
log.warn("Failed to parse published date for article: {}", link);
}
// Summary
String summary = article.selectFirst("p.c_d") != null ? article.selectFirst("p.c_d").text() : null;
// Optional: Get full content from article detail page
String htmlContent = "";
if (link != null) {
try {
Document detailDoc = Jsoup.connect(link)
.userAgent("Mozilla/5.0")
.get();
// ✅ Extract article main content
Element body = detailDoc.selectFirst("div.a_c.clearfix[data-dtm-region=articulo_cuerpo]");
if (body != null) {
htmlContent = body.html();
}
} catch (Exception e) {
log.warn("Error fetching detail page: {}", link);
e.printStackTrace();
}
}
// Build SiteNews object
SiteNews siteNews = new SiteNews();
siteNews.setAddTime(new Date());
siteNews.setSourceId(link);
siteNews.setTitle(title);
siteNews.setSourceName("CINCO_DIAS");
siteNews.setDescription(summary != null ? summary : title);
siteNews.setImgurl(imageUrl);
siteNews.setContent(htmlContent);
siteNews.setStatus(1);
siteNews.setType(1);
siteNews.setViews(0);
siteNews.setShowTime(publishedDate);
try {
newsRepository.save(siteNews);
log.info("Saved Spanish news: {}", title);
} catch (Exception e) {
log.warn("Failed to save Spanish news {}: {}", link, e.getMessage());
}
}
} catch (Exception e) {
log.error("Error fetching Spanish news: {}", e.getMessage());
e.printStackTrace();
}
}
/**
* Test method to manually trigger German news sync
* This can be called via REST API or scheduled task
*/
@GetMapping("/test-ger-news")
public String testSaveGerNews() {
log.info("Testing German news sync...");
saveGerNews();
log.info("German news sync test completed");
return "German news sync test completed. Check logs for details.";
}
} }

View File

@@ -115,15 +115,15 @@ public class MoneyScraper {
if (ulElement != null) { if (ulElement != null) {
for (Element aElement : ulElement.select("a")) { for (Element aElement : ulElement.select("a")) {
String exchangeValue = aElement.text().trim(); 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 + log.info(Thread.currentThread().getName() + ",the stock url: " + url +
", the exchange Value: " + exchangeValue); ", 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)) .detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
.selfUrl(url) .selfUrl(url)
.selfDispId(extractDispId(url)) .selfDispId(extractDispId(url))
.moneyScId(companyCodeId).saveTime(new Date()).build(); .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)) { if (CollectionUtil.isEmpty(all)) {
moneyStockRepository.save(build); moneyStockRepository.save(build);
} }
@@ -264,15 +264,15 @@ public class MoneyScraper {
for (Element aElement : ulElement.select("a")) { for (Element aElement : ulElement.select("a")) {
String exchangeValue = aElement.text().trim(); 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 + log.info(Thread.currentThread().getName()+",stockName: " + textContent + ", self_link: " + linkAttribute +
", the exchange Value: " + exchangeValue); ", 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)) .detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
.selfUrl(linkAttribute) .selfUrl(linkAttribute)
.selfDispId(extractDispId(linkAttribute)) .selfDispId(extractDispId(linkAttribute))
.moneyScId(companyCodeId).saveTime(new Date()).build(); .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)){ if(CollectionUtil.isEmpty(all)){
moneyStockRepository.save(build); moneyStockRepository.save(build);
} }

View File

@@ -16,7 +16,7 @@ public class RealTimeTask {
/*每天9点定时删除股票k线数据*/ /*每天9点定时删除股票k线数据*/
@Transactional @Transactional
@Scheduled(cron = "0 00 9 * * MON-FRI") // @Scheduled(cron = "0 00 9 * * MON-FRI")
public void deleteStockCode() { public void deleteStockCode() {
log.info("每天9点定时删除股票k线数据"); log.info("每天9点定时删除股票k线数据");
repo.deleteStockCode(); repo.deleteStockCode();
@@ -24,7 +24,7 @@ public class RealTimeTask {
/*每天0点定时删除期货k线数据*/ /*每天0点定时删除期货k线数据*/
@Transactional @Transactional
@Scheduled(cron = "0 00 0 * * MON-FRI") // @Scheduled(cron = "0 00 0 * * MON-FRI")
public void deleteStockFuturesCode() { public void deleteStockFuturesCode() {
log.info("每天0点定时删除期货k线数据"); log.info("每天0点定时删除期货k线数据");
repo.deleteStockFuturesCode(); repo.deleteStockFuturesCode();

View File

@@ -1,14 +1,20 @@
package cn.stock.market.infrastructure.job; package cn.stock.market.infrastructure.job;
import cn.hutool.core.collection.CollectionUtil; 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.BtodayStock;
import cn.stock.market.domain.basic.entity.MoneyStock;
import cn.stock.market.domain.basic.entity.StockIpo; import cn.stock.market.domain.basic.entity.StockIpo;
import cn.stock.market.domain.basic.repository.BtodayStockRepository; 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.domain.basic.repository.StockIpoRepository;
import cn.stock.market.dto.StockIpoDTO; 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.QStockIpoPO;
import cn.stock.market.infrastructure.db.po.StockIpoPO; import cn.stock.market.infrastructure.db.po.StockIpoPO;
import cn.stock.market.infrastructure.db.repo.BtodayStockRepo; 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.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@@ -54,9 +57,13 @@ public class Scraper {
private StockIpoRepository stockIpoRepository; private StockIpoRepository stockIpoRepository;
private final ExecutorService executorService = Executors.newFixedThreadPool(5); private final ExecutorService executorService = Executors.newFixedThreadPool(5);
@Autowired
private MoneyStockRepository moneyStockRepository;
private boolean times = false;
@Scheduled(cron = "0 0 1 */2 * ?") // @Scheduled(cron = "0 0 1 */2 * ?")
@RequestMapping("/testScraperGetBusinessToday") @RequestMapping("/testScraperGetBusinessToday")
public void schedule() { public void schedule() {
String BASE_URL = "https://akm-img-a-in.tosshub.com/businesstoday/resource/market-widgets/prod/company-master-23-01-2023.json"; String BASE_URL = "https://akm-img-a-in.tosshub.com/businesstoday/resource/market-widgets/prod/company-master-23-01-2023.json";
@@ -103,126 +110,227 @@ public class Scraper {
@Scheduled(cron = "0 0 18 * * ?") // @Scheduled(cron = "0 0 18 * * ?")
// @PostConstruct
@RequestMapping("/testScraperGetMoneyControllerNewIPO") @RequestMapping("/testScraperGetMoneyControllerNewIPO")
public void getMoneyControllerNewIPOSchedule() { public void getMoneyControllerNewIPOSchedule() {
log.info("定时任务执行获取新股ipo的方法开始执行"); log.info("定时任务执行获取新股ipo的方法开始执行");
// 目标 URL // 目标 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 实例
HttpClient client = HttpClients.createDefault(); HttpClient client = HttpClients.createDefault();
// 创建 HttpGet 请求 // 创建 HttpGet 请求
HttpGet request = new HttpGet(url); for (String url : urls) {
try { HttpGet request = new HttpGet(url);
// 执行请求 try {
HttpResponse response = client.execute(request); // 执行请求
HttpResponse response = client.execute(request);
// 检查请求是否成功 // 检查请求是否成功
if (response.getStatusLine().getStatusCode() == 200) { if (response.getStatusLine().getStatusCode() == 200) {
// 获取响应体 // 获取响应体
String responseBody = EntityUtils.toString(response.getEntity()); String responseBody = EntityUtils.toString(response.getEntity());
// 使用 Jsoup 解析 HTML // 使用 Jsoup 解析 HTML
Document doc = Jsoup.parse(responseBody); Document doc = Jsoup.parse(responseBody);
// 找到包含 JSON 数据的 <script> 标签 // 找到包含 JSON 数据的 <script> 标签
Element scriptTag = doc.selectFirst("script#__NEXT_DATA__"); Element scriptTag = doc.selectFirst("script#__NEXT_DATA__");
if (scriptTag != null) { if (scriptTag != null) {
// 获取 JSON 数据 // 获取 JSON 数据
String jsonDataStr = scriptTag.html(); String jsonDataStr = scriptTag.html();
// 将 JSON 字符串解析为 Java JSONObject // 将 JSON 字符串解析为 Java JSONObject
JSONObject jsonObject = JSONObject.parseObject(jsonDataStr); JSONObject jsonObject = JSONObject.parseObject(jsonDataStr);
log.info("获取到新股的json信息:"+jsonObject.toJSONString()); log.info("获取到新股的json信息:"+jsonObject.toJSONString());
JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
JSONObject ipoTableData = pageProps.getJSONObject("ipoTableData");
// 解析 openData 和 upcomingData
JSONArray openData = ipoTableData.getJSONArray("openData"); JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData"); JSONObject ipoTableData = pageProps.getJSONObject("ipoTableData");
List<StockIpo> listStockIpoList = new ArrayList<>();
for (int i = 0; i < openData.size(); i++) {
JSONObject entry = openData.getJSONObject(i);
StockIpo stockIpo = new StockIpo(); // 解析 openData 和 upcomingData
stockIpo.setStockCode(entry.getString("sc_id")); JSONArray openData = ipoTableData.getJSONArray("openData");
stockIpo.setStockName(entry.getString("company_name")); // if (openData.isEmpty()){
stockIpo.setStockPrice(entry.getBigDecimal("issue_price")); // openData = ipoTableData.getJSONArray("openUpcomingData");
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date"))); // }
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date"))); JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData");
Integer totalNumber = 0; List<StockIpo> listStockIpoList = new ArrayList<>();
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(0))){ for (int i = 0; i < openData.size(); i++) {
Integer issue_size = entry.getInteger("issue_size"); JSONObject entry = openData.getJSONObject(i);
BigDecimal issueSize = new BigDecimal(issue_size); StockIpo stockIpo = new StockIpo();
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP); stockIpo.setStockCode(entry.getString("sc_id"));
totalNumber = totalNumberBigDecimal.intValue(); stockIpo.setStockName(entry.getString("company_name"));
stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
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))){
BigDecimal issueSize = new BigDecimal(entry.getLong("issue_size"));
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
totalNumber = totalNumberBigDecimal.intValue();
}
stockIpo.setTotalNumber(totalNumber);
stockIpo.setApply(entry.getString("total_subs"));
stockIpo.setCreateDate(new Date());
stockIpo.setUpdateDate(new Date());
stockIpo.setSourceType("3");
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);
}
} }
stockIpo.setTotalNumber(totalNumber);
stockIpo.setApply(entry.getString("total_subs"));
stockIpo.setCreateDate(new Date());
stockIpo.setUpdateDate(new Date());
stockIpo.setSourceType("3");
listStockIpoList.add(stockIpo);
}
for (int i = 0; i < upcomingData.size(); i++) { for (int i = 0; i < upcomingData.size(); i++) {
JSONObject entry = upcomingData.getJSONObject(i); JSONObject entry = upcomingData.getJSONObject(i);
StockIpo stockIpo = new StockIpo(); StockIpo stockIpo = new StockIpo();
stockIpo.setStockCode(entry.getString("sc_id")); stockIpo.setStockCode(entry.getString("sc_id"));
stockIpo.setStockName(entry.getString("company_name")); stockIpo.setStockName(entry.getString("company_name"));
stockIpo.setStockPrice(entry.getBigDecimal("issue_price")); stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date"))); stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date"))); stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
Integer totalNumber = 0; Integer totalNumber = 0;
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(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"); Integer issue_size = entry.getInteger("issue_size");
BigDecimal issueSize = new BigDecimal(issue_size); BigDecimal issueSize = new BigDecimal(issue_size);
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP); BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
totalNumber = totalNumberBigDecimal.intValue(); totalNumber = totalNumberBigDecimal.intValue();
}
stockIpo.setTotalNumber(totalNumber);
stockIpo.setApply(entry.getString("total_subs"));
stockIpo.setCreateDate(new Date());
stockIpo.setUpdateDate(new Date());
stockIpo.setSourceType("3");
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);
}
} }
stockIpo.setTotalNumber(totalNumber);
stockIpo.setApply(entry.getString("total_subs"));
stockIpo.setCreateDate(new Date());
stockIpo.setUpdateDate(new Date());
stockIpo.setSourceType("3");
listStockIpoList.add(stockIpo);
}
// stockIpoRepository.saveAll(listStockIpoList); // stockIpoRepository.saveAll(listStockIpoList);
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode); if (!listStockIpoList.isEmpty())
if(CollectionUtil.isNotEmpty(scIdList)){ {
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList)); listStockIpoList = listStockIpoList.stream().filter(a -> StringUtils.isNotBlank(a.getStockName())).collect(Collectors.toList());
List<String> existingStockScIds = existStockIpoList.stream()
.map(StockIpo::getStockCode)
.collect(Collectors.toList());
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的方法开始结束,没有数据");
} }
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode);
if(CollectionUtil.isNotEmpty(scIdList)){
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
List<String> existingStockScIds = existStockIpoList.stream()
.map(StockIpo::getStockCode)
.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的方法开始结束,没有数据");
}
}
// 输出整个 JSON 数据
} else {
log.info("未找到包含 JSON 数据的 <script> 标签");
} }
// 输出整个 JSON 数据
} else { } else {
log.info("未找到包含 JSON 数据的 <script> 标签"); log.info("HTTP请求失败状态码" + response.getStatusLine().getStatusCode());
} }
} else { } catch (IOException e) {
log.info("HTTP请求失败状态码" + response.getStatusLine().getStatusCode()); log.error("获取新股接口发生异常",e);
} }
} 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) { private void processSubMap(Map<String, String> sefUrlList) {
for (Map.Entry<String, String> entry : sefUrlList.entrySet()) { for (Map.Entry<String, String> entry : sefUrlList.entrySet()) {
String companyName = entry.getKey(); String companyName = entry.getKey();
@@ -378,4 +480,135 @@ public class Scraper {
log.info("Getting web detail URL: " + url + "..."); log.info("Getting web detail URL: " + url + "...");
return Jsoup.connect(url).ignoreContentType(true).execute().body(); 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 "";
}
} }

View File

@@ -0,0 +1,186 @@
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 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 {
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={start}&hl=1&country=DE&lang=en&search_type=stocks&domain=production&sort_by_country=US&promo=true&exchange={exchange}";
private static final String US_URL =
"https://financialmodelingprep.com/api/v3/stock-screener";
private static final String US_API_KEY = "57ZI1xeAsqHY7ag0FBuMkwQzt6TQ60dG";
@Autowired
StockRepository stockRepository;
// @PostConstruct
// @Scheduled(cron = "0 01 22 * * ?")
public void syncStock() throws Exception {
try {
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();
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);
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);
}
}
Thread.sleep(500);
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());
}
if (start >= limit) {
break;
}
} while (symbolsRemaining > 0);
}
}catch (Exception e) {
log.error("Insert stock failed: {}", e.getMessage());
e.printStackTrace();
}
}
@Scheduled(cron = "0 0 8 * * *")
// @PostConstruct
public void fetchListStock() {
try {
List<Stock> nasdaqStocks = fetchStocksByExchange("NASDAQ");
List<Stock> nyseStocks = fetchStocksByExchange("NYSE");
List<Stock> allActiveStocks = new ArrayList<>();
allActiveStocks.addAll(nasdaqStocks);
allActiveStocks.addAll(nyseStocks);
try {
if (!allActiveStocks.isEmpty()) {
stockRepository.saveAll(allActiveStocks);
}
} catch (Exception e) {
log.error("Insert stock failed: {}", e.getMessage());
}
} catch (Exception e) {
log.error("Error fetchListStock every day: {}", e.getMessage());
}
}
private static List<Stock> fetchStocksByExchange(String exchange) throws Exception {
List<Stock> result = new ArrayList<>();
String url = US_URL + "?exchange=" + exchange + "&apikey=" + US_API_KEY;
Request request = new Request.Builder()
.url(url)
.addHeader("accept", "application/json")
.addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) {
throw new RuntimeException("HTTP error code: " + response.code());
}
String body = response.body().string();
JSONArray array = new JSONArray(body);
for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i);
if (!obj.optBoolean("isActivelyTrading", false) && obj.optBoolean("isEtf", false)) {
continue;
}
Stock stock = new Stock();
String stockCodeNew = obj.getString("symbol") + ":" + obj.getString("exchangeShortName");
stock.setStockName(obj.getString("companyName"));
stock.setStockCode(stockCodeNew);
stock.setStockSpell(obj.getString("symbol"));
stock.setStockType(obj.getString("exchangeShortName"));
stock.setStockGid(stockCodeNew);
stock.setStockSymbol(obj.getString("symbol"));
result.add(stock);
}
System.out.println("Fetched " + result.size() + " stocks for exchange: " + exchange);
return result;
}
}

View File

@@ -112,7 +112,7 @@ public class StockTask {
} }
/*同步股票列表*/ /*同步股票列表*/
@Scheduled(cron = "0 0 6 * * ?") // @Scheduled(cron = "0 0 6 * * ?")
public void syncAFutureStockList() { public void syncAFutureStockList() {
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300); PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap(); Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
@@ -154,7 +154,7 @@ public class StockTask {
} }
/*同步股票列表*/ /*同步股票列表*/
@Scheduled(cron = "0 0 6 * * ?") // @Scheduled(cron = "0 0 6 * * ?")
public void syncAStockList() { public void syncAStockList() {
MdcUtil.setTraceIdIfAbsent(); MdcUtil.setTraceIdIfAbsent();
Config config = SpringUtils.getBean(Config.class); Config config = SpringUtils.getBean(Config.class);

View File

@@ -5,6 +5,8 @@ import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Calendar; import java.util.Calendar;
import java.util.Locale;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; 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) { public static void main(String[] args) {
parseToDateByMinute(10); parseToDateByMinute(10);
} }

View File

@@ -212,6 +212,109 @@ public class HttpClientRequest {
return result; return result;
} }
public static String doEttechchartsGet(String url) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
String result = "";
try {
httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
// httpGet.setHeader(":authority","ettechcharts.indiatimes.com");
// httpGet.setHeader(":method","GET");
// httpGet.setHeader(":scheme","https");
httpGet.setHeader("accept","*/*");
httpGet.setHeader("accept-encoding","gzip, deflate, br");
httpGet.setHeader("accept-language","zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
httpGet.setHeader("user-agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
httpGet.setHeader("Referer", "https://economictimes.indiatimes.com/");
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
httpGet.setConfig(requestConfig);
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != response) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
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) { public static void main(String[] args) {
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse"; String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse";
String str = doGet(url); String str = doGet(url);

View 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);
}
}
}

View File

@@ -65,6 +65,50 @@ public class RequestCacheUtils {
return response; return response;
} }
/**
* 根据时间创建缓存
* @param key key
* @param duration 时间(毫秒)
* @return
*/
public static Cache<String, ServerResponse<?>> cacheByMilliseconds(String key,long duration) {
if(! map.containsKey(key)) {
log.info("创建缓存: {}", key);
Cache<String, ServerResponse<?>> cache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(duration,TimeUnit.MILLISECONDS)
.weakValues()
.recordStats()
.build(
// new CacheLoader<String, Object>() {
// @Override
// public Object load(String key) throws Exception {
// return func.apply(key);
// }
// }
);
map.put(key, cache);
}
return map.get(key);
}
@SneakyThrows
public static <T> ServerResponse<T> cache(String module, String key,long duration, Function<String, ServerResponse<?>> func) {
Cache<String, ServerResponse<?>> cache = cacheByMilliseconds(module,duration);
AtomicBoolean bool = new AtomicBoolean(true);
ServerResponse<T> response = (ServerResponse<T>) cache.get(key, () -> {
bool.set(false);
return func.apply(key);
});
if(bool.get()) {
log.info("命中缓存 module: {}, key: {}, 时间戳: {}", module, key, System.currentTimeMillis());
}
return response;
}
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
ServerResponse<Object> response = null; ServerResponse<Object> response = null;

View File

@@ -20,7 +20,7 @@ import cn.stock.market.domain.basic.service.SiteArticleService;
import cn.stock.market.utils.ServerResponse; import cn.stock.market.utils.ServerResponse;
@Controller @Controller
@RequestMapping({"/api/market/art/", "/api/hq/art/"}) @RequestMapping({"/market/api/market/art/","/market/api/market/art/","/api/market/art/", "/api/hq/art/"})
@Api(tags = "公告信息") @Api(tags = "公告信息")
public class ArticleApiController extends BaseController { public class ArticleApiController extends BaseController {

View File

@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -35,7 +36,7 @@ public class BTodayStockController {
@Autowired @Autowired
private BtodayStockService btodayStockService; private BtodayStockService btodayStockService;
@GetMapping("/api/bToday/kLine") @GetMapping({"/market/api/bToday/kLine","/api/bToday/kLine"})
@ApiOperation(value = "股票详情K线图",httpMethod = "GET") @ApiOperation(value = "股票详情K线图",httpMethod = "GET")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="exchange",value = "BSE或者NSE"), @ApiImplicitParam(name="exchange",value = "BSE或者NSE"),
@@ -140,7 +141,7 @@ public class BTodayStockController {
"fromredis: 标志是否来自 Redis 缓存false 表示不是", response = JSONObject.class), "fromredis: 标志是否来自 Redis 缓存false 表示不是", response = JSONObject.class),
}) })
@GetMapping("/api/bToday/stockDetail") @GetMapping({"/market/api/bToday/stockDetail","/api/bToday/stockDetail"})
@EncryptFilter(decryptRequest = false) @EncryptFilter(decryptRequest = false)
public com.alibaba.fastjson.JSONObject getPriceChartCompanyPullView( public com.alibaba.fastjson.JSONObject getPriceChartCompanyPullView(
@RequestParam(value = "exchange") String exchange, @RequestParam(value = "exchange") String exchange,
@@ -159,6 +160,19 @@ public class BTodayStockController {
String forObject = restTemplate.getForObject(apiUrl, String.class); String forObject = restTemplate.getForObject(apiUrl, String.class);
JSONObject jsonObject = JSON.parseObject(forObject); 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()); jsonObject.put("id",btodayStock.getId());
return jsonObject; return jsonObject;
} }

View File

@@ -25,7 +25,7 @@ import springfox.documentation.annotations.ApiIgnore;
* @created Dec 4, 2018 10:22:44 PM * @created Dec 4, 2018 10:22:44 PM
*/ */
@RestController @RestController
@RequestMapping("/api/hq/") @RequestMapping({"/market/api/hq/","/api/hq/"})
@ApiIgnore @ApiIgnore
public class InfoController { public class InfoController {
@Value("${spring.application.name}") @Value("${spring.application.name}")
@@ -40,6 +40,7 @@ public class InfoController {
public Map<String, Object> test(@RequestParam(required = false) String key) { public Map<String, Object> test(@RequestParam(required = false) String key) {
Map<String, Object> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
map.put("stockMarketDbUrl", stockMarketDbUrl); map.put("stockMarketDbUrl", stockMarketDbUrl);
map.put("stockMarketDbUrl1", stockMarketDbUrl);
if(StringUtils.isNotBlank(key)) { if(StringUtils.isNotBlank(key)) {
map.put("key", PropertiesUtil.getProperty(key)); map.put("key", PropertiesUtil.getProperty(key));
} }

View File

@@ -1,18 +1,33 @@
package cn.stock.market.web; package cn.stock.market.web;
import cn.hutool.core.date.DateUtil;
import cn.qutaojing.common.jpa.ConditionBuilder;
import cn.stock.market.MoneyStockSuggestDTO; import cn.stock.market.MoneyStockSuggestDTO;
import cn.stock.market.domain.basic.entity.MoneyStock; import cn.stock.market.domain.basic.entity.MoneyStock;
import cn.stock.market.domain.basic.entity.OptionalStock;
import cn.stock.market.domain.basic.entity.Stock;
import cn.stock.market.domain.basic.repository.MoneyStockRepository; import cn.stock.market.domain.basic.repository.MoneyStockRepository;
import cn.stock.market.dto.StockHistoryRequest; import cn.stock.market.domain.basic.repository.OptionalStockRepository;
import cn.stock.market.dto.StockHistoryResponse; import cn.stock.market.domain.basic.repository.StockRepository;
import cn.stock.market.domain.basic.service.StockService;
import cn.stock.market.dto.*;
import cn.stock.market.dto.query.StockChartDto;
import cn.stock.market.infrastructure.db.po.QMoneyStockPO; import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
import cn.stock.market.utils.RequestCacheUtils; import cn.stock.market.infrastructure.db.po.QStockPO;
import cn.stock.market.utils.HttpRequest;
import cn.stock.market.utils.NseIndiaRequest;
import cn.stock.market.utils.ServerResponse; import cn.stock.market.utils.ServerResponse;
import cn.stock.market.web.annotations.EncryptFilter; import cn.stock.market.web.annotations.EncryptFilter;
import cn.stock.market.web.service.MoneyApiService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
@@ -22,24 +37,37 @@ import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod; import org.springframework.http.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UriUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.math.BigDecimal;
import java.util.Collection; import java.net.URLEncoder;
import java.util.List; import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -59,15 +87,26 @@ public class MoneyApiController {
@Autowired @Autowired
private MoneyStockRepository moneyStockRepository; private MoneyStockRepository moneyStockRepository;
@Autowired
private OptionalStockRepository optionalStockRepository;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private MoneyApiService moneyApiService;
private static final String EXTERNAL_API_URL = "https://priceapi.moneycontrol.com/techCharts/indianMarket/stock/history"; private static final String EXTERNAL_API_URL = "https://priceapi.moneycontrol.com/techCharts/indianMarket/stock/history";
private static final String OPTIONAL_STOCK_MONEYCONTROL_URL = "https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/";
@Autowired
private StockRepository stockRepository;
@ApiOperation(value = "股票详情信息", httpMethod = "GET")
@ApiOperation(value = "股票详情信息",httpMethod = "GET")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"), @ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
@ApiImplicitParam(name="symbol",value = "scId值"), @ApiImplicitParam(name = "symbol", value = "scId值"),
@ApiImplicitParam(name="id",value = "id值"), @ApiImplicitParam(name = "id", value = "id值"),
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "" + @ApiResponse(code = 200, message = "" +
@@ -166,80 +205,80 @@ public class MoneyApiController {
"priceprevclose: 前一交易日的收盘价\n" + "priceprevclose: 前一交易日的收盘价\n" +
"30DayAvg: 过去30天的平均", response = JSONObject.class), "30DayAvg: 过去30天的平均", response = JSONObject.class),
}) })
@GetMapping("/api/market/money/getStockDetail") @GetMapping({"/market/api/market/money/getStockDetail", "/api/market/money/getStockDetail"})
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false) @EncryptFilter(decryptRequest = false)
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol) {
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol ) { Stock stock = stockRepository.findStockByCode(symbol);
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s",stockType,symbol); if (stock == null) {
MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType) return ServerResponse.createByErrorMsg("Stock is not exist!");
.and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
.and(QMoneyStockPO.moneyStockPO.isShow.eq(0)))
.orElse(null);
/* if(moneyStock==null){
return ServerResponse.createByErrorMsg("没有找到该股票");
}*/
// 设置重试次数
int maxRetries = 3;
for (int retry = 1; retry <= maxRetries; retry++) {
try {
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
JSONObject json1 = new JSONObject();
if (responseEntity.getStatusCode().value() == 200 && responseEntity.getBody() != null ) {
JSONObject data = JSONObject.parseObject(responseEntity.getBody()).getJSONObject("data");
if(data!=null){
json1.put("company",data.getString("company"));
json1.put("pricepercentchange",data.getString("pricepercentchange"));
json1.put("stockType",stockType);
json1.put("pricechange",data.getString("pricechange"));
json1.put("pricecurrent",data.getString("pricecurrent"));
json1.put("priceprevclose",data.getString("priceprevclose"));
json1.put("PREVDATE",data.getString("PREVDATE"));
json1.put("VOL",data.getString("VOL"));
json1.put("dataSourceType","3");
json1.put("symbol",data.getString("symbol"));
json1.put("BSEID",data.getString("BSEID"));
json1.put("NSEID",data.getString("NSEID"));
json1.put("LTH",data.getString("HP"));
json1.put("LTL",data.getString("LP"));
json1.put("OPN",data.getString("OPN"));
if(null!=moneyStock){
json1.put("id",moneyStock.getId());
}
if(StringUtils.equals(data.getString("pricecurrent"),"0.00")
&& (!StringUtils.equals(data.getString("priceprevclose"),"0.00"))){
json1.put("pricecurrent",data.getString("priceprevclose"));
}
}
return ServerResponse.createBySuccess(json1);
}
} catch (Exception e) {
}
// 如果不是最后一次重试,则等待一段时间再进行下一次重试
if (retry < maxRetries) {
try {
// 1秒钟
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
} }
return null; StockQuoteData data = moneyApiService.getSingleStockQuote(symbol);
data.setName(stock.getStockName());
return ServerResponse.createBySuccess(data);
} }
private String getVolume(String scripcode) {
String url = "https://api.bseindia.com/BseIndiaAPI/api/StockTrading/w?flag=&quotetype=EQ&scripcode=" + scripcode;
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json, text/plain, */*");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
headers.add("origin", "https://www.bseindia.com");
headers.add("referer", "https://www.bseindia.com/");
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
headers.add("sec-ch-ua-mobile", "?0");
headers.add("sec-ch-ua-platform", "\"Windows\"");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
private static List<MoneyStockSuggestDTO> nseActives() { HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
BigDecimal volume = BigDecimal.ZERO;
if (response.getStatusCode().value() == 200 && response.getBody() != null) {
JSONObject volumeData = JSONObject.parseObject(response.getBody());
if (volumeData.getString("TTQ") != null) {
volume = new BigDecimal(volumeData.getString("TTQ"));
}
}
return volume.toString();
}
private String getChartData(String scripcode, String resolution) {
String url = "https://charting.bseindia.com/charting/RestDataProvider.svc/getDat?exch=B&type=b&mode=bseL&fromdate=01-01-1991-01%3A01%3A00-AM&scode=" + scripcode;
if (resolution.equals("H")) {
url = "https://charting.bseindia.com/charting/RestDataProvider.svc/getDatI?exch=B&type=b&mode=bseL&fromdate=01-01-1991-01%3A01%3A00-AM&scode=" + scripcode;
}
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json, text/plain, */*");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
headers.add("origin", "https://www.bseindia.com");
headers.add("referer", "https://www.bseindia.com/");
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
headers.add("sec-ch-ua-mobile", "?0");
headers.add("sec-ch-ua-platform", "\"Windows\"");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
return response.getBody();
}
private static List<MoneyStockSuggestDTO> nseActives() {
List<MoneyStockSuggestDTO> list = new ArrayList<>(); List<MoneyStockSuggestDTO> list = new ArrayList<>();
String url = "https://www.moneycontrol.com/stocks/marketstats/nse-mostactive-stocks/nifty-50-9/"; String url = "https://www.moneycontrol.com/stocks/marketstats/nse-mostactive-stocks/nifty-50-9/";
try { try {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size(); int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
for (int i =1;i<=size;i++){ for (int i = 1; i <= size; i++) {
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO(); MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > a").first(); Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
if (company_a != null) { if (company_a != null) {
String stockUrl = company_a.attr("href"); String stockUrl = company_a.attr("href");
String stockName = company_a.text(); String stockName = company_a.text();
@@ -247,7 +286,7 @@ public class MoneyApiController {
dto.setStockUrl(stockUrl); dto.setStockUrl(stockUrl);
} }
String highPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td:nth-child(2)").first()); String highPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td:nth-child(2)").first());
dto.setHighPrice(highPrice); dto.setHighPrice(highPrice);
String lowPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td:nth-child(3)").first()); String lowPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td:nth-child(3)").first());
@@ -272,7 +311,7 @@ public class MoneyApiController {
return list; return list;
} }
private static List<MoneyStockSuggestDTO> bseActives() { private static List<MoneyStockSuggestDTO> bseActives() {
List<MoneyStockSuggestDTO> list = new ArrayList<>(); List<MoneyStockSuggestDTO> list = new ArrayList<>();
String url = "https://www.moneycontrol.com/stocks/marketstats/bsemact1/index.php"; String url = "https://www.moneycontrol.com/stocks/marketstats/bsemact1/index.php";
@@ -280,9 +319,9 @@ public class MoneyApiController {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size(); int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
System.err.println(size); System.err.println(size);
for (int i =1;i<=size;i++){ for (int i = 1; i <= size; i++) {
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO(); MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > a").first(); Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
if (company_a != null) { if (company_a != null) {
String stockUrl = company_a.attr("href"); String stockUrl = company_a.attr("href");
String stockName = company_a.text(); String stockName = company_a.text();
@@ -311,19 +350,19 @@ public class MoneyApiController {
} }
} catch (IOException e) { } catch (IOException e) {
log.error("occur Exception",e); log.error("occur Exception", e);
} }
return list; return list;
} }
private static List<MoneyStockSuggestDTO> bseGainer() { private static List<MoneyStockSuggestDTO> bseGainer() {
String url = "https://www.moneycontrol.com/stocks/marketstats/bse-gainer/sensex_4/"; String url = "https://www.moneycontrol.com/stocks/marketstats/bse-gainer/sensex_4/";
List<MoneyStockSuggestDTO> list = Lists.newArrayList(); List<MoneyStockSuggestDTO> list = Lists.newArrayList();
try { try {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size(); int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
for (int i =1;i<=size;i++){ for (int i = 1; i <= size; i++) {
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > a").first(); Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO(); MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
if (company_a != null) { if (company_a != null) {
String stockUrl = company_a.attr("href"); String stockUrl = company_a.attr("href");
@@ -367,9 +406,9 @@ public class MoneyApiController {
try { try {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size(); int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
for (int i =1;i<=size;i++){ for (int i = 1; i <= size; i++) {
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO(); MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > h3 > a").first(); Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > h3 > a").first();
if (company_a != null) { if (company_a != null) {
String stockUrl = company_a.attr("href"); String stockUrl = company_a.attr("href");
String stockName = company_a.text(); String stockName = company_a.text();
@@ -404,20 +443,20 @@ public class MoneyApiController {
return list; return list;
} }
private static List<MoneyStockSuggestDTO> nseTopLoser() { private static List<MoneyStockSuggestDTO> nseTopLoser() {
String url = "https://www.moneycontrol.com/stocks/marketstats/nseloser/index.php"; String url = "https://www.moneycontrol.com/stocks/marketstats/nseloser/index.php";
List<MoneyStockSuggestDTO> list = Lists.newArrayList(); List<MoneyStockSuggestDTO> list = Lists.newArrayList();
try { try {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size(); int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
for (int i =1;i<=size;i++){ for (int i = 1; i <= size; i++) {
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO(); MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > h3 > a").first(); Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > h3 > a").first();
if (company_a != null) { if (company_a != null) {
String stockUrl = company_a.attr("href"); String stockUrl = company_a.attr("href");
String stockName = company_a.text(); String stockName = company_a.text();
dto.setStockUrl(stockUrl); dto.setStockUrl(stockUrl);
dto.setStockName(stockName); dto.setStockName(stockName);
} }
@@ -444,7 +483,7 @@ public class MoneyApiController {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return list; return list;
} }
private static List<MoneyStockSuggestDTO> bseTopLoser() { private static List<MoneyStockSuggestDTO> bseTopLoser() {
@@ -454,7 +493,7 @@ public class MoneyApiController {
try { try {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size(); int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
for (int i =1;i<=size;i++){ for (int i = 1; i <= size; i++) {
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first(); Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO(); MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
if (company_a != null) { if (company_a != null) {
@@ -499,234 +538,233 @@ public class MoneyApiController {
} }
@ApiOperation(value = "股票推荐TopGainer", httpMethod = "GET")
@ApiOperation(value = "股票推荐TopGainer",httpMethod = "GET")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"), @ApiImplicitParam(name = "stockType", value = "BSE或者NSE或者germany"),
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "" + @ApiResponse(code = 200, message = "" +
"股票推荐相关: top gainer", response = JSONObject.class), "股票推荐相关: top gainer", response = JSONObject.class),
}) })
@GetMapping("/api/market/money/getTopGainer") @GetMapping({"/market/api/market/money/getTopGainer", "/api/market/money/getTopGainer"})
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false) @EncryptFilter(decryptRequest = false)
public List<MoneyStockSuggestDTO> getTopGainer(@RequestParam String stockType) { public List<MoneyStockSuggestDTO> getTopGainer(@RequestParam(required = false, defaultValue = "germany") String stockType) {
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null; List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
// 尝试从缓存中获取结果 // 尝试从缓存中获取结果
moneyStockSuggestDTOS = gainerStockSuggestCache.getIfPresent(stockType); // Use TradingView API for German stocks
List<StockQuoteData> stockQuoteDataList = moneyApiService.getTopGainersFromTradingView();
moneyStockSuggestDTOS = convertStockQuoteDataToMoneyStockSuggestDTO(stockQuoteDataList);
if (moneyStockSuggestDTOS == null) {
// 缓存未命中,执行业务查询
if (StringUtils.equals(stockType, "nse")) {
moneyStockSuggestDTOS = nseGainer();
} else if (StringUtils.equals(stockType, "bse")) {
moneyStockSuggestDTOS = bseGainer();
}
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isNotBlank(f.getStockName())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)){
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(selfUlrList)){
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
if(CollectionUtils.isNotEmpty(all)){
moneyStockSuggestDTOS.stream().filter(f->all.stream().anyMatch(s->s.getStockName().equals(f.getStockName())))
.forEach(f->f.setScId(all.stream().filter(s->s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
}
}
gainerStockSuggestCache.put(stockType, moneyStockSuggestDTOS);
}
// 将结果放入缓存
}
return moneyStockSuggestDTOS; return moneyStockSuggestDTOS;
} }
private List<MoneyStockSuggestDTO> convertStockQuoteDataToMoneyStockSuggestDTO(List<StockQuoteData> stockQuoteDataList) {
List<MoneyStockSuggestDTO> result = new ArrayList<>();
if (CollectionUtils.isNotEmpty(stockQuoteDataList)) {
for (StockQuoteData stockQuoteData : stockQuoteDataList) {
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
dto.setStockName(stockQuoteData.getName());
dto.setStockType("XETRA");
dto.setLastPrice(String.valueOf(stockQuoteData.getClose()));
dto.setChange(String.valueOf(stockQuoteData.getChange()));
dto.setChangePercent(String.valueOf(stockQuoteData.getPercent_change()));
dto.setHighPrice(String.valueOf(stockQuoteData.getHigh()));
dto.setLowPrice(String.valueOf(stockQuoteData.getLow()));
dto.setPrevClosePrice(String.valueOf(stockQuoteData.getPrevious_close()));
dto.setScId(String.valueOf(stockQuoteData.getSymbol()));
dto.setDispId(String.valueOf(stockQuoteData.getSymbol()));
result.add(dto);
}
}
return result;
}
@ApiOperation(value = "股票推荐TopLoser",httpMethod = "GET") @ApiOperation(value = "股票推荐TopLoser", httpMethod = "GET")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"), @ApiImplicitParam(name = "stockType", value = "BSE或者NSE或者germany"),
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "" + @ApiResponse(code = 200, message = "" +
"股票推荐相关: TopLoser", response = JSONObject.class), "股票推荐相关: TopLoser", response = JSONObject.class),
}) })
@GetMapping("/api/market/money/getTopLoser") @GetMapping({"/market/api/market/money/getTopLoser", "/api/market/money/getTopLoser"})
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false) @EncryptFilter(decryptRequest = false)
public List<MoneyStockSuggestDTO> getTopLoser(@RequestParam String stockType) { public List<MoneyStockSuggestDTO> getTopLoser(@RequestParam(required = false) String stockType) {
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null; List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
moneyStockSuggestDTOS = loserStockSuggestCache.getIfPresent(stockType); List<StockQuoteData> stockQuoteDataList = moneyApiService.getTopLosersFromTradingView();
if(null==moneyStockSuggestDTOS){ moneyStockSuggestDTOS = convertStockQuoteDataToMoneyStockSuggestDTO(stockQuoteDataList);
if(StringUtils.equals(stockType,"nse")){
moneyStockSuggestDTOS = nseTopLoser();
}else if(StringUtils.equals(stockType,"bse")){
moneyStockSuggestDTOS = bseTopLoser();
}
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isNotBlank(f.getStockName())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)){
moneyStockSuggestDTOS.stream().forEach(f->f.setDispId(extractLastSegment(f.getStockUrl())));
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(selfUlrList)){
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
if(CollectionUtils.isNotEmpty(all)){
moneyStockSuggestDTOS.stream().filter(f->all.stream().anyMatch(s->s.getStockName().equals(f.getStockName())))
.forEach(f->f.setScId(all.stream().filter(s->s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
}
List<MoneyStockSuggestDTO> noScIdList = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isBlank(f.getScId())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(noScIdList)){
List<String> dispIdList = noScIdList.stream().map(MoneyStockSuggestDTO::getDispId).collect(Collectors.toList());
List<MoneyStock> all1 = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.selfDispId.in(dispIdList));
if(CollectionUtils.isNotEmpty(all1)){
moneyStockSuggestDTOS.stream().filter(f->all1.stream().anyMatch(s->s.getSelfDispId().equals(f.getDispId())))
.forEach(f->f.setScId(all.stream().filter(s->s.getSelfDispId().equals(f.getDispId())).findFirst().orElse(null).getMoneyScId()));
}
}
}
loserStockSuggestCache.put(stockType, moneyStockSuggestDTOS);
}
}
return moneyStockSuggestDTOS; return moneyStockSuggestDTOS;
} }
@ApiOperation(value = "股票推荐TopActive", httpMethod = "GET")
@ApiOperation(value = "股票推荐TopActive",httpMethod = "GET")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"), @ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "" + @ApiResponse(code = 200, message = "" +
"股票推荐相关: top active", response = JSONObject.class), "股票推荐相关: top active", response = JSONObject.class),
}) })
@GetMapping("/api/market/money/getTopActives") @GetMapping({"/market/api/market/money/getTopActives", "/api/market/money/getTopActives"})
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false) @EncryptFilter(decryptRequest = false)
public List<MoneyStockSuggestDTO> getTopActive(@RequestParam String stockType) { public List<StockQuoteData> getTopActive(@RequestParam(value = "stockType", required = false) String stockType, @RequestParam(value = "type", required = false) String type) {
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null; List<String> topActiveCode = Arrays.asList("AAPL:NASDAQ","MSFT:NASDAQ","GOOGL:NASDAQ","AMZN:NASDAQ","META:NASDAQ","TSLA:NASDAQ","NVDA:NASDAQ","BRK.B:NYSE","JPM:NYSE",
moneyStockSuggestDTOS = activesStockSuggestCache.getIfPresent(stockType); "UNH:NYSE", "V:NYSE", "MA:NYSE","JNJ:NYSE","XOM:NYSE","PG:NYSE","HD:NYSE","LLY:NYSE","KO:NYSE", "PEP:NASDAQ", "NFLX:NASDAQ",
if(moneyStockSuggestDTOS ==null){ "SAP:XETR", "SIE:XETR", "DTE:XETR", "ALV:XETR", "BAS:XETR", "BMW:XETR", "VOW3:XETR", "ADS:XETR", "BAYN:XETR", "RWE:XETR",
if(StringUtils.equals(stockType,"nse")){ "DBK:XETR", "MUV2:XETR", "FME:XETR", "FRE:XETR", "HEI:XETR", "HEN3:XETR", "LIN:XETR", "IFX:XETR", "CON:XETR", "ZAL:XETR",
moneyStockSuggestDTOS = nseActives(); "ITX:BME", "AIR:BME", "SAN:BME", "IBE:BME", "BBVA:BME", "XPBR:BME", "XPBRA:BME", "CABK:BME", "XAMXB:BME", "CCEP:BME",
}else if(StringUtils.equals(stockType,"bse")){ "XVALO:BME", "AENA:BME", "FER:BME", "AMS:BME", "ELE:BME", "TEF:BME", "NTGY:BME", "XBBDC:BME", "CLNX:BME", "XNOR:BME"
moneyStockSuggestDTOS = bseActives(); );
} QStockPO q = QStockPO.stockPO;
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isNotBlank(f.getStockName())).collect(Collectors.toList()); ConditionBuilder builder = ConditionBuilder.builder();
if(CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)){ builder.and(q.stockCode.in(topActiveCode));
moneyStockSuggestDTOS.stream().forEach(f->f.setDispId(extractLastSegment(f.getStockUrl()))); if(type != null && !type.trim().isEmpty()) {
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList()); if (type.equals("us")) {
if(CollectionUtils.isNotEmpty(selfUlrList)){ builder.and(q.stockType.in("NASDAQ", "NYSE"));
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList)); } else if (type.equals("dg")) {
if(CollectionUtils.isNotEmpty(all)){ builder.and(q.stockType.in("XETR"));
moneyStockSuggestDTOS.stream().filter(f->all.stream().anyMatch(s->s.getStockName().equals(f.getStockName()))) } else if (type.equals("es")) {
.forEach(f->f.setScId(all.stream().filter(s->s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId())); builder.and(q.stockType.in("BME"));
}
List<MoneyStockSuggestDTO> noScIdList = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isBlank(f.getScId())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(noScIdList)){
List<String> dispIdList = noScIdList.stream().map(MoneyStockSuggestDTO::getDispId).collect(Collectors.toList());
List<MoneyStock> all1 = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.selfDispId.in(dispIdList));
if(CollectionUtils.isNotEmpty(all1)){
moneyStockSuggestDTOS.stream().filter(f->all1.stream().anyMatch(s->s.getSelfDispId().equals(f.getDispId())))
.forEach(f->f.setScId(all.stream().filter(s->s.getSelfDispId().equals(f.getDispId())).findFirst().orElse(null).getMoneyScId()));
}
}
}
activesStockSuggestCache.put(stockType, moneyStockSuggestDTOS);
} }
} }
List<Stock> stocks = stockRepository.findAll(builder.build());
return moneyStockSuggestDTOS; List<StockQuoteData> stockQuoteDatas = moneyApiService.getStocksQuote(stocks);
for (StockQuoteData stockQuoteData : stockQuoteDatas) {
Stock name = stocks.stream().filter(e->e.getStockCode().equals(stockQuoteData.getSymbol())).findFirst().orElse(null);
if (name != null) {
stockQuoteData.setName(name.getStockName());
}
}
return stockQuoteDatas;
} }
private static void addToListDouble(List<Double> list, String value) {
String[] values = value.split(",");
@GetMapping("/api/market/money/history/kLine") for (String v : values) {
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源",response = StockHistoryResponse.class) list.add(Double.parseDouble(v));
@ApiImplicitParams({
@ApiImplicitParam(name = "symbol", value = "Stock symbol 对应的是NSEID 或者是BSEID", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "resolution", value = "单位:60 1D 1W 1D 对应H,D,W,Y", required = true, dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "from", value = "Start timestamp", required = true, dataType = "long", paramType = "query"),
@ApiImplicitParam(name = "to", value = "End timestamp", required = true, dataType = "long", paramType = "query"),
@ApiImplicitParam(name = "countback", value = "开始时间和结束时间区间的计划展示的数量", required = true, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "currencyCode", value = "INR 不变", required = true, dataType = "String", paramType = "query")
})
@ResponseBody
@EncryptFilter(decryptRequest = false)
public ResponseEntity<StockHistoryResponse> getStockHistory( @RequestParam String symbol,
@RequestParam String resolution
) {
// 向外部API发起请求并获取响应
StockHistoryRequest request = new StockHistoryRequest();
request.setSymbol(symbol);
Long to = null;
Long from = null;
int countback = 5;
if(StringUtils.equals("H",resolution)){
to = (long) (System.currentTimeMillis() / 1000);
from = to - (1* 24 * 60 * 60 );
countback = 16;
request.setResolution("60");
}else if(StringUtils.equals("D",resolution)){
to = (long) (System.currentTimeMillis() / 1000);
from = to - (24 * 60 * 60 );
countback = 30;
request.setResolution("60");
}else if(StringUtils.equals("W",resolution)){
to = (long) (System.currentTimeMillis() / 1000);
from = to - (10 * 24 * 60 * 60 );
countback = 30;
request.setResolution("1D");
}else if(StringUtils.equals("M",resolution)){
to = (long) (System.currentTimeMillis() / 1000);
from = to - (35 * 24 * 60 * 60 );
countback = 30;
request.setResolution("1D");
} }
}
request.setFrom(from); private static void addToList(List<Long> list, String value) {
request.setTo(to); String[] values = value.split(",");
request.setCountback(countback); for (String v : values) {
request.setCurrencyCode("INR"); list.add(Math.round(Double.parseDouble(v)));
String apiUrl = buildApiUrl(request); }
log.info("request url:"+apiUrl); }
StockHistoryResponse response = null;
int maxRetries = 3;
int retryCount = 0;
while (response == null && retryCount < maxRetries) { private static void addDatesToList(List<Long> list, String value) {
String[] dates = value.split(",");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
for (String dateStr : dates) {
try { try {
response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class); Date date = sdf.parse(dateStr);
} catch (RestClientException e) { list.add(date.getTime() / 1000);
// Log the exception or perform any other error handling } catch (ParseException e) {
log.error("Error while making API request. Retrying... (Retry count: {})", retryCount + 1); e.printStackTrace();
// Increment the retry count
retryCount++;
// Add some delay before the next retry (you can adjust this as needed)
try {
Thread.sleep(300); // 1 second delay
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
} }
} }
if (response != null) {
// API request successful, return the response
return ResponseEntity.ok(response);
} else {
// All retries failed, return an error response
log.error("Failed to get a successful response after {} retries.", maxRetries);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
// 返回响应
} }
private Long convertToTimestamp(String dateStr) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
Date date = sdf.parse(dateStr);
return date.getTime() / 1000;
} catch (ParseException e) {
e.printStackTrace();
return 0L;
}
}
@GetMapping({"/market/api/market/money/history/kLine", "/api/market/money/history/kLine"})
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源", response = StockHistoryResponse.class)
@ResponseBody
@EncryptFilter(decryptRequest = false)
public ResponseEntity<StockHistoryResponse> getStockChart(@RequestParam String symbol,
@RequestParam String interval,
@RequestParam(required = false) Integer amount
) {
return ResponseEntity.ok(moneyApiService.getStockHistory(symbol, interval, amount));
}
@GetMapping({"/market/api/market/stock/optional", "/api/market/stock/optional"})
@ResponseBody
@EncryptFilter(decryptRequest = false)
public ResponseEntity<List<Object>> getOptionalStock() {
List<OptionalStock> optionalStocks = optionalStockRepository.findAll();
List<Object> data = optionalStocks.stream().map(stock -> {
try {
String responseStr = HttpRequest.doGrabGet(OPTIONAL_STOCK_MONEYCONTROL_URL + URLEncoder.encode(stock.getSymbol(), "UTF-8"));
OptionalStockResponse response = objectMapper.readValue(responseStr, OptionalStockResponse.class);
if (response != null && response.getCode().equals(200)) {
return response.getData();
}
}
catch (Exception e) {
log.error("Failed to get optional stock from moneycontrol for " + stock.getSymbol(), e);
}
OptionalStockResponse response = new OptionalStockResponse();
response.getData().setSymbol(stock.getSymbol());
response.getData().setSymbol(stock.getCompany());
return response.getData();
}).collect(Collectors.toList());
return ResponseEntity.ok(data);
}
private void setResponse(StockHistoryResponse response, String resolution) {
if (!"ok".equals(response.getS())) {
return;
}
if (Objects.isNull(response.getT())) {
return;
}
if (StringUtils.equals("H", resolution) || StringUtils.equals("D", resolution)) {
List<Long> t = new ArrayList<>();
List<Double> o = new ArrayList<>();
List<Double> h = new ArrayList<>();
List<Double> l = new ArrayList<>();
List<Double> c = new ArrayList<>();
List<Long> v = new ArrayList<>();
//根据时间过滤,只留当天的数据
Date currentTime = new Date();
//判断最后一条是不是当天的数据,如果不是,把最后一条的时间作为当天的时间
long getTime = response.getT().get(response.getT().size() - 1) * 1000L;
if (!DateUtil.isSameDay(currentTime, new Date(getTime))) {
currentTime = new Date(getTime);
}
int i = 0;
for (Long time : response.getT()) {
time = time * 1000;
if (DateUtil.isSameDay(currentTime, new Date(time))) {
t.add(response.getT().get(i));
o.add(response.getO().get(i));
h.add(response.getH().get(i));
l.add(response.getL().get(i));
c.add(response.getC().get(i));
v.add(response.getV().get(i));
}
i++;
}
response.setT(t);
response.setO(o);
response.setH(h);
response.setL(l);
response.setC(c);
response.setV(v);
}
}
private String buildApiUrl(StockHistoryRequest request) { private String buildApiUrl(StockHistoryRequest request) {
@@ -734,7 +772,9 @@ public class MoneyApiController {
return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d&currencyCode=%s", return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d&currencyCode=%s",
EXTERNAL_API_URL, request.getSymbol(), request.getResolution(), request.getFrom(), EXTERNAL_API_URL, request.getSymbol(), request.getResolution(), request.getFrom(),
request.getTo(), request.getCountback(), request.getCurrencyCode()); request.getTo(), request.getCountback(), request.getCurrencyCode());
}; }
;
private static String extractLastSegment(String url) { private static String extractLastSegment(String url) {
@@ -750,13 +790,16 @@ public class MoneyApiController {
public static void main(String[] args) { public static void main(String[] args) {
nseGainer(); // nseGainer();
nseActives(); //// nseActives();
nseTopLoser(); //// nseTopLoser();
////
bseActives(); //// bseActives();
bseGainer(); //// bseGainer();
bseTopLoser(); //// bseTopLoser();
System.out.println(new Date());
System.out.println(new Date(1713949200000L));
System.out.println(DateUtil.isSameDay(new Date(), new Date(1713949200000L)));
} }
private Cache<String, List<MoneyStockSuggestDTO>> gainerStockSuggestCache = CacheBuilder.newBuilder() private Cache<String, List<MoneyStockSuggestDTO>> gainerStockSuggestCache = CacheBuilder.newBuilder()

View File

@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -23,15 +24,16 @@ import java.net.URL;
public class MoneyProxyApiControl { public class MoneyProxyApiControl {
@RequestMapping(value = "/api/proxy/queryStockMoneyProxy",method = RequestMethod.GET) @GetMapping({"/market/api/proxy/queryStockMoneyProxy","/api/proxy/queryStockMoneyProxy"})
public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){ public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){
log.info("queryStockByMoneyIdAndExchangeType");
return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType); return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType);
} }
public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) { public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) {
try { 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); URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET"); con.setRequestMethod("GET");
@@ -52,7 +54,8 @@ public class MoneyProxyApiControl {
log.error("HTTP request failed with response code: " + responseCode); log.error("HTTP request failed with response code: " + responseCode);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("stockByMoneyIdAndExchangeTypeFromHttp",e); e.printStackTrace();
log.error("stockByMoneyIdAndExchangeTypeFromHttp failed {}",e.getMessage());
} }
return new JSONObject(); return new JSONObject();
} }

View File

@@ -18,7 +18,7 @@ import cn.stock.market.domain.basic.service.SiteNewsService;
import cn.stock.market.utils.ServerResponse; import cn.stock.market.utils.ServerResponse;
@Controller @Controller
@RequestMapping({"/api/market/news/", "/api/hq/news/"}) @RequestMapping({"/market/api/market/news/", "/market/api/hq/news/","/api/market/news/", "/api/hq/news/"})
@Api(tags="新闻资讯") @Api(tags="新闻资讯")
public class SiteNewsController { public class SiteNewsController {
private static final Logger log = LoggerFactory.getLogger(SiteNewsController.class); private static final Logger log = LoggerFactory.getLogger(SiteNewsController.class);

View File

@@ -3,6 +3,8 @@ package cn.stock.market.web;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest; 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.entity.SiteNews;
import cn.stock.market.domain.basic.repository.SiteNewsRepository; import cn.stock.market.domain.basic.repository.SiteNewsRepository;
import cn.stock.market.infrastructure.db.po.QSiteNewsPO; import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
import cn.stock.market.infrastructure.job.InvestingTask;
import cn.stock.market.web.annotations.EncryptFilter; import cn.stock.market.web.annotations.EncryptFilter;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@@ -56,7 +59,7 @@ import springfox.documentation.annotations.ApiIgnore;
@Controller @Controller
@Api(value = "/StockApiController", tags = "股票行情") @Api(value = "/StockApiController", tags = "股票行情")
@RequestMapping({"/api/market/stock/", "/api/hq/stock/"}) @RequestMapping({"/market/api/market/stock/", "/market/api/hq/stock/","/api/market/stock/", "/api/hq/stock/"})
public class StockApiController { public class StockApiController {
private static final Logger log = LoggerFactory.getLogger(StockApiController.class); private static final Logger log = LoggerFactory.getLogger(StockApiController.class);
@@ -164,20 +167,27 @@ public class StockApiController {
@ApiOperation(value = "印度新闻列表", httpMethod = "GET") @ApiOperation(value = "印度新闻列表", httpMethod = "GET")
@ResponseBody @ResponseBody
public ServerResponse getINDNews(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum) { public ServerResponse getINDNews(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum) {
return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc())); return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.showTime.desc()));
} }
@RequestMapping({"test.do"}) @RequestMapping({"test.do"})
@ResponseBody @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(); String news = stockService.getNews();
List<String> newsList = Arrays.asList(news.split("<a href=")); List<String> newsList = Arrays.asList(news.split("<a href="));
newsList = newsList.subList(1, newsList.size()); newsList = newsList.subList(1, newsList.size());
newsList.forEach( n -> { newsList.forEach( n -> {
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2); String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_")); String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?")); String imgUrl = InvestingTask.extractImgSrc(n);
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9); // 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 siteNews = new SiteNews();
siteNews.setAddTime(new Date()); siteNews.setAddTime(new Date());
@@ -234,12 +244,28 @@ public class StockApiController {
} }
@RequestMapping({"getIndiaIndexByToday.do"}) @RequestMapping({"getIndiaIndexByToday.do"})
@ApiOperation(value = "印度--获取指定指数信息", httpMethod = "GET") @ApiOperation(value = "德国--获取指定指数信息最近交易日K线", httpMethod = "GET")
@ResponseBody @ResponseBody
public ServerResponse getIndiaIndexByToday() { public ServerResponse getIndiaIndexByToday() {
String INDEX_CODE = "TODAY_INDEX"; String INDEX_CODE = "TODAY_INDEX";
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE, (string) -> { // 优化缓存时间为15秒平衡数据实时性和系统性能
return this.stockService.getIndexByBtoday(); // 由于只返回最近交易日数据,可以适当延长缓存时间
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE, 15000, (string) -> {
try {
return this.stockService.getIndexByBtoday();
} catch (Exception e) {
log.error("获取德国指数数据失败: {}", e.getMessage(), e);
throw new RuntimeException("获取指数数据失败: " + e.getMessage(), e);
}
});
}
@RequestMapping({"getIndiaIndexByEttech.do"})
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
@ResponseBody
public ServerResponse getIndiaIndexByEttech() {
String INDEX_CODE = "TODAY_INDEX";
return RequestCacheUtils.cache("getIndiaIndexByEttech.do", INDEX_CODE, (string) -> {
return this.stockService.getEttechcharts();
}); });
} }

View File

@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller @Controller
@Api(value = "/TodayApiController", tags = "today股票行情") @Api(value = "/TodayApiController", tags = "today股票行情")
@RequestMapping({"/api/market/today/"}) @RequestMapping({"/market/api/market/today/","/api/market/today/"})
public class TodayApiController { public class TodayApiController {
@RequestMapping({"getTopGainers.do"}) @RequestMapping({"getTopGainers.do"})

View File

@@ -39,4 +39,5 @@ public class Config {
String aliyunAccessKeyId; String aliyunAccessKeyId;
String aliyunAccessKeySecret; String aliyunAccessKeySecret;
String aliyunAppCode; String aliyunAppCode;
String stockUrlPrefix;
} }

View File

@@ -0,0 +1,264 @@
package cn.stock.market.web.service;
import cn.qutaojing.common.utils.SpringUtils;
import cn.stock.market.domain.basic.entity.Stock;
import cn.stock.market.domain.basic.repository.StockRepository;
import cn.stock.market.dto.*;
import cn.stock.market.infrastructure.db.po.QStockPO;
import cn.stock.market.web.config.Config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class MoneyApiService {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private StockRepository stockRepository;
public StockHistoryResponse getStockHistory(String symbol, String interval, Integer amount) {
Stock stock = stockRepository.findStockByCode(symbol);
if (stock != null) {
RawStockApiResponse rawData = fetchChartData(symbol, interval, amount);
return convertToHistoryResponse(rawData);
} else {
StockHistoryResponse stockHistoryResponse = new StockHistoryResponse();
stockHistoryResponse.setS("fail!");
return stockHistoryResponse;
}
}
private RawStockApiResponse fetchChartData(String symbol, String interval, Integer amount) {
Config config = SpringUtils.getBean(Config.class);
String url = config.getStockUrlPrefix() + "/api/ger-market/chart?symbol=" + symbol + "&interval=" + interval;
if (amount != null) {
url += "&amount=" + amount;
}
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json, text/plain, */*");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
headers.add("origin", "https://moneytj.com");
headers.add("referer", "https://moneytj.com/");
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
headers.add("sec-ch-ua-mobile", "?0");
headers.add("sec-ch-ua-platform", "\"Windows\"");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(response.getBody(), RawStockApiResponse.class);
} catch (Exception e) {
e.printStackTrace();
return new RawStockApiResponse();
}
}
public StockQuoteData getSingleStockQuote(String symbol) {
Config config = SpringUtils.getBean(Config.class);
String url = config.getStockUrlPrefix() + "/api/ger-market/stocks/query-list?symbols=" + symbol;
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json, text/plain, */*");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
headers.add("origin", "https://moneytj.com");
headers.add("referer", "https://moneytj.com/");
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
headers.add("sec-ch-ua-mobile", "?0");
headers.add("sec-ch-ua-platform", "\"Windows\"");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
StockQuoteResponse quoteResponse = mapper.readValue(response.getBody(), StockQuoteResponse.class);
if (quoteResponse != null && quoteResponse.getData() != null && !quoteResponse.getData().isEmpty()) {
return quoteResponse.getData().get(0);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public List<StockQuoteData> getStocksQuote(List<Stock> stocks) {
Config config = SpringUtils.getBean(Config.class);
String codes = stocks.stream().map(e->e.getStockCode()).collect(Collectors.joining(","));
String url = config.getStockUrlPrefix() + "/api/ger-market/stocks/query-list?symbols=" + codes;
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json, text/plain, */*");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
headers.add("origin", "https://moneytj.com");
headers.add("referer", "https://moneytj.com/");
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
headers.add("sec-ch-ua-mobile", "?0");
headers.add("sec-ch-ua-platform", "\"Windows\"");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
StockQuoteResponse quoteResponse = mapper.readValue(response.getBody(), StockQuoteResponse.class);
if (quoteResponse != null && quoteResponse.getData() != null && !quoteResponse.getData().isEmpty()) {
return quoteResponse.getData();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private StockHistoryResponse convertToHistoryResponse(RawStockApiResponse apiResponse) {
StockHistoryResponse response = new StockHistoryResponse();
response.setS("ok");
response.setT(new ArrayList<>());
response.setO(new ArrayList<>());
response.setH(new ArrayList<>());
response.setL(new ArrayList<>());
response.setC(new ArrayList<>());
response.setV(new ArrayList<>());
List<StockDataDto> data = apiResponse.getData();
for (int i = data.size() - 1; i >= 0; i--) {
StockDataDto item = data.get(i);
response.getT().add(item.getTime());
response.getO().add(item.getOpen());
response.getH().add(item.getMax());
response.getL().add(item.getMin());
response.getC().add(item.getClose());
response.getV().add(item.getVolume());
}
return response;
}
public List<StockQuoteData> getTopGainersFromTradingView() {
List<StockQuoteData> result = getTopStocksFromTradingView("desc");
// Sort by percent_change in descending order for gainers
return result.stream()
.sorted((a, b) -> Double.compare(b.getPercent_change(), a.getPercent_change()))
.collect(Collectors.toList());
}
public List<StockQuoteData> getTopLosersFromTradingView() {
List<StockQuoteData> result = getTopStocksFromTradingView("asc");
// Sort by percent_change in ascending order for losers
return result.stream()
.sorted((a, b) -> Double.compare(a.getPercent_change(), b.getPercent_change()))
.collect(Collectors.toList());
}
public List<StockQuoteData> getTopStocksFromTradingView(String sortOrder) {
String url = "https://scanner.tradingview.com/germany/scan";
// Determine preset based on sort order
String preset = "desc".equals(sortOrder) ? "gainers" : "losers";
// Prepare request body
String requestBody = "{\n" +
" \"columns\": [\n" +
" \"name\",\n" +
" \"description\",\n" +
" \"logoid\",\n" +
" \"update_mode\",\n" +
" \"type\",\n" +
" \"currency\",\n" +
" \"change\",\n" +
" \"volume\",\n" +
" \"exchange\"\n" +
" ],\n" +
" \"filter\": [\n" +
" {\n" +
" \"left\": \"is_primary\",\n" +
" \"operation\": \"equal\",\n" +
" \"right\": true\n" +
" }\n" +
" ],\n" +
" \"options\": {\n" +
" \"lang\": \"en\"\n" +
" },\n" +
" \"preset\": \"" + preset + "\",\n" +
" \"range\": [\n" +
" 0,\n" +
" 30\n" +
" ],\n" +
" \"sort\": {\n" +
" \"sortBy\": \"change\",\n" +
" \"sortOrder\": \"" + sortOrder + "\"\n" +
" },\n" +
" \"markets\": [\n" +
" \"germany\"\n" +
" ]\n" +
"}";
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "application/json");
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8,ug;q=0.7,fr;q=0.6");
headers.add("origin", "https://www.tradingview.com");
headers.add("referer", "https://www.tradingview.com/");
headers.add("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36");
headers.add("Content-Type", "application/json");
HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
TradingViewResponse tradingViewResponse = mapper.readValue(response.getBody(), TradingViewResponse.class);
if (tradingViewResponse != null && tradingViewResponse.getData() != null) {
// Extract symbols from TradingView response
List<String> symbols = tradingViewResponse.getData().stream()
.filter(item -> item.getS() != null && item.getS().startsWith("XETR:"))
.map(item -> item.getS().substring(5)) // Remove "XETR:" prefix
.limit(30)
.collect(Collectors.toList());
if (!symbols.isEmpty()) {
// Find stocks in database
List<Stock> stocks = stockRepository.findAll(QStockPO.stockPO.stockCode.in(symbols));
if (!stocks.isEmpty()) {
List<StockQuoteData> stockQuoteDatas = getStocksQuote(stocks);
for (StockQuoteData stockQuoteData : stockQuoteDatas) {
Stock name = stocks.stream().filter(e->e.getStockCode().equals(stockQuoteData.getSymbol())).findFirst().orElse(null);
if (name != null) {
stockQuoteData.setName(name.getStockName());
}
}
return stockQuoteDatas;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}

View File

@@ -1,11 +1,12 @@
spring: spring:
jpa: jpa:
show-sql: true show-sql: true
# Redis配置 # Redis配置
redis: redis:
host: 43.132.212.180 host: 167.235.39.59
password: ruTZ9J3gaDhknJ password: a5v8b86P4mVzFlUqJV
port: 36379 port: 47379
database: 1 database: 1
lettuce: lettuce:
pool: pool:
@@ -17,9 +18,9 @@ spring:
datasource: datasource:
stock-market: stock-market:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8 url: jdbc:mysql://de-cdb-pj5o5m8b.sql.tencentcdb.com:24110/stock-api?useUnicode=true&characterEncoding=utf-8
username: root username: root
password: 33BsUUcnXRYgwtIND password: 6QJXv8dA76klnqsWh6f
maxActive: 500 maxActive: 500
testWhileIdle: true testWhileIdle: true
validationQuery: SELECT 1 validationQuery: SELECT 1
@@ -28,7 +29,7 @@ spring:
stock: stock:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
#url: jdbc:mysql://129.226.172.67:3306/vip_huananyong_c?useUnicode=true&characterEncoding=utf-8&useSSL=true&verifyServerCertificate=true&requireSSL=true&clientCertificateKeyStoreUrl=classpath:keystoremysql&clientCertificateKeyStorePassword=abs1234567890&trustCertificateKeyStoreUrl=classpath:truststoremysql&trustCertificateKeyStorePassword=abs1234567890 #url: jdbc:mysql://129.226.172.67:3306/vip_huananyong_c?useUnicode=true&characterEncoding=utf-8&useSSL=true&verifyServerCertificate=true&requireSSL=true&clientCertificateKeyStoreUrl=classpath:keystoremysql&clientCertificateKeyStorePassword=abs1234567890&trustCertificateKeyStoreUrl=classpath:truststoremysql&trustCertificateKeyStorePassword=abs1234567890
url: jdbc:mysql://124.156.133.209:33306/vip_huananyong_c?useUnicode=true&characterEncoding=utf-8&useSSL=true url: jdbc:mysql://43.153.142.41:33306/vip_huananyong_c?useUnicode=true&characterEncoding=utf-8&useSSL=true
username: root username: root
password: 33BsUUcnXRYgwt password: 33BsUUcnXRYgwt
maxActive: 500 maxActive: 500
@@ -42,6 +43,8 @@ gugudataAppKey: K5LZKV8KAYM4
aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu
aliyunAccessKeySecret: fnCI9LUcqLuH7D6nkhvSHQMob1JSm8 aliyunAccessKeySecret: fnCI9LUcqLuH7D6nkhvSHQMob1JSm8
aliyunAppCode: 75ef2615da614eaaa71e2e2058fc53b0 aliyunAppCode: 75ef2615da614eaaa71e2e2058fc53b0
stockUrlPrefix: https://apinode-dgdev.moneytj.com
# 具体看类:CloudStorageConfig # 具体看类:CloudStorageConfig
oss: oss:
type: 2 # 类型 1七牛 2阿里云 3腾讯云 type: 2 # 类型 1七牛 2阿里云 3腾讯云