diff --git a/src/stocks/base/dataTransform.ts b/src/stocks/base/dataTransform.ts index 16afd59..7838586 100644 --- a/src/stocks/base/dataTransform.ts +++ b/src/stocks/base/dataTransform.ts @@ -1,5 +1,5 @@ // Types -import Dictionary from "types/dictionary"; +import Stock from "types/stock"; /** * 基础股票数据解析 @@ -53,6 +53,22 @@ class BaseDataTransform { getPercent(): number { throw new Error('未实现获取涨跌'); } + + /** + * 获取股票数据 + */ + getStock(): Stock { + return { + code: this.getCode(), + name: this.getName(), + percent: this.getPercent(), + + now: this.getNow(), + low: this.getLow(), + high: this.getHigh(), + yesterday: this.getYesterday(), + }; + } } export default BaseDataTransform; diff --git a/src/stocks/netease/api.ts b/src/stocks/netease/api.ts index 754e96f..7de35d0 100644 --- a/src/stocks/netease/api.ts +++ b/src/stocks/netease/api.ts @@ -34,16 +34,7 @@ class Netease extends Base { const params = items[transform]; const data = (new NeteaseDataTransform(code, params)); - return { - code: data.getCode(), - name: data.getName(), - percent: data.getPercent(), - - now: data.getNow(), - low: data.getLow(), - high: data.getHigh(), - yesterday: data.getYesterday(), - }; + return data.getStock(); } /** @@ -63,16 +54,7 @@ class Netease extends Base { const params = items[transform]; const data = (new NeteaseDataTransform(code, params)); - return { - code: data.getCode(), - name: data.getName(), - percent: data.getPercent(), - - now: data.getNow(), - low: data.getLow(), - high: data.getHigh(), - yesterday: data.getYesterday(), - } + return data.getStock(); }); } } diff --git a/src/stocks/netease/dataTransform.ts b/src/stocks/netease/dataTransform.ts index 7557d3d..ea1fd25 100644 --- a/src/stocks/netease/dataTransform.ts +++ b/src/stocks/netease/dataTransform.ts @@ -2,6 +2,7 @@ import BaseDataTransform from "@stocks/base/dataTransform"; // Types +import Stock from "types/stock"; import Dictionary from "types/dictionary"; /** @@ -63,6 +64,22 @@ class NeteaseDataTransform extends BaseDataTransform { getPercent(): number { return Number(this.params.percent); } + + /** + * 获取股票数据 + */ + getStock(): Stock { + return { + code: this.getCode(), + name: this.getName(), + percent: this.getPercent(), + + now: this.getNow(), + low: this.getLow(), + high: this.getHigh(), + yesterday: this.getYesterday(), + }; + } } export default NeteaseDataTransform; diff --git a/src/stocks/sina/api.ts b/src/stocks/sina/api.ts index 7580a7e..93e3eb8 100644 --- a/src/stocks/sina/api.ts +++ b/src/stocks/sina/api.ts @@ -41,16 +41,7 @@ class Sina extends Base { const params = paramsUnformat.replace('"', '').split(","); const data = (new SinaDataTransform(code, params)); - return { - code: data.getCode(), - name: data.getName(), - percent: data.getPercent(), - - now: data.getNow(), - low: data.getLow(), - high: data.getHigh(), - yesterday: data.getYesterday(), - }; + return data.getStock(); } /** @@ -73,16 +64,7 @@ class Sina extends Base { const params = paramsUnformat.replace('"', '').split(","); const data = (new SinaDataTransform(code, params)); - return { - code: data.getCode(), - name: data.getName(), - percent: data.getPercent(), - - now: data.getNow(), - low: data.getLow(), - high: data.getHigh(), - yesterday: data.getYesterday(), - }; + return data.getStock(); }) } } diff --git a/src/stocks/sina/dataTransform.ts b/src/stocks/sina/dataTransform.ts index ecf1d64..bf5f83b 100644 --- a/src/stocks/sina/dataTransform.ts +++ b/src/stocks/sina/dataTransform.ts @@ -4,6 +4,9 @@ import BaseDataTransform from "@stocks/base/dataTransform"; // Utils import { SZ, HK, US, SH } from "@utils/constant"; +// Types +import Stock from "types/stock"; + /** * 新浪股票数据解析 */ @@ -118,6 +121,22 @@ class SinaDataTransform extends BaseDataTransform { getPercent(): number { return this.getNow() ? this.getNow() / this.getYesterday() - 1 : 0; } + + /** + * 获取股票数据 + */ + getStock(): Stock { + return { + code: this.getCode(), + name: this.getName(), + percent: this.getPercent(), + + now: this.getNow(), + low: this.getLow(), + high: this.getHigh(), + yesterday: this.getYesterday(), + }; + } } export default SinaDataTransform; diff --git a/src/stocks/tencent/api.ts b/src/stocks/tencent/api.ts index cae9b3f..f0d5eb3 100644 --- a/src/stocks/tencent/api.ts +++ b/src/stocks/tencent/api.ts @@ -40,16 +40,7 @@ class Tencent extends Base { const params = paramsUnformat.replace('"', '').split("~"); const data = (new TencentDataTransform(code, params)); - return { - code: data.getCode(), - name: data.getName(), - percent: data.getPercent(), - - now: data.getNow(), - low: data.getLow(), - high: data.getHigh(), - yesterday: data.getYesterday(), - }; + return data.getStock(); } /** @@ -72,16 +63,7 @@ class Tencent extends Base { const params = paramsUnformat.replace('"', '').split("~"); const data = (new TencentDataTransform(code, params)); - return { - code: data.getCode(), - name: data.getName(), - percent: data.getPercent(), - - now: data.getNow(), - low: data.getLow(), - high: data.getHigh(), - yesterday: data.getYesterday(), - }; + return data.getStock(); }) } } diff --git a/src/stocks/tencent/dataTransform.ts b/src/stocks/tencent/dataTransform.ts index 1c56d88..243cfad 100644 --- a/src/stocks/tencent/dataTransform.ts +++ b/src/stocks/tencent/dataTransform.ts @@ -1,6 +1,9 @@ // Stocks import BaseDataTransform from "@stocks/base/dataTransform"; +// Types +import { Stock } from "types/stock"; + /** * 腾讯股票数据解析 */ @@ -60,6 +63,22 @@ class TencentDataTransform extends BaseDataTransform { getPercent(): number { return this.getNow() ? this.getNow() / this.getYesterday() - 1 : 0; } + + /** + * 获取股票数据 + */ + getStock(): Stock { + return { + code: this.getCode(), + name: this.getName(), + percent: this.getPercent(), + + now: this.getNow(), + low: this.getLow(), + high: this.getHigh(), + yesterday: this.getYesterday(), + }; + } } export default TencentDataTransform;