@dshtrading/connector-ccxt 0.5.0 → 0.6.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/README.md +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -3
- package/lib/rest.d.ts +7 -0
- package/lib/rest.js +15 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
node scripts/new-connector.mjs --slug bybit --title Bybit --market crypto
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
生成后按 [docs/connector-playbook.md](../../docs/connector-playbook.md) 的填写顺序
|
|
10
|
+
生成后按 [docs/guides/connector-playbook.md](../../docs/guides/connector-playbook.md) 的填写顺序
|
|
11
11
|
(src/rest.ts 头部清单 7 项)实现 TODO。每个 TODO 的参照段都在 connector-okx
|
|
12
12
|
(packages/connector-okx/),它是本仓第一个真实 TradeService 连接器。
|
|
13
13
|
|
package/lib/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ declare class CcxtMarketDataService extends Service implements MarketDataService
|
|
|
25
25
|
}
|
|
26
26
|
declare class CcxtTradeService extends Service implements TradeService {
|
|
27
27
|
private readonly client;
|
|
28
|
-
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading
|
|
28
|
+
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading 非权威镜像——实盘授权由 @dshtrading/authority 的人工签署平面裁定)。 */
|
|
29
29
|
private readonly config;
|
|
30
30
|
constructor(ctx: Context, options: CcxtRestOptions & {
|
|
31
31
|
config: Config;
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { CcxtRestClient, INTERVAL_VOCABULARY, SUPPORTED_EXCHANGES, TradingServiceError, normalizeSymbol } from "./rest.js";
|
|
2
|
+
import { liveTradingEnabled } from "@dshtrading/authority";
|
|
2
3
|
import { Service } from "@deepseek-ai/cordis";
|
|
3
4
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
5
|
import Schema from "@deepseek-ai/schemastery";
|
|
5
6
|
//#region src/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* @dshtrading/connector-ccxt
|
|
9
|
+
* CCXT 跨所加密通用连接器插件(提供 tradingCryptoMarketData 与多所聚合工具)。
|
|
10
|
+
*/
|
|
6
11
|
const name = "dsh-trading-crypto-connector-ccxt";
|
|
7
12
|
const Config = Schema.object({
|
|
8
13
|
enabled: Schema.boolean().default(true).description("是否激活 CCXT 连接器"),
|
|
@@ -37,7 +42,7 @@ var CcxtMarketDataService = class extends Service {
|
|
|
37
42
|
};
|
|
38
43
|
var CcxtTradeService = class extends Service {
|
|
39
44
|
client;
|
|
40
|
-
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading
|
|
45
|
+
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading 非权威镜像——实盘授权由 @dshtrading/authority 的人工签署平面裁定)。 */
|
|
41
46
|
config;
|
|
42
47
|
constructor(ctx, options, serviceName = TRADING_CRYPTO_TRADE_KEY) {
|
|
43
48
|
super(ctx, serviceName);
|
|
@@ -49,7 +54,7 @@ var CcxtTradeService = class extends Service {
|
|
|
49
54
|
}
|
|
50
55
|
async placeOrder(order) {
|
|
51
56
|
const requestedDryRun = order.dryRun ?? true;
|
|
52
|
-
if (!requestedDryRun && !this.config.liveTrading) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", `CCXT TradeService.placeOrder rejected: the request asks for real execution (dryRun=${String(order.dryRun)}) but
|
|
57
|
+
if (!requestedDryRun && !liveTradingEnabled(this.config.liveTrading)) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", `CCXT TradeService.placeOrder rejected: the request asks for real execution (dryRun=${String(order.dryRun)}) but the signed live-trading authority does not grant real execution (see @dshtrading/authority) — keep dryRun=true for a simulated fill.`);
|
|
53
58
|
if (requestedDryRun || this.config.dryRun) return {
|
|
54
59
|
id: `dry-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
55
60
|
symbol: order.symbol,
|
|
@@ -64,7 +69,7 @@ var CcxtTradeService = class extends Service {
|
|
|
64
69
|
return this.client.placeOrder(void 0, order);
|
|
65
70
|
}
|
|
66
71
|
async cancelOrder(orderId) {
|
|
67
|
-
if (!this.config.liveTrading || this.config.dryRun) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", "CCXT TradeService.cancelOrder rejected at the service seam: cancel is a live action and requires
|
|
72
|
+
if (!liveTradingEnabled(this.config.liveTrading) || this.config.dryRun) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", "CCXT TradeService.cancelOrder rejected at the service seam: cancel is a live action and requires a signed live-trading grant (see @dshtrading/authority) with dryRun=false.");
|
|
68
73
|
return this.client.cancelOrder(void 0, orderId);
|
|
69
74
|
}
|
|
70
75
|
async getPositions() {
|
package/lib/rest.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ declare class TradingServiceError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
declare const INTERVAL_VOCABULARY: readonly ["1m", "5m", "15m", "30m", "1h", "4h", "1d", "1w", "1M"];
|
|
8
8
|
declare const SUPPORTED_EXCHANGES: readonly ["binance", "okx", "bybit", "gateio", "kucoin", "kraken", "coinbase", "bitfinex", "htx"];
|
|
9
|
+
/**
|
|
10
|
+
* 现货符号归一化(本轮 CCXT 面只做现货)。
|
|
11
|
+
*
|
|
12
|
+
* 入参带规范永续后缀 `-SWAP` 时**显式报 TRADING_UNSUPPORTED_SYMBOL**:此前实现会先剥掉
|
|
13
|
+
* 后缀、再拿同一个符号去打现货端点,等于把永续静默报成现货价(P3 硬不变量:任何路径
|
|
14
|
+
* 不得把 `-SWAP` 落到 spot 端点)。CCXT 的合约面不属本轮范围,要做得走单独的卡。
|
|
15
|
+
*/
|
|
9
16
|
declare function normalizeSymbol(raw: string): string;
|
|
10
17
|
interface CcxtRestOptions {
|
|
11
18
|
exchange?: string;
|
package/lib/rest.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { instrumentFormOf } from "@dshtrading/api";
|
|
1
2
|
//#region src/rest.ts
|
|
3
|
+
/**
|
|
4
|
+
* @dshtrading/connector-ccxt/rest
|
|
5
|
+
* CCXT 跨所加密通用 REST 客户端。
|
|
6
|
+
*/
|
|
2
7
|
var TradingServiceError = class extends Error {
|
|
3
8
|
code;
|
|
4
9
|
constructor(code, message, cause) {
|
|
@@ -30,8 +35,17 @@ const SUPPORTED_EXCHANGES = [
|
|
|
30
35
|
"bitfinex",
|
|
31
36
|
"htx"
|
|
32
37
|
];
|
|
38
|
+
/**
|
|
39
|
+
* 现货符号归一化(本轮 CCXT 面只做现货)。
|
|
40
|
+
*
|
|
41
|
+
* 入参带规范永续后缀 `-SWAP` 时**显式报 TRADING_UNSUPPORTED_SYMBOL**:此前实现会先剥掉
|
|
42
|
+
* 后缀、再拿同一个符号去打现货端点,等于把永续静默报成现货价(P3 硬不变量:任何路径
|
|
43
|
+
* 不得把 `-SWAP` 落到 spot 端点)。CCXT 的合约面不属本轮范围,要做得走单独的卡。
|
|
44
|
+
*/
|
|
33
45
|
function normalizeSymbol(raw) {
|
|
34
|
-
const
|
|
46
|
+
const upper = raw.trim().toUpperCase();
|
|
47
|
+
if (instrumentFormOf(upper) === "perp") throw new TradingServiceError("TRADING_UNSUPPORTED_SYMBOL", `CCXT connector is spot-only: ${upper} is a perpetual (form=perp). Use a spot symbol such as ${upper.replace(/-SWAP$/, "")}, or a perpetual-capable connector (okx/bybit) for contract quotes.`);
|
|
48
|
+
const clean = upper.replace(/[-_]/g, "");
|
|
35
49
|
if (clean.includes("/")) return clean.replace("/", "");
|
|
36
50
|
return clean;
|
|
37
51
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dshtrading/connector-ccxt",
|
|
3
3
|
"description": "【模板】交易所连接器插件脚手架:CCXT(ccxt)v2 插件骨架 —— 市场数据服务 + 交易服务 + 三态闸门 + BYOK 凭证 ref。生成器:node scripts/new-connector.mjs --slug <exchange>",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@dshtrading/
|
|
24
|
+
"@dshtrading/authority": "^0.6.1",
|
|
25
|
+
"@dshtrading/api": "^0.6.1"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"@deepseek-ai/cordis": ">=4.0.0",
|