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
1d40c7dde0
commit
d3e8bce06a
@ -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;
|
||||||
|
@ -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(),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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(),
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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(),
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user