From fc83dcb4115765f358e55627975d7cdd9d3357b0 Mon Sep 17 00:00:00 2001 From: zhangxiangliang Date: Wed, 29 Jul 2020 02:31:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20=E6=96=B0=E6=B5=AA?= =?UTF-8?q?=E8=82=A1=E7=A5=A8=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- test/stocks/sina/api.test.ts | 16 +++++ test/stocks/sina/exchangeTransform.test.ts | 70 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/stocks/sina/api.test.ts create mode 100644 test/stocks/sina/exchangeTransform.test.ts diff --git a/README.md b/README.md index 968782b..8b823c0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ | 名称 | 接口名 | 官网 | | --- | --- | --- | | 基础示例 | base | 无 | -| 网易财经 | netease | [传送门](https://money.163.com/) +| 网易财经 | netease | [传送门](https://money.163.com/) | +| 新浪股票 | sina | [传送门](https://finance.sina.com.cn/) | ## 安装 diff --git a/test/stocks/sina/api.test.ts b/test/stocks/sina/api.test.ts new file mode 100644 index 0000000..d331b18 --- /dev/null +++ b/test/stocks/sina/api.test.ts @@ -0,0 +1,16 @@ +// Stock +import Sina from "../../../src/stocks/sina/api"; + +describe("【网易】股票代码接口", () => { + it("需要获取的股票代码", async () => { + await expect(new Sina().getStock("SH510500")) + .resolves + .toMatchObject({ code: "SH510500", name: "500ETF" }); + }); + + it("需要获取的股票组代码", async () => { + await expect((new Sina()).getStocks(["SH510500"])) + .resolves + .toMatchObject([{ code: "SH510500", name: "500ETF" }]); + }); +}); diff --git a/test/stocks/sina/exchangeTransform.test.ts b/test/stocks/sina/exchangeTransform.test.ts new file mode 100644 index 0000000..c3f7c65 --- /dev/null +++ b/test/stocks/sina/exchangeTransform.test.ts @@ -0,0 +1,70 @@ +// Stock +import SinaExchangeTransform from "../../../src/stocks/sina/exchangeTransform"; + +describe("【新浪】股票代码转换测试", () => { + it("深交所股票代码转换", async () => { + expect(() => (new SinaExchangeTransform()).SZExchangeTransform("000000")) + .toThrow(new Error("请检查股票代码是否正确")); + + expect((new SinaExchangeTransform()).SZExchangeTransform("SZ000000")) + .toBe("sz000000"); + }); + + it("上交所股票代码转换", async () => { + expect(() => (new SinaExchangeTransform()).SHExchangeTransform("000000")) + .toThrow(new Error("请检查股票代码是否正确")); + + expect((new SinaExchangeTransform()).SHExchangeTransform("SH000000")) + .toBe("sh000000"); + }); + + it("港交所股票代码转换", async () => { + expect(() => (new SinaExchangeTransform()).HKExchangeTransform("000000")) + .toThrow(new Error("请检查股票代码是否正确")); + + expect((new SinaExchangeTransform()).HKExchangeTransform("HK000000")) + .toBe("hk000000"); + }); + + it("美交所股票代码转换", async () => { + expect(() => (new SinaExchangeTransform()).USExchangeTransform("000000")) + .toThrow(new Error("请检查股票代码是否正确")); + + expect((new SinaExchangeTransform()).USExchangeTransform("US000000")) + .toBe("gb_000000"); + }); + + it("交易所股票代码转换", async () => { + expect((new SinaExchangeTransform()).transform("SZ000000")) + .toBe("sz000000"); + + expect((new SinaExchangeTransform()).transform("SH000000")) + .toBe("sh000000"); + + expect((new SinaExchangeTransform()).transform("HK000000")) + .toBe("hk000000"); + + expect((new SinaExchangeTransform()).transform("US000000")) + .toBe("gb_000000"); + + expect(() => (new SinaExchangeTransform()).transform("000000")) + .toThrow(new Error("请检查股票代码是否正确")); + }); + + it("交易所股票组代码转换", async () => { + expect((new SinaExchangeTransform()).transforms(["SZ000000"])) + .toStrictEqual(["sz000000"]); + + expect((new SinaExchangeTransform()).transforms(["SH000000"])) + .toStrictEqual(["sh000000"]); + + expect((new SinaExchangeTransform()).transforms(["HK000000"])) + .toStrictEqual(["hk000000"]); + + expect((new SinaExchangeTransform()).transforms(["US000000"])) + .toStrictEqual(["gb_000000"]); + + expect(() => (new SinaExchangeTransform()).transforms(["000000"])) + .toThrow(new Error("请检查股票代码是否正确")); + }); +});