@dshtrading/kit-hk 0.5.0 → 0.6.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.
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: indicator-authoring
|
|
3
|
+
description: 自定义技术指标创作指南:根据用户自然语言需求生成符合契约的指标代码(TD9/SuperTrend/OBV+MA等),并通过 indicator_author 工具验证与落库。
|
|
4
|
+
---
|
|
1
5
|
# 指标创作指南(Indicator Authoring Guide)
|
|
2
6
|
|
|
3
7
|
当用户在会话列中用自然语言提出编写或添加技术指标的需求时(例如:"帮我写一个 TD9 指标"、"帮我写一个 SuperTrend 指标"、"给 OBV 加一个 34 天均线"),请遵循本指南生成符合 `@dshtrading/indicators` 契约规范的 JavaScript 纯函数代码,并调用 `indicator_author` 工具进行沙箱校验与落库。
|
package/lib/api/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import "./instrument-form.js";
|
|
2
|
+
import "@deepseek-ai/cordis";
|
|
1
3
|
//#region ../api/lib/index.d.ts
|
|
2
4
|
//#region src/index.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* @dshtrading/api — 纯类型契约包(crypto-slice-plan §关键接口草案)。
|
|
5
|
-
*
|
|
6
|
-
* 零运行时、零依赖:服务契约由连接器实现(ctx 键按市场命名空间,如 ctx.tradingCrypto),
|
|
7
|
-
* 消费方只依赖这里的类型。交易安全闸门(铁律 #3)在类型层面体现为
|
|
8
|
-
* OrderRequest.dryRun 默认 true、错误词汇含 LIVE_TRADING_DISABLED / APPROVAL_DENIED。
|
|
9
|
-
*
|
|
10
|
-
* @module @dshtrading/api
|
|
11
|
-
*/
|
|
12
5
|
/** K线周期(Binance 现货/合约 interval 词汇)。 */
|
|
13
6
|
type Interval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '6h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
14
7
|
/** 最新行情快照(公共数据,无需凭证)。 */
|
|
@@ -423,16 +416,32 @@ interface FundamentalsPackage {
|
|
|
423
416
|
readonly dragonTiger?: DragonTigerItem;
|
|
424
417
|
}
|
|
425
418
|
type PositionSide = 'long' | 'short';
|
|
419
|
+
/**
|
|
420
|
+
* 保证金模式(合约交易语义,P7):`cross` = 全仓、`isolated` = 逐仓。
|
|
421
|
+
* 现货(cash)不使用该字段——缺席即「非保证金/未设置」。
|
|
422
|
+
*/
|
|
423
|
+
type MarginMode = 'cross' | 'isolated';
|
|
426
424
|
/** 持仓快照。 */
|
|
427
425
|
interface Position {
|
|
428
426
|
readonly symbol: string;
|
|
429
427
|
readonly side: PositionSide;
|
|
430
|
-
/** 仓位数量(正数;方向由 side
|
|
428
|
+
/** 仓位数量(正数;方向由 side 表达)。合约仓位是 **base 币数**(连接器已按合约乘数 ctVal 由张换算)。 */
|
|
431
429
|
readonly size: number;
|
|
432
430
|
readonly entryPrice: number;
|
|
433
431
|
readonly markPrice?: number;
|
|
434
432
|
readonly unrealizedPnl?: number;
|
|
435
433
|
readonly leverage?: number;
|
|
434
|
+
/**
|
|
435
|
+
* 强平价(交易所回传原样透传;交易所未提供或不适用时缺席,绝不本地推算强平价——
|
|
436
|
+
* 强平口径与保证金模式、账户级保证金、维持保证金率有关,本地公式会给出错误的安全感)。
|
|
437
|
+
*/
|
|
438
|
+
readonly liquidationPrice?: number;
|
|
439
|
+
/** 维持保证金率(OKX `mgnRatio`;口径由交易所定义,原样透传,不在本地换算或反推)。 */
|
|
440
|
+
readonly marginRatio?: number;
|
|
441
|
+
/** 该仓位的保证金模式;现货持仓与交易所未提供时缺席。 */
|
|
442
|
+
readonly marginMode?: MarginMode;
|
|
443
|
+
/** 名义价值(USD,交易所口径;用于敞口核对,不参与本地风控公式)。 */
|
|
444
|
+
readonly notionalUsd?: number;
|
|
436
445
|
readonly timestamp: number;
|
|
437
446
|
}
|
|
438
447
|
type OrderSide = 'buy' | 'sell';
|
|
@@ -443,10 +452,18 @@ interface OrderRequest {
|
|
|
443
452
|
readonly symbol: string;
|
|
444
453
|
readonly side: OrderSide;
|
|
445
454
|
readonly type: OrderType;
|
|
455
|
+
/** **base 币数量**:合约(永续)由连接器按合约乘数换算成张,消费方恒用币数语义。 */
|
|
446
456
|
readonly quantity: number;
|
|
447
457
|
/** limit 单必填。 */
|
|
448
458
|
readonly price?: number;
|
|
449
|
-
/**
|
|
459
|
+
/**
|
|
460
|
+
* 合约订单的保证金模式(缺省 `cross`)。仅对永续(`-SWAP`)有效:
|
|
461
|
+
* 现货订单只允许 cash 语义,传该字段由连接器结构化拒绝
|
|
462
|
+
* (现货逐仓/杠杆是另一个产品面,本仓未接线)。
|
|
463
|
+
* `isolated` 需先在交易所侧设好该标的的逐仓杠杆(OKX `setLeverage`)。
|
|
464
|
+
*/
|
|
465
|
+
readonly marginMode?: MarginMode;
|
|
466
|
+
/** 缺省/true 时仅模拟,不触碰交易所。实盘还受 @dshtrading/authority 的人工签署授权与 approval 约束 [S4]。 */
|
|
450
467
|
readonly dryRun?: boolean;
|
|
451
468
|
}
|
|
452
469
|
/** 订单回执/状态。 */
|
|
@@ -486,9 +503,49 @@ interface TradeFill {
|
|
|
486
503
|
interface Disposable {
|
|
487
504
|
dispose(): void;
|
|
488
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* 标的形态轴(2026-10-08 加密永续与 TradFi 永续落地):与 `market` 正交,**不新增市场键**。
|
|
508
|
+
* 缺省 = `spot`——已存自选、localStorage 与 iOS 冻结契约因此零迁移。
|
|
509
|
+
*
|
|
510
|
+
* 形态由规范符号后缀承载(`-SWAP` = 永续),见 docs/guides/symbol-vocabulary.md;
|
|
511
|
+
* `form` 只出现在名册/检索/wire 元数据里,行情方法不新增 form 形参。
|
|
512
|
+
*/
|
|
513
|
+
type InstrumentForm = 'spot' | 'perp';
|
|
514
|
+
/**
|
|
515
|
+
* 标的资产类别标签(仅展示与检索排序用,不承载交易语义)。
|
|
516
|
+
* **只信交易所元数据**(OKX `instCategory`、Binance `underlyingType`+`underlyingSubType`);
|
|
517
|
+
* 取不到时留空,禁止按符号字面猜(`SPX` 在 OKX 是迷因币 SPX6900,标普 500 是 `US500`)。
|
|
518
|
+
*/
|
|
519
|
+
type InstrumentAssetClass = 'crypto' | 'equity' | 'commodity' | 'index';
|
|
520
|
+
/** 合约专有元数据(仅 `form=perp` 有值):交易所元数据原样透传,不本地推断。 */
|
|
521
|
+
interface InstrumentContract {
|
|
522
|
+
/** 合约乘数(OKX ctVal / Binance contractSize)。 */
|
|
523
|
+
readonly multiplier?: number;
|
|
524
|
+
/** 最小价格变动。 */
|
|
525
|
+
readonly tickSize?: number;
|
|
526
|
+
/** 最小下单量/张数步长。 */
|
|
527
|
+
readonly lotSize?: number;
|
|
528
|
+
/** 交易所允许的最大杠杆。 */
|
|
529
|
+
readonly maxLeverage?: number;
|
|
530
|
+
/** 结算币种(如 USDT)。 */
|
|
531
|
+
readonly settleCcy?: string;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* 标的检索结果的最小元数据(名册/搜索/wire 共用)。
|
|
535
|
+
* 元素形状对既有 `{ symbol, name? }` 实现向后兼容:`form`/`assetClass`/`contract` 全可选。
|
|
536
|
+
*/
|
|
537
|
+
interface InstrumentRef {
|
|
538
|
+
/** 市场规范词汇符号(docs/guides/symbol-vocabulary.md)。 */
|
|
539
|
+
readonly symbol: string;
|
|
540
|
+
readonly name?: string;
|
|
541
|
+
/** 缺省 = spot(老数据零迁移)。 */
|
|
542
|
+
readonly form?: InstrumentForm;
|
|
543
|
+
readonly assetClass?: InstrumentAssetClass;
|
|
544
|
+
readonly contract?: InstrumentContract;
|
|
545
|
+
}
|
|
489
546
|
/**
|
|
490
547
|
* 行情服务契约:由市场连接器实现,注册到按市场命名空间的 ctx 键(如 ctx.tradingCrypto)。
|
|
491
|
-
* 符号词汇(2026-08-31 规范,docs/symbol-vocabulary.md):入参接受市场规范形与连接器原生形,
|
|
548
|
+
* 符号词汇(2026-08-31 规范,docs/guides/symbol-vocabulary.md):入参接受市场规范形与连接器原生形,
|
|
492
549
|
* 输出 `symbol` 一律市场规范形——消费方(GUI/Agent/工作流)与数据源方言解耦。
|
|
493
550
|
*/
|
|
494
551
|
interface MarketDataService {
|
|
@@ -497,13 +554,12 @@ interface MarketDataService {
|
|
|
497
554
|
subscribeTicker(symbol: string, cb: (ticker: Ticker) => void): Disposable;
|
|
498
555
|
/**
|
|
499
556
|
* 查询本市场/交易所支持的全部标的名册(动态全集,Issue #15)。
|
|
500
|
-
* 输出 `symbol` 一律市场规范词汇(docs/symbol-vocabulary.md
|
|
557
|
+
* 输出 `symbol` 一律市场规范词汇(docs/guides/symbol-vocabulary.md),形态由符号后缀承载
|
|
558
|
+
* (`-SWAP` = 永续,`instrumentFormOf` 是唯一裁决实现);每行可带
|
|
559
|
+
* `form`/`assetClass`/`contract` 元数据(InstrumentRef),缺省 = 现货。
|
|
501
560
|
* 可选方法:无公开全集端点的数据源(如 tencent/yahoo/stooq)可缺省或由桥/前端回退。
|
|
502
561
|
*/
|
|
503
|
-
listInstruments?(): Promise<
|
|
504
|
-
symbol: string;
|
|
505
|
-
name?: string;
|
|
506
|
-
}>>;
|
|
562
|
+
listInstruments?(): Promise<InstrumentRef[]>;
|
|
507
563
|
/**
|
|
508
564
|
* 标的基本面与估值快照(GUI「基本面」页签用,2026-09-02)。
|
|
509
565
|
* 可选方法:仅当数据源在同一公共端点里携带基本面字段时实现
|
|
@@ -539,11 +595,41 @@ interface MarketDataService {
|
|
|
539
595
|
getRecentTrades?(symbol: string, limit?: number): Promise<TradeTick[]>;
|
|
540
596
|
}
|
|
541
597
|
/**
|
|
542
|
-
*
|
|
598
|
+
* 杠杆设置请求(合约交易语义,P7;仅 `form=perp` 的标的可传)。
|
|
599
|
+
* dryRun 缺省视为 true:只回本地模拟回执,不触碰交易所(与 placeOrder 同语义)。
|
|
600
|
+
*/
|
|
601
|
+
interface SetLeverageRequest {
|
|
602
|
+
readonly symbol: string;
|
|
603
|
+
/** 目标杠杆倍数(> 0;上限以交易所规格 `InstrumentContract.maxLeverage` 为准,超出即结构化拒绝)。 */
|
|
604
|
+
readonly leverage: number;
|
|
605
|
+
readonly marginMode: MarginMode;
|
|
606
|
+
/** 双向持仓模式下的方向(OKX `posSide`);净持仓模式下缺席。 */
|
|
607
|
+
readonly posSide?: 'long' | 'short';
|
|
608
|
+
/** 全仓模式下按币种设置杠杆时的保证金币(OKX `ccy`);逐仓与净持仓模式缺席。 */
|
|
609
|
+
readonly ccy?: string;
|
|
610
|
+
/** 缺省/true 时仅模拟。实盘还受 @dshtrading/authority 的人工签署授权与 approval 约束 [S4]。 */
|
|
611
|
+
readonly dryRun?: boolean;
|
|
612
|
+
}
|
|
613
|
+
/** 杠杆设置回执(dryRun=true 时是本地模拟回执,不触网)。 */
|
|
614
|
+
interface LeverageSetting {
|
|
615
|
+
readonly symbol: string;
|
|
616
|
+
readonly leverage: number;
|
|
617
|
+
readonly marginMode: MarginMode;
|
|
618
|
+
readonly posSide?: 'long' | 'short';
|
|
619
|
+
readonly ccy?: string;
|
|
620
|
+
/** 本次是否为模拟回执(回执必须显式回带,防 dry-run 语义丢失)。 */
|
|
621
|
+
readonly dryRun: boolean;
|
|
622
|
+
readonly timestamp: number;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* 交易服务契约:placeOrder 默认 dry-run;实盘前必须过 @dshtrading/authority 的人工签署授权与
|
|
543
626
|
* ctx.approval.request(交互形态;headless 下 ask=deny,fail-closed [S4])。
|
|
544
627
|
*
|
|
545
628
|
* R3(okx 切片 2026-08-29)修订:cancelOrder 增加可选 symbol、新增 getOrder——
|
|
546
629
|
* OKX 按 (instId, ordId) 双键定位订单,单参 id 形态不够;无其他实现方,扩展向后兼容。
|
|
630
|
+
*
|
|
631
|
+
* P7(合约交易 Tier 2,2026-10-08)修订:新增可选 `setLeverage`——杠杆/保证金模式变更
|
|
632
|
+
* 是实盘动作,必须与下单同门槛(服务缝三态闸门 + base 审批闸门 + 人工签署授权)。
|
|
547
633
|
*/
|
|
548
634
|
interface TradeService {
|
|
549
635
|
placeOrder(req: OrderRequest): Promise<Order>;
|
|
@@ -568,6 +654,13 @@ interface TradeService {
|
|
|
568
654
|
* 可选方法:时间升序(旧→新),最多 limit 条(缺省 ≤50)。
|
|
569
655
|
*/
|
|
570
656
|
listTradeFills?(symbol?: string, limit?: number): Promise<TradeFill[]>;
|
|
657
|
+
/**
|
|
658
|
+
* 设置合约杠杆与保证金模式(P7 合约交易 Tier 2;仅支持合约的交易所实现)。
|
|
659
|
+
* 可选方法:不实现的连接器缺席即可,消费方按 TRADING_NOT_IMPLEMENTED 语义处理。
|
|
660
|
+
* 这是会改变账户真实风险参数的实盘动作:dryRun 缺省 true(只回本地模拟回执),
|
|
661
|
+
* dryRun=false 必须同时具备人工签署的实盘授权,并经 base 审批闸门。
|
|
662
|
+
*/
|
|
663
|
+
setLeverage?(req: SetLeverageRequest): Promise<LeverageSetting>;
|
|
571
664
|
}
|
|
572
665
|
/**
|
|
573
666
|
* Cordis Context 服务键(能力三角色之「声明」):市场命名空间键由契约包统一声明,
|
|
@@ -598,7 +691,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
598
691
|
* 交易服务注册表(issue #40 GUI 交易台,@dshtrading/api 类型声明):
|
|
599
692
|
* 与 tradingMarketDataRegistry 同构的宿主平面注册面——交易连接器 host 面数据行
|
|
600
693
|
* 注册,GUI 桥按路由当前值惰性解析。**注册不改变安全语义**:placeOrder 的
|
|
601
|
-
* 服务缝闸门(dryRun 缺省 true +
|
|
694
|
+
* 服务缝闸门(dryRun 缺省 true + @dshtrading/authority 人工签署授权)随服务实例生效;
|
|
602
695
|
* GUI 桥只放行 dry-run 下单与只读查询,实盘路径仍走 Agent 工具的 base 审批闸门。
|
|
603
696
|
*/
|
|
604
697
|
tradingTradeRegistry: TradeRegistry;
|
|
@@ -799,4 +892,4 @@ interface TradingNewsRegistry {
|
|
|
799
892
|
markets(): string[];
|
|
800
893
|
}
|
|
801
894
|
//#endregion
|
|
802
|
-
export { AccountBalance, AggregateNewsOptions, AggregateNewsResult, AuctionSnapshot, BuybackItem, CompanyProfile, CryptoFundamentals, DerivativesData, DerivativesHistory, DerivativesPoint, Disposable, DividendItem, DragonTigerItem, FinancialCell, FinancialIndicatorRow, FinancialReportGroup, FinancialReportMatrix, FlashFeedService, ForecastSummary, FundamentalsPackage, HolderNumSummary, InsiderTradeItem, InstitutionalHoldingItem, Interval, Kline, LimitUpPoolItem, MacroCalendarEntry, MacroFeedService, MacroRateEntry, MainOperationSegment, MarketDataRegistration, MarketDataRegistry, MarketDataService, MarketRouterService, NewsAggregator, NewsItem, OperatingEfficiency, Order, OrderRequest, OrderSide, OrderStatus, OrderType, Orderbook, OrderbookLevel, Position, PositionSide, ResearchReportItem, ShareholderItem, SplitItem, StockFundamentals, Ticker, TradeFill, TradeRegistration, TradeRegistry, TradeService, TradeTick, TradingNewsRegistry };
|
|
895
|
+
export { AccountBalance, AggregateNewsOptions, AggregateNewsResult, AuctionSnapshot, BuybackItem, CompanyProfile, CryptoFundamentals, DerivativesData, DerivativesHistory, DerivativesPoint, Disposable, DividendItem, DragonTigerItem, FinancialCell, FinancialIndicatorRow, FinancialReportGroup, FinancialReportMatrix, FlashFeedService, ForecastSummary, FundamentalsPackage, HolderNumSummary, InsiderTradeItem, InstitutionalHoldingItem, InstrumentAssetClass, InstrumentContract, InstrumentForm, InstrumentRef, Interval, Kline, LeverageSetting, LimitUpPoolItem, MacroCalendarEntry, MacroFeedService, MacroRateEntry, MainOperationSegment, MarginMode, MarketDataRegistration, MarketDataRegistry, MarketDataService, MarketRouterService, NewsAggregator, NewsItem, OperatingEfficiency, Order, OrderRequest, OrderSide, OrderStatus, OrderType, Orderbook, OrderbookLevel, Position, PositionSide, ResearchReportItem, SetLeverageRequest, ShareholderItem, SplitItem, StockFundamentals, Ticker, TradeFill, TradeRegistration, TradeRegistry, TradeService, TradeTick, TradingNewsRegistry };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./index.js";
|
package/lib/index.js
CHANGED
|
@@ -170,7 +170,7 @@ function renderNewsItem(item) {
|
|
|
170
170
|
function createGetNewsTool(toolOptions = {}) {
|
|
171
171
|
return defineTool({
|
|
172
172
|
name: "hk_get_news",
|
|
173
|
-
description: "Get recent Hong Kong stock
|
|
173
|
+
description: "Get recent Hong Kong stock news from the Eastmoney fast-news HK column, filtered to HK-relevant items (HKEX marketId=116 or HK keywords). DEGRADED SOURCE — Eastmoney is a unified CN feed; HK coverage is PARTIAL (news without an HK code or keyword is missed), not a dedicated HK source. Each item carries source (东方财富), time and link; metadata only, never article bodies. Optional symbol filter (e.g. 00700 / 00700.HK) and window; no credentials required.",
|
|
174
174
|
parameters: {
|
|
175
175
|
symbol: {
|
|
176
176
|
type: "string",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dshtrading/kit-hk",
|
|
3
3
|
"description": "Hong Kong market toolkit plugin for dsh-trading: HK risk checklist skill provider and HK fast-news (degraded) / fundamentals tools; runs as an hk-trader preset row (session-scoped)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dshtrading/indicators": "0.
|
|
22
|
-
"@dshtrading/knowledge": "0.
|
|
21
|
+
"@dshtrading/indicators": "0.6.0",
|
|
22
|
+
"@dshtrading/knowledge": "0.6.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@deepseek-ai/cordis": ">=4.0.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"tsdown": "^0.22.0",
|
|
32
32
|
"vitest": "^3.0.0",
|
|
33
|
-
"@dshtrading/api": "0.
|
|
33
|
+
"@dshtrading/api": "0.6.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsdown",
|