@dshtrading/connector-alpaca 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 +11 -5
- 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
|
@@ -49,7 +49,7 @@ declare class AlpacaMarketDataService extends Service implements MarketDataServi
|
|
|
49
49
|
}
|
|
50
50
|
declare class AlpacaTradeService extends Service implements TradeService {
|
|
51
51
|
private readonly client;
|
|
52
|
-
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading
|
|
52
|
+
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading 非权威镜像——实盘授权由 @dshtrading/authority 的人工签署平面裁定)。 */
|
|
53
53
|
private readonly config;
|
|
54
54
|
private readonly getCredentials;
|
|
55
55
|
constructor(ctx: Context, options: AlpacaRestOptions & {
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { AlpacaRestClient, INTERVAL_TO_ALPACA, INTERVAL_VOCABULARY, TradingServiceError, normalizeUsSymbol } 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
|
+
* Alpaca 连接器插件(dsh-trading us 切片):MarketDataService 与 TradeService。
|
|
9
|
+
*
|
|
10
|
+
* @module @dshtrading/connector-alpaca
|
|
11
|
+
*/
|
|
6
12
|
const name = "dsh-trading-us-connector-alpaca";
|
|
7
13
|
const Config = Schema.object({
|
|
8
14
|
enabled: Schema.boolean().default(false),
|
|
@@ -97,7 +103,7 @@ var AlpacaMarketDataService = class extends Service {
|
|
|
97
103
|
};
|
|
98
104
|
var AlpacaTradeService = class extends Service {
|
|
99
105
|
client;
|
|
100
|
-
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading
|
|
106
|
+
/** 插件配置(服务缝闸门 P0:dryRun 强制模拟 / liveTrading 非权威镜像——实盘授权由 @dshtrading/authority 的人工签署平面裁定)。 */
|
|
101
107
|
config;
|
|
102
108
|
getCredentials;
|
|
103
109
|
constructor(ctx, options, getCredentials, serviceName = TRADING_US_TRADE_KEY) {
|
|
@@ -116,7 +122,7 @@ var AlpacaTradeService = class extends Service {
|
|
|
116
122
|
}
|
|
117
123
|
async placeOrder(order) {
|
|
118
124
|
const requestedDryRun = order.dryRun ?? true;
|
|
119
|
-
if (!requestedDryRun && !this.config.liveTrading) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", `Alpaca TradeService.placeOrder rejected: the request asks for real execution (dryRun=${String(order.dryRun)}) but
|
|
125
|
+
if (!requestedDryRun && !liveTradingEnabled(this.config.liveTrading)) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", `Alpaca 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.`);
|
|
120
126
|
if (requestedDryRun || this.config.dryRun) return {
|
|
121
127
|
id: `dry-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
122
128
|
symbol: order.symbol,
|
|
@@ -138,7 +144,7 @@ var AlpacaTradeService = class extends Service {
|
|
|
138
144
|
});
|
|
139
145
|
}
|
|
140
146
|
async cancelOrder(orderId, _symbol) {
|
|
141
|
-
if (!this.config.liveTrading || this.config.dryRun) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", "Alpaca TradeService.cancelOrder rejected at the service seam: cancel is a live action and requires
|
|
147
|
+
if (!liveTradingEnabled(this.config.liveTrading) || this.config.dryRun) throw new TradingServiceError("TRADING_LIVE_TRADING_DISABLED", "Alpaca 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.");
|
|
142
148
|
const creds = await this.getCredentials();
|
|
143
149
|
await this.client.cancelOrder(creds, orderId);
|
|
144
150
|
}
|
|
@@ -173,10 +179,10 @@ var AlpacaTradeService = class extends Service {
|
|
|
173
179
|
};
|
|
174
180
|
function evaluateOrderGate(config, args) {
|
|
175
181
|
const requestedDryRun = args.dryRun ?? true;
|
|
176
|
-
if (!requestedDryRun && !config.liveTrading) return {
|
|
182
|
+
if (!requestedDryRun && !liveTradingEnabled(config.liveTrading)) return {
|
|
177
183
|
action: "reject",
|
|
178
184
|
code: "TRADING_LIVE_TRADING_DISABLED",
|
|
179
|
-
message: `us_place_order rejected: real execution requested (dryRun=${String(args.dryRun)}) but live trading is disabled (
|
|
185
|
+
message: `us_place_order rejected: real execution requested (dryRun=${String(args.dryRun)}) but live trading is disabled (no signed live-trading grant from the authority plane). Ask the operator to sign a live-trading grant, or keep dryRun=true.`
|
|
180
186
|
};
|
|
181
187
|
if (requestedDryRun || config.dryRun) return { action: "simulate" };
|
|
182
188
|
return { action: "live" };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dshtrading/connector-alpaca",
|
|
3
3
|
"description": "【模板】交易所连接器插件脚手架:Alpaca(alpaca)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",
|