更新股票交易日计算逻辑,修复获取股票数据的API地址,并统一修改页面数据获取函数名称。
This commit is contained in:
parent
39deb7bd70
commit
c4b11ec76a
@ -31,27 +31,43 @@ const options = {
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
const getFormattedFriday = () => {
|
||||
/*
|
||||
美股的常规发行日(交易日)为周一至周五,遇到法定假日则顺延。
|
||||
如果你只需要“上一个交易日”(不考虑法定假日),可以这样实现:
|
||||
获取当前美东时间。
|
||||
如果今天是周一,则上一个交易日为上周五。
|
||||
如果今天是周日,则上一个交易日为上周五。
|
||||
如果今天是周六,则上一个交易日为周五。
|
||||
其他情况,上一个交易日为昨天。
|
||||
*/
|
||||
const getLastTradingDay = () => {
|
||||
const now = dayjs().tz('America/New_York')
|
||||
// 本周五16:00
|
||||
const thisFriday = now.day() >= 5
|
||||
? now.day(5).hour(16).minute(0).second(0).millisecond(0)
|
||||
: now.day(5 - 7).hour(16).minute(0).second(0).millisecond(0)
|
||||
// 判断当前是否已到本周五16:00
|
||||
let showFriday
|
||||
if (now.isAfter(thisFriday)) {
|
||||
showFriday = thisFriday
|
||||
let lastTradingDay
|
||||
const dayOfWeek = now.day() // 0:周日, 1:周一, ..., 5:周五, 6:周六
|
||||
const isBeforeClose = now.hour() < 16 || (now.hour() === 16 && now.minute() === 0 && now.second() === 0)
|
||||
|
||||
if (dayOfWeek === 0) { // 周日
|
||||
// 返回本周五16:00
|
||||
lastTradingDay = now.day(-2).hour(16).minute(0).second(0).millisecond(0)
|
||||
} else if (dayOfWeek === 6) { // 周六
|
||||
// 返回本周五16:00
|
||||
lastTradingDay = now.day(-1).hour(16).minute(0).second(0).millisecond(0)
|
||||
} else if (dayOfWeek === 1 && isBeforeClose) { // 周一16:00前
|
||||
// 返回上周五16:00
|
||||
lastTradingDay = now.day(-2).hour(16).minute(0).second(0).millisecond(0)
|
||||
} else if (isBeforeClose) { // 工作日16:00前
|
||||
// 返回前一天16:00
|
||||
lastTradingDay = now.subtract(1, 'day').hour(16).minute(0).second(0).millisecond(0)
|
||||
} else {
|
||||
// 上周五16:00
|
||||
showFriday = thisFriday.subtract(7, 'day')
|
||||
// 工作日16:00后,返回今天16:00
|
||||
lastTradingDay = now.hour(16).minute(0).second(0).millisecond(0)
|
||||
}
|
||||
return showFriday.format('MMM D, YYYY, h:mm A [EDT]')
|
||||
return lastTradingDay.format('MMM D, YYYY, h:mm A [EDT]')
|
||||
}
|
||||
|
||||
const formatted = ref(getFormattedFriday())
|
||||
const formatted = ref(getLastTradingDay())
|
||||
const getStockQuate= async()=>{
|
||||
const res = await axios.get('https://saas-test.szjixun.cn/api/chart/forward/test')
|
||||
const res = await axios.get('https://saas-test.szjixun.cn/api/fiee/chart/forward/test')
|
||||
stockQuote.value=res.data
|
||||
}
|
||||
return {
|
||||
|
@ -249,7 +249,7 @@ const scrollToTop = () => {
|
||||
});
|
||||
};
|
||||
onMounted(() => {
|
||||
getPageDefaultData();
|
||||
getPageData();
|
||||
});
|
||||
|
||||
const getPageDefaultData = async () => {
|
||||
|
@ -249,13 +249,13 @@ const scrollToTop = () => {
|
||||
});
|
||||
};
|
||||
onMounted(() => {
|
||||
getPageDefaultData();
|
||||
getPageData();
|
||||
});
|
||||
|
||||
const getPageDefaultData = async () => {
|
||||
try {
|
||||
let url =
|
||||
"https://stockanalysis.com/api/symbol/a/OTC-MINM/history?type=chart";
|
||||
"https://stockanalysis.com/api/symbol/a/OTC-MINM/history?period=Daily&range=3M";
|
||||
const res = await axios.get(url);
|
||||
let originalData = res.data.data;
|
||||
|
||||
|
@ -248,7 +248,7 @@ const scrollToTop = () => {
|
||||
});
|
||||
};
|
||||
onMounted(() => {
|
||||
getPageDefaultData();
|
||||
getPageData();
|
||||
});
|
||||
|
||||
const getPageDefaultData = async () => {
|
||||
|
@ -249,7 +249,7 @@ const scrollToTop = () => {
|
||||
});
|
||||
};
|
||||
onMounted(() => {
|
||||
getPageDefaultData();
|
||||
getPageData();
|
||||
});
|
||||
|
||||
const getPageDefaultData = async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user