@dshtrading/connector-eastmoney 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ Copyright (c) 2026 zhu1090093659 (dsh-trading)
2
+
3
+ # PolyForm Noncommercial License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
14
+
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
22
+
23
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
24
+
25
+ ## Changes and New Works License
26
+
27
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
28
+
29
+ ## Patent License
30
+
31
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
32
+
33
+ ## Noncommercial Purposes
34
+
35
+ Any noncommercial purpose is a permitted purpose.
36
+
37
+ ## Personal Uses
38
+
39
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
40
+
41
+ ## Noncommercial Organizations
42
+
43
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
44
+
45
+ ## Fair Use
46
+
47
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
48
+
49
+ ## No Other Rights
50
+
51
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
52
+
53
+ ## Patent Defense
54
+
55
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
56
+
57
+ ## Violations
58
+
59
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
60
+
61
+ ## No Liability
62
+
63
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
64
+
65
+ ## Definitions
66
+
67
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
68
+
69
+ **You** refers to the individual or entity agreeing to these terms.
70
+
71
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
72
+
73
+ **Your licenses** are all the licenses granted to you for the software under these terms.
74
+
75
+ **Use** means anything you do with the software requiring one of your licenses.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @dshtrading/connector-template
2
+
3
+ **本包是脚手架源,不是可安装的连接器**:不入任何 bundle 依赖,仅在 `pnpm -r build/test`
4
+ 基线内保证可编译、冒烟测试绿。真实接入用生成器:
5
+
6
+ ```sh
7
+ node scripts/new-connector.mjs --slug bybit --title Bybit --market crypto
8
+ ```
9
+
10
+ 生成后按 [docs/connector-playbook.md](../../docs/connector-playbook.md) 的填写顺序
11
+ (src/rest.ts 头部清单 7 项)实现 TODO。每个 TODO 的参照段都在 connector-okx
12
+ (packages/connector-okx/),它是本仓第一个真实 TradeService 连接器。
13
+
14
+ ## 结构
15
+
16
+ - `src/rest.ts` —— 错误载体(TradingServiceError)+ 通用请求管线(超时/错误映射/
17
+ 模拟盘头/注入 fetch)直接可用;签名与端点 TODO。
18
+ - `src/index.ts` —— Config(enabled/env/dryRun/liveTrading + 三 ref 凭证组)、
19
+ 闸门三态判定、凭证解析(BYOK + 环境变量回落)、MarketDataService/TradeService 骨架、
20
+ 7 个市场前缀工具注册(duplicate-safe)、apply(enabled=false 静默退出)。
21
+ - `test/template.test.ts` —— 结构冒烟 7 用例。
22
+
23
+ ## Token
24
+
25
+ `eastmoney`(slug)/ `Eastmoney`(title)/ `EASTMONEY`(ref 前缀)/
26
+ `cn`(工具前缀)/ `Cn`(服务键 infix)。token 未展开也可编译;
27
+ 生成器保证全部替换。
28
+
29
+ ## 注意(勿改的坑)
30
+
31
+ - 服务类用 TS 编译期 `private`(禁 ECMAScript `#`,realm 代理会炸)。
32
+ - 工具名 = 市场前缀 + 语义词(不带交易所名)——base 闸门正则只认市场前缀。
33
+ - 行 id = `dsh-trading-<market>-connector-<slug>`,全仓唯一(insert-only 铁律 #1)。
34
+ - 凭证只进 ref,绝不内置/落日志(铁律 #3/#5)。
@@ -0,0 +1,7 @@
1
+ import { Config } from "./index.js";
2
+ import { Context } from "@deepseek-ai/cordis";
3
+ //#region src/dataplane.d.ts
4
+ declare const inject: string[];
5
+ declare function apply(ctx: Context, config: Config): void;
6
+ //#endregion
7
+ export { apply, inject };
@@ -0,0 +1,22 @@
1
+ import { EastmoneyMarketDataService, TRADING_CN_MARKET_DATA_KEY } from "./index.js";
2
+ //#region src/dataplane.ts
3
+ const inject = [];
4
+ function resolveMarketDataRegistry(ctx) {
5
+ const candidate = ctx.get?.("tradingMarketDataRegistry", false);
6
+ return candidate !== void 0 ? candidate : void 0;
7
+ }
8
+ const ROUTER_PROVIDER = "eastmoney";
9
+ const MARKET = "cn";
10
+ function apply(ctx, config) {
11
+ if (!config.enabled) return;
12
+ const registry = resolveMarketDataRegistry(ctx);
13
+ if (registry === void 0) {
14
+ new EastmoneyMarketDataService(ctx);
15
+ return;
16
+ }
17
+ const inner = ctx.isolate(TRADING_CN_MARKET_DATA_KEY);
18
+ const service = new EastmoneyMarketDataService(inner);
19
+ ctx.effect(() => registry.register(MARKET, ROUTER_PROVIDER, service));
20
+ }
21
+ //#endregion
22
+ export { apply, inject };
package/lib/index.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { EastmoneyRestClient, EastmoneyRestOptions, INTERVAL_VOCABULARY, Interval, Kline, Ticker, TradingServiceError, mapIntervalToKlt, parseIntervalMs, toEastmoneySecid } from "./rest.js";
2
+ import { Context, Service } from "@deepseek-ai/cordis";
3
+ import Schema from "@deepseek-ai/schemastery";
4
+ import { Disposable, Interval as Interval$1, Kline as Kline$1, MarketDataService, Ticker as Ticker$1 } from "@dshtrading/api";
5
+ //#region src/index.d.ts
6
+ declare const name = "dsh-trading-cn-connector-eastmoney";
7
+ interface Config {
8
+ enabled: boolean;
9
+ }
10
+ declare const Config: Schema<Config>;
11
+ declare const TRADING_CN_MARKET_DATA_KEY = "tradingCnMarketData";
12
+ declare class EastmoneyMarketDataService extends Service implements MarketDataService {
13
+ private readonly client;
14
+ constructor(ctx: Context, options?: EastmoneyRestOptions, serviceName?: string);
15
+ getTicker(symbol: string): Promise<Ticker$1>;
16
+ getKlines(symbol: string, interval?: Interval$1, limit?: number): Promise<Kline$1[]>;
17
+ listInstruments(query?: string): Promise<Array<{
18
+ symbol: string;
19
+ name: string;
20
+ }>>;
21
+ subscribeTicker(symbol: string, cb: (ticker: Ticker$1) => void, options?: {
22
+ intervalMs?: number;
23
+ }): Disposable;
24
+ }
25
+ declare const ROUTER_PROVIDER = "eastmoney";
26
+ declare function routeAllows(ctx: Context, config: Config, market: string): boolean;
27
+ declare function apply(ctx: Context, config: Config): void;
28
+ //#endregion
29
+ export { Config, EastmoneyMarketDataService, EastmoneyRestClient, EastmoneyRestOptions, INTERVAL_VOCABULARY, type Interval, type Kline, ROUTER_PROVIDER, TRADING_CN_MARKET_DATA_KEY, type Ticker, TradingServiceError, apply, mapIntervalToKlt, name, parseIntervalMs, routeAllows, toEastmoneySecid };
package/lib/index.js ADDED
@@ -0,0 +1,105 @@
1
+ import { EastmoneyRestClient, INTERVAL_VOCABULARY, TradingServiceError, mapIntervalToKlt, parseIntervalMs, toEastmoneySecid } from "./rest.js";
2
+ import { Service } from "@deepseek-ai/cordis";
3
+ import { defineTool } from "@deepseek-ai/dsh-tools";
4
+ import Schema from "@deepseek-ai/schemastery";
5
+ //#region src/index.ts
6
+ const name = "dsh-trading-cn-connector-eastmoney";
7
+ const Config = Schema.object({ enabled: Schema.boolean().default(true).description("是否激活东财连接器") });
8
+ const TRADING_CN_MARKET_DATA_KEY = "tradingCnMarketData";
9
+ var EastmoneyMarketDataService = class extends Service {
10
+ client;
11
+ constructor(ctx, options = {}, serviceName = TRADING_CN_MARKET_DATA_KEY) {
12
+ super(ctx, serviceName);
13
+ this.client = new EastmoneyRestClient(options);
14
+ }
15
+ async getTicker(symbol) {
16
+ return this.client.getTicker(symbol);
17
+ }
18
+ async getKlines(symbol, interval = "1d", limit = 100) {
19
+ return this.client.getKlines(symbol, interval, limit);
20
+ }
21
+ async listInstruments(query) {
22
+ return this.client.listInstruments(query);
23
+ }
24
+ subscribeTicker(symbol, cb, options) {
25
+ const ms = Math.max(options?.intervalMs ?? 5e3, 1e3);
26
+ const tick = () => {
27
+ this.getTicker(symbol).then(cb, () => {});
28
+ };
29
+ tick();
30
+ const timer = setInterval(tick, ms);
31
+ return { dispose: () => clearInterval(timer) };
32
+ }
33
+ };
34
+ const ROUTER_PROVIDER = "eastmoney";
35
+ function routeAllows(ctx, config, market) {
36
+ if (!config.enabled) return false;
37
+ const router = ctx.get?.("tradingMarketRouter", false);
38
+ if (router === void 0) return true;
39
+ return router.activeProvider(market) === ROUTER_PROVIDER;
40
+ }
41
+ function apply(ctx, config) {
42
+ if (!config.enabled) return;
43
+ if (!routeAllows(ctx, config, "cn")) return;
44
+ const marketData = new EastmoneyMarketDataService(ctx);
45
+ ctx.inject(["tools"], (ctx) => {
46
+ const tools = ctx.tools;
47
+ const register = (t) => {
48
+ if (tools.get(t.name) === void 0) tools.register(t);
49
+ };
50
+ register(defineTool({
51
+ name: "cn_get_ticker",
52
+ description: "Get the latest trade price and quote for an A-share stock via Eastmoney API.",
53
+ parameters: { symbol: {
54
+ type: "string",
55
+ required: true,
56
+ description: "A-share stock symbol, e.g. 600519.SH"
57
+ } },
58
+ output: {
59
+ schema: { type: "string" },
60
+ render: (_a, v) => [{
61
+ type: "text",
62
+ text: v
63
+ }]
64
+ },
65
+ async execute(args) {
66
+ return JSON.stringify(await marketData.getTicker(args.symbol));
67
+ }
68
+ }));
69
+ register(defineTool({
70
+ name: "cn_get_klines",
71
+ description: "Get recent public klines for an A-share stock via Eastmoney API. Supports 1m/5m/15m/30m/1h/1d/1w/1M.",
72
+ parameters: {
73
+ symbol: {
74
+ type: "string",
75
+ required: true,
76
+ description: "A-share stock symbol, e.g. 600519.SH"
77
+ },
78
+ interval: {
79
+ type: "string",
80
+ enum: INTERVAL_VOCABULARY,
81
+ default: "1d",
82
+ description: "Interval"
83
+ },
84
+ limit: {
85
+ type: "integer",
86
+ default: 100,
87
+ description: "Limit"
88
+ }
89
+ },
90
+ output: {
91
+ schema: { type: "string" },
92
+ render: (_a, v) => [{
93
+ type: "text",
94
+ text: v
95
+ }]
96
+ },
97
+ async execute(args) {
98
+ const klines = await marketData.getKlines(args.symbol, args.interval ?? "1d", args.limit);
99
+ return JSON.stringify(klines);
100
+ }
101
+ }));
102
+ });
103
+ }
104
+ //#endregion
105
+ export { Config, EastmoneyMarketDataService, EastmoneyRestClient, INTERVAL_VOCABULARY, ROUTER_PROVIDER, TRADING_CN_MARKET_DATA_KEY, TradingServiceError, apply, mapIntervalToKlt, name, parseIntervalMs, routeAllows, toEastmoneySecid };
package/lib/rest.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { Interval as Interval$1, Kline as Kline$1, Ticker as Ticker$1, TradingErrorCode } from "@dshtrading/api";
2
+ //#region src/rest.d.ts
3
+ declare class TradingServiceError extends Error {
4
+ readonly code: TradingErrorCode;
5
+ constructor(code: TradingErrorCode, message: string, cause?: unknown);
6
+ }
7
+ declare const INTERVAL_VOCABULARY: readonly ["1m", "5m", "15m", "30m", "1h", "1d", "1w", "1M"];
8
+ declare function mapIntervalToKlt(interval: Interval$1): string;
9
+ declare function parseIntervalMs(interval: Interval$1): number;
10
+ /**
11
+ * 将标准代码(如 600519.SH / 000001.SZ / 600519 / 000001)转为东财 secid。
12
+ * 上海(60/68/51等)= 1.xxxxxx
13
+ * 深圳(00/30/15等)= 0.xxxxxx
14
+ * 北京(83/87/43/92等)= 0.xxxxxx
15
+ */
16
+ declare function toEastmoneySecid(symbol: string): {
17
+ secid: string;
18
+ canonical: string;
19
+ };
20
+ interface EastmoneyRestOptions {
21
+ baseUrl?: string;
22
+ historyBaseUrl?: string;
23
+ searchBaseUrl?: string;
24
+ fetchImpl?: typeof fetch;
25
+ }
26
+ declare class EastmoneyRestClient {
27
+ readonly baseUrl: string;
28
+ readonly historyBaseUrl: string;
29
+ readonly searchBaseUrl: string;
30
+ private readonly fetchImpl;
31
+ constructor(options?: EastmoneyRestOptions);
32
+ private requestJson;
33
+ getTicker(symbol: string): Promise<Ticker$1>;
34
+ getKlines(symbol: string, interval?: Interval$1, limit?: number): Promise<Kline$1[]>;
35
+ listInstruments(query?: string): Promise<Array<{
36
+ symbol: string;
37
+ name: string;
38
+ }>>;
39
+ }
40
+ //#endregion
41
+ export { EastmoneyRestClient, EastmoneyRestOptions, INTERVAL_VOCABULARY, type Interval$1 as Interval, type Kline$1 as Kline, type Ticker$1 as Ticker, TradingServiceError, mapIntervalToKlt, parseIntervalMs, toEastmoneySecid };
package/lib/rest.js ADDED
@@ -0,0 +1,182 @@
1
+ //#region src/rest.ts
2
+ var TradingServiceError = class extends Error {
3
+ code;
4
+ constructor(code, message, cause) {
5
+ super(message);
6
+ this.name = "TradingServiceError";
7
+ this.code = code;
8
+ if (cause !== void 0) this.cause = cause;
9
+ }
10
+ };
11
+ const INTERVAL_VOCABULARY = [
12
+ "1m",
13
+ "5m",
14
+ "15m",
15
+ "30m",
16
+ "1h",
17
+ "1d",
18
+ "1w",
19
+ "1M"
20
+ ];
21
+ function mapIntervalToKlt(interval) {
22
+ switch (interval) {
23
+ case "1m": return "1";
24
+ case "5m": return "5";
25
+ case "15m": return "15";
26
+ case "30m": return "30";
27
+ case "1h": return "60";
28
+ case "1d": return "101";
29
+ case "1w": return "102";
30
+ case "1M": return "103";
31
+ default: throw new TradingServiceError("TRADING_INVALID_ARGUMENT", `Unsupported interval "${interval}" for Eastmoney. Valid: ${INTERVAL_VOCABULARY.join(", ")}`);
32
+ }
33
+ }
34
+ function parseIntervalMs(interval) {
35
+ switch (interval) {
36
+ case "1m": return 6e4;
37
+ case "5m": return 3e5;
38
+ case "15m": return 9e5;
39
+ case "30m": return 18e5;
40
+ case "1h": return 36e5;
41
+ case "1d": return 864e5;
42
+ case "1w": return 6048e5;
43
+ case "1M": return 2592e6;
44
+ }
45
+ }
46
+ /**
47
+ * 上游分精度整数(×100,如昨收 f60=129740 → 1297.40)→ 数值;
48
+ * '-'/‘−’ 停牌占位或缺失返回 undefined。
49
+ */
50
+ function parseScaledHundred(value) {
51
+ if (typeof value === "number") return Number.isFinite(value) ? value / 100 : void 0;
52
+ if (typeof value === "string" && value !== "-" && value !== "−") {
53
+ const parsed = parseFloat(value);
54
+ return Number.isNaN(parsed) ? void 0 : parsed / 100;
55
+ }
56
+ }
57
+ /**
58
+ * 将标准代码(如 600519.SH / 000001.SZ / 600519 / 000001)转为东财 secid。
59
+ * 上海(60/68/51等)= 1.xxxxxx
60
+ * 深圳(00/30/15等)= 0.xxxxxx
61
+ * 北京(83/87/43/92等)= 0.xxxxxx
62
+ */
63
+ function toEastmoneySecid(symbol) {
64
+ const clean = symbol.trim().toUpperCase();
65
+ let code = clean;
66
+ let market = "";
67
+ if (clean.includes(".")) {
68
+ const parts = clean.split(".");
69
+ code = parts[0];
70
+ market = parts[1];
71
+ } else if (/^\d{6}$/.test(clean)) {
72
+ code = clean;
73
+ if (code.startsWith("6") || code.startsWith("5") || code.startsWith("9")) market = "SH";
74
+ else if (code.startsWith("0") || code.startsWith("3") || code.startsWith("1")) market = "SZ";
75
+ else if (code.startsWith("8") || code.startsWith("4") || code.startsWith("92")) market = "BJ";
76
+ }
77
+ if (!market) {
78
+ if (code.startsWith("6") || code.startsWith("5")) market = "SH";
79
+ else market = "SZ";
80
+ }
81
+ return {
82
+ secid: `${market === "SH" ? "1" : "0"}.${code}`,
83
+ canonical: `${code}.${market}`
84
+ };
85
+ }
86
+ var EastmoneyRestClient = class {
87
+ baseUrl;
88
+ historyBaseUrl;
89
+ searchBaseUrl;
90
+ fetchImpl;
91
+ constructor(options = {}) {
92
+ this.baseUrl = options.baseUrl ?? "https://push2.eastmoney.com";
93
+ this.historyBaseUrl = options.historyBaseUrl ?? "https://push2his.eastmoney.com";
94
+ this.searchBaseUrl = options.searchBaseUrl ?? "https://searchapi.eastmoney.com";
95
+ this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
96
+ }
97
+ async requestJson(url) {
98
+ try {
99
+ const res = await this.fetchImpl(url, { headers: {
100
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)",
101
+ "Referer": "https://quote.eastmoney.com/"
102
+ } });
103
+ if (!res.ok) throw new TradingServiceError("TRADING_UPSTREAM_ERROR", `Eastmoney HTTP request failed: status ${res.status} ${res.statusText}`);
104
+ return await res.json();
105
+ } catch (err) {
106
+ if (err instanceof TradingServiceError) throw err;
107
+ throw new TradingServiceError("TRADING_NETWORK", `Eastmoney network error: ${err instanceof Error ? err.message : String(err)}`, err);
108
+ }
109
+ }
110
+ async getTicker(symbol) {
111
+ const { secid, canonical } = toEastmoneySecid(symbol);
112
+ const url = `${this.baseUrl}/api/qt/stock/get?secid=${secid}&fields=f43,f44,f45,f46,f47,f48,f57,f58,f60,f86,f169,f170`;
113
+ const res = await this.requestJson(url);
114
+ if (!res.data) throw new TradingServiceError("TRADING_SYMBOL_NOT_FOUND", `Eastmoney symbol not found: ${symbol}`);
115
+ const d = res.data;
116
+ let rawPrice = 0;
117
+ if (typeof d.f43 === "number") rawPrice = d.f43 / 100;
118
+ else if (typeof d.f43 === "string" && d.f43 !== "-" && d.f43 !== "−") {
119
+ const parsed = parseFloat(d.f43);
120
+ rawPrice = Number.isNaN(parsed) ? 0 : parsed / 100;
121
+ }
122
+ const price = rawPrice > 0 ? rawPrice : 0;
123
+ const volume = typeof d.f47 === "number" ? d.f47 : typeof d.f47 === "string" ? parseFloat(d.f47) : 0;
124
+ const timestamp = typeof d.f86 === "number" ? d.f86 * 1e3 : Date.now();
125
+ const prevClose = parseScaledHundred(d.f60);
126
+ const changePercent = parseScaledHundred(d.f170);
127
+ const name = typeof d.f58 === "string" && d.f58.trim() ? d.f58.trim() : void 0;
128
+ return {
129
+ symbol: canonical,
130
+ ...name ? { name } : {},
131
+ price,
132
+ volume: volume > 0 ? volume : 0,
133
+ timestamp,
134
+ ...prevClose !== void 0 && prevClose > 0 ? { prevClose } : {},
135
+ ...changePercent !== void 0 ? { changePercent } : {}
136
+ };
137
+ }
138
+ async getKlines(symbol, interval = "1d", limit = 100) {
139
+ const { secid } = toEastmoneySecid(symbol);
140
+ const klt = mapIntervalToKlt(interval);
141
+ const stepMs = parseIntervalMs(interval);
142
+ const url = `${this.historyBaseUrl}/api/qt/stock/kline/get?secid=${secid}&klt=${klt}&fqt=1&lmt=${limit}&end=20500101&fields1=f1,f2,f3,f4,f5,f6&fields2=f51,f52,f53,f54,f55,f56,f57,f58`;
143
+ const res = await this.requestJson(url);
144
+ if (!res.data || !Array.isArray(res.data.klines)) return [];
145
+ const klines = [];
146
+ for (const line of res.data.klines) {
147
+ const parts = line.split(",");
148
+ if (parts.length < 6) continue;
149
+ const timeStr = parts[0];
150
+ const open = parseFloat(parts[1]);
151
+ const close = parseFloat(parts[2]);
152
+ const high = parseFloat(parts[3]);
153
+ const low = parseFloat(parts[4]);
154
+ const volume = parseFloat(parts[5]);
155
+ const openTime = new Date(timeStr.replace(/-/g, "/")).getTime();
156
+ if (Number.isNaN(openTime)) continue;
157
+ klines.push({
158
+ openTime,
159
+ open,
160
+ high,
161
+ low,
162
+ close,
163
+ volume,
164
+ closeTime: openTime + stepMs - 1
165
+ });
166
+ }
167
+ return klines;
168
+ }
169
+ async listInstruments(query) {
170
+ if (!query) return [];
171
+ const url = `${this.searchBaseUrl}/api/suggest/get?input=${encodeURIComponent(query)}&type=14`;
172
+ return ((await this.requestJson(url)).QuotationCodeTable?.Data ?? []).map((item) => {
173
+ const { canonical } = toEastmoneySecid(item.Code);
174
+ return {
175
+ symbol: canonical,
176
+ name: item.Name
177
+ };
178
+ });
179
+ }
180
+ };
181
+ //#endregion
182
+ export { EastmoneyRestClient, INTERVAL_VOCABULARY, TradingServiceError, mapIntervalToKlt, parseIntervalMs, toEastmoneySecid };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@dshtrading/connector-eastmoney",
3
+ "description": "【模板】交易所连接器插件脚手架:Eastmoney(eastmoney)v2 插件骨架 —— 市场数据服务 + 交易服务 + 三态闸门 + BYOK 凭证 ref。生成器:node scripts/new-connector.mjs --slug <exchange>",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./dataplane": {
14
+ "types": "./lib/dataplane.d.ts",
15
+ "default": "./lib/dataplane.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "lib"
21
+ ],
22
+ "license": "PolyForm-Noncommercial-1.0.0",
23
+ "dependencies": {
24
+ "@dshtrading/api": "^0.1.0"
25
+ },
26
+ "peerDependencies": {
27
+ "@deepseek-ai/cordis": ">=4.0.0",
28
+ "@deepseek-ai/dsh-tools": ">=0.1.2-alpha.1",
29
+ "@deepseek-ai/schemastery": ">=3.18.0"
30
+ },
31
+ "devDependencies": {
32
+ "tsdown": "^0.22.0",
33
+ "vitest": "^3.0.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsdown",
37
+ "test": "vitest run"
38
+ }
39
+ }