@dshtrading/connector-yahoo 0.6.1 → 0.6.2
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/lib/dataplane.d.ts +2 -1
- package/lib/dataplane.js +2 -4
- package/lib/index.d.ts +14 -3
- package/lib/index.js +16 -3
- package/lib/rest.d.ts +30 -4
- package/lib/rest.js +37 -4
- package/package.json +4 -4
package/lib/dataplane.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Config } from "./index.js";
|
|
1
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
2
3
|
//#region src/dataplane.d.ts
|
|
3
4
|
declare const inject: string[];
|
|
4
5
|
declare function apply(ctx: Context): void;
|
|
5
6
|
//#endregion
|
|
6
|
-
export { apply, inject };
|
|
7
|
+
export { Config, apply, inject };
|
package/lib/dataplane.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TRADING_US_MARKET_DATA_KEY, YahooMarketDataService } from "./index.js";
|
|
1
|
+
import { Config, ROUTER_PROVIDER, TRADING_US_MARKET_DATA_KEY, YahooMarketDataService } from "./index.js";
|
|
2
2
|
//#region src/dataplane.ts
|
|
3
3
|
const inject = [];
|
|
4
4
|
/** 解析注册表服务;老部署(base/router 未升级)返回 undefined → 调用方回退旧的直接 provide 路径。 */
|
|
@@ -6,8 +6,6 @@ function resolveMarketDataRegistry(ctx) {
|
|
|
6
6
|
const candidate = ctx.get?.("tradingMarketDataRegistry", false);
|
|
7
7
|
return candidate !== void 0 ? candidate : void 0;
|
|
8
8
|
}
|
|
9
|
-
/** 本连接器的路由 provider slug(路由层词汇,docs/exchange-routing.md §2.2)。 */
|
|
10
|
-
const ROUTER_PROVIDER = "yahoo";
|
|
11
9
|
function apply(ctx) {
|
|
12
10
|
const registry = resolveMarketDataRegistry(ctx);
|
|
13
11
|
if (registry === void 0) {
|
|
@@ -19,4 +17,4 @@ function apply(ctx) {
|
|
|
19
17
|
ctx.effect(() => registry.register("us", ROUTER_PROVIDER, service));
|
|
20
18
|
}
|
|
21
19
|
//#endregion
|
|
22
|
-
export { apply, inject };
|
|
20
|
+
export { Config, apply, inject };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { INTERVAL_VOCABULARY, TradingServiceError, YahooChartEnvelope, YahooChartResult, YahooRestClient, YahooRestOptions, isSupportedInterval, normalizeYahooSymbol, parseChartBars } from "./rest.js";
|
|
1
|
+
import { INTERVAL_VOCABULARY, TradingServiceError, YAHOO_KLINE_MAX_BARS, YAHOO_ONE_MINUTE_MAX_BARS, YahooChartEnvelope, YahooChartResult, YahooRestClient, YahooRestOptions, isSupportedInterval, normalizeYahooSymbol, parseChartBars, yahooKlineCapabilities } from "./rest.js";
|
|
2
2
|
import { Context, Service } from "@deepseek-ai/cordis";
|
|
3
3
|
import Schema from "@deepseek-ai/schemastery";
|
|
4
|
-
import { Disposable, Interval, Kline, MarketDataService, Ticker } from "@dshtrading/api";
|
|
4
|
+
import { Disposable, Interval, Kline, KlineCapability, MarketDataService, Ticker } from "@dshtrading/api";
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Cordis 插件名 = patch 行 id(TEMPLATES §8):`dsh-trading-us-*` 市场命名空间,
|
|
@@ -28,8 +28,19 @@ declare class YahooMarketDataService extends Service implements MarketDataServic
|
|
|
28
28
|
constructor(ctx: Context, options?: YahooRestOptions, name?: string);
|
|
29
29
|
getTicker(symbol: string): Promise<Ticker>;
|
|
30
30
|
getKlines(symbol: string, interval: Interval, limit?: number): Promise<Kline[]>;
|
|
31
|
+
/**
|
|
32
|
+
* K 线能力声明(api 可选契约,2026-10-15 跨源 K 线路由):周期集 = Yahoo chart 的受支持
|
|
33
|
+
* 子集;深度只有 1m 有实测值(2730 根 = range=7d 原窗口),其余周期声明承接闸门
|
|
34
|
+
* (口径与证据见 rest.ts 的 yahooKlineCapabilities)。
|
|
35
|
+
*/
|
|
36
|
+
klineCapabilities(): readonly KlineCapability[];
|
|
31
37
|
subscribeTicker(symbol: string, cb: (ticker: Ticker) => void, options?: SubscribeTickerOptions): Disposable;
|
|
32
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 本连接器在路由层的 provider slug(路由层词汇 = 交易所 slug;
|
|
41
|
+
* docs/guides/exchange-routing.md §2.2)。
|
|
42
|
+
*/
|
|
43
|
+
declare const ROUTER_PROVIDER = "yahoo";
|
|
33
44
|
/** us_place_order 参数契约(美股词汇,dryRun 缺省 true)。 */
|
|
34
45
|
interface PlaceOrderArgs {
|
|
35
46
|
/** 股票代码,如 `AAPL` 或 `brk-b`(执行前归一化为 Yahoo 大写形态)。 */
|
|
@@ -80,4 +91,4 @@ interface PlaceOrderToolDeps {
|
|
|
80
91
|
declare function createPlaceOrderTool(deps: PlaceOrderToolDeps): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
81
92
|
declare function apply(ctx: Context, config: Config): void;
|
|
82
93
|
//#endregion
|
|
83
|
-
export { Config, DryRunReference, INTERVAL_VOCABULARY, OrderGateVerdict, PlaceOrderArgs, PlaceOrderToolDeps, SubscribeTickerOptions, TRADING_US_MARKET_DATA_KEY, TradingServiceError, YahooChartEnvelope, YahooChartResult, YahooMarketDataService, YahooRestClient, YahooRestOptions, apply, buildDryRunReceipt, createPlaceOrderTool, evaluateOrderGate, inject, isSupportedInterval, name, normalizeYahooSymbol, parseChartBars };
|
|
94
|
+
export { Config, DryRunReference, INTERVAL_VOCABULARY, OrderGateVerdict, PlaceOrderArgs, PlaceOrderToolDeps, ROUTER_PROVIDER, SubscribeTickerOptions, TRADING_US_MARKET_DATA_KEY, TradingServiceError, YAHOO_KLINE_MAX_BARS, YAHOO_ONE_MINUTE_MAX_BARS, YahooChartEnvelope, YahooChartResult, YahooMarketDataService, YahooRestClient, YahooRestOptions, apply, buildDryRunReceipt, createPlaceOrderTool, evaluateOrderGate, inject, isSupportedInterval, name, normalizeYahooSymbol, parseChartBars, yahooKlineCapabilities };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INTERVAL_VOCABULARY, TradingServiceError, YahooRestClient, isSupportedInterval, normalizeYahooSymbol, parseChartBars } from "./rest.js";
|
|
1
|
+
import { INTERVAL_VOCABULARY, TradingServiceError, YAHOO_KLINE_MAX_BARS, YAHOO_ONE_MINUTE_MAX_BARS, YahooRestClient, isSupportedInterval, normalizeYahooSymbol, parseChartBars, yahooKlineCapabilities } from "./rest.js";
|
|
2
2
|
import { liveTradingEnabled } from "@dshtrading/authority";
|
|
3
3
|
import { Service } from "@deepseek-ai/cordis";
|
|
4
4
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
@@ -46,7 +46,15 @@ var YahooMarketDataService = class extends Service {
|
|
|
46
46
|
return this.client.getTicker(symbol);
|
|
47
47
|
}
|
|
48
48
|
getKlines(symbol, interval, limit) {
|
|
49
|
-
return this.client.getKlines(symbol, interval
|
|
49
|
+
return this.client.getKlines(symbol, interval, limit);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* K 线能力声明(api 可选契约,2026-10-15 跨源 K 线路由):周期集 = Yahoo chart 的受支持
|
|
53
|
+
* 子集;深度只有 1m 有实测值(2730 根 = range=7d 原窗口),其余周期声明承接闸门
|
|
54
|
+
* (口径与证据见 rest.ts 的 yahooKlineCapabilities)。
|
|
55
|
+
*/
|
|
56
|
+
klineCapabilities() {
|
|
57
|
+
return this.client.klineCapabilities();
|
|
50
58
|
}
|
|
51
59
|
subscribeTicker(symbol, cb, options) {
|
|
52
60
|
const ms = Math.max(options?.intervalMs ?? SUBSCRIBE_DEFAULT_MS, SUBSCRIBE_MIN_MS);
|
|
@@ -58,6 +66,11 @@ var YahooMarketDataService = class extends Service {
|
|
|
58
66
|
return { dispose: () => clearInterval(timer) };
|
|
59
67
|
}
|
|
60
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* 本连接器在路由层的 provider slug(路由层词汇 = 交易所 slug;
|
|
71
|
+
* docs/guides/exchange-routing.md §2.2)。
|
|
72
|
+
*/
|
|
73
|
+
const ROUTER_PROVIDER = "yahoo";
|
|
61
74
|
function evaluateOrderGate(config, args) {
|
|
62
75
|
const requestedDryRun = args.dryRun ?? true;
|
|
63
76
|
if (!requestedDryRun && !liveTradingEnabled(config.liveTrading)) return {
|
|
@@ -250,4 +263,4 @@ function apply(ctx, config) {
|
|
|
250
263
|
});
|
|
251
264
|
}
|
|
252
265
|
//#endregion
|
|
253
|
-
export { Config, INTERVAL_VOCABULARY, TRADING_US_MARKET_DATA_KEY, TradingServiceError, YahooMarketDataService, YahooRestClient, apply, buildDryRunReceipt, createPlaceOrderTool, evaluateOrderGate, inject, isSupportedInterval, name, normalizeYahooSymbol, parseChartBars };
|
|
266
|
+
export { Config, INTERVAL_VOCABULARY, ROUTER_PROVIDER, TRADING_US_MARKET_DATA_KEY, TradingServiceError, YAHOO_KLINE_MAX_BARS, YAHOO_ONE_MINUTE_MAX_BARS, YahooMarketDataService, YahooRestClient, apply, buildDryRunReceipt, createPlaceOrderTool, evaluateOrderGate, inject, isSupportedInterval, name, normalizeYahooSymbol, parseChartBars, yahooKlineCapabilities };
|
package/lib/rest.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Interval, Kline, Ticker, TradingErrorCode } from "@dshtrading/api";
|
|
1
|
+
import { Interval, Kline, KlineCapability, Ticker, TradingErrorCode } from "@dshtrading/api";
|
|
2
2
|
//#region src/rest.d.ts
|
|
3
3
|
/** api 包 TradingError 契约的运行时 Error 实现。 */
|
|
4
4
|
declare class TradingServiceError extends Error {
|
|
@@ -10,6 +10,24 @@ declare function normalizeYahooSymbol(symbol: string): string;
|
|
|
10
10
|
/** 工具 parameters enum 用:受支持 interval 词汇(与 connector-stooq 同一子集口径)。 */
|
|
11
11
|
declare const INTERVAL_VOCABULARY: readonly string[];
|
|
12
12
|
declare function isSupportedInterval(value: Interval): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 能承接的请求深度上限 = 桥的 K 线参数闸门(packages/bot-api MAX_KLINE_LIMIT = 2500):
|
|
15
|
+
* 上游没有 limit 语义(窗口由 range= 决定,本客户端只在返回后按 limit 截尾),故闸门内的
|
|
16
|
+
* 任何 limit 都被诚实承接、返回根数以该周期的取数窗口(RANGE_BY_INTERVAL)为界。
|
|
17
|
+
*/
|
|
18
|
+
declare const YAHOO_KLINE_MAX_BARS = 2500;
|
|
19
|
+
/**
|
|
20
|
+
* 1m 的实测窗口深度 = 2730 根(chart/AAPL|MSFT?interval=1m&range=7d → 2730 根非空 bar,
|
|
21
|
+
* 覆盖 7 个会话,2026-10-05..10-13;窗口超出即上游 422「Only 8 days worth of 1m
|
|
22
|
+
* granularity data are allowed」)——见 spikes/impl-five-day-1m-probe/EVIDENCE.md §5。
|
|
23
|
+
*/
|
|
24
|
+
declare const YAHOO_ONE_MINUTE_MAX_BARS = 2730;
|
|
25
|
+
/**
|
|
26
|
+
* K 线能力声明(api 可选契约 klineCapabilities):周期集 = INTERVAL_TO_YAHOO 的键。
|
|
27
|
+
* 深度只有 1m 有实测值(窗口型端点,上表 2730 根的原始证据),其余周期声明承接闸门
|
|
28
|
+
* ——它们的窗口根数随市场与交易日数浮动,本客户端代码里没有可报的实测数字,不据印象编。
|
|
29
|
+
*/
|
|
30
|
+
declare function yahooKlineCapabilities(): KlineCapability[];
|
|
13
31
|
/** v8 chart 响应的最小类型面(只取本客户端消费的字段)。 */
|
|
14
32
|
interface YahooChartResult {
|
|
15
33
|
meta: {
|
|
@@ -60,8 +78,16 @@ interface YahooRestOptions {
|
|
|
60
78
|
declare class YahooRestClient {
|
|
61
79
|
#private;
|
|
62
80
|
constructor(options?: YahooRestOptions);
|
|
63
|
-
/**
|
|
64
|
-
|
|
81
|
+
/** K 线能力声明(api 可选契约):周期集与深度口径见 yahooKlineCapabilities。 */
|
|
82
|
+
klineCapabilities(): readonly KlineCapability[];
|
|
83
|
+
/**
|
|
84
|
+
* 拉取并解析 K 线(旧→新全窗口);limit 给出时取尾部最近 limit 根。
|
|
85
|
+
*
|
|
86
|
+
* 窗口由上游 range 决定、上游没有 limit 语义(1m 的 range=7d ≈ 7 个会话 2730 根,
|
|
87
|
+
* 1m 单请求上限 8 天,见 spikes/impl-five-day-1m-probe/ §5),因此「只要最近 N 根」
|
|
88
|
+
* 只能在这一层截尾:消费方拿到几根就是几根。
|
|
89
|
+
*/
|
|
90
|
+
getKlines(symbol: string, interval: Interval, limit?: number): Promise<Kline[]>;
|
|
65
91
|
/**
|
|
66
92
|
* 最新行情快照:单请求 interval=1d&range=1d。
|
|
67
93
|
* price/time/volume/prevClose 全取 meta(权威实时面):昨收锚点取 meta.chartPreviousClose
|
|
@@ -74,4 +100,4 @@ declare class YahooRestClient {
|
|
|
74
100
|
getTicker(symbol: string): Promise<Ticker>;
|
|
75
101
|
}
|
|
76
102
|
//#endregion
|
|
77
|
-
export { INTERVAL_VOCABULARY, TradingServiceError, YahooChartEnvelope, YahooChartResult, YahooRestClient, YahooRestOptions, isSupportedInterval, normalizeYahooSymbol, parseChartBars };
|
|
103
|
+
export { INTERVAL_VOCABULARY, TradingServiceError, YAHOO_KLINE_MAX_BARS, YAHOO_ONE_MINUTE_MAX_BARS, YahooChartEnvelope, YahooChartResult, YahooRestClient, YahooRestOptions, isSupportedInterval, normalizeYahooSymbol, parseChartBars, yahooKlineCapabilities };
|
package/lib/rest.js
CHANGED
|
@@ -34,6 +34,29 @@ const INTERVAL_VOCABULARY = [...INTERVAL_TO_YAHOO.keys()];
|
|
|
34
34
|
function isSupportedInterval(value) {
|
|
35
35
|
return INTERVAL_TO_YAHOO.has(value);
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* 能承接的请求深度上限 = 桥的 K 线参数闸门(packages/bot-api MAX_KLINE_LIMIT = 2500):
|
|
39
|
+
* 上游没有 limit 语义(窗口由 range= 决定,本客户端只在返回后按 limit 截尾),故闸门内的
|
|
40
|
+
* 任何 limit 都被诚实承接、返回根数以该周期的取数窗口(RANGE_BY_INTERVAL)为界。
|
|
41
|
+
*/
|
|
42
|
+
const YAHOO_KLINE_MAX_BARS = 2500;
|
|
43
|
+
/**
|
|
44
|
+
* 1m 的实测窗口深度 = 2730 根(chart/AAPL|MSFT?interval=1m&range=7d → 2730 根非空 bar,
|
|
45
|
+
* 覆盖 7 个会话,2026-10-05..10-13;窗口超出即上游 422「Only 8 days worth of 1m
|
|
46
|
+
* granularity data are allowed」)——见 spikes/impl-five-day-1m-probe/EVIDENCE.md §5。
|
|
47
|
+
*/
|
|
48
|
+
const YAHOO_ONE_MINUTE_MAX_BARS = 2730;
|
|
49
|
+
/**
|
|
50
|
+
* K 线能力声明(api 可选契约 klineCapabilities):周期集 = INTERVAL_TO_YAHOO 的键。
|
|
51
|
+
* 深度只有 1m 有实测值(窗口型端点,上表 2730 根的原始证据),其余周期声明承接闸门
|
|
52
|
+
* ——它们的窗口根数随市场与交易日数浮动,本客户端代码里没有可报的实测数字,不据印象编。
|
|
53
|
+
*/
|
|
54
|
+
function yahooKlineCapabilities() {
|
|
55
|
+
return [...INTERVAL_TO_YAHOO].map(([interval]) => ({
|
|
56
|
+
interval,
|
|
57
|
+
maxBars: interval === "1m" ? YAHOO_ONE_MINUTE_MAX_BARS : YAHOO_KLINE_MAX_BARS
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
37
60
|
/** 每个 interval 的默认取数窗口(1m 上限 7 天;日线给足近三年——服务层再按 limit 截尾)。 */
|
|
38
61
|
const RANGE_BY_INTERVAL = /* @__PURE__ */ new Map([
|
|
39
62
|
["1m", "7d"],
|
|
@@ -131,12 +154,22 @@ var YahooRestClient = class {
|
|
|
131
154
|
if (!result || !Array.isArray(result.timestamp) || result.timestamp.length === 0) throw new TradingServiceError("TRADING_UNSUPPORTED_SYMBOL", `Yahoo chart ${sym}: no data rows (unknown/delisted symbol?)`);
|
|
132
155
|
return result;
|
|
133
156
|
}
|
|
134
|
-
/**
|
|
135
|
-
|
|
157
|
+
/** K 线能力声明(api 可选契约):周期集与深度口径见 yahooKlineCapabilities。 */
|
|
158
|
+
klineCapabilities() {
|
|
159
|
+
return yahooKlineCapabilities();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 拉取并解析 K 线(旧→新全窗口);limit 给出时取尾部最近 limit 根。
|
|
163
|
+
*
|
|
164
|
+
* 窗口由上游 range 决定、上游没有 limit 语义(1m 的 range=7d ≈ 7 个会话 2730 根,
|
|
165
|
+
* 1m 单请求上限 8 天,见 spikes/impl-five-day-1m-probe/ §5),因此「只要最近 N 根」
|
|
166
|
+
* 只能在这一层截尾:消费方拿到几根就是几根。
|
|
167
|
+
*/
|
|
168
|
+
async getKlines(symbol, interval, limit) {
|
|
136
169
|
const sym = normalizeYahooSymbol(symbol);
|
|
137
170
|
const bars = parseChartBars(await this.#requestChart(sym, interval), interval);
|
|
138
171
|
if (bars.length === 0) throw new TradingServiceError("TRADING_EXCHANGE_ERROR", `Yahoo klines for ${sym}: no non-null bars in range`);
|
|
139
|
-
return bars;
|
|
172
|
+
return typeof limit === "number" && Number.isInteger(limit) && limit > 0 ? bars.slice(-limit) : bars;
|
|
140
173
|
}
|
|
141
174
|
/**
|
|
142
175
|
* 最新行情快照:单请求 interval=1d&range=1d。
|
|
@@ -172,4 +205,4 @@ var YahooRestClient = class {
|
|
|
172
205
|
}
|
|
173
206
|
};
|
|
174
207
|
//#endregion
|
|
175
|
-
export { INTERVAL_VOCABULARY, TradingServiceError, YahooRestClient, isSupportedInterval, normalizeYahooSymbol, parseChartBars };
|
|
208
|
+
export { INTERVAL_VOCABULARY, TradingServiceError, YAHOO_KLINE_MAX_BARS, YAHOO_ONE_MINUTE_MAX_BARS, YahooRestClient, isSupportedInterval, normalizeYahooSymbol, parseChartBars, yahooKlineCapabilities };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dshtrading/connector-yahoo",
|
|
3
3
|
"description": "US market connector plugin for dsh-trading: public market data from the Yahoo Finance v8 chart API implementing the @dshtrading/api contracts (unofficial API, no key; personal use per Yahoo terms of use)",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@dshtrading/authority": "^0.6.
|
|
25
|
-
"@dshtrading/api": "^0.6.
|
|
24
|
+
"@dshtrading/authority": "^0.6.2",
|
|
25
|
+
"@dshtrading/api": "^0.6.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@deepseek-ai/cordis": ">=4.0.0",
|
|
29
|
-
"@deepseek-ai/dsh-tools": ">=0.2.
|
|
29
|
+
"@deepseek-ai/dsh-tools": ">=0.2.1-rc.2",
|
|
30
30
|
"@deepseek-ai/schemastery": ">=3.18.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|