mirror of
https://github.com/zhangxiangliang/stock-api.git
synced 2025-01-23 22:40:21 +08:00
feat: 增加 新浪股票数据内容
This commit is contained in:
parent
2fcdfd4c59
commit
0ddb0e4daf
@ -44,8 +44,12 @@ class Sina extends Base {
|
||||
return {
|
||||
code: code,
|
||||
name: data.getName(),
|
||||
price: data.getPrice(),
|
||||
percent: data.getPercent(),
|
||||
|
||||
now: data.getNow(),
|
||||
low: data.getLow(),
|
||||
high: data.getHigh(),
|
||||
yesterday: data.getYesterday(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -72,8 +76,12 @@ class Sina extends Base {
|
||||
return {
|
||||
code: code,
|
||||
name: data.getName(),
|
||||
price: data.getPrice(),
|
||||
percent: data.getPercent(),
|
||||
|
||||
now: data.getNow(),
|
||||
low: data.getLow(),
|
||||
high: data.getHigh(),
|
||||
yesterday: data.getYesterday(),
|
||||
};
|
||||
})
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class SinaDataTransform {
|
||||
/**
|
||||
* 获取现价
|
||||
*/
|
||||
getPrice(): number {
|
||||
getNow(): number {
|
||||
switch (this.code.slice(0, 2)) {
|
||||
case SH:
|
||||
return Number(this.params[3]);
|
||||
@ -46,6 +46,42 @@ class SinaDataTransform {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最低价
|
||||
*/
|
||||
getLow(): number {
|
||||
switch (this.code.slice(0, 2)) {
|
||||
case SH:
|
||||
return Number(this.params[5]);
|
||||
case SZ:
|
||||
return Number(this.params[5]);
|
||||
case HK:
|
||||
return Number(this.params[5]);
|
||||
case US:
|
||||
return Number(this.params[7]);
|
||||
default:
|
||||
throw new Error('不支持当前交易所');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最高价
|
||||
*/
|
||||
getHigh(): number {
|
||||
switch (this.code.slice(0, 2)) {
|
||||
case SH:
|
||||
return Number(this.params[4]);
|
||||
case SZ:
|
||||
return Number(this.params[4]);
|
||||
case HK:
|
||||
return Number(this.params[4]);
|
||||
case US:
|
||||
return Number(this.params[6]);
|
||||
default:
|
||||
throw new Error('不支持当前交易所');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昨日收盘价
|
||||
*/
|
||||
@ -68,7 +104,7 @@ class SinaDataTransform {
|
||||
* 获取涨跌
|
||||
*/
|
||||
getPercent(): number {
|
||||
return this.getPrice() ? this.getPrice() / this.getYesterday() - 1 : 0;
|
||||
return this.getNow() ? this.getNow() / this.getYesterday() - 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user