Compare commits
33 Commits
twelvedata
...
feature/kl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
549345719a | ||
|
|
3870400411 | ||
|
|
94d2936ffb | ||
|
|
59e4aa9e1a | ||
|
|
bae645e3c6 | ||
|
|
94d9aea2c8 | ||
|
|
5ae9762d45 | ||
|
|
ece52491dd | ||
|
|
6235d41711 | ||
|
|
c865eccaf4 | ||
|
|
136020a497 | ||
|
|
d7da59aca1 | ||
|
|
8427bed427 | ||
|
|
269f02b79d | ||
|
|
7cc456bcd8 | ||
|
|
be05d403af | ||
|
|
4a29bf6659 | ||
|
|
5b2eb8519a | ||
|
|
2e4449bd64 | ||
|
|
b321fd9d4e | ||
|
|
2f9e54bf4f | ||
| 3bb354bbc6 | |||
| a403cba964 | |||
|
|
99bde81670 | ||
|
|
bae941828e | ||
|
|
2f86571578 | ||
|
|
d491bef735 | ||
|
|
74c64eb7d4 | ||
|
|
f50b6b5519 | ||
| 2446d89b30 | |||
|
|
33a68eb7e8 | ||
|
|
7b0a08150d | ||
|
|
146e9d9bc0 |
@@ -2,7 +2,7 @@ stages:
|
|||||||
# 构建
|
# 构建
|
||||||
- build
|
- build
|
||||||
- dockerize
|
- dockerize
|
||||||
- webhook
|
- deploy
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3.6.3-openjdk-8
|
image: maven:3.6.3-openjdk-8
|
||||||
@@ -60,16 +60,20 @@ dockerize:
|
|||||||
- docker push juyoutech/india_stock_market:latest
|
- docker push juyoutech/india_stock_market:latest
|
||||||
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
||||||
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
||||||
webhook:
|
deploy-dev:
|
||||||
stage: webhook
|
stage: deploy
|
||||||
only:
|
only:
|
||||||
- develop
|
- develop
|
||||||
script:
|
script:
|
||||||
- echo ">>>>>>Start Deploy<<<<<<"
|
- echo "Deploying application..."
|
||||||
- ls
|
- ls
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y curl
|
- apt-get install -y curl
|
||||||
- curl --max-time 30 http://149.88.86.7:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=deploy-test.sh
|
- |
|
||||||
- echo ">>>>>>Start Deploy Finish<<<<<<"
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"namespace":"yddev", "deployment_name":"india-stock-market"}' \
|
||||||
|
https://updater-yddev.moneytj.com/restart-deployment
|
||||||
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||||
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.select.Elements;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
@@ -252,7 +254,13 @@ public class StockService {
|
|||||||
.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=\"shortvideoimg\" style=\"position:relative\">"),doc.html().lastIndexOf("<div class=\"shortvideoimg\" style=\"position:relative\">")+1200);
|
// 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();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.toString();
|
return e.toString();
|
||||||
}
|
}
|
||||||
@@ -974,7 +982,7 @@ public class StockService {
|
|||||||
String exchange = "bse";
|
String exchange = "bse";
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
String coCode = "20558";
|
String coCode = "20558";
|
||||||
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = objToVo(object);
|
||||||
market.setName("BSESENSEX指数");
|
market.setName("BSESENSEX指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
@@ -1004,7 +1012,7 @@ public class StockService {
|
|||||||
String exchange = "nse";
|
String exchange = "nse";
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
String coCode = "20559";
|
String coCode = "20559";
|
||||||
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = objToVo(object);
|
||||||
market.setName("NIFTY50指数");
|
market.setName("NIFTY50指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
@@ -1034,23 +1042,23 @@ public class StockService {
|
|||||||
}
|
}
|
||||||
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"));
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -25,6 +26,8 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -118,8 +121,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 +151,22 @@ public class InvestingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String extractImgSrc(String htmlData) {
|
||||||
|
String searchString = "<noscript>";
|
||||||
|
int startPos = htmlData.indexOf(searchString);
|
||||||
|
|
||||||
|
if (startPos != -1) {
|
||||||
|
String startTag = "src=";
|
||||||
|
startPos = htmlData.indexOf(startTag, startPos) + startTag.length() + 1;
|
||||||
|
|
||||||
|
int endPos = htmlData.indexOf("?", startPos);
|
||||||
|
|
||||||
|
if (endPos != -1) {
|
||||||
|
return htmlData.substring(startPos, endPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
181
src/main/java/cn/stock/market/utils/NseIndiaRequest.java
Normal file
181
src/main/java/cn/stock/market/utils/NseIndiaRequest.java
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
package cn.stock.market.utils;
|
||||||
|
|
||||||
|
import cn.stock.market.dto.StockHistoryRequest;
|
||||||
|
import cn.stock.market.dto.StockHistoryResponse;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import okhttp3.*;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class NseIndiaRequest {
|
||||||
|
private static final String NSE_INDIA_URL = "https://www.nseindia.com";
|
||||||
|
private static final String NSE_INDIA_CHART_URL = "https://charting.nseindia.com";
|
||||||
|
private static final OkHttpClient client;
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
client = new OkHttpClient.Builder()
|
||||||
|
.cookieJar(new CookieJar() {
|
||||||
|
private final Map<String, List<Cookie>> cookieStore = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
|
||||||
|
cookieStore.put(url.host(), cookies);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Cookie> loadForRequest(HttpUrl url) {
|
||||||
|
List<Cookie> cookies = cookieStore.get(url.host());
|
||||||
|
return cookies != null ? cookies : new ArrayList<Cookie>();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Request createRequest(String url) {
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.header("accept", "application/json, text/plain, */*")
|
||||||
|
.header("accept-language", "en-US,en;q=0.9")
|
||||||
|
.header("cache-control", "no-cache")
|
||||||
|
.header("pragma", "no-cache")
|
||||||
|
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initCookie(String url) {
|
||||||
|
Request request = createRequest(url);
|
||||||
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new IOException("Failed to fetch initial cookies");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to initialize cookies", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Integer getCode(String symbol) {
|
||||||
|
Request request = createRequest(NSE_INDIA_CHART_URL + "//Charts/GetEQMasters").newBuilder()
|
||||||
|
.addHeader("referer", NSE_INDIA_CHART_URL)
|
||||||
|
.addHeader("origin", NSE_INDIA_CHART_URL)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new IOException("Failed to get EQ code");
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = response.body().string();
|
||||||
|
|
||||||
|
String regex = "(\\d+)\\|" + symbol + "\\|.*";
|
||||||
|
Pattern pattern = Pattern.compile(regex);
|
||||||
|
Matcher matcher = pattern.matcher(result);
|
||||||
|
|
||||||
|
if (matcher.find()) {
|
||||||
|
return Integer.valueOf(matcher.group(1));
|
||||||
|
}
|
||||||
|
throw new IOException("No data found");
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to get EQ code", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONObject stockByJYSFromHttp(String stockType, String symbol, String nseIndiaId) {
|
||||||
|
initCookie(NSE_INDIA_URL);
|
||||||
|
|
||||||
|
String url = NSE_INDIA_URL + "/api/quote-equity?symbol=" + nseIndiaId;
|
||||||
|
Request request = createRequest(url).newBuilder()
|
||||||
|
.addHeader("referer", NSE_INDIA_URL)
|
||||||
|
.addHeader("origin", NSE_INDIA_URL)
|
||||||
|
.build();
|
||||||
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new IOException("Request failed with code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject jsonData = JSONObject.parseObject(response.body().string());
|
||||||
|
JSONObject data =jsonData.getJSONObject("priceInfo");
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
json.put("pricepercentchange",data.getString("pChange"));
|
||||||
|
json.put("stockType",stockType);
|
||||||
|
json.put("pricechange",data.getString("change"));
|
||||||
|
json.put("pricecurrent",data.getString("lastPrice"));
|
||||||
|
json.put("priceprevclose",data.getString("previousClose"));
|
||||||
|
json.put("PREVDATE","");
|
||||||
|
json.put("VOL",jsonData.getJSONObject("preOpenMarket").getString("totalTradedVolume"));
|
||||||
|
json.put("dataSourceType","3");
|
||||||
|
json.put("symbol",symbol);
|
||||||
|
json.put("BSEID",symbol);
|
||||||
|
json.put("NSEID",symbol);
|
||||||
|
json.put("LTH",data.getString("upperCP"));
|
||||||
|
json.put("LTL",data.getString("lowerCP"));
|
||||||
|
json.put("OPN",data.getString("open"));
|
||||||
|
|
||||||
|
return json;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to fetch data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StockHistoryResponse stockKLineFromHttp(StockHistoryRequest stockHistoryRequest, String resolution) {
|
||||||
|
initCookie(NSE_INDIA_CHART_URL);
|
||||||
|
|
||||||
|
Integer code = getCode(stockHistoryRequest.getSymbol());
|
||||||
|
|
||||||
|
int interval = 1;
|
||||||
|
if (StringUtils.equals("H", resolution)) {
|
||||||
|
resolution = "I";
|
||||||
|
interval = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("chartPeriod", resolution);
|
||||||
|
body.put("chartStart", 0);
|
||||||
|
body.put("exch", "N");
|
||||||
|
body.put("fromDate", 0);
|
||||||
|
body.put("instrType", "C");
|
||||||
|
body.put("scripCode", code);
|
||||||
|
body.put("timeInterval", interval);
|
||||||
|
body.put("toDate", stockHistoryRequest.getTo() + 18000);
|
||||||
|
body.put("ulToken", code);
|
||||||
|
|
||||||
|
String payload;
|
||||||
|
try {
|
||||||
|
payload = objectMapper.writeValueAsString(body);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to serialize body", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestBody requestBody = RequestBody.create(
|
||||||
|
MediaType.get("application/json; charset=utf-8"),
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
|
||||||
|
Request request = createRequest(NSE_INDIA_CHART_URL + "//Charts/symbolhistoricaldata/").newBuilder()
|
||||||
|
.addHeader("referer", NSE_INDIA_CHART_URL)
|
||||||
|
.addHeader("origin", NSE_INDIA_CHART_URL)
|
||||||
|
.post(requestBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = client.newCall(request).execute()) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new IOException("Request failed with code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
StockHistoryResponse result = objectMapper.readValue(response.body().string(), StockHistoryResponse.class);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Failed to fetch data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import 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;
|
||||||
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
|||||||
import cn.stock.market.dto.StockHistoryRequest;
|
import cn.stock.market.dto.StockHistoryRequest;
|
||||||
import cn.stock.market.dto.StockHistoryResponse;
|
import cn.stock.market.dto.StockHistoryResponse;
|
||||||
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.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 com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -39,10 +39,7 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,8 +60,6 @@ public class MoneyApiController {
|
|||||||
|
|
||||||
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";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "股票详情信息", httpMethod = "GET")
|
@ApiOperation(value = "股票详情信息", httpMethod = "GET")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
||||||
@@ -173,7 +168,6 @@ public class MoneyApiController {
|
|||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
|
||||||
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol) {
|
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol) {
|
||||||
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s",stockType,symbol);
|
|
||||||
MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType)
|
MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType)
|
||||||
.and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
|
.and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
|
||||||
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
||||||
@@ -183,6 +177,20 @@ public class MoneyApiController {
|
|||||||
return ServerResponse.createByErrorMsg("没有找到该股票");
|
return ServerResponse.createByErrorMsg("没有找到该股票");
|
||||||
}*/
|
}*/
|
||||||
// 设置重试次数
|
// 设置重试次数
|
||||||
|
if ("ANI".equals(symbol)) {
|
||||||
|
JSONObject json1 = new JSONObject();
|
||||||
|
json1.put("company", "Archit Nuwood Industries Ltd");
|
||||||
|
json1.put("pricepercentchange", "Archit Nuwood Industries Ltd");
|
||||||
|
json1.put("stockType", stockType);
|
||||||
|
json1.put("pricecurrent", "386");
|
||||||
|
json1.put("dataSourceType", "3");
|
||||||
|
json1.put("symbol", "ANI");
|
||||||
|
json1.put("BSEID", "ANI");
|
||||||
|
json1.put("NSEID", "ANI");
|
||||||
|
return ServerResponse.createBySuccess(json1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", stockType, symbol);
|
||||||
int maxRetries = 3;
|
int maxRetries = 3;
|
||||||
for (int retry = 1; retry <= maxRetries; retry++) {
|
for (int retry = 1; retry <= maxRetries; retry++) {
|
||||||
try {
|
try {
|
||||||
@@ -191,7 +199,7 @@ public class MoneyApiController {
|
|||||||
if (responseEntity.getStatusCode().value() == 200 && responseEntity.getBody() != null) {
|
if (responseEntity.getStatusCode().value() == 200 && responseEntity.getBody() != null) {
|
||||||
JSONObject data = JSONObject.parseObject(responseEntity.getBody()).getJSONObject("data");
|
JSONObject data = JSONObject.parseObject(responseEntity.getBody()).getJSONObject("data");
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
json1.put("company",data.getString("company"));
|
json1.put("company", data.getString("SC_FULLNM"));
|
||||||
json1.put("pricepercentchange", data.getString("pricepercentchange"));
|
json1.put("pricepercentchange", data.getString("pricepercentchange"));
|
||||||
json1.put("stockType", stockType);
|
json1.put("stockType", stockType);
|
||||||
json1.put("pricechange", data.getString("pricechange"));
|
json1.put("pricechange", data.getString("pricechange"));
|
||||||
@@ -214,6 +222,7 @@ public class MoneyApiController {
|
|||||||
json1.put("pricecurrent", data.getString("priceprevclose"));
|
json1.put("pricecurrent", data.getString("priceprevclose"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (json1.size() > 0)
|
||||||
return ServerResponse.createBySuccess(json1);
|
return ServerResponse.createBySuccess(json1);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -228,9 +237,20 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (moneyStock != null && moneyStock.getNseIndiaId() != null && !moneyStock.getNseIndiaId().isEmpty()) {
|
||||||
|
try {
|
||||||
|
// Get data from nseindia
|
||||||
|
JSONObject json = NseIndiaRequest.stockByJYSFromHttp(stockType, symbol, moneyStock.getNseIndiaId());
|
||||||
|
json.put("id", moneyStock.getId());
|
||||||
|
json.put("company",moneyStock.getStockName());
|
||||||
|
return ServerResponse.createBySuccess(json);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static List<MoneyStockSuggestDTO> nseActives() {
|
private static List<MoneyStockSuggestDTO> nseActives() {
|
||||||
@@ -501,8 +521,6 @@ 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"),
|
||||||
@@ -599,8 +617,6 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "股票推荐TopActive", httpMethod = "GET")
|
@ApiOperation(value = "股票推荐TopActive", httpMethod = "GET")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
||||||
@@ -653,7 +669,6 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping({"/market/api/market/money/history/kLine", "/api/market/money/history/kLine"})
|
@GetMapping({"/market/api/market/money/history/kLine", "/api/market/money/history/kLine"})
|
||||||
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源", response = StockHistoryResponse.class)
|
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源", response = StockHistoryResponse.class)
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@@ -725,11 +740,27 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null && !response.getS().equals("error")) {
|
||||||
setResponse(response, resolution);
|
setResponse(response, resolution);
|
||||||
// API request successful, return the response
|
// API request successful, return the response
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
|
MoneyStock moneyStock = moneyStockRepository.findOne((QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.isShow.eq(0)))
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (moneyStock != null && moneyStock.getNseIndiaChartId() != null && !moneyStock.getNseIndiaChartId().isEmpty()) {
|
||||||
|
request.setSymbol(moneyStock.getNseIndiaChartId());
|
||||||
|
response = NseIndiaRequest.stockKLineFromHttp(request, resolution);
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to get data from nseindia.", e.getMessage());
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
|
||||||
// All retries failed, return an error response
|
// All retries failed, return an error response
|
||||||
log.error("Failed to get a successful response after {} retries.", maxRetries);
|
log.error("Failed to get a successful response after {} retries.", maxRetries);
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
@@ -782,14 +813,14 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String buildApiUrl(StockHistoryRequest request) {
|
private String buildApiUrl(StockHistoryRequest request) {
|
||||||
// 构建外部API的URL
|
// 构建外部API的URL
|
||||||
return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d¤cyCode=%s",
|
return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d¤cyCode=%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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -169,15 +172,22 @@ public class StockApiController {
|
|||||||
|
|
||||||
@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());
|
||||||
@@ -238,7 +248,7 @@ public class StockApiController {
|
|||||||
@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,60000, (string) -> {
|
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||||
return this.stockService.getIndexByBtoday();
|
return this.stockService.getIndexByBtoday();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ spring:
|
|||||||
show-sql: true
|
show-sql: true
|
||||||
# Redis配置
|
# Redis配置
|
||||||
redis:
|
redis:
|
||||||
host: 43.132.212.180
|
host: lb-b6sze686-7db6hgvsx05ef8nz.clb.sg-tencentclb.net
|
||||||
password: ruTZ9J3gaDhknJ
|
password: a5v8b86P4mVzFlUqJV
|
||||||
port: 36379
|
port: 56379
|
||||||
database: 1
|
database: 1
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -17,9 +17,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://lb-1ju43bvw-p0ecnv4by9ju8six.clb.ap-singapore.tencentclb.com:53306/india_stock?useUnicode=true&characterEncoding=utf-8
|
||||||
username: root
|
username: root
|
||||||
password: 33BsUUcnXRYgwtIND
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
testWhileIdle: true
|
testWhileIdle: true
|
||||||
validationQuery: SELECT 1
|
validationQuery: SELECT 1
|
||||||
|
|||||||
Reference in New Issue
Block a user