@123456btc/123456btc-cli 1.0.1 → 1.0.3
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 +182 -39
- package/README.zh-CN.md +78 -0
- package/dist/api/client.d.ts +4 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +74 -16
- package/dist/api/client.js.map +1 -1
- package/dist/api/provider.d.ts +163 -0
- package/dist/api/provider.d.ts.map +1 -0
- package/dist/api/provider.js +123 -0
- package/dist/api/provider.js.map +1 -0
- package/dist/api/signal-crypto.d.ts +17 -0
- package/dist/api/signal-crypto.d.ts.map +1 -0
- package/dist/api/signal-crypto.js +48 -0
- package/dist/api/signal-crypto.js.map +1 -0
- package/dist/api/signals.d.ts +47 -0
- package/dist/api/signals.d.ts.map +1 -0
- package/dist/api/signals.js +34 -0
- package/dist/api/signals.js.map +1 -0
- package/dist/api/strategy-stream.d.ts +59 -0
- package/dist/api/strategy-stream.d.ts.map +1 -0
- package/dist/api/strategy-stream.js +136 -0
- package/dist/api/strategy-stream.js.map +1 -0
- package/dist/api/strategy.d.ts +66 -20
- package/dist/api/strategy.d.ts.map +1 -1
- package/dist/api/strategy.js +15 -18
- package/dist/api/strategy.js.map +1 -1
- package/dist/api/token-manager.d.ts +37 -0
- package/dist/api/token-manager.d.ts.map +1 -0
- package/dist/api/token-manager.js +191 -0
- package/dist/api/token-manager.js.map +1 -0
- package/dist/api/wallet.d.ts +38 -0
- package/dist/api/wallet.d.ts.map +1 -0
- package/dist/api/wallet.js +23 -0
- package/dist/api/wallet.js.map +1 -0
- package/dist/cli.js +12 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +149 -3
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/health.d.ts +3 -0
- package/dist/commands/health.d.ts.map +1 -0
- package/dist/commands/health.js +77 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +127 -24
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/provider.d.ts +3 -0
- package/dist/commands/provider.d.ts.map +1 -0
- package/dist/commands/provider.js +371 -0
- package/dist/commands/provider.js.map +1 -0
- package/dist/commands/signals.d.ts +3 -0
- package/dist/commands/signals.d.ts.map +1 -0
- package/dist/commands/signals.js +104 -0
- package/dist/commands/signals.js.map +1 -0
- package/dist/commands/strategy.d.ts.map +1 -1
- package/dist/commands/strategy.js +147 -59
- package/dist/commands/strategy.js.map +1 -1
- package/dist/commands/tier.d.ts +3 -0
- package/dist/commands/tier.d.ts.map +1 -0
- package/dist/commands/tier.js +105 -0
- package/dist/commands/tier.js.map +1 -0
- package/dist/commands/vault.d.ts +7 -0
- package/dist/commands/vault.d.ts.map +1 -0
- package/dist/commands/vault.js +377 -0
- package/dist/commands/vault.js.map +1 -0
- package/dist/commands/wallet.d.ts +3 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +74 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -6
- package/dist/index.js.map +1 -1
- package/dist/providers/executor.d.ts +55 -20
- package/dist/providers/executor.d.ts.map +1 -1
- package/dist/providers/executor.js +260 -58
- package/dist/providers/executor.js.map +1 -1
- package/dist/providers/risk.d.ts +17 -0
- package/dist/providers/risk.d.ts.map +1 -0
- package/dist/providers/risk.js +67 -0
- package/dist/providers/risk.js.map +1 -0
- package/dist/providers/state.d.ts +30 -0
- package/dist/providers/state.d.ts.map +1 -0
- package/dist/providers/state.js +190 -0
- package/dist/providers/state.js.map +1 -0
- package/dist/types/strategy.d.ts +65 -1
- package/dist/types/strategy.d.ts.map +1 -1
- package/dist/types/strategy.js +1 -0
- package/dist/types/strategy.js.map +1 -1
- package/dist/utils/auth.d.ts +1 -0
- package/dist/utils/auth.d.ts.map +1 -1
- package/dist/utils/device.d.ts +13 -0
- package/dist/utils/device.d.ts.map +1 -0
- package/dist/utils/device.js +104 -0
- package/dist/utils/device.js.map +1 -0
- package/dist/vault/backends/file.d.ts +15 -0
- package/dist/vault/backends/file.d.ts.map +1 -0
- package/dist/vault/backends/file.js +39 -0
- package/dist/vault/backends/file.js.map +1 -0
- package/dist/vault/backends/os-keychain.d.ts +13 -0
- package/dist/vault/backends/os-keychain.d.ts.map +1 -0
- package/dist/vault/backends/os-keychain.js +60 -0
- package/dist/vault/backends/os-keychain.js.map +1 -0
- package/dist/vault/backends/os-secret.d.ts +13 -0
- package/dist/vault/backends/os-secret.d.ts.map +1 -0
- package/dist/vault/backends/os-secret.js +57 -0
- package/dist/vault/backends/os-secret.js.map +1 -0
- package/dist/vault/backends/os-win-cred.d.ts +13 -0
- package/dist/vault/backends/os-win-cred.d.ts.map +1 -0
- package/dist/vault/backends/os-win-cred.js +76 -0
- package/dist/vault/backends/os-win-cred.js.map +1 -0
- package/dist/vault/crypto.d.ts +49 -0
- package/dist/vault/crypto.d.ts.map +1 -0
- package/dist/vault/crypto.js +122 -0
- package/dist/vault/crypto.js.map +1 -0
- package/dist/vault/index.d.ts +88 -0
- package/dist/vault/index.d.ts.map +1 -0
- package/dist/vault/index.js +276 -0
- package/dist/vault/index.js.map +1 -0
- package/dist/vault/storage.d.ts +14 -0
- package/dist/vault/storage.d.ts.map +1 -0
- package/dist/vault/storage.js +68 -0
- package/dist/vault/storage.js.map +1 -0
- package/dist/vault/types.d.ts +41 -0
- package/dist/vault/types.d.ts.map +1 -0
- package/dist/vault/types.js +6 -0
- package/dist/vault/types.js.map +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { ApiClient } from './client';
|
|
2
|
+
import { ApiResponse } from '../types/api';
|
|
3
|
+
export interface ProviderInfo {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
contact_email: string;
|
|
8
|
+
status: string;
|
|
9
|
+
total_signals_pushed: number;
|
|
10
|
+
total_earnings: number;
|
|
11
|
+
total_burned: number;
|
|
12
|
+
total_revenue_settled: number;
|
|
13
|
+
created_at: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ProviderStats {
|
|
16
|
+
provider: ProviderInfo;
|
|
17
|
+
strategy_count: number;
|
|
18
|
+
signal_count: number;
|
|
19
|
+
active_subscriptions: number;
|
|
20
|
+
pending_review_count: number;
|
|
21
|
+
}
|
|
22
|
+
export interface EarningsSummary {
|
|
23
|
+
total_earnings: number;
|
|
24
|
+
total_settled: number;
|
|
25
|
+
available: number;
|
|
26
|
+
pending_withdrawal: number;
|
|
27
|
+
approved_withdrawal: number;
|
|
28
|
+
}
|
|
29
|
+
export interface Withdrawal {
|
|
30
|
+
id: string;
|
|
31
|
+
amount: number;
|
|
32
|
+
sol_address: string;
|
|
33
|
+
status: string;
|
|
34
|
+
note: string | null;
|
|
35
|
+
reviewed_at: number | null;
|
|
36
|
+
completed_at: number | null;
|
|
37
|
+
tx_signature: string | null;
|
|
38
|
+
created_at: number;
|
|
39
|
+
}
|
|
40
|
+
export interface ProviderStrategy {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
status: string;
|
|
45
|
+
market_type: string;
|
|
46
|
+
symbol_pattern: string;
|
|
47
|
+
pricing_model: string;
|
|
48
|
+
price_per_day: number;
|
|
49
|
+
price_per_signal: number;
|
|
50
|
+
min_bbt_tier: number;
|
|
51
|
+
burn_rate: number;
|
|
52
|
+
provider_revenue_rate: number;
|
|
53
|
+
review_status: string;
|
|
54
|
+
total_signals: number;
|
|
55
|
+
subscriber_count: number;
|
|
56
|
+
created_at: number;
|
|
57
|
+
updated_at: number;
|
|
58
|
+
}
|
|
59
|
+
export declare class ProviderApi {
|
|
60
|
+
private client;
|
|
61
|
+
constructor(client: ApiClient);
|
|
62
|
+
/** 申请成为 Provider (JWT) */
|
|
63
|
+
apply(body: {
|
|
64
|
+
name: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
contact_email?: string;
|
|
67
|
+
}): Promise<ApiResponse<{
|
|
68
|
+
provider_id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
key: string;
|
|
71
|
+
prefix: string;
|
|
72
|
+
bbt_verified: number;
|
|
73
|
+
}>>;
|
|
74
|
+
/** 我的 Provider 信息 (JWT) */
|
|
75
|
+
me(): Promise<ApiResponse<ProviderStats>>;
|
|
76
|
+
/** 更新 Provider 信息 (JWT) */
|
|
77
|
+
updateMe(body: {
|
|
78
|
+
name?: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
contact_email?: string;
|
|
81
|
+
ws_url?: string;
|
|
82
|
+
}): Promise<ApiResponse<{
|
|
83
|
+
ok: boolean;
|
|
84
|
+
}>>;
|
|
85
|
+
/** 重新生成 API Key (JWT) */
|
|
86
|
+
regenerateKey(): Promise<ApiResponse<{
|
|
87
|
+
key: string;
|
|
88
|
+
prefix: string;
|
|
89
|
+
}>>;
|
|
90
|
+
/** 收益统计 (JWT) */
|
|
91
|
+
earnings(): Promise<ApiResponse<EarningsSummary>>;
|
|
92
|
+
/** 申请提现 (JWT) */
|
|
93
|
+
withdraw(body: {
|
|
94
|
+
amount: number;
|
|
95
|
+
sol_address: string;
|
|
96
|
+
}): Promise<ApiResponse<{
|
|
97
|
+
id: string;
|
|
98
|
+
amount: number;
|
|
99
|
+
status: string;
|
|
100
|
+
}>>;
|
|
101
|
+
/** 提现记录 (JWT) */
|
|
102
|
+
withdrawals(): Promise<ApiResponse<{
|
|
103
|
+
withdrawals: Withdrawal[];
|
|
104
|
+
}>>;
|
|
105
|
+
/** 我的策略列表 (JWT) */
|
|
106
|
+
strategies(): Promise<ApiResponse<{
|
|
107
|
+
strategies: ProviderStrategy[];
|
|
108
|
+
}>>;
|
|
109
|
+
/** 创建策略 (JWT) */
|
|
110
|
+
createStrategy(body: Record<string, unknown>): Promise<ApiResponse<{
|
|
111
|
+
id: string;
|
|
112
|
+
status: string;
|
|
113
|
+
name: string;
|
|
114
|
+
}>>;
|
|
115
|
+
/** 提交审核 (JWT) */
|
|
116
|
+
submitStrategy(id: string): Promise<ApiResponse<{
|
|
117
|
+
ok: boolean;
|
|
118
|
+
status: string;
|
|
119
|
+
review_status: string;
|
|
120
|
+
}>>;
|
|
121
|
+
/** 暂停策略 (JWT) */
|
|
122
|
+
pauseStrategy(id: string): Promise<ApiResponse<{
|
|
123
|
+
ok: boolean;
|
|
124
|
+
status: string;
|
|
125
|
+
}>>;
|
|
126
|
+
/** 恢复策略 (JWT) */
|
|
127
|
+
resumeStrategy(id: string): Promise<ApiResponse<{
|
|
128
|
+
ok: boolean;
|
|
129
|
+
status: string;
|
|
130
|
+
}>>;
|
|
131
|
+
/** 删除策略 (JWT) */
|
|
132
|
+
deleteStrategy(id: string): Promise<ApiResponse<{
|
|
133
|
+
ok: boolean;
|
|
134
|
+
}>>;
|
|
135
|
+
private resolveProviderUrl;
|
|
136
|
+
/** 推送信号 (pk-bbt API Key) */
|
|
137
|
+
pushSignal(pkKey: string, baseUrl: string, body: {
|
|
138
|
+
strategy_id: string;
|
|
139
|
+
symbol: string;
|
|
140
|
+
decision: string;
|
|
141
|
+
price?: number;
|
|
142
|
+
confidence?: number;
|
|
143
|
+
stop_loss?: number;
|
|
144
|
+
take_profit?: number;
|
|
145
|
+
reasoning?: string;
|
|
146
|
+
}): Promise<ApiResponse<{
|
|
147
|
+
id: string;
|
|
148
|
+
strategy_id: string;
|
|
149
|
+
created_at: number;
|
|
150
|
+
dispatched: boolean;
|
|
151
|
+
}>>;
|
|
152
|
+
/** 查询 Provider 统计 (pk-bbt API Key) */
|
|
153
|
+
stats(pkKey: string, baseUrl: string): Promise<ApiResponse<{
|
|
154
|
+
provider: {
|
|
155
|
+
total_signals_pushed: number;
|
|
156
|
+
total_earnings: number;
|
|
157
|
+
};
|
|
158
|
+
strategy_count: number;
|
|
159
|
+
signal_count: number;
|
|
160
|
+
active_subscriptions: number;
|
|
161
|
+
}>>;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,MA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AE,oBAAoB,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,oBAAoB,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAStN"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ProviderApi = void 0;
|
|
37
|
+
class ProviderApi {
|
|
38
|
+
client;
|
|
39
|
+
constructor(client) {
|
|
40
|
+
this.client = client;
|
|
41
|
+
}
|
|
42
|
+
/** 申请成为 Provider (JWT) */
|
|
43
|
+
async apply(body) {
|
|
44
|
+
return this.client.post('/provider/apply', body);
|
|
45
|
+
}
|
|
46
|
+
/** 我的 Provider 信息 (JWT) */
|
|
47
|
+
async me() {
|
|
48
|
+
return this.client.get('/provider/me');
|
|
49
|
+
}
|
|
50
|
+
/** 更新 Provider 信息 (JWT) */
|
|
51
|
+
async updateMe(body) {
|
|
52
|
+
return this.client.put('/provider/me', body);
|
|
53
|
+
}
|
|
54
|
+
/** 重新生成 API Key (JWT) */
|
|
55
|
+
async regenerateKey() {
|
|
56
|
+
return this.client.post('/provider/regenerate-key');
|
|
57
|
+
}
|
|
58
|
+
/** 收益统计 (JWT) */
|
|
59
|
+
async earnings() {
|
|
60
|
+
return this.client.get('/provider/earnings');
|
|
61
|
+
}
|
|
62
|
+
/** 申请提现 (JWT) */
|
|
63
|
+
async withdraw(body) {
|
|
64
|
+
return this.client.post('/provider/withdraw', body);
|
|
65
|
+
}
|
|
66
|
+
/** 提现记录 (JWT) */
|
|
67
|
+
async withdrawals() {
|
|
68
|
+
return this.client.get('/provider/withdrawals');
|
|
69
|
+
}
|
|
70
|
+
/** 我的策略列表 (JWT) */
|
|
71
|
+
async strategies() {
|
|
72
|
+
return this.client.get('/provider/strategies');
|
|
73
|
+
}
|
|
74
|
+
/** 创建策略 (JWT) */
|
|
75
|
+
async createStrategy(body) {
|
|
76
|
+
return this.client.post('/provider/strategies', body);
|
|
77
|
+
}
|
|
78
|
+
/** 提交审核 (JWT) */
|
|
79
|
+
async submitStrategy(id) {
|
|
80
|
+
return this.client.post(`/provider/strategies/${id}/submit`);
|
|
81
|
+
}
|
|
82
|
+
/** 暂停策略 (JWT) */
|
|
83
|
+
async pauseStrategy(id) {
|
|
84
|
+
return this.client.post(`/provider/strategies/${id}/pause`);
|
|
85
|
+
}
|
|
86
|
+
/** 恢复策略 (JWT) */
|
|
87
|
+
async resumeStrategy(id) {
|
|
88
|
+
return this.client.post(`/provider/strategies/${id}/resume`);
|
|
89
|
+
}
|
|
90
|
+
/** 删除策略 (JWT) */
|
|
91
|
+
async deleteStrategy(id) {
|
|
92
|
+
return this.client.delete(`/provider/strategies/${id}`);
|
|
93
|
+
}
|
|
94
|
+
resolveProviderUrl(baseUrl) {
|
|
95
|
+
// /ext-api → 根域名,因为 /provider/provider-api 不在 /ext-api 下
|
|
96
|
+
return baseUrl.replace(/\/ext-api\/?$/, '');
|
|
97
|
+
}
|
|
98
|
+
/** 推送信号 (pk-bbt API Key) */
|
|
99
|
+
async pushSignal(pkKey, baseUrl, body) {
|
|
100
|
+
const axios = (await Promise.resolve().then(() => __importStar(require('axios')))).default;
|
|
101
|
+
const url = this.resolveProviderUrl(baseUrl);
|
|
102
|
+
const res = await axios.post(`${url}/provider/provider-api/signals`, body, {
|
|
103
|
+
headers: {
|
|
104
|
+
'Authorization': `Bearer ${pkKey}`,
|
|
105
|
+
'Content-Type': 'application/json',
|
|
106
|
+
},
|
|
107
|
+
timeout: 30000,
|
|
108
|
+
});
|
|
109
|
+
return res.data;
|
|
110
|
+
}
|
|
111
|
+
/** 查询 Provider 统计 (pk-bbt API Key) */
|
|
112
|
+
async stats(pkKey, baseUrl) {
|
|
113
|
+
const axios = (await Promise.resolve().then(() => __importStar(require('axios')))).default;
|
|
114
|
+
const url = this.resolveProviderUrl(baseUrl);
|
|
115
|
+
const res = await axios.get(`${url}/provider/provider-api/stats`, {
|
|
116
|
+
headers: { 'Authorization': `Bearer ${pkKey}` },
|
|
117
|
+
timeout: 30000,
|
|
118
|
+
});
|
|
119
|
+
return res.data;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.ProviderApi = ProviderApi;
|
|
123
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAa,WAAW;IACd,MAAM,CAAY;IAE1B,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,0BAA0B;IAC1B,KAAK,CAAC,KAAK,CAAC,IAAoE;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,2BAA2B;IAC3B,KAAK,CAAC,EAAE;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzC,CAAC;IAED,2BAA2B;IAC3B,KAAK,CAAC,QAAQ,CAAC,IAAsF;QACnG,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,yBAAyB;IACzB,KAAK,CAAC,aAAa;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACtD,CAAC;IAED,iBAAiB;IACjB,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC/C,CAAC;IAED,iBAAiB;IACjB,KAAK,CAAC,QAAQ,CAAC,IAA6C;QAC1D,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,iBAAiB;IACjB,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IAClD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,GAAG,GAAG,gCAAgC,EAAE,IAAI,EAAE;YACzE,OAAO,EAAE;gBACP,eAAe,EAAE,UAAU,KAAK,EAAE;gBAClC,cAAc,EAAE,kBAAkB;aACnC;YACD,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,sCAAsC;IACtC,KAAK,CAAC,KAAK,CAAC,KAAa,EAAE,OAAe;QACxC,MAAM,KAAK,GAAG,CAAC,wDAAa,OAAO,GAAC,CAAC,CAAC,OAAO,CAAC;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,8BAA8B,EAAE;YAChE,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,KAAK,EAAE,EAAE;YAC/C,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF;AAlHD,kCAkHC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signal E2EE decryption (Node.js crypto)
|
|
3
|
+
* Platform encrypts with Web Crypto API, CLI decrypts with Node.js crypto
|
|
4
|
+
* Both use AES-256-GCM with same envelope format
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Decrypt signal envelope
|
|
8
|
+
* Input: base64(iv(12) + ciphertext + authTag(16))
|
|
9
|
+
* Key: 64-char hex string (32 bytes)
|
|
10
|
+
*/
|
|
11
|
+
export declare function decryptSignal(envelopeB64: string, keyHex: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a message looks like encrypted envelope (base64, length > 32)
|
|
14
|
+
* vs plaintext JSON
|
|
15
|
+
*/
|
|
16
|
+
export declare function looksEncrypted(data: string): boolean;
|
|
17
|
+
//# sourceMappingURL=signal-crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-crypto.d.ts","sourceRoot":"","sources":["../../src/api/signal-crypto.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAqBzE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQpD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Signal E2EE decryption (Node.js crypto)
|
|
4
|
+
* Platform encrypts with Web Crypto API, CLI decrypts with Node.js crypto
|
|
5
|
+
* Both use AES-256-GCM with same envelope format
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.decryptSignal = decryptSignal;
|
|
9
|
+
exports.looksEncrypted = looksEncrypted;
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
11
|
+
/**
|
|
12
|
+
* Decrypt signal envelope
|
|
13
|
+
* Input: base64(iv(12) + ciphertext + authTag(16))
|
|
14
|
+
* Key: 64-char hex string (32 bytes)
|
|
15
|
+
*/
|
|
16
|
+
function decryptSignal(envelopeB64, keyHex) {
|
|
17
|
+
const envelope = Buffer.from(envelopeB64, 'base64');
|
|
18
|
+
if (envelope.length < 28) {
|
|
19
|
+
throw new Error('Envelope too short');
|
|
20
|
+
}
|
|
21
|
+
const iv = envelope.slice(0, 12);
|
|
22
|
+
const ciphertext = envelope.slice(12, -16);
|
|
23
|
+
const authTag = envelope.slice(-16);
|
|
24
|
+
const key = Buffer.from(keyHex, 'hex');
|
|
25
|
+
if (key.length !== 32) {
|
|
26
|
+
throw new Error('Invalid key length');
|
|
27
|
+
}
|
|
28
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
|
|
29
|
+
decipher.setAuthTag(authTag);
|
|
30
|
+
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
31
|
+
return decrypted.toString('utf-8');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a message looks like encrypted envelope (base64, length > 32)
|
|
35
|
+
* vs plaintext JSON
|
|
36
|
+
*/
|
|
37
|
+
function looksEncrypted(data) {
|
|
38
|
+
if (data.startsWith('{'))
|
|
39
|
+
return false;
|
|
40
|
+
try {
|
|
41
|
+
const buf = Buffer.from(data, 'base64');
|
|
42
|
+
return buf.length >= 28;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=signal-crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-crypto.js","sourceRoot":"","sources":["../../src/api/signal-crypto.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AASH,sCAqBC;AAMD,wCAQC;AA1CD,mCAA0C;AAE1C;;;;GAIG;AACH,SAAgB,aAAa,CAAC,WAAmB,EAAE,MAAc;IAC/D,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAEpD,IAAI,QAAQ,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAEpC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,yBAAgB,EAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAC1D,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAE7B,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjF,OAAO,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,SAAgB,cAAc,CAAC,IAAY;IACzC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACxC,OAAO,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ApiClient } from './client';
|
|
2
|
+
import { ApiResponse } from '../types/api';
|
|
3
|
+
export interface Signal {
|
|
4
|
+
id: string;
|
|
5
|
+
strategy_id: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
decision: 'long' | 'short' | 'close_long' | 'close_short' | 'tp' | 'sl' | 'partial_close' | 'cancel' | 'hold';
|
|
8
|
+
confidence: number;
|
|
9
|
+
price: number;
|
|
10
|
+
stop_loss?: number;
|
|
11
|
+
take_profit?: number;
|
|
12
|
+
reasoning: string;
|
|
13
|
+
created_at: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SignalAckResponse {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
bbt_charged: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class SignalsApi {
|
|
20
|
+
private client;
|
|
21
|
+
constructor(client: ApiClient);
|
|
22
|
+
/**
|
|
23
|
+
* Get latest signals for subscribed strategies
|
|
24
|
+
*/
|
|
25
|
+
latest(params?: {
|
|
26
|
+
market_type?: string;
|
|
27
|
+
}): Promise<ApiResponse<{
|
|
28
|
+
signals: Signal[];
|
|
29
|
+
count: number;
|
|
30
|
+
}>>;
|
|
31
|
+
/**
|
|
32
|
+
* Get signal history
|
|
33
|
+
*/
|
|
34
|
+
history(params?: {
|
|
35
|
+
limit?: number;
|
|
36
|
+
offset?: number;
|
|
37
|
+
market_type?: string;
|
|
38
|
+
}): Promise<ApiResponse<{
|
|
39
|
+
signals: Signal[];
|
|
40
|
+
total: number;
|
|
41
|
+
}>>;
|
|
42
|
+
/**
|
|
43
|
+
* Acknowledge a signal (triggers per-signal BBT billing if applicable)
|
|
44
|
+
*/
|
|
45
|
+
ack(signalId: string, action?: string, quantity?: number): Promise<ApiResponse<SignalAckResponse>>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=signals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/api/signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,YAAY,GAAG,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,eAAe,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9G,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAY;gBAEd,MAAM,EAAE,SAAS;IAI7B;;OAEG;IACG,MAAM,CAAC,MAAM,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAI3G;;OAEG;IACG,OAAO,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAI7I;;OAEG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;CAMzG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignalsApi = void 0;
|
|
4
|
+
class SignalsApi {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get latest signals for subscribed strategies
|
|
11
|
+
*/
|
|
12
|
+
async latest(params) {
|
|
13
|
+
return this.client.get('/signals/latest', params);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get signal history
|
|
17
|
+
*/
|
|
18
|
+
async history(params) {
|
|
19
|
+
return this.client.get('/signals/history', params);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Acknowledge a signal (triggers per-signal BBT billing if applicable)
|
|
23
|
+
*/
|
|
24
|
+
async ack(signalId, action, quantity) {
|
|
25
|
+
const body = { signal_id: signalId };
|
|
26
|
+
if (action)
|
|
27
|
+
body.action = action;
|
|
28
|
+
if (quantity !== undefined)
|
|
29
|
+
body.quantity = quantity;
|
|
30
|
+
return this.client.post('/signals/ack', body);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SignalsApi = SignalsApi;
|
|
34
|
+
//# sourceMappingURL=signals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.js","sourceRoot":"","sources":["../../src/api/signals.ts"],"names":[],"mappings":";;;AAqBA,MAAa,UAAU;IACb,MAAM,CAAY;IAE1B,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,MAAiC;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAuC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC1F,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,MAAkE;QAC9E,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAuC,kBAAkB,EAAE,MAAM,CAAC,CAAC;IAC3F,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,QAAgB,EAAE,MAAe,EAAE,QAAiB;QAC5D,MAAM,IAAI,GAA4B,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;QAC9D,IAAI,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACjC,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAoB,cAAc,EAAE,IAAI,CAAC,CAAC;IACnE,CAAC;CACF;AA9BD,gCA8BC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ApiClient } from './client';
|
|
2
|
+
import { ApiResponse } from '../types/api';
|
|
3
|
+
export interface StreamDispatchResponse {
|
|
4
|
+
ws_url: string;
|
|
5
|
+
token: string;
|
|
6
|
+
strategy_id: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
pricing_model: string;
|
|
9
|
+
price_per_signal: number;
|
|
10
|
+
expires_at: number;
|
|
11
|
+
encryption_key?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface StreamSignal {
|
|
14
|
+
type: 'signal' | 'connected';
|
|
15
|
+
id?: string;
|
|
16
|
+
strategy_id?: string;
|
|
17
|
+
symbol?: string;
|
|
18
|
+
decision?: 'long' | 'short' | 'hold';
|
|
19
|
+
confidence?: number;
|
|
20
|
+
price?: number;
|
|
21
|
+
ema14?: number;
|
|
22
|
+
timestamp?: number;
|
|
23
|
+
user_id?: string;
|
|
24
|
+
}
|
|
25
|
+
export type SignalHandler = (signal: StreamSignal) => void | Promise<void>;
|
|
26
|
+
export declare class StrategyStream {
|
|
27
|
+
private client;
|
|
28
|
+
private ws;
|
|
29
|
+
private reconnectTimer;
|
|
30
|
+
private strategyId;
|
|
31
|
+
private encryptionKey;
|
|
32
|
+
private signalHandler;
|
|
33
|
+
private onErrorHandler;
|
|
34
|
+
private onCloseHandler;
|
|
35
|
+
private ackApi;
|
|
36
|
+
private autoAck;
|
|
37
|
+
private processedSignals;
|
|
38
|
+
constructor(client: ApiClient, options?: {
|
|
39
|
+
autoAck?: boolean;
|
|
40
|
+
});
|
|
41
|
+
setAckApi(ackApi: {
|
|
42
|
+
ack: (signalId: string) => Promise<ApiResponse<{
|
|
43
|
+
ok: boolean;
|
|
44
|
+
bbt_charged: number;
|
|
45
|
+
}>>;
|
|
46
|
+
}): void;
|
|
47
|
+
/**
|
|
48
|
+
* 请求策略服务器地址并建立 WebSocket 连接
|
|
49
|
+
*/
|
|
50
|
+
connect(strategyId: string): Promise<ApiResponse<StreamDispatchResponse>>;
|
|
51
|
+
private connectWs;
|
|
52
|
+
private scheduleReconnect;
|
|
53
|
+
onSignal(handler: SignalHandler): void;
|
|
54
|
+
onError(handler: (err: Error) => void): void;
|
|
55
|
+
onClose(handler: () => void): void;
|
|
56
|
+
disconnect(): void;
|
|
57
|
+
isConnected(): boolean;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=strategy-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy-stream.d.ts","sourceRoot":"","sources":["../../src/api/strategy-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAI3C,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf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136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StrategyStream = void 0;
|
|
4
|
+
const signal_crypto_1 = require("./signal-crypto");
|
|
5
|
+
const device_1 = require("../utils/device");
|
|
6
|
+
class StrategyStream {
|
|
7
|
+
client;
|
|
8
|
+
ws = null;
|
|
9
|
+
reconnectTimer = null;
|
|
10
|
+
strategyId = '';
|
|
11
|
+
encryptionKey = '';
|
|
12
|
+
signalHandler = () => { };
|
|
13
|
+
onErrorHandler = () => { };
|
|
14
|
+
onCloseHandler = () => { };
|
|
15
|
+
ackApi = null;
|
|
16
|
+
autoAck = true;
|
|
17
|
+
processedSignals = new Set();
|
|
18
|
+
constructor(client, options) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
this.autoAck = options?.autoAck !== false;
|
|
21
|
+
}
|
|
22
|
+
setAckApi(ackApi) {
|
|
23
|
+
this.ackApi = ackApi;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 请求策略服务器地址并建立 WebSocket 连接
|
|
27
|
+
*/
|
|
28
|
+
async connect(strategyId) {
|
|
29
|
+
this.strategyId = strategyId;
|
|
30
|
+
// 1. 请求 dispatch 获取 ws_url
|
|
31
|
+
const dispatch = await this.client.post('/strategy/dispatch', {
|
|
32
|
+
strategy_id: strategyId,
|
|
33
|
+
device_hash: (0, device_1.getDeviceHash)(),
|
|
34
|
+
});
|
|
35
|
+
if (!dispatch.success || !dispatch.data) {
|
|
36
|
+
return dispatch;
|
|
37
|
+
}
|
|
38
|
+
const { ws_url, encryption_key } = dispatch.data;
|
|
39
|
+
if (encryption_key) {
|
|
40
|
+
this.encryptionKey = encryption_key;
|
|
41
|
+
}
|
|
42
|
+
// 2. 建立 WebSocket 连接
|
|
43
|
+
await this.connectWs(ws_url);
|
|
44
|
+
return dispatch;
|
|
45
|
+
}
|
|
46
|
+
connectWs(url) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
try {
|
|
49
|
+
this.ws = new WebSocket(url);
|
|
50
|
+
this.ws.onopen = () => {
|
|
51
|
+
console.log(`[StrategyStream] WebSocket connected: ${this.strategyId}`);
|
|
52
|
+
resolve();
|
|
53
|
+
};
|
|
54
|
+
this.ws.onmessage = async (event) => {
|
|
55
|
+
try {
|
|
56
|
+
let rawData = event.data;
|
|
57
|
+
let signal;
|
|
58
|
+
// 尝试解密(如果收到的是加密信封)
|
|
59
|
+
if (this.encryptionKey && (0, signal_crypto_1.looksEncrypted)(rawData)) {
|
|
60
|
+
try {
|
|
61
|
+
const decrypted = (0, signal_crypto_1.decryptSignal)(rawData, this.encryptionKey);
|
|
62
|
+
rawData = decrypted;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.warn('[StrategyStream] Decryption failed, treating as plaintext:', e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
signal = JSON.parse(rawData);
|
|
69
|
+
if (signal.type === 'signal' && signal.id && this.autoAck && this.ackApi) {
|
|
70
|
+
// 自动 ack(上报接收 + 扣费)
|
|
71
|
+
try {
|
|
72
|
+
await this.ackApi.ack(signal.id);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
// ack 失败不影响信号处理
|
|
76
|
+
console.warn(`[StrategyStream] Auto-ack failed for ${signal.id}:`, e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
await this.signalHandler(signal);
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
console.warn('[StrategyStream] Failed to parse message:', e);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
this.ws.onerror = (err) => {
|
|
86
|
+
const error = new Error(`WebSocket error: ${err.type}`);
|
|
87
|
+
this.onErrorHandler(error);
|
|
88
|
+
reject(error);
|
|
89
|
+
};
|
|
90
|
+
this.ws.onclose = () => {
|
|
91
|
+
console.log('[StrategyStream] WebSocket closed');
|
|
92
|
+
this.onCloseHandler();
|
|
93
|
+
this.scheduleReconnect();
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
reject(e);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
scheduleReconnect() {
|
|
102
|
+
if (this.reconnectTimer)
|
|
103
|
+
return;
|
|
104
|
+
console.log('[StrategyStream] Reconnecting in 5s...');
|
|
105
|
+
this.reconnectTimer = setTimeout(() => {
|
|
106
|
+
this.reconnectTimer = null;
|
|
107
|
+
this.connect(this.strategyId).catch((e) => {
|
|
108
|
+
console.error('[StrategyStream] Reconnect failed:', e);
|
|
109
|
+
});
|
|
110
|
+
}, 5000);
|
|
111
|
+
}
|
|
112
|
+
onSignal(handler) {
|
|
113
|
+
this.signalHandler = handler;
|
|
114
|
+
}
|
|
115
|
+
onError(handler) {
|
|
116
|
+
this.onErrorHandler = handler;
|
|
117
|
+
}
|
|
118
|
+
onClose(handler) {
|
|
119
|
+
this.onCloseHandler = handler;
|
|
120
|
+
}
|
|
121
|
+
disconnect() {
|
|
122
|
+
if (this.reconnectTimer) {
|
|
123
|
+
clearTimeout(this.reconnectTimer);
|
|
124
|
+
this.reconnectTimer = null;
|
|
125
|
+
}
|
|
126
|
+
if (this.ws) {
|
|
127
|
+
this.ws.close();
|
|
128
|
+
this.ws = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
isConnected() {
|
|
132
|
+
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.StrategyStream = StrategyStream;
|
|
136
|
+
//# sourceMappingURL=strategy-stream.js.map
|