feat: 增加 新浪股票数据内容

This commit is contained in:
zhangxiangliang 2020-07-29 19:55:53 +08:00
parent 2fcdfd4c59
commit 0ddb0e4daf
2 changed files with 48 additions and 4 deletions

View File

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

View File

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