feat: 增加 股票数据解析获取股票数据方法、修改 股票数据接口生成股票数据方法

This commit is contained in:
zhangxiangliang 2020-07-30 01:57:43 +08:00
parent 1d40c7dde0
commit d3e8bce06a
7 changed files with 78 additions and 61 deletions

View File

@ -1,5 +1,5 @@
// Types // Types
import Dictionary from "types/dictionary"; import Stock from "types/stock";
/** /**
* *
@ -53,6 +53,22 @@ class BaseDataTransform {
getPercent(): number { getPercent(): number {
throw new Error('未实现获取涨跌'); 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; export default BaseDataTransform;

View File

@ -34,16 +34,7 @@ class Netease extends Base {
const params = items[transform]; const params = items[transform];
const data = (new NeteaseDataTransform(code, params)); const data = (new NeteaseDataTransform(code, params));
return { return data.getStock();
code: data.getCode(),
name: data.getName(),
percent: data.getPercent(),
now: data.getNow(),
low: data.getLow(),
high: data.getHigh(),
yesterday: data.getYesterday(),
};
} }
/** /**
@ -63,16 +54,7 @@ class Netease extends Base {
const params = items[transform]; const params = items[transform];
const data = (new NeteaseDataTransform(code, params)); const data = (new NeteaseDataTransform(code, params));
return { return data.getStock();
code: data.getCode(),
name: data.getName(),
percent: data.getPercent(),
now: data.getNow(),
low: data.getLow(),
high: data.getHigh(),
yesterday: data.getYesterday(),
}
}); });
} }
} }

View File

@ -2,6 +2,7 @@
import BaseDataTransform from "@stocks/base/dataTransform"; import BaseDataTransform from "@stocks/base/dataTransform";
// Types // Types
import Stock from "types/stock";
import Dictionary from "types/dictionary"; import Dictionary from "types/dictionary";
/** /**
@ -63,6 +64,22 @@ class NeteaseDataTransform extends BaseDataTransform {
getPercent(): number { getPercent(): number {
return Number(this.params.percent); 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; export default NeteaseDataTransform;

View File

@ -41,16 +41,7 @@ class Sina extends Base {
const params = paramsUnformat.replace('"', '').split(","); const params = paramsUnformat.replace('"', '').split(",");
const data = (new SinaDataTransform(code, params)); const data = (new SinaDataTransform(code, params));
return { return data.getStock();
code: data.getCode(),
name: data.getName(),
percent: data.getPercent(),
now: data.getNow(),
low: data.getLow(),
high: data.getHigh(),
yesterday: data.getYesterday(),
};
} }
/** /**
@ -73,16 +64,7 @@ class Sina extends Base {
const params = paramsUnformat.replace('"', '').split(","); const params = paramsUnformat.replace('"', '').split(",");
const data = (new SinaDataTransform(code, params)); const data = (new SinaDataTransform(code, params));
return { return data.getStock();
code: data.getCode(),
name: data.getName(),
percent: data.getPercent(),
now: data.getNow(),
low: data.getLow(),
high: data.getHigh(),
yesterday: data.getYesterday(),
};
}) })
} }
} }

View File

@ -4,6 +4,9 @@ import BaseDataTransform from "@stocks/base/dataTransform";
// Utils // Utils
import { SZ, HK, US, SH } from "@utils/constant"; import { SZ, HK, US, SH } from "@utils/constant";
// Types
import Stock from "types/stock";
/** /**
* *
*/ */
@ -118,6 +121,22 @@ class SinaDataTransform extends BaseDataTransform {
getPercent(): number { getPercent(): number {
return this.getNow() ? this.getNow() / this.getYesterday() - 1 : 0; 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; export default SinaDataTransform;

View File

@ -40,16 +40,7 @@ class Tencent extends Base {
const params = paramsUnformat.replace('"', '').split("~"); const params = paramsUnformat.replace('"', '').split("~");
const data = (new TencentDataTransform(code, params)); const data = (new TencentDataTransform(code, params));
return { return data.getStock();
code: data.getCode(),
name: data.getName(),
percent: data.getPercent(),
now: data.getNow(),
low: data.getLow(),
high: data.getHigh(),
yesterday: data.getYesterday(),
};
} }
/** /**
@ -72,16 +63,7 @@ class Tencent extends Base {
const params = paramsUnformat.replace('"', '').split("~"); const params = paramsUnformat.replace('"', '').split("~");
const data = (new TencentDataTransform(code, params)); const data = (new TencentDataTransform(code, params));
return { return data.getStock();
code: data.getCode(),
name: data.getName(),
percent: data.getPercent(),
now: data.getNow(),
low: data.getLow(),
high: data.getHigh(),
yesterday: data.getYesterday(),
};
}) })
} }
} }

View File

@ -1,6 +1,9 @@
// Stocks // Stocks
import BaseDataTransform from "@stocks/base/dataTransform"; import BaseDataTransform from "@stocks/base/dataTransform";
// Types
import { Stock } from "types/stock";
/** /**
* *
*/ */
@ -60,6 +63,22 @@ class TencentDataTransform extends BaseDataTransform {
getPercent(): number { getPercent(): number {
return this.getNow() ? this.getNow() / this.getYesterday() - 1 : 0; 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; export default TencentDataTransform;