mirror of
https://github.com/zhangxiangliang/stock-api.git
synced 2025-01-23 14:20:23 +08:00
feat: 增加 股票数据解析获取股票数据方法、修改 股票数据接口生成股票数据方法
This commit is contained in:
parent
1d40c7dde0
commit
d3e8bce06a
@ -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;
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user