@dshtrading/kit-crypto 0.1.6 → 0.2.1
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/index.d.ts +16 -1
- package/lib/index.js +76 -2
- package/package.json +6 -6
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MarketDataService } from "./api/lib/index.js";
|
|
1
2
|
import { CryptoFundamentalsOptions, CryptoFundamentalsResult, fetchCryptoFundamentals, fetchCryptoFundamentalsPackage, renderCryptoFundamentals } from "./fundamentals.js";
|
|
2
3
|
import { DerivativesFetchOptions, DerivativesResult, extractBaseAsset, fetchCryptoDerivatives, normalizeBinanceFuturesSymbol, renderDerivativesData } from "./derivatives.js";
|
|
3
4
|
import { AggregateNewsOptions, AggregateNewsResult, NewsItem, NewsSource, aggregateNews, deriveSymbolTokens, parseCryptoPanic, parseRss2 } from "./news.js";
|
|
@@ -21,6 +22,20 @@ declare function apply(ctx: Context, config: Config): void;
|
|
|
21
22
|
declare function createGetDerivativesTool(options?: {
|
|
22
23
|
fetch?: typeof globalThis.fetch;
|
|
23
24
|
}): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
25
|
+
/** 行情注册表最小形状(与 @dshtrading/router 的 MarketDataRegistryLike 同构)。 */
|
|
26
|
+
interface CryptoMarketDataRegistry {
|
|
27
|
+
active(market: string): {
|
|
28
|
+
provider: string;
|
|
29
|
+
service: MarketDataService;
|
|
30
|
+
} | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 衍生品历史序列工具(只读)。数据源恒为路由选中的 crypto 行情服务,不直连交易所:
|
|
34
|
+
* 与 crypto_get_derivatives 的硬编码 Binance 数据源不一致(审计既存项)有意不复刻。
|
|
35
|
+
*/
|
|
36
|
+
declare function createGetDerivativesHistoryTool(options: {
|
|
37
|
+
getRegistry: () => CryptoMarketDataRegistry | undefined;
|
|
38
|
+
}): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
24
39
|
declare function createGetFundamentalsTool(options?: {
|
|
25
40
|
fetch?: typeof globalThis.fetch;
|
|
26
41
|
}): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
@@ -28,4 +43,4 @@ declare function createGetNewsTool(toolOptions?: {
|
|
|
28
43
|
cryptoPanicKey?: string;
|
|
29
44
|
}): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
30
45
|
//#endregion
|
|
31
|
-
export { AggregateNewsOptions, AggregateNewsResult, Config, CryptoFundamentalsOptions, CryptoFundamentalsResult, DerivativesFetchOptions, DerivativesResult, NewsItem, NewsSource, aggregateNews, apply, createGetDerivativesTool, createGetFundamentalsTool, createGetNewsTool, deriveSymbolTokens, extractBaseAsset, fetchCryptoDerivatives, fetchCryptoFundamentals, fetchCryptoFundamentalsPackage, inject, name, normalizeBinanceFuturesSymbol, parseCryptoPanic, parseRss2, provider, providerForSkills, renderCryptoFundamentals, renderDerivativesData };
|
|
46
|
+
export { AggregateNewsOptions, AggregateNewsResult, Config, CryptoFundamentalsOptions, CryptoFundamentalsResult, DerivativesFetchOptions, DerivativesResult, NewsItem, NewsSource, aggregateNews, apply, createGetDerivativesHistoryTool, createGetDerivativesTool, createGetFundamentalsTool, createGetNewsTool, deriveSymbolTokens, extractBaseAsset, fetchCryptoDerivatives, fetchCryptoFundamentals, fetchCryptoFundamentalsPackage, inject, name, normalizeBinanceFuturesSymbol, parseCryptoPanic, parseRss2, provider, providerForSkills, renderCryptoFundamentals, renderDerivativesData };
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
|
14
14
|
* 1. skill provider:crypto-risk-checklist、crypto-instrument-analysis、indicator-authoring、trading-strategy-paradigms、knowledge-curation 与 trading-notes-setup 随包分发;
|
|
15
15
|
* 2. crypto_funding_rate(Binance 公共资金费率);
|
|
16
16
|
* 3. crypto_get_news(动态聚合新闻);
|
|
17
|
-
* 4. crypto_get_derivatives 与 crypto_get_fundamentals 工具;
|
|
17
|
+
* 4. crypto_get_derivatives、crypto_get_derivatives_history 与 crypto_get_fundamentals 工具;
|
|
18
18
|
* 5. indicator_author 创作工具(Issue #19);
|
|
19
19
|
* 6. knowledge_ingest 与 knowledge_search 知识库工具(Issue #24)。
|
|
20
20
|
*
|
|
@@ -222,6 +222,7 @@ function apply(ctx, config) {
|
|
|
222
222
|
registerOnce(createGetNewsTool({ cryptoPanicKey: router?.newsKey?.() }));
|
|
223
223
|
registerOnce(createGetDerivativesTool());
|
|
224
224
|
registerOnce(createGetFundamentalsTool());
|
|
225
|
+
registerOnce(createGetDerivativesHistoryTool({ getRegistry: () => resolveCryptoMarketDataRegistry(ctx) }));
|
|
225
226
|
const lifecycle = ctx;
|
|
226
227
|
lifecycle.inject?.(["tradingNewsRegistry"], (scope) => {
|
|
227
228
|
const registry = scope.tradingNewsRegistry;
|
|
@@ -256,6 +257,79 @@ function createGetDerivativesTool(options = {}) {
|
|
|
256
257
|
}
|
|
257
258
|
});
|
|
258
259
|
}
|
|
260
|
+
const DERIVATIVES_HISTORY_MIN_LIMIT = 1;
|
|
261
|
+
const DERIVATIVES_HISTORY_MAX_LIMIT = 200;
|
|
262
|
+
/** registry-first 解析(惰性:每次调用重新读取,路由切换即刻生效;老部署无此服务则 undefined)。 */
|
|
263
|
+
function resolveCryptoMarketDataRegistry(ctx) {
|
|
264
|
+
return ctx.get?.("tradingMarketDataRegistry", false);
|
|
265
|
+
}
|
|
266
|
+
function parseDerivativesHistoryLimit(raw) {
|
|
267
|
+
if (raw === void 0 || raw === null) return void 0;
|
|
268
|
+
if (typeof raw !== "number" || !Number.isFinite(raw)) throw new Error(`crypto_get_derivatives_history: invalid limit ${JSON.stringify(raw)} — limit must be a number in ${DERIVATIVES_HISTORY_MIN_LIMIT}..${DERIVATIVES_HISTORY_MAX_LIMIT}`);
|
|
269
|
+
const limit = Math.trunc(raw);
|
|
270
|
+
if (limit < DERIVATIVES_HISTORY_MIN_LIMIT || limit > DERIVATIVES_HISTORY_MAX_LIMIT) throw new Error(`crypto_get_derivatives_history: invalid limit ${raw} — limit must be in ${DERIVATIVES_HISTORY_MIN_LIMIT}..${DERIVATIVES_HISTORY_MAX_LIMIT}`);
|
|
271
|
+
return limit;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 衍生品历史序列工具(只读)。数据源恒为路由选中的 crypto 行情服务,不直连交易所:
|
|
275
|
+
* 与 crypto_get_derivatives 的硬编码 Binance 数据源不一致(审计既存项)有意不复刻。
|
|
276
|
+
*/
|
|
277
|
+
function createGetDerivativesHistoryTool(options) {
|
|
278
|
+
return defineTool({
|
|
279
|
+
name: "crypto_get_derivatives_history",
|
|
280
|
+
description: `Read-only. Get the derivatives history series for a crypto perpetual contract — funding-rate history and open-interest history, both time-ascending (oldest first) — from the currently routed crypto market data provider (registry-first; never a hardcoded exchange). The returned symbol is the provider-canonical form. Optional limit keeps only the most recent N points per series (${DERIVATIVES_HISTORY_MIN_LIMIT}-${DERIVATIVES_HISTORY_MAX_LIMIT}) and reports truncatedTo. If the routed provider does not implement getDerivativesHistory the call fails with TRADING_NOT_IMPLEMENTED — an empty series is never substituted for "no data"; if no crypto provider is routed it fails with TRADING_NO_PROVIDER.`,
|
|
281
|
+
parameters: {
|
|
282
|
+
symbol: {
|
|
283
|
+
type: "string",
|
|
284
|
+
required: true,
|
|
285
|
+
description: "Perpetual contract symbol, market-canonical vocabulary, e.g. BTCUSDT or BTCUSDT-SWAP"
|
|
286
|
+
},
|
|
287
|
+
limit: {
|
|
288
|
+
type: "number",
|
|
289
|
+
description: `Keep only the most recent N points per series (${DERIVATIVES_HISTORY_MIN_LIMIT}-${DERIVATIVES_HISTORY_MAX_LIMIT}). Omit to return the provider's full series.`
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
output: {
|
|
293
|
+
schema: { type: "string" },
|
|
294
|
+
render: (_args, value) => [{
|
|
295
|
+
type: "text",
|
|
296
|
+
text: String(value)
|
|
297
|
+
}]
|
|
298
|
+
},
|
|
299
|
+
async execute(raw) {
|
|
300
|
+
const args = raw ?? {};
|
|
301
|
+
const symbol = typeof args.symbol === "string" ? args.symbol.trim() : "";
|
|
302
|
+
if (!symbol) throw new Error("crypto_get_derivatives_history: symbol parameter is required (e.g. BTCUSDT or BTCUSDT-SWAP)");
|
|
303
|
+
const limit = parseDerivativesHistoryLimit(args.limit);
|
|
304
|
+
const entry = options.getRegistry()?.active("crypto");
|
|
305
|
+
if (entry === void 0) throw new Error("crypto_get_derivatives_history: TRADING_NO_PROVIDER — no crypto market data provider is active (market data registry absent, or no crypto provider installed/routed)");
|
|
306
|
+
const getHistory = entry.service.getDerivativesHistory;
|
|
307
|
+
if (typeof getHistory !== "function") throw new Error(`crypto_get_derivatives_history: TRADING_NOT_IMPLEMENTED — provider ${entry.provider} does not implement getDerivativesHistory (this is not "no data")`);
|
|
308
|
+
const returned = await getHistory.call(entry.service, symbol);
|
|
309
|
+
if (returned === null || typeof returned !== "object") throw new Error(`crypto_get_derivatives_history: provider ${entry.provider} returned an invalid derivatives history payload`);
|
|
310
|
+
const history = returned;
|
|
311
|
+
const longest = Math.max(history.fundingRates?.length ?? 0, history.openInterest?.length ?? 0);
|
|
312
|
+
const truncated = limit !== void 0 && longest > limit;
|
|
313
|
+
const result = {
|
|
314
|
+
ok: true,
|
|
315
|
+
market: "crypto",
|
|
316
|
+
provider: entry.provider,
|
|
317
|
+
symbol: typeof history.symbol === "string" && history.symbol !== "" ? history.symbol : symbol,
|
|
318
|
+
history,
|
|
319
|
+
truncated
|
|
320
|
+
};
|
|
321
|
+
if (truncated && limit !== void 0) {
|
|
322
|
+
result.truncatedTo = limit;
|
|
323
|
+
result.history = {
|
|
324
|
+
...history,
|
|
325
|
+
...history.fundingRates === void 0 ? {} : { fundingRates: history.fundingRates.slice(-limit) },
|
|
326
|
+
...history.openInterest === void 0 ? {} : { openInterest: history.openInterest.slice(-limit) }
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return JSON.stringify(result);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
259
333
|
function createGetFundamentalsTool(options = {}) {
|
|
260
334
|
return defineTool({
|
|
261
335
|
name: "crypto_get_fundamentals",
|
|
@@ -336,4 +410,4 @@ function createGetNewsTool(toolOptions = {}) {
|
|
|
336
410
|
});
|
|
337
411
|
}
|
|
338
412
|
//#endregion
|
|
339
|
-
export { Config, aggregateNews, apply, createGetDerivativesTool, createGetFundamentalsTool, createGetNewsTool, deriveSymbolTokens, extractBaseAsset, fetchCryptoDerivatives, fetchCryptoFundamentals, fetchCryptoFundamentalsPackage, inject, name, normalizeBinanceFuturesSymbol, parseCryptoPanic, parseRss2, provider, providerForSkills, renderCryptoFundamentals, renderDerivativesData };
|
|
413
|
+
export { Config, aggregateNews, apply, createGetDerivativesHistoryTool, createGetDerivativesTool, createGetFundamentalsTool, createGetNewsTool, deriveSymbolTokens, extractBaseAsset, fetchCryptoDerivatives, fetchCryptoFundamentals, fetchCryptoFundamentalsPackage, inject, name, normalizeBinanceFuturesSymbol, parseCryptoPanic, parseRss2, provider, providerForSkills, renderCryptoFundamentals, renderDerivativesData };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dshtrading/kit-crypto",
|
|
3
3
|
"description": "Crypto toolkit plugin for dsh-trading: market-specific tools and bundled trading skills (skill provider); runs as a crypto-trader preset row (session-scoped)",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dshtrading/
|
|
22
|
-
"@dshtrading/
|
|
21
|
+
"@dshtrading/knowledge": "0.2.1",
|
|
22
|
+
"@dshtrading/indicators": "0.2.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@deepseek-ai/cordis": ">=4.0.0",
|
|
26
|
-
"@deepseek-ai/dsh-skill": ">=0.1.
|
|
27
|
-
"@deepseek-ai/dsh-tools": ">=0.1.
|
|
26
|
+
"@deepseek-ai/dsh-skill": ">=0.1.5-rc.1",
|
|
27
|
+
"@deepseek-ai/dsh-tools": ">=0.1.5-rc.1",
|
|
28
28
|
"@deepseek-ai/schemastery": ">=3.18.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"tsdown": "^0.22.0",
|
|
32
32
|
"vitest": "^3.0.0",
|
|
33
|
-
"@dshtrading/api": "0.1
|
|
33
|
+
"@dshtrading/api": "0.2.1"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsdown",
|