更新股票交易日计算逻辑,修复获取股票数据的API地址,并统一修改页面数据获取函数名称。

This commit is contained in:
齐斌 2025-05-28 15:07:00 +08:00
parent 39deb7bd70
commit c4b11ec76a
5 changed files with 36 additions and 20 deletions

View File

@ -31,27 +31,43 @@ const options = {
dayjs.extend(utc) dayjs.extend(utc)
dayjs.extend(timezone) dayjs.extend(timezone)
/*
const getFormattedFriday = () => { 美股的常规发行日交易日为周一至周五遇到法定假日则顺延
如果你只需要上一个交易日不考虑法定假日可以这样实现
获取当前美东时间
如果今天是周一则上一个交易日为上周五
如果今天是周日则上一个交易日为上周五
如果今天是周六则上一个交易日为周五
其他情况上一个交易日为昨天
*/
const getLastTradingDay = () => {
const now = dayjs().tz('America/New_York') const now = dayjs().tz('America/New_York')
// 本周五16:00 let lastTradingDay
const thisFriday = now.day() >= 5 const dayOfWeek = now.day() // 0:周日, 1:周一, ..., 5:周五, 6:周六
? now.day(5).hour(16).minute(0).second(0).millisecond(0) const isBeforeClose = now.hour() < 16 || (now.hour() === 16 && now.minute() === 0 && now.second() === 0)
: now.day(5 - 7).hour(16).minute(0).second(0).millisecond(0)
// 判断当前是否已到本周五16:00 if (dayOfWeek === 0) { // 周日
let showFriday // 返回本周五16:00
if (now.isAfter(thisFriday)) { lastTradingDay = now.day(-2).hour(16).minute(0).second(0).millisecond(0)
showFriday = thisFriday } 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 { } else {
// 上周五16:00 // 工作日16:00后返回今天16:00
showFriday = thisFriday.subtract(7, 'day') 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 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 stockQuote.value=res.data
} }
return { return {

View File

@ -249,7 +249,7 @@ const scrollToTop = () => {
}); });
}; };
onMounted(() => { onMounted(() => {
getPageDefaultData(); getPageData();
}); });
const getPageDefaultData = async () => { const getPageDefaultData = async () => {

View File

@ -249,13 +249,13 @@ const scrollToTop = () => {
}); });
}; };
onMounted(() => { onMounted(() => {
getPageDefaultData(); getPageData();
}); });
const getPageDefaultData = async () => { const getPageDefaultData = async () => {
try { try {
let url = 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); const res = await axios.get(url);
let originalData = res.data.data; let originalData = res.data.data;

View File

@ -248,7 +248,7 @@ const scrollToTop = () => {
}); });
}; };
onMounted(() => { onMounted(() => {
getPageDefaultData(); getPageData();
}); });
const getPageDefaultData = async () => { const getPageDefaultData = async () => {

View File

@ -249,7 +249,7 @@ const scrollToTop = () => {
}); });
}; };
onMounted(() => { onMounted(() => {
getPageDefaultData(); getPageData();
}); });
const getPageDefaultData = async () => { const getPageDefaultData = async () => {