atlaas 0.1.1 → 0.3.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.
- package/README.md +657 -402
- package/dist/index.d.ts +2029 -119
- package/dist/index.js +632 -249
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.ts +231 -370
- package/dist/schemas.js +127 -15
- package/dist/schemas.js.map +1 -1
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
|
|
3
|
-
interface HttpTransportOptions {
|
|
4
|
-
baseUrl: string;
|
|
5
|
-
apiKey: string;
|
|
6
|
-
timeoutMs?: number;
|
|
7
|
-
maxRetries?: number;
|
|
8
|
-
logger?: AtlasLogger;
|
|
9
|
-
}
|
|
10
|
-
interface AtlasLogger {
|
|
11
|
-
debug?: (message: string, meta?: Record<string, unknown>) => void;
|
|
12
|
-
info?: (message: string, meta?: Record<string, unknown>) => void;
|
|
13
|
-
warn?: (message: string, meta?: Record<string, unknown>) => void;
|
|
14
|
-
error?: (message: string, meta?: Record<string, unknown>) => void;
|
|
15
|
-
}
|
|
16
|
-
interface RequestOptions {
|
|
17
|
-
method: string;
|
|
18
|
-
path: string;
|
|
19
|
-
body?: unknown;
|
|
20
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
21
|
-
signal?: AbortSignal;
|
|
22
|
-
}
|
|
23
|
-
declare class HttpTransport {
|
|
24
|
-
private readonly baseUrl;
|
|
25
|
-
private readonly apiKey;
|
|
26
|
-
private readonly timeoutMs;
|
|
27
|
-
private readonly maxRetries;
|
|
28
|
-
private readonly logger?;
|
|
29
|
-
constructor(options: HttpTransportOptions);
|
|
30
|
-
request<T>(options: RequestOptions): Promise<T>;
|
|
31
|
-
private mapError;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
3
|
type InstanceState = "PENDING" | "DEPLOYING" | "DEPLOYED" | "RUNNING" | "STOPPED" | "ERROR";
|
|
35
4
|
type InstanceType = "TICK" | "TICKS_TRADE" | "TRADE";
|
|
36
5
|
type OrderDirection = "BUY" | "SELL";
|
|
@@ -55,42 +24,108 @@ interface Instance {
|
|
|
55
24
|
createdAt: string;
|
|
56
25
|
updatedAt: string;
|
|
57
26
|
}
|
|
27
|
+
/** An instance on `/api/atlas/instances`: an MT5 terminal or a broker connection. */
|
|
58
28
|
interface AtlasInstance {
|
|
59
29
|
id: string;
|
|
30
|
+
atlasAccountId: string | null;
|
|
60
31
|
externalRef: string | null;
|
|
61
32
|
externalUserId: string | null;
|
|
62
33
|
instanceKind: string | null;
|
|
63
34
|
/** Broker-side account identifier: MT5 login or broker clientId (Dhan/Kite). */
|
|
64
35
|
accountId: string | null;
|
|
65
36
|
runnerId: string;
|
|
37
|
+
name: string | null;
|
|
66
38
|
state: InstanceState;
|
|
67
39
|
enabled: boolean;
|
|
40
|
+
autoRestart: boolean;
|
|
41
|
+
containerCpus: string | null;
|
|
42
|
+
containerMemory: string | null;
|
|
43
|
+
/** The IPv4 address the broker whitelists for this connection. */
|
|
68
44
|
registeredIp: string | null;
|
|
45
|
+
ipVerifiedAt: string | null;
|
|
69
46
|
lastActiveAt: string | null;
|
|
70
47
|
connectedAt: string | null;
|
|
71
48
|
disconnectedAt: string | null;
|
|
49
|
+
/** A 64-bit counter, sent as a decimal string. */
|
|
50
|
+
ticksReceived: string;
|
|
51
|
+
/** A 64-bit counter, sent as a decimal string. */
|
|
52
|
+
tradesExecuted: string;
|
|
53
|
+
errorCount: number;
|
|
54
|
+
avgLatencyMs: number | null;
|
|
72
55
|
statusMessage: string | null;
|
|
73
56
|
errorMessage: string | null;
|
|
74
|
-
lastError
|
|
75
|
-
lastErrorAt
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
57
|
+
lastError: string | null;
|
|
58
|
+
lastErrorAt: string | null;
|
|
59
|
+
lastSyncedAt: string | null;
|
|
60
|
+
retryCount: number;
|
|
61
|
+
nextRetryAt: string | null;
|
|
62
|
+
displayName: string | null;
|
|
63
|
+
metadata: Record<string, unknown> | null;
|
|
64
|
+
/** Broker funds, as decimal strings. */
|
|
65
|
+
availableBalance: string | null;
|
|
66
|
+
equity: string | null;
|
|
67
|
+
utilizedAmount: string | null;
|
|
68
|
+
collateralAmount: string | null;
|
|
69
|
+
withdrawableBalance: string | null;
|
|
70
|
+
profileData: unknown;
|
|
71
|
+
fundsSyncedAt: string | null;
|
|
72
|
+
runner: {
|
|
73
|
+
ipAddress: string | null;
|
|
74
|
+
health: "HEALTHY" | "DEGRADED" | "UNHEALTHY";
|
|
75
|
+
lastSeenAt: string | null;
|
|
76
|
+
managedRunner: {
|
|
77
|
+
state: "PROVISIONING" | "ACTIVE" | "FAILED" | "DEPROVISIONING" | "DELETED";
|
|
78
|
+
ipAddress: string | null;
|
|
79
|
+
lastError: string | null;
|
|
80
|
+
} | null;
|
|
81
|
+
};
|
|
82
|
+
createdAt: string;
|
|
83
|
+
updatedAt: string;
|
|
80
84
|
}
|
|
85
|
+
/** POST /api/external/instances: deploy an MT5 terminal. */
|
|
81
86
|
interface CreateInstanceBody {
|
|
87
|
+
/** The MT5 login. */
|
|
82
88
|
accountId: string;
|
|
83
89
|
password?: string;
|
|
90
|
+
/** A `serverName` from `mt5.servers()`. */
|
|
84
91
|
serverName: string;
|
|
85
92
|
brokerName?: string;
|
|
86
93
|
name?: string;
|
|
94
|
+
/** Default TICK. */
|
|
87
95
|
type?: InstanceType;
|
|
96
|
+
/** A region `id` from `mt5.regions()`; omitted, Atlaas picks one. */
|
|
97
|
+
regionId?: string;
|
|
98
|
+
/** Your own id for the terminal. */
|
|
99
|
+
externalRef?: string;
|
|
100
|
+
}
|
|
101
|
+
/** An MT5 server the deploy catalogue offers. */
|
|
102
|
+
interface DeployServer {
|
|
103
|
+
/** What `mt5.create()` takes as `serverName`. */
|
|
104
|
+
serverName: string;
|
|
105
|
+
brokerName: string;
|
|
106
|
+
displayName: string | null;
|
|
107
|
+
/** `demo` or `live`. */
|
|
108
|
+
serverType: string | null;
|
|
109
|
+
defaultSymbol: string | null;
|
|
110
|
+
}
|
|
111
|
+
/** A region with room for a new MT5 terminal. */
|
|
112
|
+
interface DeployRegion {
|
|
113
|
+
/** What `mt5.create()` takes as `regionId`. */
|
|
114
|
+
id: string;
|
|
115
|
+
code: string;
|
|
116
|
+
displayName: string;
|
|
117
|
+
description: string | null;
|
|
88
118
|
}
|
|
89
119
|
interface CreateAtlasInstanceBody {
|
|
120
|
+
/** Upsert key: an existing instance of yours with this ref is updated instead. */
|
|
90
121
|
externalRef?: string;
|
|
91
122
|
externalUserId?: string;
|
|
92
123
|
instanceKind: string;
|
|
93
|
-
|
|
124
|
+
/** Omit it for a broker connection (dhan, kite, motilal, angelone, fyers,
|
|
125
|
+
* upstox, shoonya, bybit, deribit, kraken, hyperliquid, coindcx, delta,
|
|
126
|
+
* alpaca, tastytrade, lime): Atlaas places it on a server of its own.
|
|
127
|
+
* Required for every other kind, `mt5` included. */
|
|
128
|
+
runnerId?: string;
|
|
94
129
|
name?: string;
|
|
95
130
|
metadata?: Record<string, unknown>;
|
|
96
131
|
credentials: Record<string, unknown>;
|
|
@@ -98,14 +133,53 @@ interface CreateAtlasInstanceBody {
|
|
|
98
133
|
* account); only master-key callers set it, and it must be a real AtlasAccount. */
|
|
99
134
|
atlasAccountId?: string;
|
|
100
135
|
}
|
|
136
|
+
interface CreateAtlasInstanceResult {
|
|
137
|
+
id: string;
|
|
138
|
+
externalRef: string | null;
|
|
139
|
+
runnerId: string;
|
|
140
|
+
/** False while a managed server is still being built. */
|
|
141
|
+
runnerReady: boolean;
|
|
142
|
+
/** The address the broker sees: the managed server's reserved IP, or the runner's. */
|
|
143
|
+
ipAddress: string | null;
|
|
144
|
+
managedRunnerId: string | null;
|
|
145
|
+
}
|
|
101
146
|
interface UpdateAtlasInstanceBody {
|
|
102
147
|
state?: InstanceState;
|
|
103
148
|
enabled?: boolean;
|
|
104
149
|
autoRestart?: boolean;
|
|
150
|
+
name?: string;
|
|
105
151
|
metadata?: Record<string, unknown>;
|
|
152
|
+
/** Replaces the stored credentials. */
|
|
106
153
|
credentials?: Record<string, unknown>;
|
|
154
|
+
/** Merges into the stored credentials; ignored when `credentials` is sent. */
|
|
107
155
|
credentialsPatch?: Record<string, unknown>;
|
|
108
156
|
}
|
|
157
|
+
interface ValidateBrokerCredentialsBody {
|
|
158
|
+
brokerName: string;
|
|
159
|
+
/** For Dhan: `{ clientId, pin, totpSecret }`. */
|
|
160
|
+
credentials: Record<string, unknown>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Validity is data: a well-formed request always answers 200. Only Dhan is
|
|
164
|
+
* checked today, by logging in (which mints a real access token, at most one
|
|
165
|
+
* every two minutes); any other broker's credentials come back unchanged with
|
|
166
|
+
* `validated: false`.
|
|
167
|
+
*/
|
|
168
|
+
type ValidateBrokerCredentialsResult = {
|
|
169
|
+
valid: true;
|
|
170
|
+
validated: false;
|
|
171
|
+
credentials: Record<string, unknown>;
|
|
172
|
+
} | {
|
|
173
|
+
valid: true;
|
|
174
|
+
validated: true;
|
|
175
|
+
credentials: Record<string, unknown> & {
|
|
176
|
+
accessToken: string;
|
|
177
|
+
accessTokenExpiry: number;
|
|
178
|
+
};
|
|
179
|
+
} | {
|
|
180
|
+
valid: false;
|
|
181
|
+
error: string;
|
|
182
|
+
};
|
|
109
183
|
interface ListInstancesQuery {
|
|
110
184
|
instanceKind?: string;
|
|
111
185
|
state?: string;
|
|
@@ -127,21 +201,137 @@ interface AccountInfo {
|
|
|
127
201
|
marginLevel?: number;
|
|
128
202
|
tradeAllowed?: boolean;
|
|
129
203
|
}
|
|
204
|
+
/** One open MT5 position, as the EA last pushed it. */
|
|
130
205
|
interface Position {
|
|
131
206
|
ticket: number;
|
|
207
|
+
/** POSITION_IDENTIFIER, the id deals carry. Absent from older connector EAs. */
|
|
208
|
+
identifier?: number;
|
|
132
209
|
symbol: string;
|
|
133
210
|
type: OrderDirection;
|
|
134
211
|
volume: number;
|
|
135
212
|
openPrice: number;
|
|
136
213
|
currentPrice: number;
|
|
214
|
+
/** 0 is none. */
|
|
137
215
|
sl: number;
|
|
216
|
+
/** 0 is none. */
|
|
138
217
|
tp: number;
|
|
139
218
|
profit: number;
|
|
140
219
|
swap: number;
|
|
220
|
+
/** Epoch seconds, broker server clock. */
|
|
141
221
|
openTime: number;
|
|
222
|
+
/** @deprecated Never sent on this route; closed positions carry it. */
|
|
142
223
|
commission?: number;
|
|
143
224
|
comment?: string;
|
|
225
|
+
/** 0 is a manual trade. */
|
|
144
226
|
magic?: number;
|
|
227
|
+
digits?: number;
|
|
228
|
+
point?: number;
|
|
229
|
+
volumeMin?: number;
|
|
230
|
+
volumeStep?: number;
|
|
231
|
+
}
|
|
232
|
+
interface PositionDetailBase {
|
|
233
|
+
ticket: number;
|
|
234
|
+
symbol: string;
|
|
235
|
+
type: OrderDirection;
|
|
236
|
+
volume: number;
|
|
237
|
+
openPrice: number;
|
|
238
|
+
profit: number;
|
|
239
|
+
swap: number;
|
|
240
|
+
/** Epoch seconds, broker server clock. */
|
|
241
|
+
openTime: number;
|
|
242
|
+
comment?: string;
|
|
243
|
+
}
|
|
244
|
+
interface OpenPositionDetail extends PositionDetailBase {
|
|
245
|
+
status: "OPEN";
|
|
246
|
+
currentPrice: number;
|
|
247
|
+
sl: number;
|
|
248
|
+
tp: number;
|
|
249
|
+
closePrice?: undefined;
|
|
250
|
+
closeTime?: undefined;
|
|
251
|
+
}
|
|
252
|
+
interface ClosedPositionDetail extends PositionDetailBase {
|
|
253
|
+
status: "CLOSED";
|
|
254
|
+
closePrice: number;
|
|
255
|
+
/** Epoch seconds, broker server clock. */
|
|
256
|
+
closeTime: number;
|
|
257
|
+
currentPrice?: undefined;
|
|
258
|
+
sl?: undefined;
|
|
259
|
+
tp?: undefined;
|
|
260
|
+
}
|
|
261
|
+
/** One position by ticket: open, or closed from the terminal's history. */
|
|
262
|
+
type PositionDetail = OpenPositionDetail | ClosedPositionDetail;
|
|
263
|
+
interface ClosedPositionsQuery {
|
|
264
|
+
/** Epoch ms, exclusive: pass the last `closeTimeMs` you processed (0 for everything). */
|
|
265
|
+
since: number;
|
|
266
|
+
/** Epoch ms; omitted means now. */
|
|
267
|
+
until?: number;
|
|
268
|
+
/** 1..200, default 200. */
|
|
269
|
+
limit?: number;
|
|
270
|
+
}
|
|
271
|
+
/** A fully closed MT5 position from the terminal's deal history. */
|
|
272
|
+
interface ClosedPosition {
|
|
273
|
+
ticket: number;
|
|
274
|
+
symbol: string;
|
|
275
|
+
status: "CLOSED";
|
|
276
|
+
type: OrderDirection | "";
|
|
277
|
+
volume: number;
|
|
278
|
+
/** Volume-weighted. */
|
|
279
|
+
openPrice: number;
|
|
280
|
+
/** Volume-weighted. */
|
|
281
|
+
closePrice: number;
|
|
282
|
+
profit: number;
|
|
283
|
+
swap: number;
|
|
284
|
+
commission: number;
|
|
285
|
+
/** Epoch seconds, broker server clock. */
|
|
286
|
+
openTime: number;
|
|
287
|
+
/** Epoch seconds, broker server clock. */
|
|
288
|
+
closeTime: number;
|
|
289
|
+
/** Epoch ms: the cursor for the next page. */
|
|
290
|
+
closeTimeMs: number;
|
|
291
|
+
magic: number;
|
|
292
|
+
comment: string;
|
|
293
|
+
}
|
|
294
|
+
interface ClosedPositionsResult {
|
|
295
|
+
/** Oldest close first. */
|
|
296
|
+
positions: ClosedPosition[];
|
|
297
|
+
/** The page is full: ask again from the last `closeTimeMs`. */
|
|
298
|
+
hasMore: boolean;
|
|
299
|
+
}
|
|
300
|
+
/** One symbol's contract spec as the MT5 terminal reports it, for every
|
|
301
|
+
* symbol on the server (not only Market Watch). Raw terminal values. */
|
|
302
|
+
interface Mt5SymbolSpec {
|
|
303
|
+
symbol: string;
|
|
304
|
+
description: string;
|
|
305
|
+
path: string;
|
|
306
|
+
baseCurrency: string;
|
|
307
|
+
profitCurrency: string;
|
|
308
|
+
marginCurrency: string;
|
|
309
|
+
digits: number;
|
|
310
|
+
point: number;
|
|
311
|
+
contractSize: number;
|
|
312
|
+
volumeMin: number;
|
|
313
|
+
volumeMax: number;
|
|
314
|
+
volumeStep: number;
|
|
315
|
+
tickSize: number;
|
|
316
|
+
/** 0 for symbols outside Market Watch. */
|
|
317
|
+
tickValue: number;
|
|
318
|
+
stopsLevel: number;
|
|
319
|
+
/** MQL5 ENUM_SYMBOL_TRADE_MODE as an integer. */
|
|
320
|
+
tradeMode: number;
|
|
321
|
+
/** MQL5 ENUM_SYMBOL_CALC_MODE as an integer. */
|
|
322
|
+
calcMode: number;
|
|
323
|
+
}
|
|
324
|
+
/** A read with the freshness fields the MT5 terminal reads carry. */
|
|
325
|
+
interface Fresh<T> {
|
|
326
|
+
data: T;
|
|
327
|
+
/** When the data was produced (ISO 8601). */
|
|
328
|
+
dataAsOf: string;
|
|
329
|
+
/** The terminal's last EA heartbeat (ISO 8601), null if none was ever seen. */
|
|
330
|
+
lastHeartbeatAt: string | null;
|
|
331
|
+
}
|
|
332
|
+
interface FreshnessOption {
|
|
333
|
+
/** Return `{ data, dataAsOf, lastHeartbeatAt }` instead of the data alone. */
|
|
334
|
+
withFreshness: true;
|
|
145
335
|
}
|
|
146
336
|
interface ModifyPositionBody {
|
|
147
337
|
sl?: number;
|
|
@@ -153,6 +343,32 @@ interface ClosePositionBody {
|
|
|
153
343
|
interface CloseBySymbolBody {
|
|
154
344
|
symbol: string;
|
|
155
345
|
}
|
|
346
|
+
interface ModifyMt5PositionResult {
|
|
347
|
+
ticket: number;
|
|
348
|
+
sl?: number;
|
|
349
|
+
tp?: number;
|
|
350
|
+
}
|
|
351
|
+
interface CloseMt5PositionResult {
|
|
352
|
+
ticket: number;
|
|
353
|
+
/** Absent when the terminal's reply did not carry it. */
|
|
354
|
+
closePrice?: number;
|
|
355
|
+
profit?: number;
|
|
356
|
+
/** The position was already closed; nothing was sent. */
|
|
357
|
+
alreadyClosed: boolean;
|
|
358
|
+
}
|
|
359
|
+
interface CloseBySymbolResult {
|
|
360
|
+
symbol: string;
|
|
361
|
+
closedCount: number;
|
|
362
|
+
totalProfit: number;
|
|
363
|
+
positions: Array<{
|
|
364
|
+
ticket: number;
|
|
365
|
+
symbol: string;
|
|
366
|
+
type: string;
|
|
367
|
+
volume: number;
|
|
368
|
+
profit: number;
|
|
369
|
+
closePrice: number;
|
|
370
|
+
}>;
|
|
371
|
+
}
|
|
156
372
|
interface Order {
|
|
157
373
|
ticket: number;
|
|
158
374
|
symbol: string;
|
|
@@ -335,6 +551,152 @@ interface EaVersion {
|
|
|
335
551
|
deploymentCount: number;
|
|
336
552
|
uploadedAt: string;
|
|
337
553
|
}
|
|
554
|
+
/** What registering or saving a version returns: the version without its
|
|
555
|
+
* parsed inputs. Read the full `EaVersion` with `eas.get()` or `listVersions()`. */
|
|
556
|
+
interface RegisteredEaVersion {
|
|
557
|
+
id: string;
|
|
558
|
+
version: string;
|
|
559
|
+
status: EaVersionStatus;
|
|
560
|
+
sourceType: EaSourceType;
|
|
561
|
+
compileStatus: EaCompileStatus;
|
|
562
|
+
deployable: boolean;
|
|
563
|
+
sha256: string | null;
|
|
564
|
+
sizeBytes: number | null;
|
|
565
|
+
magicInput: string | null;
|
|
566
|
+
magicInputWarning: string | null;
|
|
567
|
+
}
|
|
568
|
+
interface SaveEaSourceBody {
|
|
569
|
+
/** 1 to 40 of `A-Za-z0-9._-`. Saving a label again overwrites it, unless it is deployed. */
|
|
570
|
+
version: string;
|
|
571
|
+
/** The .mq5 text, up to 4 MiB. */
|
|
572
|
+
mq5Source: string;
|
|
573
|
+
}
|
|
574
|
+
/** The body of a 422 from `saveSource`: the compile check failed. Read it from `AtlasError.body`. */
|
|
575
|
+
interface EaCompileFailure {
|
|
576
|
+
success: false;
|
|
577
|
+
error: "Compile check failed";
|
|
578
|
+
/** Errors only, at most 50. */
|
|
579
|
+
diagnostics: Array<{
|
|
580
|
+
line?: number;
|
|
581
|
+
column?: number;
|
|
582
|
+
severity?: string;
|
|
583
|
+
message: string;
|
|
584
|
+
}>;
|
|
585
|
+
/** The end of the raw log, when there are no diagnostics. */
|
|
586
|
+
log?: string;
|
|
587
|
+
}
|
|
588
|
+
interface EaVersionSource {
|
|
589
|
+
version: string;
|
|
590
|
+
sourceType: "MQ5";
|
|
591
|
+
source: string;
|
|
592
|
+
}
|
|
593
|
+
interface EaPreset {
|
|
594
|
+
id: string;
|
|
595
|
+
name: string;
|
|
596
|
+
note: string | null;
|
|
597
|
+
/** .set key=value text. */
|
|
598
|
+
setBlob: string;
|
|
599
|
+
createdAt: string;
|
|
600
|
+
updatedAt: string;
|
|
601
|
+
}
|
|
602
|
+
interface CreateEaPresetBody {
|
|
603
|
+
/** 1 to 120 characters, unique per EA. */
|
|
604
|
+
name: string;
|
|
605
|
+
note?: string | null;
|
|
606
|
+
/** Up to 100,000 characters. */
|
|
607
|
+
setBlob: string;
|
|
608
|
+
}
|
|
609
|
+
interface LiveComparisonMatch {
|
|
610
|
+
livePositionId: string;
|
|
611
|
+
simPositionId: string;
|
|
612
|
+
symbol: string;
|
|
613
|
+
type: "buy" | "sell";
|
|
614
|
+
/** Live open time minus simulated open time, seconds. */
|
|
615
|
+
openDeltaSec: number;
|
|
616
|
+
/** Positive is worse for the trader. */
|
|
617
|
+
openSlippagePts: number;
|
|
618
|
+
closeSlippagePts: number | null;
|
|
619
|
+
liveNet: number;
|
|
620
|
+
simNet: number;
|
|
621
|
+
}
|
|
622
|
+
/** A deployment's live trades matched against a backtest of the same window. */
|
|
623
|
+
interface LiveComparisonSummary {
|
|
624
|
+
liveTrades: number;
|
|
625
|
+
simTrades: number;
|
|
626
|
+
matchedPct: number;
|
|
627
|
+
liveNet: number;
|
|
628
|
+
simNet: number;
|
|
629
|
+
avgOpenSlippagePts: number | null;
|
|
630
|
+
medianOpenSlippagePts: number | null;
|
|
631
|
+
p90OpenSlippagePts: number | null;
|
|
632
|
+
/** Live net as a share of simulated net, percent; null when simNet is 0. */
|
|
633
|
+
realisedPct: number | null;
|
|
634
|
+
}
|
|
635
|
+
interface LiveComparison {
|
|
636
|
+
deploymentId: string;
|
|
637
|
+
runId: string;
|
|
638
|
+
instanceId: string;
|
|
639
|
+
magicNumber: number;
|
|
640
|
+
window: {
|
|
641
|
+
from: string;
|
|
642
|
+
to: string;
|
|
643
|
+
};
|
|
644
|
+
computedAt: string;
|
|
645
|
+
matchToleranceSec: number;
|
|
646
|
+
matched: LiveComparisonMatch[];
|
|
647
|
+
unmatchedLive: Array<{
|
|
648
|
+
positionId: string;
|
|
649
|
+
symbol: string;
|
|
650
|
+
type: "buy" | "sell";
|
|
651
|
+
openTime: string;
|
|
652
|
+
net: number;
|
|
653
|
+
}>;
|
|
654
|
+
unmatchedSim: Array<{
|
|
655
|
+
positionId: string;
|
|
656
|
+
symbol: string;
|
|
657
|
+
type: "buy" | "sell";
|
|
658
|
+
openTime: string;
|
|
659
|
+
net: number;
|
|
660
|
+
}>;
|
|
661
|
+
summary: LiveComparisonSummary;
|
|
662
|
+
equity: {
|
|
663
|
+
live: Array<{
|
|
664
|
+
t: string;
|
|
665
|
+
equity: number;
|
|
666
|
+
}>;
|
|
667
|
+
sim: Array<{
|
|
668
|
+
t: string;
|
|
669
|
+
equity: number;
|
|
670
|
+
}>;
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
interface RunLiveComparisonBody {
|
|
674
|
+
/** YYYY-MM-DD. */
|
|
675
|
+
from: string;
|
|
676
|
+
/** YYYY-MM-DD, after `from`. */
|
|
677
|
+
to: string;
|
|
678
|
+
}
|
|
679
|
+
type MonitorVerdict = "OK" | "DECAY" | "SLIPPAGE" | "NO_LIVE_TRADES" | "FAILED";
|
|
680
|
+
/** A deployment's scheduled re-backtest against its live trades. */
|
|
681
|
+
interface MonitorStatus {
|
|
682
|
+
deploymentId: string;
|
|
683
|
+
enabled: boolean;
|
|
684
|
+
windowDays: number;
|
|
685
|
+
lastCheckedAt: string | null;
|
|
686
|
+
lastGroupId: string | null;
|
|
687
|
+
verdict: MonitorVerdict | null;
|
|
688
|
+
detail: string | null;
|
|
689
|
+
liveNet: number | null;
|
|
690
|
+
simNet: number | null;
|
|
691
|
+
simP5Net: number | null;
|
|
692
|
+
simP95Net: number | null;
|
|
693
|
+
medianSlippagePts: number | null;
|
|
694
|
+
}
|
|
695
|
+
interface SetMonitorBody {
|
|
696
|
+
enabled: boolean;
|
|
697
|
+
/** 7..365; default 30, and kept when omitted on an update. */
|
|
698
|
+
windowDays?: number;
|
|
699
|
+
}
|
|
338
700
|
interface CreateEaBody {
|
|
339
701
|
name: string;
|
|
340
702
|
slug?: string;
|
|
@@ -363,6 +725,8 @@ interface ListDeploymentsResult {
|
|
|
363
725
|
interface PresignEaVersionBody {
|
|
364
726
|
version: string;
|
|
365
727
|
sourceType: EaSourceType;
|
|
728
|
+
/** Lowercase hex SHA-256 of the file. Required for EX5: the upload must
|
|
729
|
+
* then send it, base64, as `x-amz-checksum-sha256`. */
|
|
366
730
|
sha256?: string;
|
|
367
731
|
sizeBytes: number;
|
|
368
732
|
contentType?: string;
|
|
@@ -376,6 +740,7 @@ interface RegisterEaVersionBody {
|
|
|
376
740
|
r2Key: string;
|
|
377
741
|
version: string;
|
|
378
742
|
sourceType: EaSourceType;
|
|
743
|
+
/** Required for EX5, the same value given to `presignVersion`. */
|
|
379
744
|
sha256?: string;
|
|
380
745
|
sizeBytes?: number;
|
|
381
746
|
}
|
|
@@ -423,9 +788,16 @@ interface UpdateDeploymentBody {
|
|
|
423
788
|
timeframe?: EaTimeframe;
|
|
424
789
|
setBlob?: string | null;
|
|
425
790
|
}
|
|
791
|
+
/** A broker order in the broker's own fields (Dhan: `securityId`,
|
|
792
|
+
* `exchangeSegment`, `transactionType`, `quantity`, `orderType`,
|
|
793
|
+
* `productType`…; Motilal: `exchange`, `symboltoken`, `buyorsell`,
|
|
794
|
+
* `quantityinlot`…), forwarded to the broker as it is. */
|
|
795
|
+
type BrokerOrder = Record<string, unknown>;
|
|
796
|
+
/** @deprecated Pass the order itself. `{ order }` is still unwrapped for you. */
|
|
426
797
|
interface BrokerOrderBody {
|
|
427
798
|
order: Record<string, unknown>;
|
|
428
799
|
}
|
|
800
|
+
/** @deprecated Pass the changes themselves. `{ changes }` is still unwrapped for you. */
|
|
429
801
|
interface BrokerModifyOrderBody {
|
|
430
802
|
changes: Record<string, unknown>;
|
|
431
803
|
}
|
|
@@ -450,10 +822,63 @@ interface BrokerUnsubscribeBody {
|
|
|
450
822
|
interface BrokerCandlesQuery {
|
|
451
823
|
[key: string]: string | number | boolean | undefined;
|
|
452
824
|
}
|
|
453
|
-
type
|
|
825
|
+
type DhanSegment = "IDX_I" | "NSE_EQ" | "NSE_FNO" | "NSE_CURRENCY" | "BSE_EQ" | "MCX_COMM" | "BSE_FNO" | "BSE_CURRENCY";
|
|
826
|
+
/** Name the underlying by Dhan security id and segment, or by symbol. */
|
|
827
|
+
type DhanUnderlying = {
|
|
828
|
+
underlyingSecurityId: string;
|
|
829
|
+
underlyingSegment: DhanSegment;
|
|
830
|
+
} | {
|
|
831
|
+
underlyingSymbol: string;
|
|
832
|
+
};
|
|
833
|
+
interface DhanOptionLeg {
|
|
834
|
+
securityId?: string;
|
|
835
|
+
averagePrice?: number;
|
|
836
|
+
ltp: number;
|
|
837
|
+
volume: number;
|
|
838
|
+
oi: number;
|
|
839
|
+
previousClosePrice?: number;
|
|
840
|
+
previousOi?: number;
|
|
841
|
+
previousVolume?: number;
|
|
842
|
+
topAskPrice?: number;
|
|
843
|
+
topAskQuantity?: number;
|
|
844
|
+
topBidPrice?: number;
|
|
845
|
+
topBidQuantity?: number;
|
|
846
|
+
impliedVolatility?: number;
|
|
847
|
+
/** Same value as `impliedVolatility`. */
|
|
848
|
+
iv?: number;
|
|
849
|
+
delta?: number;
|
|
850
|
+
gamma?: number;
|
|
851
|
+
theta?: number;
|
|
852
|
+
vega?: number;
|
|
853
|
+
}
|
|
854
|
+
/** Dhan's option chain as Dhan reports it, through your own connection. */
|
|
855
|
+
interface DhanOptionChain {
|
|
856
|
+
underlyingSecurityId: string;
|
|
857
|
+
underlyingSegment: DhanSegment;
|
|
858
|
+
expiry: string;
|
|
859
|
+
spot: number;
|
|
860
|
+
/** In Dhan's order, not sorted. */
|
|
861
|
+
strikes: Array<{
|
|
862
|
+
strike: number;
|
|
863
|
+
ce?: DhanOptionLeg;
|
|
864
|
+
pe?: DhanOptionLeg;
|
|
865
|
+
}>;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* @deprecated `orders` is retired: the server refuses it in the `subscribed`
|
|
869
|
+
* reply's `refusedChannels`. Follow MT5 orders on `trading.orders`, or as raw
|
|
870
|
+
* `trade_event` frames on `trades`. Kept in `WSChannel` so existing code compiles.
|
|
871
|
+
*/
|
|
872
|
+
type RetiredWSChannel = "orders";
|
|
873
|
+
/** A `/ws/service` channel. `orders` is retired (see `RetiredWSChannel`). */
|
|
874
|
+
type WSChannel = "ticks" | "candles" | "positions" | "trades" | RetiredWSChannel | "broker_ticks" | "broker_orders" | "market.ticks" | "market.candles" | "market.chain" | "market.scanner" | "trading.orders";
|
|
454
875
|
interface WSSubscribeOptions {
|
|
455
876
|
channels: WSChannel[];
|
|
877
|
+
/** MT5 logins to receive MT5 frames for (empty: every terminal you own).
|
|
878
|
+
* Applies once a subscribe has accepted one of `ticks`, `candles`,
|
|
879
|
+
* `positions` or `trades`; before that every MT5 frame of the account arrives. */
|
|
456
880
|
accountIds?: string[];
|
|
881
|
+
/** Narrows `ticks` and `candles` to these MT5 symbols (empty: every symbol). */
|
|
457
882
|
symbols?: string[];
|
|
458
883
|
brokerConnectionIds?: string[];
|
|
459
884
|
brokerSecurityKeys?: string[];
|
|
@@ -470,13 +895,20 @@ interface WSSubscribeOptions {
|
|
|
470
895
|
* deployment-wide each refreshes about every N x 3.2 s. */
|
|
471
896
|
chains?: ChainSelector[];
|
|
472
897
|
}
|
|
898
|
+
interface WSUnsubscribeOptions {
|
|
899
|
+
channels?: WSChannel[];
|
|
900
|
+
/** Drop just these keys; the channels stay subscribed. */
|
|
901
|
+
instrumentKeys?: string[];
|
|
902
|
+
/** Drop just these chains; `market.chain` stays subscribed. */
|
|
903
|
+
chains?: ChainSelector[];
|
|
904
|
+
}
|
|
473
905
|
/** One option chain on the `market.chain` channel. */
|
|
474
906
|
interface ChainSelector {
|
|
475
907
|
underlyingKey: string;
|
|
476
908
|
/** YYYY-MM-DD. */
|
|
477
909
|
expiry: string;
|
|
478
910
|
}
|
|
479
|
-
type UnifiedInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "1d";
|
|
911
|
+
type UnifiedInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "4h" | "1d";
|
|
480
912
|
interface UnifiedCandle {
|
|
481
913
|
ts: number;
|
|
482
914
|
o: number;
|
|
@@ -602,29 +1034,183 @@ type TradingOrderMessage = UnifiedOrder & {
|
|
|
602
1034
|
eventTs: number;
|
|
603
1035
|
sequence: number;
|
|
604
1036
|
};
|
|
1037
|
+
/** `tick` WS message (channel `ticks`): one MT5 bid/ask from a terminal the
|
|
1038
|
+
* account owns, also narrowed by `symbols`. Once a subscribe has accepted one of
|
|
1039
|
+
* `ticks`, `candles`, `positions` or `trades`, only the channels named arrive,
|
|
1040
|
+
* narrowed by `accountIds`; until then every MT5 frame of the account does. */
|
|
605
1041
|
interface MT5Tick {
|
|
606
|
-
type: "
|
|
1042
|
+
type: "tick";
|
|
1043
|
+
/** The MT5 login. */
|
|
607
1044
|
accountId: string;
|
|
608
1045
|
symbol: string;
|
|
609
1046
|
bid: number;
|
|
610
1047
|
ask: number;
|
|
1048
|
+
/** Terminal time of the tick (epoch ms). */
|
|
611
1049
|
ts: number;
|
|
1050
|
+
/** When Atlaas received it (epoch ms). */
|
|
612
1051
|
timestamp: number;
|
|
1052
|
+
runnerId?: string;
|
|
613
1053
|
}
|
|
1054
|
+
/** `candle` WS message (channel `candles`): one bar from a terminal's candle
|
|
1055
|
+
* subscription, also narrowed by `symbols`. Once a subscribe has accepted one of
|
|
1056
|
+
* `ticks`, `candles`, `positions` or `trades`, only the channels named arrive,
|
|
1057
|
+
* narrowed by `accountIds`; until then every MT5 frame of the account does. */
|
|
614
1058
|
interface MT5Candle {
|
|
615
|
-
type: "
|
|
1059
|
+
type: "candle";
|
|
616
1060
|
accountId: string;
|
|
617
1061
|
symbol: string;
|
|
1062
|
+
/** MT5 timeframe as the subscription named it (e.g. `M1`, `H1`). */
|
|
618
1063
|
timeframe: string;
|
|
1064
|
+
/** Bar open time (epoch ms). */
|
|
619
1065
|
time: number;
|
|
620
1066
|
open: number;
|
|
621
1067
|
high: number;
|
|
622
1068
|
low: number;
|
|
623
1069
|
close: number;
|
|
624
1070
|
volume: number;
|
|
1071
|
+
/** True on the first update of a new bar. */
|
|
625
1072
|
isNew?: boolean;
|
|
626
1073
|
ts: number;
|
|
627
1074
|
timestamp: number;
|
|
1075
|
+
runnerId?: string;
|
|
1076
|
+
}
|
|
1077
|
+
/** One open MT5 position inside a `position_update` message. */
|
|
1078
|
+
interface MT5LivePosition {
|
|
1079
|
+
ticket: number;
|
|
1080
|
+
/** POSITION_IDENTIFIER, the id deals carry; differs from the ticket after a
|
|
1081
|
+
* netting reversal. Absent from older connector EAs. */
|
|
1082
|
+
identifier?: number;
|
|
1083
|
+
symbol: string;
|
|
1084
|
+
/** `BUY` or `SELL`, as the terminal reports it. */
|
|
1085
|
+
type: string;
|
|
1086
|
+
volume: number;
|
|
1087
|
+
openPrice: number;
|
|
1088
|
+
currentPrice: number;
|
|
1089
|
+
sl: number;
|
|
1090
|
+
tp: number;
|
|
1091
|
+
profit: number;
|
|
1092
|
+
swap: number;
|
|
1093
|
+
openTime: number;
|
|
1094
|
+
/** 0 is a manual trade. Absent from older connector EAs. */
|
|
1095
|
+
magic?: number;
|
|
1096
|
+
comment?: string;
|
|
1097
|
+
digits?: number;
|
|
1098
|
+
point?: number;
|
|
1099
|
+
volumeMin?: number;
|
|
1100
|
+
volumeStep?: number;
|
|
1101
|
+
}
|
|
1102
|
+
/** `position_update` WS message: the terminal's open positions and funds,
|
|
1103
|
+
* pushed by the EA (channel `positions`). Once a subscribe has accepted one of
|
|
1104
|
+
* `ticks`, `candles`, `positions` or `trades`, only the channels named arrive,
|
|
1105
|
+
* narrowed by `accountIds`; until then every MT5 frame of the account does. */
|
|
1106
|
+
interface MT5PositionUpdate {
|
|
1107
|
+
type: "position_update";
|
|
1108
|
+
accountId: string;
|
|
1109
|
+
balance: number;
|
|
1110
|
+
equity: number;
|
|
1111
|
+
margin: number;
|
|
1112
|
+
freeMargin: number;
|
|
1113
|
+
positions: MT5LivePosition[];
|
|
1114
|
+
ts: number;
|
|
1115
|
+
/** Absent from runners that send the compact frame (0.90.3 and later). */
|
|
1116
|
+
timestamp?: number;
|
|
1117
|
+
}
|
|
1118
|
+
/** `trade_event` WS message: one MT5 trade transaction (order or deal) as the
|
|
1119
|
+
* terminal reported it (channel `trades`). Once a subscribe has accepted one of
|
|
1120
|
+
* `ticks`, `candles`, `positions` or `trades`, only the channels named arrive,
|
|
1121
|
+
* narrowed by `accountIds`; until then every MT5 frame of the account does. */
|
|
1122
|
+
interface MT5TradeEvent {
|
|
1123
|
+
type: "trade_event";
|
|
1124
|
+
accountId: string;
|
|
1125
|
+
/** MQL5 TRADE_TRANSACTION_* name. */
|
|
1126
|
+
transType: string;
|
|
1127
|
+
symbol: string;
|
|
1128
|
+
order: number;
|
|
1129
|
+
orderType: string;
|
|
1130
|
+
orderState: string;
|
|
1131
|
+
dealType: string;
|
|
1132
|
+
deal: number;
|
|
1133
|
+
volume: number;
|
|
1134
|
+
price: number;
|
|
1135
|
+
sl: number;
|
|
1136
|
+
tp: number;
|
|
1137
|
+
ts: number;
|
|
1138
|
+
timestamp: number;
|
|
1139
|
+
}
|
|
1140
|
+
/** `heartbeat` WS message: the EA's periodic heartbeat with the account's
|
|
1141
|
+
* balance and equity. On no channel: it follows `accountIds` once MT5
|
|
1142
|
+
* channels are chosen, and otherwise reaches every socket of the account. */
|
|
1143
|
+
interface MT5Heartbeat {
|
|
1144
|
+
type: "heartbeat";
|
|
1145
|
+
runnerId: string;
|
|
1146
|
+
accountId: string;
|
|
1147
|
+
balance?: number;
|
|
1148
|
+
equity?: number;
|
|
1149
|
+
ts: number;
|
|
1150
|
+
timestamp: number;
|
|
1151
|
+
}
|
|
1152
|
+
/** `market.chain` WS message: a full option chain for one subscribed
|
|
1153
|
+
* (underlying, expiry) pair. */
|
|
1154
|
+
type MarketChainMessage = UnifiedOptionChain & {
|
|
1155
|
+
type: "market.chain";
|
|
1156
|
+
};
|
|
1157
|
+
/** `market.scanner` WS message: the whole NSE scanner board, the same one
|
|
1158
|
+
* `v2.scanner.board()` returns, plus `append`. */
|
|
1159
|
+
type MarketScannerMessage = Omit<ScannerBoard, "paths" | "pathsFrom"> & {
|
|
1160
|
+
type: "market.scanner";
|
|
1161
|
+
/** Each stock's move since the session open, in basis points, for the
|
|
1162
|
+
* minute just computed: append it to the paths you hold. */
|
|
1163
|
+
append: Record<string, number>;
|
|
1164
|
+
};
|
|
1165
|
+
type MarketFeedState = "unconfigured" | "disabled" | "connecting" | "connected" | "disconnected";
|
|
1166
|
+
/** Why an `instrumentKeys` entry was left out of a subscription. */
|
|
1167
|
+
type RefusedInstrumentKeyReason = "account_quota" | "capacity" | "unsupported" | "india_entitlement" | "no_account";
|
|
1168
|
+
/** `subscribed` WS reply: what the subscription now holds. Anything refused
|
|
1169
|
+
* is named here rather than accepted and never delivered. */
|
|
1170
|
+
interface SubscribedMessage {
|
|
1171
|
+
type: "subscribed";
|
|
1172
|
+
/** The channels this subscribe accepted. */
|
|
1173
|
+
channels: WSChannel[];
|
|
1174
|
+
/** Channels refused, with the reason: `"trading.orders (needs orders:r)"`,
|
|
1175
|
+
* `"market.scanner (needs the india entitlement)"`, `"orders (retired: use trading.orders)"`. */
|
|
1176
|
+
refusedChannels?: string[];
|
|
1177
|
+
refusedInstrumentKeys?: Array<{
|
|
1178
|
+
instrumentKey: string;
|
|
1179
|
+
reason: RefusedInstrumentKeyReason;
|
|
1180
|
+
}>;
|
|
1181
|
+
/** The per-account instrument limit, sent with `refusedInstrumentKeys`. */
|
|
1182
|
+
instrumentKeyLimit?: number;
|
|
1183
|
+
/** Ids the key's account does not own. */
|
|
1184
|
+
refusedAccountIds?: string[];
|
|
1185
|
+
refusedBrokerConnectionIds?: string[];
|
|
1186
|
+
refusedBrokerOrderConnectionIds?: string[];
|
|
1187
|
+
/** The whole filter after this subscribe, across every subscribe on the socket. */
|
|
1188
|
+
accountIds: string[];
|
|
1189
|
+
symbols: string[];
|
|
1190
|
+
brokerConnectionIds: string[];
|
|
1191
|
+
brokerSecurityKeys: string[];
|
|
1192
|
+
brokerOrderConnectionIds: string[];
|
|
1193
|
+
instrumentKeys: string[];
|
|
1194
|
+
/** Subscribed chains as `"<underlyingKey>|<expiry>"`. */
|
|
1195
|
+
chains: string[];
|
|
1196
|
+
/** State of the Atlaas market data feed that serves NSE/BSE keys. */
|
|
1197
|
+
feed: MarketFeedState;
|
|
1198
|
+
ts: number;
|
|
1199
|
+
}
|
|
1200
|
+
/** `subscribe_failed` WS reply: the account is inactive, suspended or out of
|
|
1201
|
+
* credits (or could not be checked), so the subscribe changed nothing. What
|
|
1202
|
+
* the socket already subscribed to keeps streaming. */
|
|
1203
|
+
interface SubscribeFailedMessage {
|
|
1204
|
+
type: "subscribe_failed";
|
|
1205
|
+
/** E.g. `Account is inactive`, `Account is suspended`, `Account has no credits remaining`. */
|
|
1206
|
+
reason: string;
|
|
1207
|
+
ts: number;
|
|
1208
|
+
}
|
|
1209
|
+
/** `unsubscribed` WS reply. */
|
|
1210
|
+
interface UnsubscribedMessage {
|
|
1211
|
+
type: "unsubscribed";
|
|
1212
|
+
channels: WSChannel[];
|
|
1213
|
+
ts: number;
|
|
628
1214
|
}
|
|
629
1215
|
interface BrokerTick {
|
|
630
1216
|
type: "broker_tick";
|
|
@@ -649,12 +1235,13 @@ interface BrokerOrderUpdate {
|
|
|
649
1235
|
* Standalone copy, field-for-field — the SDK does not import contracts. */
|
|
650
1236
|
interface UnifiedInstrument {
|
|
651
1237
|
instrumentKey: string;
|
|
652
|
-
exchange: "NSE" | "BSE" | "MCX" | "FX";
|
|
653
|
-
segment: "EQ" | "FNO" | "IDX" | "CDS" | "COMM" | "FX";
|
|
1238
|
+
exchange: "NSE" | "BSE" | "MCX" | "FX" | "US" | "CRYPTO";
|
|
1239
|
+
segment: "EQ" | "FNO" | "IDX" | "CDS" | "COMM" | "FX" | "SPOT" | "PERP";
|
|
654
1240
|
symbol: string;
|
|
655
1241
|
name?: string;
|
|
656
1242
|
isin?: string;
|
|
657
|
-
instrumentType: "EQUITY" | "INDEX" | "FUTIDX" | "FUTSTK" | "OPTIDX" | "OPTSTK" | "FUTCOM" | "OPTCOM" | "FUTCUR" | "OPTCUR" | "FOREX";
|
|
1243
|
+
instrumentType: "EQUITY" | "INDEX" | "FUTIDX" | "FUTSTK" | "OPTIDX" | "OPTSTK" | "FUTCOM" | "OPTCOM" | "FUTCUR" | "OPTCUR" | "FOREX" | "CRYPTO_SPOT" | "CRYPTO_PERP";
|
|
1244
|
+
/** YYYY-MM-DD, derivatives only. */
|
|
658
1245
|
expiry?: string;
|
|
659
1246
|
strike?: number;
|
|
660
1247
|
optionType?: "CE" | "PE";
|
|
@@ -681,8 +1268,21 @@ interface UnifiedInstrument {
|
|
|
681
1268
|
symbol: string;
|
|
682
1269
|
server?: string;
|
|
683
1270
|
};
|
|
1271
|
+
/** Brokers synced from their own masters: `refId` is the broker's own
|
|
1272
|
+
* instrument id (Angel One / Shoonya token, Fyers symbol, Upstox
|
|
1273
|
+
* instrument_key), `segment` its exchange code. */
|
|
1274
|
+
angelone?: BrokerInstrumentRef;
|
|
1275
|
+
fyers?: BrokerInstrumentRef;
|
|
1276
|
+
upstox?: BrokerInstrumentRef;
|
|
1277
|
+
shoonya?: BrokerInstrumentRef;
|
|
684
1278
|
};
|
|
685
1279
|
}
|
|
1280
|
+
/** One broker's own id for an instrument (Angel One, Fyers, Upstox, Shoonya). */
|
|
1281
|
+
interface BrokerInstrumentRef {
|
|
1282
|
+
refId: string;
|
|
1283
|
+
segment?: string;
|
|
1284
|
+
tradingsymbol?: string;
|
|
1285
|
+
}
|
|
686
1286
|
/** Mirror of @atlaas/contracts UnifiedOrder (packages/contracts/src/schemas.ts).
|
|
687
1287
|
* Standalone copy, field-for-field — the SDK does not import contracts. */
|
|
688
1288
|
interface UnifiedOrder {
|
|
@@ -749,6 +1349,26 @@ interface UnifiedPosition {
|
|
|
749
1349
|
magic?: number;
|
|
750
1350
|
openTime?: number;
|
|
751
1351
|
};
|
|
1352
|
+
/** Margined crypto positions (perpetuals): what the exchange reports about
|
|
1353
|
+
* the leverage behind the position. Each venue reports a different subset. */
|
|
1354
|
+
margin?: {
|
|
1355
|
+
leverage?: number;
|
|
1356
|
+
liquidationPrice?: number;
|
|
1357
|
+
mode?: "CROSS" | "ISOLATED";
|
|
1358
|
+
/** Margin locked by the position, in its settlement asset. */
|
|
1359
|
+
used?: number;
|
|
1360
|
+
};
|
|
1361
|
+
/** Perpetuals only: the venue's current funding rate, a fraction per
|
|
1362
|
+
* funding interval (0.0001 = 0.01%). A positive rate means longs pay shorts. */
|
|
1363
|
+
funding?: {
|
|
1364
|
+
rate: number;
|
|
1365
|
+
/** When the current rate is next charged (epoch ms). */
|
|
1366
|
+
nextFundingTime?: number;
|
|
1367
|
+
intervalHours?: number;
|
|
1368
|
+
/** The next payment at the current rate and mark, in the settlement
|
|
1369
|
+
* asset: negative when the position pays, positive when it receives. */
|
|
1370
|
+
estimatedPayment?: number;
|
|
1371
|
+
};
|
|
752
1372
|
raw?: unknown;
|
|
753
1373
|
}
|
|
754
1374
|
/** Mirror of @atlaas/contracts UnifiedHolding (packages/contracts/src/schemas.ts).
|
|
@@ -797,8 +1417,9 @@ interface UnifiedProfile {
|
|
|
797
1417
|
}
|
|
798
1418
|
/** Mirror of @atlaas/contracts UnifiedError (packages/contracts/src/errors.ts).
|
|
799
1419
|
* Standalone copy, field-for-field — the SDK does not import contracts. */
|
|
1420
|
+
type UnifiedErrorCode = "BROKER_REJECTED" | "OUTCOME_UNKNOWN" | "UNSUPPORTED_CAPABILITY" | "INSTRUMENT_UNRESOLVED" | "SESSION_DOWN" | "RATE_LIMITED" | "VALIDATION" | "FEED_UNAVAILABLE" | "TIMEZONE_UNCONFIGURED" | "IDEMPOTENCY_IN_PROGRESS" | "IDEMPOTENCY_KEY_REUSED" | "IDEMPOTENCY_UNAVAILABLE";
|
|
800
1421
|
interface UnifiedError {
|
|
801
|
-
code:
|
|
1422
|
+
code: UnifiedErrorCode;
|
|
802
1423
|
message: string;
|
|
803
1424
|
brokerCode?: string;
|
|
804
1425
|
raw?: unknown;
|
|
@@ -810,6 +1431,21 @@ interface DroppedRow {
|
|
|
810
1431
|
reason: "INSTRUMENT_UNRESOLVED" | "UNMAPPABLE";
|
|
811
1432
|
refId: string;
|
|
812
1433
|
detail?: string;
|
|
1434
|
+
/** MT5 only: the open position or pending order behind the dropped row,
|
|
1435
|
+
* so a client that cannot place it under an instrument still sees it is
|
|
1436
|
+
* there and can close it by ticket. */
|
|
1437
|
+
mt5?: DroppedMt5Row;
|
|
1438
|
+
}
|
|
1439
|
+
/** Mirror of @atlaas/broker DroppedMt5Row: what the terminal reported for a
|
|
1440
|
+
* dropped MT5 row, as the terminal spells it. */
|
|
1441
|
+
interface DroppedMt5Row {
|
|
1442
|
+
ticket: number;
|
|
1443
|
+
/** The terminal's own symbol (e.g. `XAUUSD.r`). */
|
|
1444
|
+
symbol: string;
|
|
1445
|
+
/** MT5 volume. Absent when the terminal sent none. */
|
|
1446
|
+
lots?: number;
|
|
1447
|
+
/** MT5 direction: a BUY position is long, a SELL position short. Absent for an order type Atlas does not map. */
|
|
1448
|
+
side?: "BUY" | "SELL";
|
|
813
1449
|
}
|
|
814
1450
|
/** Mirror of @atlaas/broker BrokerCapabilities (packages/broker/src/normalizers/capabilities.ts).
|
|
815
1451
|
* Standalone copy, field-for-field — the SDK does not import broker. */
|
|
@@ -823,6 +1459,8 @@ interface BrokerCapabilities {
|
|
|
823
1459
|
candles: "native" | "feed" | "none";
|
|
824
1460
|
holdings: boolean;
|
|
825
1461
|
amo: boolean;
|
|
1462
|
+
/** Accepts a non-integer `quantity` (crypto amounts, fractional shares). */
|
|
1463
|
+
fractionalQuantity: boolean;
|
|
826
1464
|
}
|
|
827
1465
|
/** POST /api/v2/connections/:id/orders. Size it in `quantity` (units; Atlas
|
|
828
1466
|
* converts to MOFSL lots / MT5 volume and fails closed on a non-multiple) or
|
|
@@ -846,6 +1484,10 @@ interface PlaceOrderV2Body {
|
|
|
846
1484
|
validity?: "DAY" | "IOC" | "GTC" | "GTD" | "TTL";
|
|
847
1485
|
/** Sanitized per broker (Dhan 30, Kite 20, MOFSL 10 chars). */
|
|
848
1486
|
clientTag?: string;
|
|
1487
|
+
/** MT5 only: the terminal's own symbol to trade (`XAUUSD.r`), for when the
|
|
1488
|
+
* terminal lists several spellings of the instrument. It must be listed on
|
|
1489
|
+
* the terminal and be a spelling of `instrumentKey`; other brokers refuse it. */
|
|
1490
|
+
symbol?: string;
|
|
849
1491
|
/** Synthetic MARKET (Motilal) chase policy. Defaults { maxDriftPct: 1, maxReprices: 3, timeoutMs: 60000 }. */
|
|
850
1492
|
chase?: {
|
|
851
1493
|
maxDriftPct?: number;
|
|
@@ -893,10 +1535,12 @@ interface PlaceOrderResult {
|
|
|
893
1535
|
connectionId: string;
|
|
894
1536
|
instrumentKey: string;
|
|
895
1537
|
broker: string;
|
|
896
|
-
/** Units. Omitted only for an MT5 order placed by `lots` on a symbol
|
|
1538
|
+
/** Units. Omitted only for an MT5 order placed by `lots` on a symbol whose contract size the terminal has not reported. */
|
|
897
1539
|
quantity?: number;
|
|
898
1540
|
/** MOFSL lots / MT5 volume actually sent. */
|
|
899
1541
|
lots?: number;
|
|
1542
|
+
/** MT5: the terminal symbol the order went to. */
|
|
1543
|
+
symbol?: string;
|
|
900
1544
|
/** Set when the order was synthesized as a chased LIMIT. */
|
|
901
1545
|
synthetic?: {
|
|
902
1546
|
restingPrice: number;
|
|
@@ -984,6 +1628,1153 @@ interface V2Snapshot {
|
|
|
984
1628
|
};
|
|
985
1629
|
};
|
|
986
1630
|
}
|
|
1631
|
+
type ScannerSessionState = "pre" | "live" | "closed" | "holiday";
|
|
1632
|
+
interface ScannerSession {
|
|
1633
|
+
/** IST trading date, YYYY-MM-DD. */
|
|
1634
|
+
date: string;
|
|
1635
|
+
state: ScannerSessionState;
|
|
1636
|
+
/** Session minute since 09:15 IST. */
|
|
1637
|
+
minute: number;
|
|
1638
|
+
}
|
|
1639
|
+
interface ScannerRow {
|
|
1640
|
+
instrumentKey: string;
|
|
1641
|
+
symbol: string;
|
|
1642
|
+
sector: string;
|
|
1643
|
+
ltp: number;
|
|
1644
|
+
prevClose: number;
|
|
1645
|
+
/** % change from the previous close. */
|
|
1646
|
+
pct: number;
|
|
1647
|
+
/** % move from the session open. */
|
|
1648
|
+
move: number;
|
|
1649
|
+
hiMove: number;
|
|
1650
|
+
loMove: number;
|
|
1651
|
+
/** 1 bullish, -1 bearish. */
|
|
1652
|
+
side: 1 | -1;
|
|
1653
|
+
strength: number;
|
|
1654
|
+
conviction: number;
|
|
1655
|
+
/** Rank within its side. */
|
|
1656
|
+
sideRank: number;
|
|
1657
|
+
/** Rank among the picks on its side; null when not a pick. */
|
|
1658
|
+
pickRank: number | null;
|
|
1659
|
+
rankDelta: number;
|
|
1660
|
+
percentile: number;
|
|
1661
|
+
/** % change in open interest from the previous day; null without a future. */
|
|
1662
|
+
oiChgPct: number | null;
|
|
1663
|
+
/** Session minutes where an order block formed. */
|
|
1664
|
+
obMinutes: number[];
|
|
1665
|
+
}
|
|
1666
|
+
interface ScannerBoard {
|
|
1667
|
+
/** When the board was computed (ISO 8601). */
|
|
1668
|
+
asOf: string;
|
|
1669
|
+
session: ScannerSession;
|
|
1670
|
+
/** How many stocks were ranked. */
|
|
1671
|
+
universe: number;
|
|
1672
|
+
breadth: {
|
|
1673
|
+
up: number;
|
|
1674
|
+
down: number;
|
|
1675
|
+
bullish: number;
|
|
1676
|
+
bearish: number;
|
|
1677
|
+
medianPct: number;
|
|
1678
|
+
};
|
|
1679
|
+
sectors: Array<{
|
|
1680
|
+
name: string;
|
|
1681
|
+
avgPct: number;
|
|
1682
|
+
avgMove: number;
|
|
1683
|
+
up: number;
|
|
1684
|
+
down: number;
|
|
1685
|
+
}>;
|
|
1686
|
+
rows: ScannerRow[];
|
|
1687
|
+
/** instrumentKeys of the picks on each side. */
|
|
1688
|
+
picks: {
|
|
1689
|
+
bullish: string[];
|
|
1690
|
+
bearish: string[];
|
|
1691
|
+
};
|
|
1692
|
+
/** Move in basis points per session minute since 09:15, per instrumentKey. Only with `paths: true`. */
|
|
1693
|
+
paths?: Record<string, number[]>;
|
|
1694
|
+
/** First minute index in each `paths` array, when `after` was given. */
|
|
1695
|
+
pathsFrom?: number;
|
|
1696
|
+
}
|
|
1697
|
+
interface ScannerZones {
|
|
1698
|
+
instrumentKey: string;
|
|
1699
|
+
interval: "5m";
|
|
1700
|
+
asOf: string;
|
|
1701
|
+
/** The last two sessions of 5m bars. */
|
|
1702
|
+
bars: UnifiedCandle[];
|
|
1703
|
+
/** Session VWAP per bar. */
|
|
1704
|
+
vwap: number[];
|
|
1705
|
+
zones: Array<{
|
|
1706
|
+
side: 1 | -1;
|
|
1707
|
+
formedAt: string;
|
|
1708
|
+
top: number;
|
|
1709
|
+
bot: number;
|
|
1710
|
+
mitigatedAt: string | null;
|
|
1711
|
+
}>;
|
|
1712
|
+
/** Index into `zones` of the active zone. */
|
|
1713
|
+
active: number;
|
|
1714
|
+
/** The entry reference inside the active zone. */
|
|
1715
|
+
z: number;
|
|
1716
|
+
stops: Array<{
|
|
1717
|
+
price: number;
|
|
1718
|
+
formedAt: string;
|
|
1719
|
+
}>;
|
|
1720
|
+
targets: Array<{
|
|
1721
|
+
price: number;
|
|
1722
|
+
formedAt: string;
|
|
1723
|
+
}>;
|
|
1724
|
+
rr: number;
|
|
1725
|
+
riskPct: number;
|
|
1726
|
+
liquidity: Array<{
|
|
1727
|
+
price: number;
|
|
1728
|
+
formedAt: string;
|
|
1729
|
+
kind: "swingHigh" | "swingLow";
|
|
1730
|
+
}>;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
type BacktestTickMode = "EVERY_TICK" | "M1_OHLC" | "OPEN_PRICES" | "REAL_TICKS";
|
|
1734
|
+
type BacktestStatus = "QUEUED" | "CLAIMED" | "RUNNING" | "DONE" | "FAILED" | "CANCELED";
|
|
1735
|
+
type BacktestWindow = "FULL" | "IS" | "OOS" | "WF_IS" | "WF_OOS";
|
|
1736
|
+
type BacktestRunMode = "SINGLE" | "OPTIMIZE" | "SPEC";
|
|
1737
|
+
type BacktestExecutor = "ATLAS_OPERATED" | "SELF_HOSTED";
|
|
1738
|
+
type BacktestGroupKind = "SINGLE" | "OPTIMIZATION" | "WALK_FORWARD";
|
|
1739
|
+
type BacktestBatchKind = "SYMBOLS" | "NOISE" | "WF_MATRIX";
|
|
1740
|
+
type OptimizationAlgorithm = "COMPLETE" | "GENETIC";
|
|
1741
|
+
type OptimizationCriterion = "BALANCE" | "PROFIT_FACTOR" | "EXPECTED_PAYOFF" | "DRAWDOWN" | "RECOVERY_FACTOR" | "SHARPE" | "CUSTOM" | "COMPLEX";
|
|
1742
|
+
interface OptimizationRange {
|
|
1743
|
+
/** EA input name, as in the .set file. */
|
|
1744
|
+
name: string;
|
|
1745
|
+
start: number;
|
|
1746
|
+
step: number;
|
|
1747
|
+
stop: number;
|
|
1748
|
+
}
|
|
1749
|
+
interface OptimizationConfig {
|
|
1750
|
+
algorithm: OptimizationAlgorithm;
|
|
1751
|
+
criterion: OptimizationCriterion;
|
|
1752
|
+
ranges: OptimizationRange[];
|
|
1753
|
+
}
|
|
1754
|
+
interface WalkForwardConfig {
|
|
1755
|
+
/** 2..10 out-of-sample segments. */
|
|
1756
|
+
folds: number;
|
|
1757
|
+
/** In-sample length as a multiple of one out-of-sample segment, 1..10. */
|
|
1758
|
+
isRatio: number;
|
|
1759
|
+
/** Every in-sample window starts at fromDate; rolling otherwise. */
|
|
1760
|
+
anchored: boolean;
|
|
1761
|
+
}
|
|
1762
|
+
/** Tester report numbers. Fields after `finalEquity` are absent on older runs. */
|
|
1763
|
+
interface BacktestStats {
|
|
1764
|
+
initialDeposit: number;
|
|
1765
|
+
netProfit: number;
|
|
1766
|
+
grossProfit: number;
|
|
1767
|
+
grossLoss: number;
|
|
1768
|
+
profitFactor: number | null;
|
|
1769
|
+
expectedPayoff: number | null;
|
|
1770
|
+
recoveryFactor: number | null;
|
|
1771
|
+
sharpeRatio: number | null;
|
|
1772
|
+
balanceDrawdownAbs: number;
|
|
1773
|
+
balanceDrawdownMaxPct: number;
|
|
1774
|
+
equityDrawdownAbs: number;
|
|
1775
|
+
equityDrawdownMaxPct: number;
|
|
1776
|
+
totalTrades: number;
|
|
1777
|
+
totalDeals: number;
|
|
1778
|
+
shortTrades: number;
|
|
1779
|
+
longTrades: number;
|
|
1780
|
+
shortWinPct: number | null;
|
|
1781
|
+
longWinPct: number | null;
|
|
1782
|
+
profitTrades: number;
|
|
1783
|
+
lossTrades: number;
|
|
1784
|
+
winRatePct: number | null;
|
|
1785
|
+
largestProfitTrade: number;
|
|
1786
|
+
largestLossTrade: number;
|
|
1787
|
+
avgProfitTrade: number | null;
|
|
1788
|
+
avgLossTrade: number | null;
|
|
1789
|
+
maxConsecutiveWins: number;
|
|
1790
|
+
maxConsecutiveLosses: number;
|
|
1791
|
+
historyQualityPct: number | null;
|
|
1792
|
+
bars: number | null;
|
|
1793
|
+
ticks: number | null;
|
|
1794
|
+
finalBalance: number;
|
|
1795
|
+
finalEquity: number;
|
|
1796
|
+
balanceDrawdownMaximalAbs?: number | null;
|
|
1797
|
+
balanceDrawdownMaximalPct?: number | null;
|
|
1798
|
+
equityDrawdownMaximalAbs?: number | null;
|
|
1799
|
+
equityDrawdownMaximalPct?: number | null;
|
|
1800
|
+
zScore?: number | null;
|
|
1801
|
+
zScoreConfidencePct?: number | null;
|
|
1802
|
+
ahpr?: number | null;
|
|
1803
|
+
ghpr?: number | null;
|
|
1804
|
+
lrCorrelation?: number | null;
|
|
1805
|
+
lrStandardError?: number | null;
|
|
1806
|
+
marginLevelPct?: number | null;
|
|
1807
|
+
onTesterResult?: number | null;
|
|
1808
|
+
maxConsecutiveWinsMoney?: number | null;
|
|
1809
|
+
maxConsecutiveLossesMoney?: number | null;
|
|
1810
|
+
maximalConsecutiveProfit?: number | null;
|
|
1811
|
+
maximalConsecutiveProfitCount?: number | null;
|
|
1812
|
+
maximalConsecutiveLoss?: number | null;
|
|
1813
|
+
maximalConsecutiveLossCount?: number | null;
|
|
1814
|
+
avgConsecutiveWins?: number | null;
|
|
1815
|
+
avgConsecutiveLosses?: number | null;
|
|
1816
|
+
correlationProfitsMfe?: number | null;
|
|
1817
|
+
correlationProfitsMae?: number | null;
|
|
1818
|
+
correlationMfeMae?: number | null;
|
|
1819
|
+
minHoldingSec?: number | null;
|
|
1820
|
+
maxHoldingSec?: number | null;
|
|
1821
|
+
avgHoldingSec?: number | null;
|
|
1822
|
+
}
|
|
1823
|
+
/** How a position closed, read from the exit deal's comment. */
|
|
1824
|
+
type BacktestExitReason = "sl" | "tp" | "so" | "end" | "other";
|
|
1825
|
+
/** One closed position of a backtest. */
|
|
1826
|
+
interface BacktestTrade {
|
|
1827
|
+
positionId: string;
|
|
1828
|
+
symbol: string;
|
|
1829
|
+
type: "buy" | "sell";
|
|
1830
|
+
volume: number;
|
|
1831
|
+
openTime: string;
|
|
1832
|
+
openPrice: number;
|
|
1833
|
+
closeTime: string;
|
|
1834
|
+
closePrice: number;
|
|
1835
|
+
sl: number | null;
|
|
1836
|
+
tp: number | null;
|
|
1837
|
+
commission: number;
|
|
1838
|
+
swap: number;
|
|
1839
|
+
profit: number;
|
|
1840
|
+
durationSec: number;
|
|
1841
|
+
comment: string | null;
|
|
1842
|
+
exitComment?: string | null;
|
|
1843
|
+
exitReason?: BacktestExitReason | null;
|
|
1844
|
+
}
|
|
1845
|
+
interface BacktestAiSummary {
|
|
1846
|
+
generatedAt: string;
|
|
1847
|
+
/** The model id, or `atlas-rules` for the rule-based fallback. */
|
|
1848
|
+
model: string;
|
|
1849
|
+
headline: string;
|
|
1850
|
+
workedWell: string[];
|
|
1851
|
+
didNotWork: string[];
|
|
1852
|
+
redFlags: string[];
|
|
1853
|
+
tryNext: string[];
|
|
1854
|
+
}
|
|
1855
|
+
interface BacktestRedFlag {
|
|
1856
|
+
code: string;
|
|
1857
|
+
severity: "info" | "warn" | "critical";
|
|
1858
|
+
title: string;
|
|
1859
|
+
detail: string;
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Atlaas's analytics for a finished run. The summary sections are typed; the
|
|
1863
|
+
* long series (daily equity, underwater, rolling windows, distributions,
|
|
1864
|
+
* excursions, Monte Carlo fan) and the optional deeper sections (margin, swap,
|
|
1865
|
+
* sizing, baskets, news, pairs, arbitrage…) come through as they are stored.
|
|
1866
|
+
* `stats` and `walkForward` serve the compact form, which leaves the long
|
|
1867
|
+
* series out; `portfolio` and batch reports serve the full one.
|
|
1868
|
+
*/
|
|
1869
|
+
interface BacktestAnalytics {
|
|
1870
|
+
version: number;
|
|
1871
|
+
computedAt: string;
|
|
1872
|
+
sample: {
|
|
1873
|
+
trades: number;
|
|
1874
|
+
days: number;
|
|
1875
|
+
years: number;
|
|
1876
|
+
firstTradeAt: string | null;
|
|
1877
|
+
lastTradeAt: string | null;
|
|
1878
|
+
};
|
|
1879
|
+
returns: {
|
|
1880
|
+
totalReturnPct: number;
|
|
1881
|
+
cagrPct: number | null;
|
|
1882
|
+
annualVolPct: number | null;
|
|
1883
|
+
/** Annualised, risk-free 0, on daily returns. */
|
|
1884
|
+
sharpe: number | null;
|
|
1885
|
+
sortino: number | null;
|
|
1886
|
+
calmar: number | null;
|
|
1887
|
+
skew: number | null;
|
|
1888
|
+
kurtosis: number | null;
|
|
1889
|
+
bestDayPct: number | null;
|
|
1890
|
+
worstDayPct: number | null;
|
|
1891
|
+
positiveDaysPct: number | null;
|
|
1892
|
+
};
|
|
1893
|
+
trades: {
|
|
1894
|
+
netProfit: number;
|
|
1895
|
+
avgTrade: number | null;
|
|
1896
|
+
avgWin: number | null;
|
|
1897
|
+
avgLoss: number | null;
|
|
1898
|
+
payoffRatio: number | null;
|
|
1899
|
+
expectancy: number | null;
|
|
1900
|
+
winRatePct: number | null;
|
|
1901
|
+
profitFactor: number | null;
|
|
1902
|
+
sqn: number | null;
|
|
1903
|
+
tStat: number | null;
|
|
1904
|
+
netExTop1: number;
|
|
1905
|
+
netExTop3: number;
|
|
1906
|
+
netExTop5Pct: number;
|
|
1907
|
+
medianDurationSec: number | null;
|
|
1908
|
+
avgWinDurationSec: number | null;
|
|
1909
|
+
avgLossDurationSec: number | null;
|
|
1910
|
+
exitReasons: Array<{
|
|
1911
|
+
reason: BacktestExitReason;
|
|
1912
|
+
trades: number;
|
|
1913
|
+
net: number;
|
|
1914
|
+
winRatePct: number | null;
|
|
1915
|
+
}>;
|
|
1916
|
+
};
|
|
1917
|
+
drawdown: {
|
|
1918
|
+
maxDdPct: number;
|
|
1919
|
+
maxDdAbs: number;
|
|
1920
|
+
avgDdPct: number;
|
|
1921
|
+
ulcerIndex: number;
|
|
1922
|
+
painIndex: number;
|
|
1923
|
+
recoveryFactor: number | null;
|
|
1924
|
+
longestDdDays: number;
|
|
1925
|
+
avgRecoveryDays: number | null;
|
|
1926
|
+
timeUnderwaterPct: number;
|
|
1927
|
+
currentDdPct: number;
|
|
1928
|
+
episodes: Array<{
|
|
1929
|
+
peakAt: string;
|
|
1930
|
+
troughAt: string;
|
|
1931
|
+
recoveredAt: string | null;
|
|
1932
|
+
depthPct: number;
|
|
1933
|
+
depthAbs: number;
|
|
1934
|
+
durationDays: number;
|
|
1935
|
+
recoveryDays: number | null;
|
|
1936
|
+
}>;
|
|
1937
|
+
};
|
|
1938
|
+
tail: {
|
|
1939
|
+
var95DayPct: number | null;
|
|
1940
|
+
cvar95DayPct: number | null;
|
|
1941
|
+
var99DayPct: number | null;
|
|
1942
|
+
cvar99DayPct: number | null;
|
|
1943
|
+
var95Trade: number | null;
|
|
1944
|
+
cvar95Trade: number | null;
|
|
1945
|
+
var99Trade: number | null;
|
|
1946
|
+
cvar99Trade: number | null;
|
|
1947
|
+
};
|
|
1948
|
+
significance: {
|
|
1949
|
+
sharpeObs: number | null;
|
|
1950
|
+
n: number;
|
|
1951
|
+
skew: number | null;
|
|
1952
|
+
kurtosis: number | null;
|
|
1953
|
+
/** Probability that the true Sharpe is above 0. */
|
|
1954
|
+
psr: number | null;
|
|
1955
|
+
/** Backtests tried on this EA when `dsr` was computed. */
|
|
1956
|
+
trials: number;
|
|
1957
|
+
/** Deflated Sharpe: PSR against the expected best of `trials` tries. */
|
|
1958
|
+
dsr: number | null;
|
|
1959
|
+
};
|
|
1960
|
+
flags: BacktestRedFlag[];
|
|
1961
|
+
[section: string]: unknown;
|
|
1962
|
+
}
|
|
1963
|
+
/** One run of a backtest group, as `/api/external/backtests` serves it. */
|
|
1964
|
+
interface BacktestRun {
|
|
1965
|
+
id: string;
|
|
1966
|
+
groupId: string;
|
|
1967
|
+
atlasAccountId: string;
|
|
1968
|
+
window: BacktestWindow;
|
|
1969
|
+
mode: BacktestRunMode;
|
|
1970
|
+
/** On OPTIMIZE runs. */
|
|
1971
|
+
optimization: OptimizationConfig | null;
|
|
1972
|
+
/** Walk-forward fold, 0-based. */
|
|
1973
|
+
foldIndex: number | null;
|
|
1974
|
+
status: BacktestStatus;
|
|
1975
|
+
/** Why it failed or was canceled; `cancel requested` while a cancel is pending. */
|
|
1976
|
+
statusReason: string | null;
|
|
1977
|
+
versionId: string;
|
|
1978
|
+
/** Null once the terminal is deleted. */
|
|
1979
|
+
instanceId: string | null;
|
|
1980
|
+
symbol: string;
|
|
1981
|
+
timeframe: EaTimeframe;
|
|
1982
|
+
setBlob: string | null;
|
|
1983
|
+
tickMode: BacktestTickMode;
|
|
1984
|
+
fromDate: string;
|
|
1985
|
+
toDate: string;
|
|
1986
|
+
deposit: number;
|
|
1987
|
+
currency: string;
|
|
1988
|
+
leverage: number;
|
|
1989
|
+
runnerId: string | null;
|
|
1990
|
+
assignedRunnerId: string | null;
|
|
1991
|
+
claimedAt: string | null;
|
|
1992
|
+
startedAt: string | null;
|
|
1993
|
+
finishedAt: string | null;
|
|
1994
|
+
estimatedSeconds: number | null;
|
|
1995
|
+
attempt: number;
|
|
1996
|
+
executedOn: BacktestExecutor | null;
|
|
1997
|
+
/** Runner phase while it runs (preparing, downloading-history, testing, uploading). */
|
|
1998
|
+
phase: string | null;
|
|
1999
|
+
progressPct: number | null;
|
|
2000
|
+
/** Set once DONE, and null on a locked out-of-sample run. */
|
|
2001
|
+
statsJson: BacktestStats | null;
|
|
2002
|
+
reportKey: string | null;
|
|
2003
|
+
resultKey: string | null;
|
|
2004
|
+
/** Tester log, up to 64 KB. On `get`, not on `list`. */
|
|
2005
|
+
runnerLog?: string | null;
|
|
2006
|
+
chargedMinutes: number | null;
|
|
2007
|
+
barsKey: string | null;
|
|
2008
|
+
aiSummary: BacktestAiSummary | null;
|
|
2009
|
+
/** MT5 ExecutionMode: 0 instant, -1 random delay, above 0 a fixed delay in ms. */
|
|
2010
|
+
executionMode: number;
|
|
2011
|
+
/** The other run of a tick-model pair. */
|
|
2012
|
+
linkedRunId: string | null;
|
|
2013
|
+
liveComparisonSummary: (LiveComparisonSummary & {
|
|
2014
|
+
deploymentId: string;
|
|
2015
|
+
window: {
|
|
2016
|
+
from: string;
|
|
2017
|
+
to: string;
|
|
2018
|
+
};
|
|
2019
|
+
computedAt: string;
|
|
2020
|
+
}) | null;
|
|
2021
|
+
analyticsVersion: number | null;
|
|
2022
|
+
chartTimeframes: EaTimeframe[];
|
|
2023
|
+
createdAt: string;
|
|
2024
|
+
updatedAt: string;
|
|
2025
|
+
version: {
|
|
2026
|
+
id: string;
|
|
2027
|
+
version: string;
|
|
2028
|
+
ea: {
|
|
2029
|
+
id: string;
|
|
2030
|
+
name: string;
|
|
2031
|
+
baselineGroupId: string | null;
|
|
2032
|
+
};
|
|
2033
|
+
};
|
|
2034
|
+
instance: {
|
|
2035
|
+
id: string;
|
|
2036
|
+
name: string | null;
|
|
2037
|
+
accountId: string | null;
|
|
2038
|
+
} | null;
|
|
2039
|
+
barsTimeframes: EaTimeframe[];
|
|
2040
|
+
hasPasses: boolean;
|
|
2041
|
+
hasSpec: boolean;
|
|
2042
|
+
hasCalendar: boolean;
|
|
2043
|
+
extraSymbols: string[];
|
|
2044
|
+
tickSymbols: string[];
|
|
2045
|
+
/** 1-based queue position while QUEUED. */
|
|
2046
|
+
queuePosition: number | null;
|
|
2047
|
+
estimatedFinishAt: string | null;
|
|
2048
|
+
}
|
|
2049
|
+
interface BacktestGroup {
|
|
2050
|
+
id: string;
|
|
2051
|
+
atlasAccountId: string;
|
|
2052
|
+
createdByUserId: string | null;
|
|
2053
|
+
name: string;
|
|
2054
|
+
oosEnabled: boolean;
|
|
2055
|
+
oosRevealCount: number;
|
|
2056
|
+
oosRevealedAt: string | null;
|
|
2057
|
+
agentSessionId: string | null;
|
|
2058
|
+
kind: BacktestGroupKind;
|
|
2059
|
+
batchId: string | null;
|
|
2060
|
+
batchKind: BacktestBatchKind | null;
|
|
2061
|
+
/** NOISE and WF_MATRIX batches: how the group was made. */
|
|
2062
|
+
batchMeta: Record<string, unknown> | null;
|
|
2063
|
+
/** WALK_FORWARD groups: the fold plan. Dates are YYYY-MM-DD. */
|
|
2064
|
+
walkForward: {
|
|
2065
|
+
config: WalkForwardConfig;
|
|
2066
|
+
optimization: OptimizationConfig;
|
|
2067
|
+
holdout: string | null;
|
|
2068
|
+
toDate: string;
|
|
2069
|
+
folds: Array<{
|
|
2070
|
+
index: number;
|
|
2071
|
+
isFrom: string;
|
|
2072
|
+
isTo: string;
|
|
2073
|
+
oosFrom: string;
|
|
2074
|
+
oosTo: string;
|
|
2075
|
+
oosEstimatedSeconds?: number;
|
|
2076
|
+
}>;
|
|
2077
|
+
holdoutEstimatedSeconds?: number;
|
|
2078
|
+
warning?: string | null;
|
|
2079
|
+
} | null;
|
|
2080
|
+
note: string | null;
|
|
2081
|
+
monitorId: string | null;
|
|
2082
|
+
createdAt: string;
|
|
2083
|
+
/** The pinned baseline group of the EA this group tests. */
|
|
2084
|
+
baselineGroupId: string | null;
|
|
2085
|
+
/** Ordered by fromDate. */
|
|
2086
|
+
runs: BacktestRun[];
|
|
2087
|
+
}
|
|
2088
|
+
interface OptimizationConfigInput {
|
|
2089
|
+
/** Default COMPLETE. */
|
|
2090
|
+
algorithm?: OptimizationAlgorithm;
|
|
2091
|
+
/** Default BALANCE. */
|
|
2092
|
+
criterion?: OptimizationCriterion;
|
|
2093
|
+
/** 1 to 4 inputs; COMPLETE is refused above 10,000 combinations. */
|
|
2094
|
+
ranges: OptimizationRange[];
|
|
2095
|
+
}
|
|
2096
|
+
interface CreateBacktestBody {
|
|
2097
|
+
/** 1 to 120 characters. */
|
|
2098
|
+
name: string;
|
|
2099
|
+
/** An EA version with a compiled build. */
|
|
2100
|
+
versionId: string;
|
|
2101
|
+
/** An MT5 terminal of the account with its server set: the tester uses its broker's history. */
|
|
2102
|
+
instanceId: string;
|
|
2103
|
+
symbol: string;
|
|
2104
|
+
timeframe: EaTimeframe;
|
|
2105
|
+
/** .set inputs, up to 100,000 characters. */
|
|
2106
|
+
setBlob?: string | null;
|
|
2107
|
+
/** Default M1_OHLC. */
|
|
2108
|
+
tickMode?: BacktestTickMode;
|
|
2109
|
+
/** YYYY-MM-DD. */
|
|
2110
|
+
fromDate: string;
|
|
2111
|
+
/** YYYY-MM-DD, after fromDate. */
|
|
2112
|
+
toDate: string;
|
|
2113
|
+
/** Default 10000. */
|
|
2114
|
+
deposit?: number;
|
|
2115
|
+
/** Three letters, default USD. */
|
|
2116
|
+
currency?: string;
|
|
2117
|
+
/** 1..10000, default 100. */
|
|
2118
|
+
leverage?: number;
|
|
2119
|
+
/** Lock the run after `splitDate` as an out-of-sample run until you reveal it. */
|
|
2120
|
+
oos?: {
|
|
2121
|
+
splitDate: string;
|
|
2122
|
+
};
|
|
2123
|
+
/** Extra bar timeframes to export for charts, up to 8. */
|
|
2124
|
+
chartTimeframes?: EaTimeframe[];
|
|
2125
|
+
/** Makes an optimization group. */
|
|
2126
|
+
optimization?: OptimizationConfigInput;
|
|
2127
|
+
/** Makes a walk-forward group; needs `optimization`. */
|
|
2128
|
+
walkForward?: {
|
|
2129
|
+
folds: number;
|
|
2130
|
+
isRatio: number;
|
|
2131
|
+
anchored?: boolean;
|
|
2132
|
+
};
|
|
2133
|
+
/** 0 instant (default), -1 random delay, 1..10000 a fixed delay in ms. */
|
|
2134
|
+
executionMode?: number;
|
|
2135
|
+
/** Export the ticks the tester used. Ignored for optimizations. */
|
|
2136
|
+
exportTicks?: boolean;
|
|
2137
|
+
/** Up to 2000 characters. */
|
|
2138
|
+
note?: string;
|
|
2139
|
+
}
|
|
2140
|
+
interface CreateBacktestResult {
|
|
2141
|
+
group: BacktestGroup;
|
|
2142
|
+
runs: Array<{
|
|
2143
|
+
id: string;
|
|
2144
|
+
window: BacktestWindow;
|
|
2145
|
+
status: BacktestStatus;
|
|
2146
|
+
queuePosition: number | null;
|
|
2147
|
+
estimatedSeconds: number | null;
|
|
2148
|
+
estimatedFinishAt: string | null;
|
|
2149
|
+
}>;
|
|
2150
|
+
}
|
|
2151
|
+
interface ListBacktestsQuery {
|
|
2152
|
+
/** 1..100, default 20. */
|
|
2153
|
+
limit?: number;
|
|
2154
|
+
/** `nextCursor` of the previous page. */
|
|
2155
|
+
cursor?: string;
|
|
2156
|
+
}
|
|
2157
|
+
interface ListBacktestsResult {
|
|
2158
|
+
/** Runs carry no `runnerLog`. */
|
|
2159
|
+
items: BacktestGroup[];
|
|
2160
|
+
nextCursor: string | null;
|
|
2161
|
+
}
|
|
2162
|
+
interface BacktestEstimateQuery {
|
|
2163
|
+
tickMode?: BacktestTickMode;
|
|
2164
|
+
fromDate: string;
|
|
2165
|
+
toDate: string;
|
|
2166
|
+
/** Optimizer passes; omit for a single run. */
|
|
2167
|
+
passes?: number;
|
|
2168
|
+
/** Estimate a whole walk-forward with this many folds (2..10). */
|
|
2169
|
+
folds?: number;
|
|
2170
|
+
/** With `folds`: 1..10, default 3. */
|
|
2171
|
+
isRatio?: number;
|
|
2172
|
+
anchored?: boolean;
|
|
2173
|
+
splitDate?: string;
|
|
2174
|
+
timeframe?: EaTimeframe;
|
|
2175
|
+
/** Runs in a batch, noise test or matrix (1..12), default 1. */
|
|
2176
|
+
runs?: number;
|
|
2177
|
+
}
|
|
2178
|
+
interface BacktestEstimate {
|
|
2179
|
+
estimatedSeconds: number;
|
|
2180
|
+
queueWaitSeconds: number;
|
|
2181
|
+
estimatedFinishAt: string;
|
|
2182
|
+
creditsPerRun: number;
|
|
2183
|
+
runs: number;
|
|
2184
|
+
credits: number;
|
|
2185
|
+
/** With `folds`. */
|
|
2186
|
+
walkForward?: {
|
|
2187
|
+
optimizationSeconds: number;
|
|
2188
|
+
oosSeconds: number;
|
|
2189
|
+
holdoutSeconds: number;
|
|
2190
|
+
totalSeconds: number;
|
|
2191
|
+
estimatedCredits: number;
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
interface PortfolioBody {
|
|
2195
|
+
/** 2 to 20 finished runs. */
|
|
2196
|
+
members: Array<{
|
|
2197
|
+
runId: string /** Lot multiplier, default 1. */;
|
|
2198
|
+
weight?: number;
|
|
2199
|
+
}>;
|
|
2200
|
+
/** Starting capital; default the largest member deposit. */
|
|
2201
|
+
capital?: number;
|
|
2202
|
+
}
|
|
2203
|
+
interface PortfolioReport {
|
|
2204
|
+
capital: number;
|
|
2205
|
+
currency: string;
|
|
2206
|
+
members: Array<{
|
|
2207
|
+
runId: string;
|
|
2208
|
+
label: string;
|
|
2209
|
+
weight: number;
|
|
2210
|
+
net: number;
|
|
2211
|
+
maxDdPct: number;
|
|
2212
|
+
contributionPct: number | null;
|
|
2213
|
+
lossInWorstDd: number;
|
|
2214
|
+
}>;
|
|
2215
|
+
/** Runs left out, with the reason. */
|
|
2216
|
+
excluded: Array<{
|
|
2217
|
+
runId: string;
|
|
2218
|
+
reason: string;
|
|
2219
|
+
}>;
|
|
2220
|
+
/** Pearson correlation of members' daily returns, in `members` order. */
|
|
2221
|
+
correlation: number[][];
|
|
2222
|
+
diversification: {
|
|
2223
|
+
sumMemberMaxDdAbs: number;
|
|
2224
|
+
combinedMaxDdAbs: number;
|
|
2225
|
+
};
|
|
2226
|
+
combinedFloatingDdPct: number | null;
|
|
2227
|
+
equity: Array<{
|
|
2228
|
+
t: string;
|
|
2229
|
+
equity: number;
|
|
2230
|
+
}>;
|
|
2231
|
+
analytics: BacktestAnalytics;
|
|
2232
|
+
}
|
|
2233
|
+
interface CreateBacktestBatchBody extends Omit<CreateBacktestBody, "symbol" | "timeframe" | "optimization" | "walkForward"> {
|
|
2234
|
+
/** 1 to 12. Every symbol runs on every timeframe, up to 12 runs. */
|
|
2235
|
+
symbols: string[];
|
|
2236
|
+
timeframes: EaTimeframe[];
|
|
2237
|
+
}
|
|
2238
|
+
interface CreateBacktestBatchResult {
|
|
2239
|
+
batchId: string;
|
|
2240
|
+
groups: Array<{
|
|
2241
|
+
groupId: string;
|
|
2242
|
+
symbol: string;
|
|
2243
|
+
timeframe: string;
|
|
2244
|
+
}>;
|
|
2245
|
+
}
|
|
2246
|
+
interface NoiseTestConfig {
|
|
2247
|
+
/** 3..12 variants. */
|
|
2248
|
+
variants: number;
|
|
2249
|
+
/** Each numeric input moves by up to this percent (0..50]. */
|
|
2250
|
+
perturbPct: number;
|
|
2251
|
+
/** Default 1. */
|
|
2252
|
+
seed?: number;
|
|
2253
|
+
/** Inputs to leave alone. */
|
|
2254
|
+
skip?: string[];
|
|
2255
|
+
/** Inputs to move even when the default rule would leave them alone. */
|
|
2256
|
+
include?: string[];
|
|
2257
|
+
}
|
|
2258
|
+
interface CreateNoiseTestBody {
|
|
2259
|
+
/** A SINGLE backtest group of the account. */
|
|
2260
|
+
groupId: string;
|
|
2261
|
+
config: NoiseTestConfig;
|
|
2262
|
+
}
|
|
2263
|
+
interface CreateNoiseTestResult {
|
|
2264
|
+
batchId: string;
|
|
2265
|
+
groups: Array<{
|
|
2266
|
+
groupId: string;
|
|
2267
|
+
inputs: Record<string, number>;
|
|
2268
|
+
}>;
|
|
2269
|
+
}
|
|
2270
|
+
interface CreateWalkForwardMatrixBody extends CreateBacktestBody {
|
|
2271
|
+
optimization: OptimizationConfigInput;
|
|
2272
|
+
/** In-sample ratios, each 1..10. */
|
|
2273
|
+
isRatios: number[];
|
|
2274
|
+
/** Fold counts, each 2..10. At most 9 cells in all. */
|
|
2275
|
+
folds: number[];
|
|
2276
|
+
}
|
|
2277
|
+
interface CreateWalkForwardMatrixResult {
|
|
2278
|
+
batchId: string;
|
|
2279
|
+
groups: Array<{
|
|
2280
|
+
groupId: string;
|
|
2281
|
+
isRatio: number;
|
|
2282
|
+
folds: number;
|
|
2283
|
+
}>;
|
|
2284
|
+
}
|
|
2285
|
+
interface BacktestSourceDiff {
|
|
2286
|
+
fromVersionId: string;
|
|
2287
|
+
toVersionId: string;
|
|
2288
|
+
fromVersion: string;
|
|
2289
|
+
toVersion: string;
|
|
2290
|
+
/** Unified diff, empty when identical, at most 200 KB. */
|
|
2291
|
+
unified: string;
|
|
2292
|
+
truncated: boolean;
|
|
2293
|
+
added: number;
|
|
2294
|
+
removed: number;
|
|
2295
|
+
}
|
|
2296
|
+
interface SwapArbRow {
|
|
2297
|
+
symbol: string;
|
|
2298
|
+
longInstanceId: string;
|
|
2299
|
+
longInstanceName: string;
|
|
2300
|
+
shortInstanceId: string;
|
|
2301
|
+
shortInstanceName: string;
|
|
2302
|
+
/** Money per lot per night, account currency. Positive earns. */
|
|
2303
|
+
swapLongPerLot: number;
|
|
2304
|
+
swapShortPerLot: number;
|
|
2305
|
+
dailyCarryPerLot: number;
|
|
2306
|
+
roundTripCostPerLot: number;
|
|
2307
|
+
breakEvenDays: number | null;
|
|
2308
|
+
marginPerLot: number;
|
|
2309
|
+
annualisedPctOnMargin: number | null;
|
|
2310
|
+
specsAt: string;
|
|
2311
|
+
}
|
|
2312
|
+
interface SwapArbitrageReport {
|
|
2313
|
+
/** Best annualised first. */
|
|
2314
|
+
rows: SwapArbRow[];
|
|
2315
|
+
specsMissing: Array<{
|
|
2316
|
+
instanceId: string;
|
|
2317
|
+
instanceName: string | null;
|
|
2318
|
+
}>;
|
|
2319
|
+
assumptions: string[];
|
|
2320
|
+
}
|
|
2321
|
+
interface SpreadCalibration {
|
|
2322
|
+
instanceId: string;
|
|
2323
|
+
symbol: string;
|
|
2324
|
+
computedAt: string;
|
|
2325
|
+
byHour: Array<{
|
|
2326
|
+
hour: number;
|
|
2327
|
+
avgSpreadPts: number;
|
|
2328
|
+
p90SpreadPts: number;
|
|
2329
|
+
samples: number;
|
|
2330
|
+
}>;
|
|
2331
|
+
/** From live comparisons on this terminal and symbol, when any exist. */
|
|
2332
|
+
slippagePts: {
|
|
2333
|
+
median: number;
|
|
2334
|
+
p90: number;
|
|
2335
|
+
samples: number;
|
|
2336
|
+
} | null;
|
|
2337
|
+
/** Execution delay to give the tester, ms. */
|
|
2338
|
+
suggestedExecutionDelayMs: number;
|
|
2339
|
+
}
|
|
2340
|
+
interface BacktestBatchReport {
|
|
2341
|
+
batchId: string;
|
|
2342
|
+
batchKind: BacktestBatchKind;
|
|
2343
|
+
name: string;
|
|
2344
|
+
cells: Array<{
|
|
2345
|
+
groupId: string;
|
|
2346
|
+
runId: string | null;
|
|
2347
|
+
symbol: string;
|
|
2348
|
+
timeframe: string;
|
|
2349
|
+
status: string;
|
|
2350
|
+
netProfit: number | null;
|
|
2351
|
+
profitFactor: number | null;
|
|
2352
|
+
maxDdPct: number | null;
|
|
2353
|
+
trades: number | null;
|
|
2354
|
+
}>;
|
|
2355
|
+
consistency: {
|
|
2356
|
+
finished: number;
|
|
2357
|
+
profitablePct: number | null;
|
|
2358
|
+
medianProfitFactor: number | null;
|
|
2359
|
+
};
|
|
2360
|
+
/** Every finished cell combined as one account; null until two are DONE. */
|
|
2361
|
+
combined: PortfolioReport | null;
|
|
2362
|
+
/** NOISE batches. */
|
|
2363
|
+
noise?: {
|
|
2364
|
+
batchId: string;
|
|
2365
|
+
baseGroupId: string;
|
|
2366
|
+
config: NoiseTestConfig;
|
|
2367
|
+
variants: Array<{
|
|
2368
|
+
groupId: string;
|
|
2369
|
+
runId: string | null;
|
|
2370
|
+
status: string;
|
|
2371
|
+
inputs: Record<string, number>;
|
|
2372
|
+
netProfit: number | null;
|
|
2373
|
+
profitFactor: number | null;
|
|
2374
|
+
maxDdPct: number | null;
|
|
2375
|
+
}>;
|
|
2376
|
+
netProfit: {
|
|
2377
|
+
min: number;
|
|
2378
|
+
median: number;
|
|
2379
|
+
max: number;
|
|
2380
|
+
base: number;
|
|
2381
|
+
} | null;
|
|
2382
|
+
/** Coefficient of variation of net profit; above 0.5 reads as fragile. */
|
|
2383
|
+
fragility: number | null;
|
|
2384
|
+
};
|
|
2385
|
+
/** WF_MATRIX batches. `cells[isRatio index][folds index]`. */
|
|
2386
|
+
wfMatrix?: {
|
|
2387
|
+
batchId: string;
|
|
2388
|
+
isRatios: number[];
|
|
2389
|
+
folds: number[];
|
|
2390
|
+
cells: Array<Array<{
|
|
2391
|
+
groupId: string;
|
|
2392
|
+
wfe: number | null;
|
|
2393
|
+
status: string;
|
|
2394
|
+
}>>;
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
interface BacktestResultUrls {
|
|
2398
|
+
/** The BacktestResult JSON, presigned for 10 minutes. */
|
|
2399
|
+
resultUrl: string;
|
|
2400
|
+
/** The MT5 HTML report, presigned for 10 minutes. */
|
|
2401
|
+
reportUrl: string | null;
|
|
2402
|
+
}
|
|
2403
|
+
interface BacktestRunStats {
|
|
2404
|
+
runId: string;
|
|
2405
|
+
window: BacktestWindow;
|
|
2406
|
+
stats: BacktestStats;
|
|
2407
|
+
byMonth: Array<{
|
|
2408
|
+
month: string;
|
|
2409
|
+
trades: number;
|
|
2410
|
+
profit: number;
|
|
2411
|
+
}>;
|
|
2412
|
+
byHour: Array<{
|
|
2413
|
+
hour: number;
|
|
2414
|
+
trades: number;
|
|
2415
|
+
profit: number;
|
|
2416
|
+
}>;
|
|
2417
|
+
/** 0 is Sunday. */
|
|
2418
|
+
byWeekday: Array<{
|
|
2419
|
+
weekday: number;
|
|
2420
|
+
trades: number;
|
|
2421
|
+
profit: number;
|
|
2422
|
+
}>;
|
|
2423
|
+
/** Compact analytics: the long series are left out. */
|
|
2424
|
+
analytics: BacktestAnalytics | null;
|
|
2425
|
+
aiSummary: BacktestAiSummary | null;
|
|
2426
|
+
}
|
|
2427
|
+
type BacktestTradeSort = "openTime" | "-openTime" | "closeTime" | "-closeTime" | "net" | "-net" | "profit" | "-profit" | "durationSec" | "-durationSec" | "volume" | "-volume";
|
|
2428
|
+
type BacktestTradeAggregate = "none" | "byMonth" | "byHour" | "byWeekday" | "bySymbol" | "byExitReason";
|
|
2429
|
+
interface BacktestTradesQuery {
|
|
2430
|
+
type?: "buy" | "sell";
|
|
2431
|
+
outcome?: "win" | "loss";
|
|
2432
|
+
/** Bounds on net P/L (profit + commission + swap). */
|
|
2433
|
+
minProfit?: number;
|
|
2434
|
+
maxProfit?: number;
|
|
2435
|
+
minDurationSec?: number;
|
|
2436
|
+
maxDurationSec?: number;
|
|
2437
|
+
/** Needs per-trade R, which needs the bars the tester exported. */
|
|
2438
|
+
minR?: number;
|
|
2439
|
+
maxR?: number;
|
|
2440
|
+
/** Trades opened at or after (ISO). */
|
|
2441
|
+
from?: string;
|
|
2442
|
+
/** Trades opened at or before (ISO). */
|
|
2443
|
+
to?: string;
|
|
2444
|
+
/** Close weekdays, 0 (Sunday) to 6. */
|
|
2445
|
+
weekdays?: number[];
|
|
2446
|
+
/** Close hours, 0 to 23. */
|
|
2447
|
+
hours?: number[];
|
|
2448
|
+
exitReasons?: BacktestExitReason[];
|
|
2449
|
+
/** Case-insensitive substring of the trade comment. */
|
|
2450
|
+
commentContains?: string;
|
|
2451
|
+
/** Default openTime. */
|
|
2452
|
+
sort?: BacktestTradeSort;
|
|
2453
|
+
/** 1..200, default 50. */
|
|
2454
|
+
limit?: number;
|
|
2455
|
+
aggregate?: BacktestTradeAggregate;
|
|
2456
|
+
}
|
|
2457
|
+
interface BacktestTradeAggregateRow {
|
|
2458
|
+
/** Month `YYYY-MM`, hour, weekday, symbol or exit reason. */
|
|
2459
|
+
key: string | number;
|
|
2460
|
+
trades: number;
|
|
2461
|
+
net: number;
|
|
2462
|
+
avg: number;
|
|
2463
|
+
profitFactor: number | null;
|
|
2464
|
+
winRatePct: number;
|
|
2465
|
+
}
|
|
2466
|
+
interface BacktestTradesResult<Row = BacktestTrade | BacktestTradeAggregateRow> {
|
|
2467
|
+
runId: string;
|
|
2468
|
+
window: BacktestWindow;
|
|
2469
|
+
totalMatched: number;
|
|
2470
|
+
rows: Row[];
|
|
2471
|
+
}
|
|
2472
|
+
interface CancelBacktestRunResult {
|
|
2473
|
+
id: string;
|
|
2474
|
+
/** CANCELED when it was still queued; otherwise a stop was requested. */
|
|
2475
|
+
status: "CANCELED" | "CLAIMED" | "RUNNING";
|
|
2476
|
+
statusReason: "canceled by user" | "cancel requested";
|
|
2477
|
+
}
|
|
2478
|
+
interface OptimizationPass {
|
|
2479
|
+
pass: number;
|
|
2480
|
+
/** The criterion value MT5 ranked the pass by. */
|
|
2481
|
+
result: number;
|
|
2482
|
+
profit: number;
|
|
2483
|
+
expectedPayoff: number | null;
|
|
2484
|
+
profitFactor: number | null;
|
|
2485
|
+
recoveryFactor: number | null;
|
|
2486
|
+
sharpe: number | null;
|
|
2487
|
+
custom: number | null;
|
|
2488
|
+
equityDdPct: number | null;
|
|
2489
|
+
trades: number;
|
|
2490
|
+
params: Record<string, number>;
|
|
2491
|
+
}
|
|
2492
|
+
interface BacktestPassesQuery {
|
|
2493
|
+
/** A field or `-field` among pass, result, profit, expectedPayoff, profitFactor, recoveryFactor, sharpe, custom, equityDdPct, trades. Default `-result`. */
|
|
2494
|
+
sort?: string;
|
|
2495
|
+
/** 1..1000, default 50. */
|
|
2496
|
+
limit?: number;
|
|
2497
|
+
}
|
|
2498
|
+
interface BacktestPassesResult {
|
|
2499
|
+
runId: string;
|
|
2500
|
+
/** Before `limit`. */
|
|
2501
|
+
totalPasses: number;
|
|
2502
|
+
result: {
|
|
2503
|
+
schemaVersion: 1;
|
|
2504
|
+
algorithm: OptimizationAlgorithm;
|
|
2505
|
+
criterion: OptimizationCriterion;
|
|
2506
|
+
passes: OptimizationPass[];
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2509
|
+
/** Where a run sits among the account's other finished runs of the same EA. `thisRankPct` 100 is best. */
|
|
2510
|
+
interface BacktestPeerContext {
|
|
2511
|
+
runs: number;
|
|
2512
|
+
pf: {
|
|
2513
|
+
median: number | null;
|
|
2514
|
+
thisRankPct: number | null;
|
|
2515
|
+
};
|
|
2516
|
+
netProfit: {
|
|
2517
|
+
median: number | null;
|
|
2518
|
+
thisRankPct: number | null;
|
|
2519
|
+
};
|
|
2520
|
+
sharpe: {
|
|
2521
|
+
median: number | null;
|
|
2522
|
+
thisRankPct: number | null;
|
|
2523
|
+
};
|
|
2524
|
+
maxDdPct: {
|
|
2525
|
+
median: number | null;
|
|
2526
|
+
thisRankPct: number | null;
|
|
2527
|
+
};
|
|
2528
|
+
}
|
|
2529
|
+
interface WalkForwardReport {
|
|
2530
|
+
groupId: string;
|
|
2531
|
+
config: WalkForwardConfig;
|
|
2532
|
+
folds: Array<{
|
|
2533
|
+
index: number;
|
|
2534
|
+
isFrom: string;
|
|
2535
|
+
isTo: string;
|
|
2536
|
+
oosFrom: string;
|
|
2537
|
+
oosTo: string;
|
|
2538
|
+
isRunId: string;
|
|
2539
|
+
oosRunId: string | null;
|
|
2540
|
+
status: "OPTIMIZING" | "TESTING" | "DONE" | "FAILED";
|
|
2541
|
+
bestPass: OptimizationPass | null;
|
|
2542
|
+
isReturnAnnualPct: number | null;
|
|
2543
|
+
oosReturnAnnualPct: number | null;
|
|
2544
|
+
wfe: number | null;
|
|
2545
|
+
oosNet: number | null;
|
|
2546
|
+
}>;
|
|
2547
|
+
/** Annualised OOS return over annualised IS return. */
|
|
2548
|
+
wfe: number | null;
|
|
2549
|
+
/** The OOS segments chained into one account; compact analytics. */
|
|
2550
|
+
stitched: {
|
|
2551
|
+
equity: Array<{
|
|
2552
|
+
t: string;
|
|
2553
|
+
equity: number;
|
|
2554
|
+
}>;
|
|
2555
|
+
analytics: BacktestAnalytics;
|
|
2556
|
+
} | null;
|
|
2557
|
+
paramStability: Array<{
|
|
2558
|
+
name: string;
|
|
2559
|
+
values: number[];
|
|
2560
|
+
cv: number | null;
|
|
2561
|
+
}>;
|
|
2562
|
+
holdout: {
|
|
2563
|
+
runId: string;
|
|
2564
|
+
status: string;
|
|
2565
|
+
locked: boolean;
|
|
2566
|
+
} | null;
|
|
2567
|
+
}
|
|
2568
|
+
interface RevealOosResult {
|
|
2569
|
+
id: string;
|
|
2570
|
+
oosRevealedAt: string;
|
|
2571
|
+
/** Every reveal is counted. */
|
|
2572
|
+
oosRevealCount: number;
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
/**
|
|
2576
|
+
* The machine-readable code on a failed request. The v2 routes send one of
|
|
2577
|
+
* the `UnifiedErrorCode`s in `error.code`; the /api/external routes send a
|
|
2578
|
+
* `code` beside the message on some failures, such as `TERMINAL_UNAVAILABLE`
|
|
2579
|
+
* (503, the terminal behind a read cannot be seen right now) and
|
|
2580
|
+
* `COMMAND_UNSUPPORTED` (501, the connector EA does not implement the read).
|
|
2581
|
+
*/
|
|
2582
|
+
type AtlasErrorCode = UnifiedErrorCode | "TERMINAL_UNAVAILABLE" | "COMMAND_UNSUPPORTED" | (string & {});
|
|
2583
|
+
/** What the server said about a failure beyond its message. */
|
|
2584
|
+
interface AtlasErrorDetails {
|
|
2585
|
+
code?: AtlasErrorCode;
|
|
2586
|
+
/** The server's own verdict on retrying (v2 routes only). */
|
|
2587
|
+
retryable?: boolean;
|
|
2588
|
+
/** The broker's own error code, when the broker gave one (v2 routes only). */
|
|
2589
|
+
brokerCode?: string;
|
|
2590
|
+
/** True when the server answered from its Idempotency-Key store: this is
|
|
2591
|
+
* the stored answer of an earlier request with the same key. */
|
|
2592
|
+
replayed?: boolean;
|
|
2593
|
+
/** The parsed error body, as the server sent it. */
|
|
2594
|
+
body?: unknown;
|
|
2595
|
+
}
|
|
2596
|
+
declare class AtlasError extends Error {
|
|
2597
|
+
readonly statusCode: number;
|
|
2598
|
+
readonly errorCode?: number;
|
|
2599
|
+
readonly requestId?: string;
|
|
2600
|
+
readonly code?: AtlasErrorCode;
|
|
2601
|
+
readonly retryable?: boolean;
|
|
2602
|
+
readonly brokerCode?: string;
|
|
2603
|
+
readonly replayed?: boolean;
|
|
2604
|
+
readonly body?: unknown;
|
|
2605
|
+
constructor(message: string, statusCode?: number, errorCode?: number, requestId?: string, details?: AtlasErrorDetails);
|
|
2606
|
+
}
|
|
2607
|
+
declare class AtlasAuthError extends AtlasError {
|
|
2608
|
+
constructor(message: string, requestId?: string, details?: AtlasErrorDetails);
|
|
2609
|
+
}
|
|
2610
|
+
declare class AtlasRateLimitError extends AtlasError {
|
|
2611
|
+
readonly retryAfter?: number;
|
|
2612
|
+
constructor(message: string, retryAfter?: number, requestId?: string, details?: AtlasErrorDetails);
|
|
2613
|
+
}
|
|
2614
|
+
declare class AtlasValidationError extends AtlasError {
|
|
2615
|
+
readonly fields?: string[];
|
|
2616
|
+
constructor(message: string, fields?: string[], requestId?: string, details?: AtlasErrorDetails);
|
|
2617
|
+
}
|
|
2618
|
+
declare class AtlasNetworkError extends AtlasError {
|
|
2619
|
+
readonly cause?: unknown;
|
|
2620
|
+
constructor(message: string, cause?: unknown);
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
interface HttpTransportOptions {
|
|
2624
|
+
baseUrl: string;
|
|
2625
|
+
apiKey: string;
|
|
2626
|
+
timeoutMs?: number;
|
|
2627
|
+
maxRetries?: number;
|
|
2628
|
+
logger?: AtlasLogger;
|
|
2629
|
+
}
|
|
2630
|
+
interface AtlasLogger {
|
|
2631
|
+
debug?: (message: string, meta?: Record<string, unknown>) => void;
|
|
2632
|
+
info?: (message: string, meta?: Record<string, unknown>) => void;
|
|
2633
|
+
warn?: (message: string, meta?: Record<string, unknown>) => void;
|
|
2634
|
+
error?: (message: string, meta?: Record<string, unknown>) => void;
|
|
2635
|
+
}
|
|
2636
|
+
type QueryValue = string | number | boolean | undefined;
|
|
2637
|
+
interface RequestOptions {
|
|
2638
|
+
method: string;
|
|
2639
|
+
path: string;
|
|
2640
|
+
body?: unknown;
|
|
2641
|
+
query?: Record<string, QueryValue>;
|
|
2642
|
+
signal?: AbortSignal;
|
|
2643
|
+
/** Sent as `Idempotency-Key`. Writes get a fresh one per call when omitted,
|
|
2644
|
+
* and every retry of the call reuses it. */
|
|
2645
|
+
idempotencyKey?: string;
|
|
2646
|
+
/** The request may be sent again: the route runs it at most once per
|
|
2647
|
+
* Idempotency-Key and answers a repeat with the stored result (the order
|
|
2648
|
+
* writes), or a second copy changes nothing more than the first. Any
|
|
2649
|
+
* other write is never retried once it may have reached the server. */
|
|
2650
|
+
idempotent?: boolean;
|
|
2651
|
+
/** This request's own per-attempt timeout, for a route that holds the
|
|
2652
|
+
* request longer than the client's `timeoutMs`. */
|
|
2653
|
+
timeoutMs?: number;
|
|
2654
|
+
}
|
|
2655
|
+
/** What a caller can pass to a write that the server de-duplicates. */
|
|
2656
|
+
interface WriteOptions {
|
|
2657
|
+
/** Send your own key to retry a write safely across calls (and processes):
|
|
2658
|
+
* the server answers every request with the same key with the first
|
|
2659
|
+
* one's result for 24 hours, and refuses the key for a different request.
|
|
2660
|
+
* 1 to 255 printable ASCII characters, no spaces. Omitted, each call
|
|
2661
|
+
* gets a fresh key that only its own retries share. */
|
|
2662
|
+
idempotencyKey?: string;
|
|
2663
|
+
signal?: AbortSignal;
|
|
2664
|
+
}
|
|
2665
|
+
/** A successful body as the server sent it. Some MT5 reads add freshness
|
|
2666
|
+
* fields beside `data`. */
|
|
2667
|
+
interface ApiEnvelope<T> {
|
|
2668
|
+
success: true;
|
|
2669
|
+
data: T;
|
|
2670
|
+
message?: string;
|
|
2671
|
+
/** When the data was produced (ISO 8601). MT5 terminal reads only. */
|
|
2672
|
+
dataAsOf?: string;
|
|
2673
|
+
/** The terminal's last EA heartbeat (ISO 8601), or null if none was ever seen. MT5 terminal reads only. */
|
|
2674
|
+
lastHeartbeatAt?: string | null;
|
|
2675
|
+
}
|
|
2676
|
+
declare class HttpTransport {
|
|
2677
|
+
private readonly baseUrl;
|
|
2678
|
+
private readonly apiKey;
|
|
2679
|
+
private readonly timeoutMs;
|
|
2680
|
+
private readonly maxRetries;
|
|
2681
|
+
private readonly logger?;
|
|
2682
|
+
constructor(options: HttpTransportOptions);
|
|
2683
|
+
/** The `data` of a successful response. */
|
|
2684
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
2685
|
+
/** The whole successful body, with any freshness fields beside `data`. */
|
|
2686
|
+
requestEnvelope<T>(options: RequestOptions): Promise<ApiEnvelope<T>>;
|
|
2687
|
+
private attempt;
|
|
2688
|
+
private mapError;
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
/**
|
|
2692
|
+
* MT5 strategy tester runs (`/api/external/backtests`). A backtest is a group
|
|
2693
|
+
* of one or more runs: a single test, an optimization, or a walk-forward.
|
|
2694
|
+
*
|
|
2695
|
+
* Creating one queues real work and holds credits, and the server does not
|
|
2696
|
+
* de-duplicate these writes, so the SDK never sends one twice: after a
|
|
2697
|
+
* timeout, `list()` before you create again.
|
|
2698
|
+
*/
|
|
2699
|
+
declare class BacktestsResource {
|
|
2700
|
+
private readonly http;
|
|
2701
|
+
constructor(http: HttpTransport);
|
|
2702
|
+
private run;
|
|
2703
|
+
private group;
|
|
2704
|
+
/** Your backtests, newest first. Page with `nextCursor`. */
|
|
2705
|
+
list(query?: ListBacktestsQuery): Promise<ListBacktestsResult>;
|
|
2706
|
+
/** Queue a backtest: a single run, an optimization (`optimization`) or a
|
|
2707
|
+
* walk-forward (`optimization` + `walkForward`). 402 when credits are short. */
|
|
2708
|
+
create(body: CreateBacktestBody): Promise<CreateBacktestResult>;
|
|
2709
|
+
/** Time and credits a backtest would take. Queues nothing. */
|
|
2710
|
+
estimate(query: BacktestEstimateQuery): Promise<BacktestEstimate>;
|
|
2711
|
+
/** A group with its runs and their tester logs. */
|
|
2712
|
+
get(groupId: string): Promise<BacktestGroup>;
|
|
2713
|
+
/** 409 while a run is still on a terminal: cancel it first. */
|
|
2714
|
+
delete(groupId: string): Promise<{
|
|
2715
|
+
id: string;
|
|
2716
|
+
}>;
|
|
2717
|
+
/** Up to 2000 characters; null clears it. */
|
|
2718
|
+
setNote(groupId: string, note: string | null): Promise<BacktestGroup>;
|
|
2719
|
+
/** Pin this group as its EA's baseline. */
|
|
2720
|
+
setBaseline(groupId: string): Promise<{
|
|
2721
|
+
eaId: string;
|
|
2722
|
+
baselineGroupId: string | null;
|
|
2723
|
+
}>;
|
|
2724
|
+
/** Unpin this group if it is its EA's baseline. */
|
|
2725
|
+
clearBaseline(groupId: string): Promise<{
|
|
2726
|
+
eaId: string;
|
|
2727
|
+
baselineGroupId: string | null;
|
|
2728
|
+
}>;
|
|
2729
|
+
/** Unlock the out-of-sample run. Every call is counted in `oosRevealCount`. */
|
|
2730
|
+
revealOos(groupId: string): Promise<RevealOosResult>;
|
|
2731
|
+
/** Folds, walk-forward efficiency, the stitched OOS equity and parameter stability. */
|
|
2732
|
+
walkForward(groupId: string): Promise<WalkForwardReport>;
|
|
2733
|
+
/** Every symbol on every timeframe as its own backtest (up to 12). */
|
|
2734
|
+
createBatch(body: CreateBacktestBatchBody): Promise<CreateBacktestBatchResult>;
|
|
2735
|
+
getBatch(batchId: string): Promise<BacktestBatchReport>;
|
|
2736
|
+
/** Rerun a single backtest with its numeric inputs nudged at random, to see how fragile it is. */
|
|
2737
|
+
createNoiseTest(body: CreateNoiseTestBody): Promise<CreateNoiseTestResult>;
|
|
2738
|
+
/** One walk-forward per in-sample ratio and fold count (up to 9). */
|
|
2739
|
+
createWalkForwardMatrix(body: CreateWalkForwardMatrixBody): Promise<CreateWalkForwardMatrixResult>;
|
|
2740
|
+
/** Combine 2 to 20 finished runs into one account. Changes nothing. */
|
|
2741
|
+
portfolio(body: PortfolioBody): Promise<PortfolioReport>;
|
|
2742
|
+
/** Presigned links to the result JSON and the MT5 report, valid for 10 minutes. */
|
|
2743
|
+
result(runId: string): Promise<BacktestResultUrls>;
|
|
2744
|
+
/** Report numbers, breakdowns and compact analytics. 409 until the run is DONE. */
|
|
2745
|
+
stats(runId: string): Promise<BacktestRunStats>;
|
|
2746
|
+
/** The run's closed trades, filtered and sorted, or grouped with `aggregate`. */
|
|
2747
|
+
trades(runId: string, query?: BacktestTradesQuery & {
|
|
2748
|
+
aggregate?: "none";
|
|
2749
|
+
}): Promise<BacktestTradesResult<BacktestTrade>>;
|
|
2750
|
+
trades(runId: string, query: BacktestTradesQuery & {
|
|
2751
|
+
aggregate: Exclude<BacktestTradesQuery["aggregate"], "none" | undefined>;
|
|
2752
|
+
}): Promise<BacktestTradesResult<BacktestTradeAggregateRow>>;
|
|
2753
|
+
/** An optimization run's passes, best first by default. */
|
|
2754
|
+
passes(runId: string, query?: BacktestPassesQuery): Promise<BacktestPassesResult>;
|
|
2755
|
+
/** Where the run sits among your other finished runs of the same EA. */
|
|
2756
|
+
peer(runId: string): Promise<BacktestPeerContext>;
|
|
2757
|
+
/** Stop a queued or running run. 409 once it has finished. */
|
|
2758
|
+
cancel(runId: string): Promise<CancelBacktestRunResult>;
|
|
2759
|
+
/** An AI summary of the run, cached; `refresh` makes a new one (at most every 10 minutes). */
|
|
2760
|
+
summary(runId: string, options?: {
|
|
2761
|
+
refresh?: boolean;
|
|
2762
|
+
}): Promise<{
|
|
2763
|
+
summary: BacktestAiSummary;
|
|
2764
|
+
}>;
|
|
2765
|
+
/** A plain-language explanation of one trade of the run. */
|
|
2766
|
+
explainTrade(runId: string, positionId: string): Promise<{
|
|
2767
|
+
explanation: string;
|
|
2768
|
+
}>;
|
|
2769
|
+
/** Rerun a single run on another tick model, as a new linked backtest. */
|
|
2770
|
+
rerunOnTickModel(runId: string, tickMode: BacktestTickMode): Promise<CreateBacktestResult>;
|
|
2771
|
+
/** A unified diff of two EA versions' .mq5 source. */
|
|
2772
|
+
sourceDiff(fromVersionId: string, toVersionId: string): Promise<BacktestSourceDiff>;
|
|
2773
|
+
/** Swap carry across your terminals' brokers: long on one, short on another. */
|
|
2774
|
+
swapArbitrage(): Promise<SwapArbitrageReport>;
|
|
2775
|
+
/** The spread by hour your terminal has seen on a symbol, and the execution delay to test with. */
|
|
2776
|
+
spreadCalibration(instanceId: string, symbol: string): Promise<SpreadCalibration>;
|
|
2777
|
+
}
|
|
987
2778
|
|
|
988
2779
|
/** @internal */
|
|
989
2780
|
declare class BrokerSubscriptionsResource {
|
|
@@ -1000,29 +2791,41 @@ declare class BrokerConnectionResource {
|
|
|
1000
2791
|
/** @internal */ readonly basePath: string;
|
|
1001
2792
|
/** @internal */ readonly http: HttpTransport;
|
|
1002
2793
|
constructor(http: HttpTransport, brokerName: string, connectionId: string);
|
|
1003
|
-
|
|
2794
|
+
/** Place an order in the broker's own fields. Runs at most once per
|
|
2795
|
+
* Idempotency-Key, so a retry never places twice. */
|
|
2796
|
+
placeOrder(order: BrokerOrder | BrokerOrderBody, options?: WriteOptions): Promise<unknown>;
|
|
1004
2797
|
getOrders(): Promise<unknown>;
|
|
1005
2798
|
getOrder(orderId: string): Promise<unknown>;
|
|
1006
|
-
|
|
1007
|
-
|
|
2799
|
+
/** Change a working order, in the broker's own fields. */
|
|
2800
|
+
modifyOrder(orderId: string, changes: BrokerOrder | BrokerModifyOrderBody, options?: WriteOptions): Promise<unknown>;
|
|
2801
|
+
cancelOrder(orderId: string, body?: BrokerCancelOrderBody, options?: WriteOptions): Promise<unknown>;
|
|
1008
2802
|
/** Trade book (fills). Currently served by Motilal Oswal; brokers whose
|
|
1009
2803
|
* runner adapter doesn't implement it return an "unsupported command" error. */
|
|
1010
2804
|
getTrades(): Promise<unknown>;
|
|
1011
2805
|
getPositions(): Promise<unknown>;
|
|
1012
2806
|
getHoldings(): Promise<unknown>;
|
|
1013
2807
|
getCandles(query: BrokerCandlesQuery): Promise<unknown>;
|
|
2808
|
+
/** Option expiries for an underlying, through this Dhan connection. */
|
|
2809
|
+
getOptionExpiries(underlying: DhanUnderlying): Promise<string[]>;
|
|
2810
|
+
/** Dhan's option chain for one expiry (YYYY-MM-DD), through this Dhan connection.
|
|
2811
|
+
* `atlas.v2.market.optionChain()` serves the same data without a connection. */
|
|
2812
|
+
getOptionChain(underlying: DhanUnderlying, expiry: string): Promise<DhanOptionChain>;
|
|
1014
2813
|
}
|
|
1015
2814
|
|
|
1016
|
-
interface
|
|
2815
|
+
interface IncludeRawParams {
|
|
2816
|
+
/** Add the untranslated broker payload as `raw` on each row. */
|
|
1017
2817
|
includeRaw?: boolean;
|
|
1018
2818
|
}
|
|
2819
|
+
type OrdersListParams = IncludeRawParams;
|
|
2820
|
+
/** Options for a v2 write. */
|
|
2821
|
+
interface V2WriteOptions extends WriteOptions, IncludeRawParams {
|
|
2822
|
+
}
|
|
1019
2823
|
interface OrdersListResult {
|
|
1020
2824
|
orders: UnifiedOrder[];
|
|
1021
2825
|
dropped: DroppedRow[];
|
|
1022
2826
|
}
|
|
1023
|
-
interface PositionsListParams {
|
|
2827
|
+
interface PositionsListParams extends IncludeRawParams {
|
|
1024
2828
|
scope?: "NET" | "DAY";
|
|
1025
|
-
includeRaw?: boolean;
|
|
1026
2829
|
}
|
|
1027
2830
|
interface PositionsListResult {
|
|
1028
2831
|
positions: UnifiedPosition[];
|
|
@@ -1041,44 +2844,37 @@ interface CapabilitiesResult {
|
|
|
1041
2844
|
broker: string;
|
|
1042
2845
|
capabilities: BrokerCapabilities;
|
|
1043
2846
|
}
|
|
2847
|
+
/** One connection on the unified v2 surface: `/api/v2/connections/:id`. The
|
|
2848
|
+
* id is the Atlaas instance id or its externalRef. */
|
|
1044
2849
|
declare class ConnectionsV2 {
|
|
1045
2850
|
private readonly http;
|
|
1046
2851
|
private readonly connectionId;
|
|
1047
2852
|
constructor(http: HttpTransport, connectionId: string);
|
|
2853
|
+
private path;
|
|
2854
|
+
private read;
|
|
2855
|
+
private write;
|
|
1048
2856
|
orders(params?: OrdersListParams): Promise<OrdersListResult>;
|
|
1049
|
-
order(orderId: string, params?:
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
trades(): Promise<TradesListResult>;
|
|
2857
|
+
order(orderId: string, params?: IncludeRawParams): Promise<UnifiedOrder>;
|
|
2858
|
+
trades(params?: IncludeRawParams): Promise<TradesListResult>;
|
|
2859
|
+
/** `scope` defaults to `NET`; MT5 and Motilal are net-only and always answer `NET`. */
|
|
1053
2860
|
positions(params?: PositionsListParams): Promise<PositionsListResult>;
|
|
1054
|
-
holdings(): Promise<HoldingsListResult>;
|
|
1055
|
-
funds(): Promise<UnifiedFunds>;
|
|
1056
|
-
profile(): Promise<UnifiedProfile>;
|
|
2861
|
+
holdings(params?: IncludeRawParams): Promise<HoldingsListResult>;
|
|
2862
|
+
funds(params?: IncludeRawParams): Promise<UnifiedFunds>;
|
|
2863
|
+
profile(params?: IncludeRawParams): Promise<UnifiedProfile>;
|
|
1057
2864
|
/** MT5 only: the broker server's contract specs (contract size, volume limits, tick size…),
|
|
1058
2865
|
* keyed to instruments where a ref exists. Held server-side for ~10 min; `symbol` filters. */
|
|
1059
2866
|
symbols(params?: {
|
|
1060
2867
|
symbol?: string;
|
|
1061
2868
|
}): Promise<SymbolSpecsResult>;
|
|
1062
2869
|
capabilities(): Promise<CapabilitiesResult>;
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
modify(orderId: string, body: ModifyOrderV2Body, params?: {
|
|
1070
|
-
includeRaw?: boolean;
|
|
1071
|
-
}): Promise<ModifyOrderResult>;
|
|
1072
|
-
cancel(orderId: string, params?: {
|
|
1073
|
-
includeRaw?: boolean;
|
|
1074
|
-
}): Promise<CancelOrderResult>;
|
|
1075
|
-
closePosition(body: ClosePositionV2Body, params?: {
|
|
1076
|
-
includeRaw?: boolean;
|
|
1077
|
-
}): Promise<ClosePositionResult>;
|
|
2870
|
+
/** Every read in one call; each section reports ok or error on its own. Positions are `NET`. */
|
|
2871
|
+
snapshot(params?: IncludeRawParams): Promise<V2Snapshot>;
|
|
2872
|
+
place(body: PlaceOrderV2Body, options?: V2WriteOptions): Promise<PlaceOrderResult>;
|
|
2873
|
+
modify(orderId: string, body: ModifyOrderV2Body, options?: V2WriteOptions): Promise<ModifyOrderResult>;
|
|
2874
|
+
cancel(orderId: string, options?: V2WriteOptions): Promise<CancelOrderResult>;
|
|
2875
|
+
closePosition(body: ClosePositionV2Body, options?: V2WriteOptions): Promise<ClosePositionResult>;
|
|
1078
2876
|
/** SL / TP on a live position (MT5). An omitted side keeps its level; 0 clears it. */
|
|
1079
|
-
modifyPosition(positionId: string, body: ModifyPositionV2Body,
|
|
1080
|
-
includeRaw?: boolean;
|
|
1081
|
-
}): Promise<ModifyPositionResult>;
|
|
2877
|
+
modifyPosition(positionId: string, body: ModifyPositionV2Body, options?: V2WriteOptions): Promise<ModifyPositionResult>;
|
|
1082
2878
|
}
|
|
1083
2879
|
|
|
1084
2880
|
/**
|
|
@@ -1106,7 +2902,19 @@ declare class EasResource {
|
|
|
1106
2902
|
/** Issue a short-lived R2 upload URL for a new .ex5/.mq5 build. */
|
|
1107
2903
|
presignVersion(eaId: string, body: PresignEaVersionBody): Promise<PresignEaVersionResult>;
|
|
1108
2904
|
/** Register an already-uploaded build (the r2Key returned by presignVersion). */
|
|
1109
|
-
registerVersion(eaId: string, body: RegisterEaVersionBody): Promise<
|
|
2905
|
+
registerVersion(eaId: string, body: RegisterEaVersionBody): Promise<RegisteredEaVersion>;
|
|
2906
|
+
/** Save .mq5 source as a version. Atlaas compile-checks it first (up to a
|
|
2907
|
+
* minute): a failure is a 422 whose `AtlasError.body` is an `EaCompileFailure`
|
|
2908
|
+
* with the compiler's diagnostics. The saved version then compiles in the
|
|
2909
|
+
* background (`compileStatus: "PENDING"`). The request waits up to
|
|
2910
|
+
* `SAVE_SOURCE_TIMEOUT_MS` (2 minutes) whatever the client's `timeoutMs`,
|
|
2911
|
+
* and like every non-order write it is never sent twice. */
|
|
2912
|
+
saveSource(eaId: string, body: SaveEaSourceBody, options?: {
|
|
2913
|
+
timeoutMs?: number;
|
|
2914
|
+
signal?: AbortSignal;
|
|
2915
|
+
}): Promise<RegisteredEaVersion>;
|
|
2916
|
+
/** The .mq5 source of a version (by version id). 409 for an .ex5-only version. */
|
|
2917
|
+
getVersionSource(eaId: string, versionId: string): Promise<EaVersionSource>;
|
|
1110
2918
|
/** Mark a version LIVE (rollback) without re-uploading. */
|
|
1111
2919
|
promoteVersion(eaId: string, versionId: string): Promise<{
|
|
1112
2920
|
id: string;
|
|
@@ -1117,6 +2925,13 @@ declare class EasResource {
|
|
|
1117
2925
|
id: string;
|
|
1118
2926
|
version: string;
|
|
1119
2927
|
}>;
|
|
2928
|
+
listPresets(eaId: string): Promise<{
|
|
2929
|
+
items: EaPreset[];
|
|
2930
|
+
}>;
|
|
2931
|
+
createPreset(eaId: string, body: CreateEaPresetBody): Promise<EaPreset>;
|
|
2932
|
+
deletePreset(eaId: string, presetId: string): Promise<{
|
|
2933
|
+
id: string;
|
|
2934
|
+
}>;
|
|
1120
2935
|
listDeployments(query?: ListDeploymentsQuery): Promise<ListDeploymentsResult>;
|
|
1121
2936
|
/** Bind a version to a chart inside one of the caller's instances. The
|
|
1122
2937
|
* setBlob is the .set input-override text; edit it via updateDeployment. */
|
|
@@ -1126,8 +2941,22 @@ declare class EasResource {
|
|
|
1126
2941
|
removeDeployment(id: string): Promise<{
|
|
1127
2942
|
id: string;
|
|
1128
2943
|
}>;
|
|
2944
|
+
/** The newest live comparison of a deployment: its live trades matched against a backtest of the same window. */
|
|
2945
|
+
getLiveComparison(deploymentId: string): Promise<LiveComparison>;
|
|
2946
|
+
/** Queue a backtest of the deployment over `from`..`to` (billed as a
|
|
2947
|
+
* backtest); the comparison is ready from `getLiveComparison` once it finishes. */
|
|
2948
|
+
runLiveComparison(deploymentId: string, body: RunLiveComparisonBody): Promise<{
|
|
2949
|
+
runId: string;
|
|
2950
|
+
groupId: string;
|
|
2951
|
+
}>;
|
|
2952
|
+
/** The deployment's monitor: a scheduled re-backtest checked against its live trades. */
|
|
2953
|
+
getMonitor(deploymentId: string): Promise<MonitorStatus>;
|
|
2954
|
+
setMonitor(deploymentId: string, body: SetMonitorBody): Promise<MonitorStatus>;
|
|
1129
2955
|
}
|
|
1130
2956
|
|
|
2957
|
+
/** Instances on `/api/atlas/instances`: MT5 terminals and broker connections,
|
|
2958
|
+
* keyed by your own `externalRef`. None of these writes is de-duplicated by
|
|
2959
|
+
* the server, so the SDK never sends one twice. */
|
|
1131
2960
|
declare class InstancesResource {
|
|
1132
2961
|
private readonly http;
|
|
1133
2962
|
constructor(http: HttpTransport);
|
|
@@ -1135,25 +2964,34 @@ declare class InstancesResource {
|
|
|
1135
2964
|
get(id: string): Promise<AtlasInstance>;
|
|
1136
2965
|
getByExternalRef(ref: string): Promise<AtlasInstance>;
|
|
1137
2966
|
getByExternalRefs(refs: string[]): Promise<AtlasInstance[]>;
|
|
1138
|
-
|
|
1139
|
-
|
|
2967
|
+
/** Create an instance, or update yours that has the same `externalRef`.
|
|
2968
|
+
* Read the whole instance with `get(result.id)`. */
|
|
2969
|
+
create(body: CreateAtlasInstanceBody): Promise<CreateAtlasInstanceResult>;
|
|
2970
|
+
update(id: string, body: UpdateAtlasInstanceBody): Promise<{
|
|
2971
|
+
id: string;
|
|
2972
|
+
}>;
|
|
1140
2973
|
/**
|
|
1141
2974
|
* Wind an instance down: the host runner kills the terminal process and
|
|
1142
2975
|
* deletes the instance folder. Credentials stay stored, so the instance
|
|
1143
|
-
* can be re-enabled later. Returns the updated instance
|
|
2976
|
+
* can be re-enabled later. Returns the updated instance (null if it was
|
|
2977
|
+
* deleted meanwhile).
|
|
1144
2978
|
*/
|
|
1145
|
-
disable(id: string): Promise<AtlasInstance>;
|
|
2979
|
+
disable(id: string): Promise<AtlasInstance | null>;
|
|
1146
2980
|
/**
|
|
1147
2981
|
* Re-enable a wound-down instance: resets it to PENDING so the runner
|
|
1148
|
-
* redeploys it fresh. Returns the updated instance
|
|
2982
|
+
* redeploys it fresh. Returns the updated instance (null if it was
|
|
2983
|
+
* deleted meanwhile).
|
|
1149
2984
|
*/
|
|
1150
|
-
enable(id: string): Promise<AtlasInstance>;
|
|
2985
|
+
enable(id: string): Promise<AtlasInstance | null>;
|
|
1151
2986
|
delete(id: string): Promise<void>;
|
|
2987
|
+
/** Check broker credentials before you store them. For Dhan this logs in
|
|
2988
|
+
* and returns the minted access token; other brokers are not checked. */
|
|
2989
|
+
validateBrokerCredentials(body: ValidateBrokerCredentialsBody): Promise<ValidateBrokerCredentialsResult>;
|
|
1152
2990
|
}
|
|
1153
2991
|
|
|
1154
2992
|
interface InstrumentListParams {
|
|
1155
|
-
exchange?:
|
|
1156
|
-
segment?:
|
|
2993
|
+
exchange?: UnifiedInstrument["exchange"];
|
|
2994
|
+
segment?: UnifiedInstrument["segment"];
|
|
1157
2995
|
symbol?: string;
|
|
1158
2996
|
q?: string;
|
|
1159
2997
|
active?: boolean;
|
|
@@ -1165,7 +3003,7 @@ interface InstrumentListResult {
|
|
|
1165
3003
|
nextCursor: string | null;
|
|
1166
3004
|
}
|
|
1167
3005
|
interface ResolveInstrumentParams {
|
|
1168
|
-
broker: "dhan" | "motilal" | "kite" | "mt5";
|
|
3006
|
+
broker: "dhan" | "motilal" | "kite" | "mt5" | "angelone" | "fyers" | "upstox" | "shoonya";
|
|
1169
3007
|
refId: string;
|
|
1170
3008
|
segment?: string;
|
|
1171
3009
|
}
|
|
@@ -1179,6 +3017,7 @@ declare class InstrumentsV2 {
|
|
|
1179
3017
|
|
|
1180
3018
|
interface MarketCandlesParams {
|
|
1181
3019
|
instrumentKey: string;
|
|
3020
|
+
/** NSE/BSE (vendor feed): 1m, 5m, 15m, 1h, 1d. FX (MT5): every interval. */
|
|
1182
3021
|
interval: UnifiedInterval;
|
|
1183
3022
|
/** ISO 8601 or Date. */
|
|
1184
3023
|
from: string | Date;
|
|
@@ -1207,7 +3046,8 @@ declare class MarketV2 {
|
|
|
1207
3046
|
constructor(http: HttpTransport);
|
|
1208
3047
|
/** Latest tick. A vendor key nobody is watching is subscribed and read
|
|
1209
3048
|
* once from the vendor's REST endpoint, so this answers with a
|
|
1210
|
-
* `mode: "LTP"` snapshot
|
|
3049
|
+
* `mode: "LTP"` snapshot. An FX key with no tick yet answers a retryable
|
|
3050
|
+
* 404 (`VALIDATION`) while its subscription opens. */
|
|
1211
3051
|
quote(instrumentKey: string): Promise<UnifiedTick>;
|
|
1212
3052
|
/** Latest tick for up to 200 keys, with the cold ones read in one vendor
|
|
1213
3053
|
* call. `unresolved` names the keys that could not be priced and why —
|
|
@@ -1221,6 +3061,50 @@ declare class MarketV2 {
|
|
|
1221
3061
|
optionChain(underlyingKey: string, expiry: string): Promise<UnifiedOptionChain>;
|
|
1222
3062
|
}
|
|
1223
3063
|
|
|
3064
|
+
/**
|
|
3065
|
+
* MT5 terminals by login (`/api/external/instances`): deploy, start, stop and
|
|
3066
|
+
* remove them. Trade on one with `atlas.trading`. None of these writes is
|
|
3067
|
+
* de-duplicated by the server, so the SDK never sends one twice.
|
|
3068
|
+
*/
|
|
3069
|
+
declare class Mt5Resource {
|
|
3070
|
+
private readonly http;
|
|
3071
|
+
constructor(http: HttpTransport);
|
|
3072
|
+
private path;
|
|
3073
|
+
/** Your account's MT5 terminals, newest first. */
|
|
3074
|
+
list(): Promise<Instance[]>;
|
|
3075
|
+
/** Deploy a terminal. It starts as PENDING and the account is charged the provisioning fee. */
|
|
3076
|
+
create(body: CreateInstanceBody): Promise<Instance>;
|
|
3077
|
+
get(accountId: string): Promise<Instance>;
|
|
3078
|
+
/** Remove the terminal. No credits are refunded. */
|
|
3079
|
+
delete(accountId: string): Promise<void>;
|
|
3080
|
+
/** Enable the terminal and queue it to deploy again. */
|
|
3081
|
+
start(accountId: string): Promise<Instance>;
|
|
3082
|
+
/** Disable the terminal. Allowed even while terminals are switched to read-only. */
|
|
3083
|
+
stop(accountId: string): Promise<Instance>;
|
|
3084
|
+
/** MT5 servers `create` accepts as `serverName`. */
|
|
3085
|
+
servers(): Promise<DeployServer[]>;
|
|
3086
|
+
/** Regions with room for a new terminal, for `create`'s `regionId`. */
|
|
3087
|
+
regions(): Promise<DeployRegion[]>;
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
interface ScannerBoardParams {
|
|
3091
|
+
/** Add each stock's per-minute move since 09:15 IST as `paths`. */
|
|
3092
|
+
paths?: boolean;
|
|
3093
|
+
/** With `paths`: start each path at this session minute, to fetch only what you lack. */
|
|
3094
|
+
after?: number;
|
|
3095
|
+
}
|
|
3096
|
+
/** The NSE intraday scanner (`/api/v2/scanner/*`). Needs the `feed:r` scope
|
|
3097
|
+
* and the account's India entitlement; every row is an NSE equity. */
|
|
3098
|
+
declare class ScannerV2 {
|
|
3099
|
+
private readonly http;
|
|
3100
|
+
constructor(http: HttpTransport);
|
|
3101
|
+
/** The current board: every ranked stock, the picks on each side, breadth and sectors. */
|
|
3102
|
+
board(params?: ScannerBoardParams): Promise<ScannerBoard>;
|
|
3103
|
+
/** Order-block zones, stops and targets on the last two sessions of 5m
|
|
3104
|
+
* bars, for a stock the scanner ranks (`NSE:EQ:<symbol>`). 404 for any other. */
|
|
3105
|
+
zones(instrumentKey: string): Promise<ScannerZones>;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
1224
3108
|
declare class ServiceKeysResource {
|
|
1225
3109
|
private readonly http;
|
|
1226
3110
|
constructor(http: HttpTransport);
|
|
@@ -1245,22 +3129,47 @@ declare class SubscriptionsResource {
|
|
|
1245
3129
|
getCandleSubscriptions(instanceId: string): Promise<CandleSubscriptions>;
|
|
1246
3130
|
}
|
|
1247
3131
|
|
|
3132
|
+
/**
|
|
3133
|
+
* MT5 trading on one terminal, named by its MT5 login: `/api/external/instances/:accountId`.
|
|
3134
|
+
*
|
|
3135
|
+
* The reads that come from the terminal can return their freshness too: pass
|
|
3136
|
+
* `{ withFreshness: true }` to get `{ data, dataAsOf, lastHeartbeatAt }`. A
|
|
3137
|
+
* terminal Atlaas cannot see answers 503 with `code: "TERMINAL_UNAVAILABLE"`
|
|
3138
|
+
* rather than an empty list.
|
|
3139
|
+
*/
|
|
1248
3140
|
declare class TradingResource {
|
|
1249
3141
|
private readonly http;
|
|
1250
3142
|
constructor(http: HttpTransport);
|
|
1251
3143
|
private path;
|
|
1252
|
-
|
|
3144
|
+
private read;
|
|
3145
|
+
/** An order write: it runs at most once per Idempotency-Key. */
|
|
3146
|
+
private write;
|
|
3147
|
+
placeOrder(accountId: string, body: PlaceOrderBody, options?: WriteOptions): Promise<Order>;
|
|
1253
3148
|
getOrders(accountId: string): Promise<Order[]>;
|
|
1254
|
-
|
|
3149
|
+
getOrders(accountId: string, options: FreshnessOption): Promise<Fresh<Order[]>>;
|
|
3150
|
+
cancelOrder(accountId: string, ticket: number, options?: WriteOptions): Promise<void>;
|
|
3151
|
+
/** Open positions, as the EA last pushed them (held for a few seconds). */
|
|
1255
3152
|
getPositions(accountId: string): Promise<Position[]>;
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
3153
|
+
getPositions(accountId: string, options: FreshnessOption): Promise<Fresh<Position[]>>;
|
|
3154
|
+
/** One position by ticket. A ticket no longer open is read from the terminal's history as `status: "CLOSED"`. */
|
|
3155
|
+
getPosition(accountId: string, ticket: number): Promise<PositionDetail>;
|
|
3156
|
+
getPosition(accountId: string, ticket: number, options: FreshnessOption): Promise<Fresh<PositionDetail>>;
|
|
3157
|
+
/** Fully closed positions from the terminal's deal history, oldest first. Page with `since` = the last `closeTimeMs`. */
|
|
3158
|
+
getClosedPositions(accountId: string, query: ClosedPositionsQuery): Promise<ClosedPositionsResult>;
|
|
3159
|
+
modifyPosition(accountId: string, ticket: number, body: ModifyPositionBody, options?: WriteOptions): Promise<ModifyMt5PositionResult>;
|
|
3160
|
+
closePosition(accountId: string, ticket: number, body?: ClosePositionBody, options?: WriteOptions): Promise<CloseMt5PositionResult>;
|
|
3161
|
+
closeBySymbol(accountId: string, body: CloseBySymbolBody, options?: WriteOptions): Promise<CloseBySymbolResult>;
|
|
1260
3162
|
getPrice(accountId: string, symbol: string): Promise<Price>;
|
|
3163
|
+
getPrice(accountId: string, symbol: string, options: FreshnessOption): Promise<Fresh<Price>>;
|
|
1261
3164
|
getSymbols(accountId: string): Promise<string[]>;
|
|
3165
|
+
getSymbols(accountId: string, options: FreshnessOption): Promise<Fresh<string[]>>;
|
|
3166
|
+
/** Contract specs for every symbol on the terminal's server, raw from the terminal. */
|
|
3167
|
+
getSymbolSpecs(accountId: string): Promise<Mt5SymbolSpec[]>;
|
|
3168
|
+
getSymbolSpecs(accountId: string, options: FreshnessOption): Promise<Fresh<Mt5SymbolSpec[]>>;
|
|
1262
3169
|
getAccountInfo(accountId: string): Promise<AccountInfo>;
|
|
3170
|
+
getAccountInfo(accountId: string, options: FreshnessOption): Promise<Fresh<AccountInfo>>;
|
|
1263
3171
|
getCandles(accountId: string, query: GetCandlesQuery): Promise<Candle[]>;
|
|
3172
|
+
/** A calculation, not a write: it changes nothing on the terminal. */
|
|
1264
3173
|
calculateMargin(accountId: string, body: CalculateMarginBody): Promise<MarginResult>;
|
|
1265
3174
|
}
|
|
1266
3175
|
|
|
@@ -1272,44 +3181,29 @@ interface AtlasClientOptions {
|
|
|
1272
3181
|
logger?: AtlasLogger;
|
|
1273
3182
|
}
|
|
1274
3183
|
declare class AtlasClient {
|
|
3184
|
+
/** Instances and broker connections on `/api/atlas/instances`. */
|
|
1275
3185
|
readonly instances: InstancesResource;
|
|
3186
|
+
/** MT5 terminals by login: deploy, start, stop, remove. */
|
|
3187
|
+
readonly mt5: Mt5Resource;
|
|
1276
3188
|
readonly eas: EasResource;
|
|
3189
|
+
readonly backtests: BacktestsResource;
|
|
3190
|
+
/** MT5 trading on one terminal, by login. */
|
|
1277
3191
|
readonly trading: TradingResource;
|
|
1278
3192
|
readonly subscriptions: SubscriptionsResource;
|
|
1279
3193
|
readonly serviceKeys: ServiceKeysResource;
|
|
1280
3194
|
readonly v2: {
|
|
1281
3195
|
instruments: InstrumentsV2;
|
|
1282
3196
|
market: MarketV2;
|
|
3197
|
+
scanner: ScannerV2;
|
|
1283
3198
|
connections: (connectionId: string) => ConnectionsV2;
|
|
1284
3199
|
};
|
|
1285
3200
|
private readonly http;
|
|
1286
3201
|
private readonly brokersResource;
|
|
1287
3202
|
constructor(options: AtlasClientOptions);
|
|
3203
|
+
/** A broker connection's own API, by broker name and the connection's `externalRef`. */
|
|
1288
3204
|
broker(brokerName: string, connectionId: string): BrokerConnectionResource;
|
|
1289
3205
|
}
|
|
1290
3206
|
|
|
1291
|
-
declare class AtlasError extends Error {
|
|
1292
|
-
readonly statusCode: number;
|
|
1293
|
-
readonly errorCode?: number;
|
|
1294
|
-
readonly requestId?: string;
|
|
1295
|
-
constructor(message: string, statusCode?: number, errorCode?: number, requestId?: string);
|
|
1296
|
-
}
|
|
1297
|
-
declare class AtlasAuthError extends AtlasError {
|
|
1298
|
-
constructor(message: string, requestId?: string);
|
|
1299
|
-
}
|
|
1300
|
-
declare class AtlasRateLimitError extends AtlasError {
|
|
1301
|
-
readonly retryAfter?: number;
|
|
1302
|
-
constructor(message: string, retryAfter?: number, requestId?: string);
|
|
1303
|
-
}
|
|
1304
|
-
declare class AtlasValidationError extends AtlasError {
|
|
1305
|
-
readonly fields?: string[];
|
|
1306
|
-
constructor(message: string, fields?: string[], requestId?: string);
|
|
1307
|
-
}
|
|
1308
|
-
declare class AtlasNetworkError extends AtlasError {
|
|
1309
|
-
readonly cause?: unknown;
|
|
1310
|
-
constructor(message: string, cause?: unknown);
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
3207
|
interface AtlasWebSocketOptions {
|
|
1314
3208
|
baseUrl: string;
|
|
1315
3209
|
apiKey: string;
|
|
@@ -1321,11 +3215,21 @@ interface AtlasWebSocketOptions {
|
|
|
1321
3215
|
type WSEventMap = {
|
|
1322
3216
|
tick: [MT5Tick];
|
|
1323
3217
|
candle: [MT5Candle];
|
|
3218
|
+
position_update: [MT5PositionUpdate];
|
|
3219
|
+
trade_event: [MT5TradeEvent];
|
|
3220
|
+
heartbeat: [MT5Heartbeat];
|
|
1324
3221
|
broker_tick: [BrokerTick];
|
|
1325
3222
|
broker_order_update: [BrokerOrderUpdate];
|
|
1326
3223
|
"market.tick": [MarketTickMessage];
|
|
1327
3224
|
"market.candle": [MarketCandleMessage];
|
|
3225
|
+
"market.chain": [MarketChainMessage];
|
|
3226
|
+
"market.scanner": [MarketScannerMessage];
|
|
1328
3227
|
"trading.order": [TradingOrderMessage];
|
|
3228
|
+
/** The server's reply to `subscribe`, naming anything it refused. */
|
|
3229
|
+
subscribed: [SubscribedMessage];
|
|
3230
|
+
/** A subscribe refused on the account's standing; nothing changed. */
|
|
3231
|
+
subscribe_failed: [SubscribeFailedMessage];
|
|
3232
|
+
unsubscribed: [UnsubscribedMessage];
|
|
1329
3233
|
connected: [];
|
|
1330
3234
|
disconnected: [string];
|
|
1331
3235
|
error: [Error];
|
|
@@ -1346,8 +3250,14 @@ declare class AtlasWebSocket extends EventEmitter {
|
|
|
1346
3250
|
constructor(options: AtlasWebSocketOptions);
|
|
1347
3251
|
connect(): Promise<void>;
|
|
1348
3252
|
disconnect(): void;
|
|
3253
|
+
/** Add channels and filters. The server merges every subscribe on a socket,
|
|
3254
|
+
* and so does the reconnect replay. Its `subscribed` reply names anything
|
|
3255
|
+
* refused; `subscribe_failed` means the account's standing refused it whole. */
|
|
1349
3256
|
subscribe(options: WSSubscribeOptions): void;
|
|
1350
|
-
|
|
3257
|
+
private send;
|
|
3258
|
+
/** Drop channels, or only some instrumentKeys / chains while the channels
|
|
3259
|
+
* stay subscribed. Passing an array is the same as `{ channels }`. */
|
|
3260
|
+
unsubscribe(options: WSChannel[] | WSUnsubscribeOptions): void;
|
|
1351
3261
|
get isConnected(): boolean;
|
|
1352
3262
|
private handleMessage;
|
|
1353
3263
|
private sendJson;
|
|
@@ -1358,4 +3268,4 @@ declare class AtlasWebSocket extends EventEmitter {
|
|
|
1358
3268
|
emit<K extends keyof WSEventMap>(event: K, ...args: WSEventMap[K]): boolean;
|
|
1359
3269
|
}
|
|
1360
3270
|
|
|
1361
|
-
export { type AccountInfo, AtlasAuthError, AtlasClient, type AtlasClientOptions, AtlasError, type AtlasInstance, type AtlasLogger, AtlasNetworkError, AtlasRateLimitError, AtlasValidationError, AtlasWebSocket, type AtlasWebSocketOptions, type BrokerCancelOrderBody, type BrokerCandlesQuery, type BrokerCapabilities, type BrokerModifyOrderBody, type BrokerOrderBody, type BrokerOrderUpdate, type BrokerSubscribeBody, type BrokerTick, type BrokerUnsubscribeBody, type CalculateMarginBody, type CancelOrderResult, type Candle, type CandleSubscriptions, type CloseBySymbolBody, type ClosePositionBody, type ClosePositionResult, type ClosePositionV2Body, ConnectionsV2, type CreateAtlasInstanceBody, type CreateDeploymentBody, type CreateEaBody, type CreateInstanceBody, type CreateServiceKeyBody, type Deployment, type DeploymentState, type DroppedRow, type Ea, type EaCompileStatus, type EaInputManifest, type EaInputParam, type EaInputType, type EaSourceType, type EaTimeframe, type EaVersion, type EaVersionStatus, type GetCandlesQuery, type Instance, type InstanceState, type InstanceType, type ListDeploymentsQuery, type ListDeploymentsResult, type ListEaVersionsQuery, type ListEaVersionsResult, type ListInstancesQuery, type MT5Candle, type MT5Tick, type MarginOrderType, type MarginResult, type MarketCandleMessage, type MarketCandlesParams, type MarketCandlesResult, type MarketQuotesResult, type MarketTickMessage, MarketV2, type ModifyOrderResult, type ModifyOrderV2Body, type ModifyPositionBody, type Order, type OrderDirection, type OrderType, type PlaceOrderBody, type PlaceOrderResult, type PlaceOrderV2Body, type Position, type PresignEaVersionBody, type PresignEaVersionResult, type Price, type RegisterEaVersionBody, type ServiceKey, type ServiceKeyWithRaw, type SubscribeCandleBody, type SubscribeTickBody, type TickSubscriptions, type Timeframe, type TradingOrderMessage, type UnifiedCandle, type UnifiedError, type UnifiedFunds, type UnifiedHolding, type UnifiedInstrument, type UnifiedInterval, type UnifiedOrder, type UnifiedPosition, type UnifiedProfile, type UnifiedTick, type UnifiedTrade, type UnsubscribeCandleBody, type UnsubscribeTickBody, type UpdateAtlasInstanceBody, type UpdateDeploymentBody, type UpdateEaBody, type UpdateServiceKeyBody, type V2Snapshot, type WSChannel, type WSSubscribeOptions };
|
|
3271
|
+
export { type AccountInfo, type ApiEnvelope, AtlasAuthError, AtlasClient, type AtlasClientOptions, AtlasError, type AtlasErrorCode, type AtlasErrorDetails, type AtlasInstance, type AtlasLogger, AtlasNetworkError, AtlasRateLimitError, AtlasValidationError, AtlasWebSocket, type AtlasWebSocketOptions, type BacktestAiSummary, type BacktestAnalytics, type BacktestBatchKind, type BacktestBatchReport, type BacktestEstimate, type BacktestEstimateQuery, type BacktestExecutor, type BacktestExitReason, type BacktestGroup, type BacktestGroupKind, type BacktestPassesQuery, type BacktestPassesResult, type BacktestPeerContext, type BacktestRedFlag, type BacktestResultUrls, type BacktestRun, type BacktestRunMode, type BacktestRunStats, type BacktestSourceDiff, type BacktestStats, type BacktestStatus, type BacktestTickMode, type BacktestTrade, type BacktestTradeAggregate, type BacktestTradeAggregateRow, type BacktestTradeSort, type BacktestTradesQuery, type BacktestTradesResult, type BacktestWindow, BacktestsResource, type BrokerCancelOrderBody, type BrokerCandlesQuery, type BrokerCapabilities, BrokerConnectionResource, type BrokerInstrumentRef, type BrokerModifyOrderBody, type BrokerOrder, type BrokerOrderBody, type BrokerOrderUpdate, type BrokerSubscribeBody, BrokerSubscriptionsResource, type BrokerTick, type BrokerUnsubscribeBody, type CalculateMarginBody, type CancelBacktestRunResult, type CancelOrderResult, type Candle, type CandleSubscription, type CandleSubscriptions, type CapabilitiesResult, type ChainSelector, type CloseBySymbolBody, type CloseBySymbolResult, type CloseMt5PositionResult, type ClosePositionBody, type ClosePositionResult, type ClosePositionV2Body, type ClosedPosition, type ClosedPositionDetail, type ClosedPositionsQuery, type ClosedPositionsResult, ConnectionsV2, type CreateAtlasInstanceBody, type CreateAtlasInstanceResult, type CreateBacktestBatchBody, type CreateBacktestBatchResult, type CreateBacktestBody, type CreateBacktestResult, type CreateDeploymentBody, type CreateEaBody, type CreateEaPresetBody, type CreateInstanceBody, type CreateNoiseTestBody, type CreateNoiseTestResult, type CreateServiceKeyBody, type CreateWalkForwardMatrixBody, type CreateWalkForwardMatrixResult, type DeployRegion, type DeployServer, type Deployment, type DeploymentState, type DhanOptionChain, type DhanOptionLeg, type DhanSegment, type DhanUnderlying, type DroppedMt5Row, type DroppedRow, type Ea, type EaCompileFailure, type EaCompileStatus, type EaInputManifest, type EaInputParam, type EaInputType, type EaPreset, type EaSourceType, type EaTimeframe, type EaVersion, type EaVersionSource, type EaVersionStatus, EasResource, type ExpirationType, type FillingMode, type Fresh, type FreshnessOption, type GetCandlesQuery, type HoldingsListResult, type IncludeRawParams, type Instance, type InstanceState, type InstanceType, InstancesResource, type InstrumentListParams, type InstrumentListResult, InstrumentsV2, type ListBacktestsQuery, type ListBacktestsResult, type ListDeploymentsQuery, type ListDeploymentsResult, type ListEaVersionsQuery, type ListEaVersionsResult, type ListInstancesQuery, type LiveComparison, type LiveComparisonMatch, type LiveComparisonSummary, type MT5Candle, type MT5Heartbeat, type MT5LivePosition, type MT5PositionUpdate, type MT5Tick, type MT5TradeEvent, type MarginOrderType, type MarginResult, type MarketCandleMessage, type MarketCandlesParams, type MarketCandlesResult, type MarketChainMessage, type MarketFeedState, type MarketQuotesResult, type MarketScannerMessage, type MarketTickMessage, MarketV2, type ModifyMt5PositionResult, type ModifyOrderResult, type ModifyOrderV2Body, type ModifyPositionBody, type ModifyPositionResult, type ModifyPositionV2Body, type MonitorStatus, type MonitorVerdict, Mt5Resource, type Mt5SymbolSpec, type NoiseTestConfig, type OpenPositionDetail, type OptimizationAlgorithm, type OptimizationConfig, type OptimizationConfigInput, type OptimizationCriterion, type OptimizationPass, type OptimizationRange, type Order, type OrderDirection, type OrderType, type OrdersListParams, type OrdersListResult, type PlaceOrderBody, type PlaceOrderResult, type PlaceOrderV2Body, type PortfolioBody, type PortfolioReport, type Position, type PositionDetail, type PositionsListParams, type PositionsListResult, type PresignEaVersionBody, type PresignEaVersionResult, type Price, type RefusedInstrumentKeyReason, type RegisterEaVersionBody, type RegisteredEaVersion, type ResolveInstrumentParams, type RetiredWSChannel, type RevealOosResult, type RunLiveComparisonBody, type SaveEaSourceBody, type ScannerBoard, type ScannerBoardParams, type ScannerRow, type ScannerSession, type ScannerSessionState, ScannerV2, type ScannerZones, type ServiceKey, type ServiceKeyWithRaw, ServiceKeysResource, type SetMonitorBody, type SpreadCalibration, type SubscribeCandleBody, type SubscribeFailedMessage, type SubscribeTickBody, type SubscribedMessage, SubscriptionsResource, type SwapArbRow, type SwapArbitrageReport, type SymbolSpecsResult, type TickSubscriptions, type Timeframe, type TradesListResult, type TradingOrderMessage, TradingResource, type UnifiedCandle, type UnifiedError, type UnifiedErrorCode, type UnifiedFunds, type UnifiedHolding, type UnifiedInstrument, type UnifiedInterval, type UnifiedOptionChain, type UnifiedOptionExpiries, type UnifiedOptionLeg, type UnifiedOrder, type UnifiedPosition, type UnifiedProfile, type UnifiedSymbolSpec, type UnifiedTick, type UnifiedTrade, type UnsubscribeCandleBody, type UnsubscribeTickBody, type UnsubscribedMessage, type UpdateAtlasInstanceBody, type UpdateDeploymentBody, type UpdateEaBody, type UpdateServiceKeyBody, type V2Snapshot, type V2WriteOptions, type ValidateBrokerCredentialsBody, type ValidateBrokerCredentialsResult, type WSChannel, type WSEventMap, type WSSubscribeOptions, type WSUnsubscribeOptions, type WalkForwardConfig, type WalkForwardReport, type WriteOptions };
|