atlaas 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1361 @@
1
+ import { EventEmitter } from 'node:events';
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
+ type InstanceState = "PENDING" | "DEPLOYING" | "DEPLOYED" | "RUNNING" | "STOPPED" | "ERROR";
35
+ type InstanceType = "TICK" | "TICKS_TRADE" | "TRADE";
36
+ type OrderDirection = "BUY" | "SELL";
37
+ type OrderType = "BUY" | "SELL" | "BUY_LIMIT" | "SELL_LIMIT" | "BUY_STOP" | "SELL_STOP" | "BUY_STOP_LIMIT" | "SELL_STOP_LIMIT";
38
+ type MarginOrderType = "ORDER_TYPE_BUY" | "ORDER_TYPE_SELL" | "ORDER_TYPE_BUY_LIMIT" | "ORDER_TYPE_SELL_LIMIT" | "ORDER_TYPE_BUY_STOP" | "ORDER_TYPE_SELL_STOP" | "ORDER_TYPE_BUY_STOP_LIMIT" | "ORDER_TYPE_SELL_STOP_LIMIT";
39
+ type Timeframe = "M1" | "M5" | "M15" | "M30" | "H1" | "H2" | "H4" | "D1" | "W1" | "MN1";
40
+ type FillingMode = "ORDER_FILLING_FOK" | "ORDER_FILLING_IOC" | "ORDER_FILLING_RETURN";
41
+ type ExpirationType = "ORDER_TIME_GTC" | "ORDER_TIME_DAY" | "ORDER_TIME_SPECIFIED" | "ORDER_TIME_SPECIFIED_DAY";
42
+ interface Instance {
43
+ id: string;
44
+ accountId: string;
45
+ serverName: string | null;
46
+ brokerName: string | null;
47
+ name: string | null;
48
+ state: InstanceState;
49
+ type: InstanceType;
50
+ enabled: boolean;
51
+ lastActiveAt: string | null;
52
+ connectedAt: string | null;
53
+ errorMessage: string | null;
54
+ statusMessage: string | null;
55
+ createdAt: string;
56
+ updatedAt: string;
57
+ }
58
+ interface AtlasInstance {
59
+ id: string;
60
+ externalRef: string | null;
61
+ externalUserId: string | null;
62
+ instanceKind: string | null;
63
+ /** Broker-side account identifier: MT5 login or broker clientId (Dhan/Kite). */
64
+ accountId: string | null;
65
+ runnerId: string;
66
+ state: InstanceState;
67
+ enabled: boolean;
68
+ registeredIp: string | null;
69
+ lastActiveAt: string | null;
70
+ connectedAt: string | null;
71
+ disconnectedAt: string | null;
72
+ statusMessage: string | null;
73
+ errorMessage: string | null;
74
+ lastError?: string | null;
75
+ lastErrorAt?: string | null;
76
+ displayName?: string | null;
77
+ metadata?: Record<string, unknown> | null;
78
+ createdAt?: string;
79
+ updatedAt?: string;
80
+ }
81
+ interface CreateInstanceBody {
82
+ accountId: string;
83
+ password?: string;
84
+ serverName: string;
85
+ brokerName?: string;
86
+ name?: string;
87
+ type?: InstanceType;
88
+ }
89
+ interface CreateAtlasInstanceBody {
90
+ externalRef?: string;
91
+ externalUserId?: string;
92
+ instanceKind: string;
93
+ runnerId: string;
94
+ name?: string;
95
+ metadata?: Record<string, unknown>;
96
+ credentials: Record<string, unknown>;
97
+ /** Owner account. Service-key callers ignore this (ownership is the key's
98
+ * account); only master-key callers set it, and it must be a real AtlasAccount. */
99
+ atlasAccountId?: string;
100
+ }
101
+ interface UpdateAtlasInstanceBody {
102
+ state?: InstanceState;
103
+ enabled?: boolean;
104
+ autoRestart?: boolean;
105
+ metadata?: Record<string, unknown>;
106
+ credentials?: Record<string, unknown>;
107
+ credentialsPatch?: Record<string, unknown>;
108
+ }
109
+ interface ListInstancesQuery {
110
+ instanceKind?: string;
111
+ state?: string;
112
+ externalUserId?: string;
113
+ limit?: number;
114
+ }
115
+ interface AccountInfo {
116
+ accountId: string;
117
+ balance: number;
118
+ equity: number;
119
+ margin: number;
120
+ freeMargin: number;
121
+ leverage?: number;
122
+ currency?: string;
123
+ server?: string;
124
+ name?: string;
125
+ credit?: number;
126
+ profit?: number;
127
+ marginLevel?: number;
128
+ tradeAllowed?: boolean;
129
+ }
130
+ interface Position {
131
+ ticket: number;
132
+ symbol: string;
133
+ type: OrderDirection;
134
+ volume: number;
135
+ openPrice: number;
136
+ currentPrice: number;
137
+ sl: number;
138
+ tp: number;
139
+ profit: number;
140
+ swap: number;
141
+ openTime: number;
142
+ commission?: number;
143
+ comment?: string;
144
+ magic?: number;
145
+ }
146
+ interface ModifyPositionBody {
147
+ sl?: number;
148
+ tp?: number;
149
+ }
150
+ interface ClosePositionBody {
151
+ volume?: number;
152
+ }
153
+ interface CloseBySymbolBody {
154
+ symbol: string;
155
+ }
156
+ interface Order {
157
+ ticket: number;
158
+ symbol: string;
159
+ type: string;
160
+ volume: number;
161
+ price: number;
162
+ sl: number;
163
+ tp: number;
164
+ openTime?: number;
165
+ comment?: string;
166
+ magic?: number;
167
+ state?: string;
168
+ expiration?: number;
169
+ volumeCurrent?: number;
170
+ }
171
+ interface PlaceOrderBody {
172
+ symbol: string;
173
+ type: OrderType;
174
+ volume: number;
175
+ price?: number;
176
+ sl?: number;
177
+ tp?: number;
178
+ deviation?: number;
179
+ comment?: string;
180
+ magic?: number;
181
+ filling?: FillingMode;
182
+ expiration?: ExpirationType;
183
+ expirationTime?: string;
184
+ }
185
+ interface Price {
186
+ symbol: string;
187
+ bid: number;
188
+ ask: number;
189
+ last?: number;
190
+ volume?: number;
191
+ timestamp?: number;
192
+ }
193
+ interface Candle {
194
+ time: string;
195
+ open: number;
196
+ high: number;
197
+ low: number;
198
+ close: number;
199
+ tickVolume: number;
200
+ spread: number;
201
+ realVolume?: number;
202
+ }
203
+ interface GetCandlesQuery {
204
+ symbol: string;
205
+ timeframe: Timeframe | string;
206
+ startTime?: string;
207
+ endTime?: string;
208
+ count?: number;
209
+ }
210
+ interface CalculateMarginBody {
211
+ symbol: string;
212
+ type: MarginOrderType | string;
213
+ volume: number;
214
+ openPrice: number;
215
+ }
216
+ interface MarginResult {
217
+ margin: number;
218
+ currency?: string;
219
+ }
220
+ interface ServiceKey {
221
+ id: string;
222
+ keyName: string;
223
+ keyPrefix: string;
224
+ description: string | null;
225
+ isActive: boolean;
226
+ lastUsedAt: string | null;
227
+ expiresAt: string | null;
228
+ maxInstances: number | null;
229
+ instanceCount: number;
230
+ rateLimitPerMinute: number | null;
231
+ rateLimitPerDay: number | null;
232
+ requestCount: number;
233
+ allowedIpAddresses: string[];
234
+ createdAt: string;
235
+ updatedAt: string;
236
+ }
237
+ interface ServiceKeyWithRaw extends ServiceKey {
238
+ rawKey: string;
239
+ }
240
+ interface CreateServiceKeyBody {
241
+ keyName: string;
242
+ description?: string;
243
+ maxInstances?: number;
244
+ rateLimitPerMinute?: number;
245
+ rateLimitPerDay?: number;
246
+ expiresAt?: string;
247
+ allowedIpAddresses?: string[];
248
+ }
249
+ interface UpdateServiceKeyBody {
250
+ keyName?: string;
251
+ description?: string;
252
+ isActive?: boolean;
253
+ maxInstances?: number;
254
+ rateLimitPerMinute?: number;
255
+ rateLimitPerDay?: number;
256
+ expiresAt?: string | null;
257
+ allowedIpAddresses?: string[];
258
+ }
259
+ interface SubscribeTickBody {
260
+ symbol: string;
261
+ }
262
+ interface UnsubscribeTickBody {
263
+ symbol?: string;
264
+ }
265
+ interface TickSubscriptions {
266
+ instanceId: string;
267
+ accountId: string;
268
+ symbols: string[];
269
+ count: number;
270
+ }
271
+ interface SubscribeCandleBody {
272
+ symbol: string;
273
+ timeframe: string;
274
+ }
275
+ interface UnsubscribeCandleBody {
276
+ symbol?: string;
277
+ timeframe?: string;
278
+ }
279
+ interface CandleSubscription {
280
+ symbol: string;
281
+ timeframe: string;
282
+ }
283
+ interface CandleSubscriptions {
284
+ instanceId: string;
285
+ accountId: string;
286
+ subscriptions: CandleSubscription[];
287
+ count: number;
288
+ }
289
+ type EaInputType = "int" | "long" | "double" | "bool" | "string" | "datetime" | "color" | "enum";
290
+ /** Mirror of @atlaas/types EaInputParam — one parsed .mq5 input declaration. */
291
+ interface EaInputParam {
292
+ name: string;
293
+ type: EaInputType;
294
+ default: string;
295
+ label?: string;
296
+ group?: string;
297
+ optimizable: boolean;
298
+ enumOptions?: {
299
+ value: number;
300
+ label: string;
301
+ }[];
302
+ conditional?: boolean;
303
+ }
304
+ /** Mirror of @atlaas/types EaInputManifest. Null for .ex5-only versions. */
305
+ type EaInputManifest = EaInputParam[];
306
+ type EaSourceType = "EX5" | "MQ5";
307
+ type EaVersionStatus = "DRAFT" | "LIVE" | "ARCHIVED";
308
+ type EaCompileStatus = "NONE" | "PENDING" | "COMPILING" | "COMPILED" | "FAILED";
309
+ interface Ea {
310
+ id: string;
311
+ slug: string;
312
+ name: string;
313
+ description: string | null;
314
+ latestVersionId: string | null;
315
+ versionCount: number;
316
+ createdAt: string;
317
+ updatedAt: string;
318
+ }
319
+ interface EaVersion {
320
+ id: string;
321
+ version: string;
322
+ status: EaVersionStatus;
323
+ sourceType: EaSourceType;
324
+ compileStatus: EaCompileStatus;
325
+ /** True when the version has a runnable .ex5 (compileStatus NONE or COMPILED). */
326
+ deployable: boolean;
327
+ sha256: string | null;
328
+ sizeBytes: number | null;
329
+ /** Parsed .mq5 input params; null for .ex5-only versions. */
330
+ inputManifest: EaInputManifest | null;
331
+ /** The input Atlaas sets to each deployment's magicNumber; null for .ex5-only versions or when none is found. */
332
+ magicInput: string | null;
333
+ /** Why Atlaas can't set this version's magic number, when it can't. */
334
+ magicInputWarning: string | null;
335
+ deploymentCount: number;
336
+ uploadedAt: string;
337
+ }
338
+ interface CreateEaBody {
339
+ name: string;
340
+ slug?: string;
341
+ description?: string;
342
+ }
343
+ interface UpdateEaBody {
344
+ name?: string;
345
+ description?: string | null;
346
+ }
347
+ interface ListEaVersionsQuery {
348
+ limit?: number;
349
+ offset?: number;
350
+ }
351
+ interface ListEaVersionsResult {
352
+ items: EaVersion[];
353
+ total: number;
354
+ limit: number;
355
+ offset: number;
356
+ }
357
+ interface ListDeploymentsResult {
358
+ items: Deployment[];
359
+ total: number;
360
+ limit: number;
361
+ offset: number;
362
+ }
363
+ interface PresignEaVersionBody {
364
+ version: string;
365
+ sourceType: EaSourceType;
366
+ sha256?: string;
367
+ sizeBytes: number;
368
+ contentType?: string;
369
+ }
370
+ interface PresignEaVersionResult {
371
+ url: string;
372
+ r2Key: string;
373
+ expiresAt: string;
374
+ }
375
+ interface RegisterEaVersionBody {
376
+ r2Key: string;
377
+ version: string;
378
+ sourceType: EaSourceType;
379
+ sha256?: string;
380
+ sizeBytes?: number;
381
+ }
382
+ type EaTimeframe = "M1" | "M5" | "M15" | "M30" | "H1" | "H4" | "D1" | "W1" | "MN1";
383
+ type DeploymentState = "RUNNING" | "ERROR" | "STOPPED" | "PENDING";
384
+ interface Deployment {
385
+ id: string;
386
+ instanceId: string;
387
+ symbol: string;
388
+ timeframe: string;
389
+ /** The .set key=value input override blob, or null. */
390
+ setBlob: string | null;
391
+ /** Allocated by Atlaas, unique across the account. Written into the EA's magicInput. */
392
+ magicNumber: number;
393
+ magicInput: string | null;
394
+ magicInputWarning: string | null;
395
+ enabled: boolean;
396
+ state: DeploymentState;
397
+ stateReason: string | null;
398
+ versionId: string;
399
+ version: string;
400
+ ea: {
401
+ id: string;
402
+ name: string;
403
+ slug: string;
404
+ };
405
+ createdAt: string;
406
+ updatedAt: string;
407
+ }
408
+ interface ListDeploymentsQuery {
409
+ instanceId?: string;
410
+ limit?: number;
411
+ offset?: number;
412
+ }
413
+ interface CreateDeploymentBody {
414
+ versionId: string;
415
+ instanceId: string;
416
+ symbol: string;
417
+ timeframe: EaTimeframe;
418
+ setBlob?: string;
419
+ }
420
+ interface UpdateDeploymentBody {
421
+ enabled?: boolean;
422
+ symbol?: string;
423
+ timeframe?: EaTimeframe;
424
+ setBlob?: string | null;
425
+ }
426
+ interface BrokerOrderBody {
427
+ order: Record<string, unknown>;
428
+ }
429
+ interface BrokerModifyOrderBody {
430
+ changes: Record<string, unknown>;
431
+ }
432
+ interface BrokerCancelOrderBody {
433
+ parentOrderId?: string;
434
+ variety?: string;
435
+ }
436
+ interface BrokerSubscribeBody {
437
+ refs: Array<{
438
+ securityId: string;
439
+ exchangeSegment: string;
440
+ instrumentType?: string;
441
+ }>;
442
+ mode?: "ticker" | "ltp" | "quote" | "full" | "depth20";
443
+ }
444
+ interface BrokerUnsubscribeBody {
445
+ refs: Array<{
446
+ securityId: string;
447
+ exchangeSegment: string;
448
+ }>;
449
+ }
450
+ interface BrokerCandlesQuery {
451
+ [key: string]: string | number | boolean | undefined;
452
+ }
453
+ type WSChannel = "ticks" | "candles" | "positions" | "trades" | "orders" | "broker_ticks" | "broker_orders" | "market.ticks" | "market.candles" | "market.chain" | "trading.orders";
454
+ interface WSSubscribeOptions {
455
+ channels: WSChannel[];
456
+ accountIds?: string[];
457
+ symbols?: string[];
458
+ brokerConnectionIds?: string[];
459
+ brokerSecurityKeys?: string[];
460
+ /** Connection scoping for the broker_orders AND trading.orders channels.
461
+ * Separate dimension from brokerConnectionIds (tick scoping) so the two can differ. */
462
+ brokerOrderConnectionIds?: string[];
463
+ /** market.ticks / market.candles filter by canonical instrumentKey. You
464
+ * receive only the keys you name — an empty filter is inert, not
465
+ * "everything". NSE/BSE keys open a vendor-feed subscription on demand;
466
+ * FX keys ride the MT5 instance's existing tick subscriptions. */
467
+ instrumentKeys?: string[];
468
+ /** market.chain filter: which option chains to have pushed. Each pair is
469
+ * polled from the vendor round-robin, so with N pairs subscribed
470
+ * deployment-wide each refreshes about every N x 3.2 s. */
471
+ chains?: ChainSelector[];
472
+ }
473
+ /** One option chain on the `market.chain` channel. */
474
+ interface ChainSelector {
475
+ underlyingKey: string;
476
+ /** YYYY-MM-DD. */
477
+ expiry: string;
478
+ }
479
+ type UnifiedInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "1d";
480
+ interface UnifiedCandle {
481
+ ts: number;
482
+ o: number;
483
+ h: number;
484
+ l: number;
485
+ c: number;
486
+ v: number;
487
+ oi?: number;
488
+ }
489
+ interface UnifiedTick {
490
+ instrumentKey: string;
491
+ ts: number;
492
+ mode: "LTP" | "QUOTE" | "FULL";
493
+ ltp?: number;
494
+ lastQty?: number;
495
+ atp?: number;
496
+ volume?: number;
497
+ open?: number;
498
+ high?: number;
499
+ low?: number;
500
+ prevClose?: number;
501
+ totalBuyQty?: number;
502
+ totalSellQty?: number;
503
+ oi?: number;
504
+ oiDayHigh?: number;
505
+ oiDayLow?: number;
506
+ bid?: number;
507
+ ask?: number;
508
+ depth?: Array<{
509
+ bidPrice: number;
510
+ bidQty: number;
511
+ bidOrders?: number;
512
+ askPrice: number;
513
+ askQty: number;
514
+ askOrders?: number;
515
+ }>;
516
+ source: "dhan" | "mt5";
517
+ }
518
+ /** Mirror of @atlaas/contracts UnifiedOptionLeg / UnifiedOptionChain (ATLA-74). */
519
+ interface UnifiedOptionLeg {
520
+ /** Canonical option key for this strike and type — goes straight into a place request. */
521
+ instrumentKey: string;
522
+ ltp: number;
523
+ oi: number;
524
+ volume: number;
525
+ bid?: number;
526
+ ask?: number;
527
+ iv?: number;
528
+ greeks?: {
529
+ delta?: number;
530
+ gamma?: number;
531
+ theta?: number;
532
+ vega?: number;
533
+ };
534
+ prevClose?: number;
535
+ prevOi?: number;
536
+ }
537
+ interface UnifiedOptionChain {
538
+ underlyingKey: string;
539
+ /** ISO date. */
540
+ expiry: string;
541
+ underlyingLtp: number;
542
+ source: "dhan";
543
+ ts: number;
544
+ strikes: Array<{
545
+ strike: number;
546
+ ce?: UnifiedOptionLeg;
547
+ pe?: UnifiedOptionLeg;
548
+ }>;
549
+ }
550
+ interface UnifiedOptionExpiries {
551
+ underlyingKey: string;
552
+ /** ISO dates, ascending. */
553
+ expiries: string[];
554
+ }
555
+ /** Mirror of @atlaas/contracts UnifiedSymbolSpec (ATLA-75): one MT5 symbol's
556
+ * contract spec on one broker server. Raw terminal numbers. */
557
+ interface UnifiedSymbolSpec {
558
+ symbol: string;
559
+ /** Set when the symbol, or its suffix-stripped base, has an MT5 broker ref. */
560
+ instrumentKey?: string;
561
+ description?: string;
562
+ path?: string;
563
+ contractSize: number;
564
+ digits: number;
565
+ point: number;
566
+ tickSize: number;
567
+ tickValue?: number;
568
+ volumeMin: number;
569
+ volumeStep: number;
570
+ volumeMax: number;
571
+ stopsLevel?: number;
572
+ tradeMode: "DISABLED" | "LONG_ONLY" | "SHORT_ONLY" | "CLOSE_ONLY" | "FULL";
573
+ currencyBase?: string;
574
+ currencyProfit?: string;
575
+ currencyMargin?: string;
576
+ }
577
+ interface SymbolSpecsResult {
578
+ connectionId: string;
579
+ /** When the specs were last pulled from the terminal (held for ~10 min). */
580
+ fetchedAt: string;
581
+ symbols: UnifiedSymbolSpec[];
582
+ dropped: DroppedRow[];
583
+ }
584
+ /** `market.tick` WS message: a UnifiedTick plus the message type. */
585
+ type MarketTickMessage = UnifiedTick & {
586
+ type: "market.tick";
587
+ };
588
+ /** `market.candle` WS message. `isFinal` flips true once when the bucket closes. */
589
+ interface MarketCandleMessage {
590
+ type: "market.candle";
591
+ instrumentKey: string;
592
+ interval: UnifiedInterval;
593
+ isFinal: boolean;
594
+ candle: UnifiedCandle;
595
+ source: "dhan" | "mt5";
596
+ }
597
+ /** `trading.order` WS message: a UnifiedOrder with `eventTs` and a
598
+ * per-connection `sequence`. At-least-once — dedupe on
599
+ * (orderId, status, filledQuantity, price) if you must. */
600
+ type TradingOrderMessage = UnifiedOrder & {
601
+ type: "trading.order";
602
+ eventTs: number;
603
+ sequence: number;
604
+ };
605
+ interface MT5Tick {
606
+ type: "mt5_tick";
607
+ accountId: string;
608
+ symbol: string;
609
+ bid: number;
610
+ ask: number;
611
+ ts: number;
612
+ timestamp: number;
613
+ }
614
+ interface MT5Candle {
615
+ type: "mt5_candle";
616
+ accountId: string;
617
+ symbol: string;
618
+ timeframe: string;
619
+ time: number;
620
+ open: number;
621
+ high: number;
622
+ low: number;
623
+ close: number;
624
+ volume: number;
625
+ isNew?: boolean;
626
+ ts: number;
627
+ timestamp: number;
628
+ }
629
+ interface BrokerTick {
630
+ type: "broker_tick";
631
+ brokerName: string;
632
+ connectionId: string;
633
+ kind: "trade" | "bidask" | "oi";
634
+ securityId: string;
635
+ exchangeSegment: string;
636
+ data: Record<string, unknown>;
637
+ ts: number;
638
+ }
639
+ interface BrokerOrderUpdate {
640
+ type: "broker_order_update";
641
+ brokerName: string;
642
+ connectionId: string;
643
+ /** The broker's native order alert, untranslated (for Dhan: order_alert
644
+ * Data with PascalCase fields like OrderNo, Status, TxnType, AvgTradedPrice). */
645
+ alert: Record<string, unknown>;
646
+ ts: number;
647
+ }
648
+ /** Mirror of @atlaas/contracts UnifiedInstrument (packages/contracts/src/instrument.ts).
649
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
650
+ interface UnifiedInstrument {
651
+ instrumentKey: string;
652
+ exchange: "NSE" | "BSE" | "MCX" | "FX";
653
+ segment: "EQ" | "FNO" | "IDX" | "CDS" | "COMM" | "FX";
654
+ symbol: string;
655
+ name?: string;
656
+ isin?: string;
657
+ instrumentType: "EQUITY" | "INDEX" | "FUTIDX" | "FUTSTK" | "OPTIDX" | "OPTSTK" | "FUTCOM" | "OPTCOM" | "FUTCUR" | "OPTCUR" | "FOREX";
658
+ expiry?: string;
659
+ strike?: number;
660
+ optionType?: "CE" | "PE";
661
+ lotSize?: number;
662
+ tickSize?: number;
663
+ contractSize?: number;
664
+ isActive?: boolean;
665
+ brokerRefs: {
666
+ dhan?: {
667
+ securityId: string;
668
+ exchangeSegment: string;
669
+ };
670
+ motilal?: {
671
+ symboltoken: number;
672
+ exchange: string;
673
+ };
674
+ kite?: {
675
+ instrumentToken?: number;
676
+ tradingsymbol: string;
677
+ exchange: string;
678
+ };
679
+ /** Broker-native spelling on `server`; each MT5 server carries its own. */
680
+ mt5?: {
681
+ symbol: string;
682
+ server?: string;
683
+ };
684
+ };
685
+ }
686
+ /** Mirror of @atlaas/contracts UnifiedOrder (packages/contracts/src/schemas.ts).
687
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
688
+ interface UnifiedOrder {
689
+ orderId: string;
690
+ exchangeOrderId?: string;
691
+ clientTag?: string;
692
+ connectionId: string;
693
+ instrumentKey: string;
694
+ side: "BUY" | "SELL";
695
+ orderType: "MARKET" | "LIMIT" | "STOP" | "STOP_LIMIT";
696
+ product: "DELIVERY" | "INTRADAY" | "CARRY" | "MTF" | "COVER" | "BRACKET";
697
+ validity: "DAY" | "IOC" | "GTC" | "GTD" | "TTL";
698
+ quantity: number;
699
+ lots?: number;
700
+ filledQuantity: number;
701
+ pendingQuantity: number;
702
+ price?: number;
703
+ triggerPrice?: number;
704
+ avgFillPrice?: number;
705
+ status: "PENDING" | "OPEN" | "FILLED" | "PARTIALLY_FILLED" | "REJECTED" | "CANCELLED" | "EXPIRED" | "UNKNOWN";
706
+ rawStatus: string;
707
+ rejectionReason?: string;
708
+ placedAt?: number;
709
+ updatedAt?: number;
710
+ exchangeAt?: number;
711
+ /** Present when Atlas synthesized this MARKET order as a chased LIMIT. */
712
+ synthetic?: {
713
+ restingPrice: number;
714
+ repriceCount: number;
715
+ reference: number;
716
+ state: "CHASING" | "FILLED" | "CANCELLED" | "FAILED";
717
+ reason?: string;
718
+ };
719
+ raw?: unknown;
720
+ }
721
+ /** Mirror of @atlaas/contracts UnifiedPosition (packages/contracts/src/schemas.ts).
722
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
723
+ interface UnifiedPosition {
724
+ connectionId: string;
725
+ instrumentKey: string;
726
+ product: "DELIVERY" | "INTRADAY" | "CARRY" | "MTF" | "COVER" | "BRACKET";
727
+ side: "LONG" | "SHORT" | "FLAT";
728
+ netQty: number;
729
+ buyQty: number;
730
+ sellQty: number;
731
+ buyAvg?: number;
732
+ sellAvg?: number;
733
+ dayBuyQty?: number;
734
+ daySellQty?: number;
735
+ carryFwdBuyQty?: number;
736
+ carryFwdSellQty?: number;
737
+ realizedPnl?: number;
738
+ unrealizedPnl?: number;
739
+ lastPrice?: number;
740
+ scope: "NET" | "DAY";
741
+ mt5?: {
742
+ ticket: number;
743
+ positionId: number;
744
+ /** Lots, straight from the terminal. */
745
+ volume?: number;
746
+ sl?: number;
747
+ tp?: number;
748
+ swap?: number;
749
+ magic?: number;
750
+ openTime?: number;
751
+ };
752
+ raw?: unknown;
753
+ }
754
+ /** Mirror of @atlaas/contracts UnifiedHolding (packages/contracts/src/schemas.ts).
755
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
756
+ interface UnifiedHolding {
757
+ instrumentKey: string;
758
+ isin?: string;
759
+ totalQty: number;
760
+ freeQty: number;
761
+ t1Qty?: number;
762
+ collateralQty?: number;
763
+ avgCostPrice: number;
764
+ lastPrice?: number;
765
+ }
766
+ /** Mirror of @atlaas/contracts UnifiedFunds (packages/contracts/src/schemas.ts).
767
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
768
+ interface UnifiedFunds {
769
+ availableBalance: number;
770
+ equity?: number;
771
+ utilizedAmount?: number;
772
+ collateralAmount?: number;
773
+ withdrawableBalance?: number;
774
+ openingBalance?: number;
775
+ currency: string;
776
+ breakdown?: Record<string, number>;
777
+ }
778
+ /** Mirror of @atlaas/contracts UnifiedTrade (packages/contracts/src/schemas.ts).
779
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
780
+ interface UnifiedTrade {
781
+ tradeId: string;
782
+ orderId: string;
783
+ instrumentKey: string;
784
+ side: "BUY" | "SELL";
785
+ quantity: number;
786
+ price: number;
787
+ tradedAt: number;
788
+ raw?: unknown;
789
+ }
790
+ /** Mirror of @atlaas/contracts UnifiedProfile (packages/contracts/src/schemas.ts).
791
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
792
+ interface UnifiedProfile {
793
+ clientId: string;
794
+ displayName?: string;
795
+ segmentsEnabled?: string[];
796
+ raw?: unknown;
797
+ }
798
+ /** Mirror of @atlaas/contracts UnifiedError (packages/contracts/src/errors.ts).
799
+ * Standalone copy, field-for-field — the SDK does not import contracts. */
800
+ interface UnifiedError {
801
+ code: "BROKER_REJECTED" | "OUTCOME_UNKNOWN" | "UNSUPPORTED_CAPABILITY" | "INSTRUMENT_UNRESOLVED" | "SESSION_DOWN" | "RATE_LIMITED" | "VALIDATION";
802
+ message: string;
803
+ brokerCode?: string;
804
+ raw?: unknown;
805
+ retryable: boolean;
806
+ }
807
+ /** Mirror of @atlaas/broker DroppedRow (packages/broker/src/normalizers/core.ts).
808
+ * Standalone copy, field-for-field — the SDK does not import broker. */
809
+ interface DroppedRow {
810
+ reason: "INSTRUMENT_UNRESOLVED" | "UNMAPPABLE";
811
+ refId: string;
812
+ detail?: string;
813
+ }
814
+ /** Mirror of @atlaas/broker BrokerCapabilities (packages/broker/src/normalizers/capabilities.ts).
815
+ * Standalone copy, field-for-field — the SDK does not import broker. */
816
+ interface BrokerCapabilities {
817
+ cancelOrder: boolean;
818
+ modifyOrder: boolean;
819
+ closePosition: "native" | "synthetic" | "none";
820
+ positionSlTp: boolean;
821
+ marketOrders: "native" | "synthetic" | "none";
822
+ orderStream: "push" | "poll";
823
+ candles: "native" | "feed" | "none";
824
+ holdings: boolean;
825
+ amo: boolean;
826
+ }
827
+ /** POST /api/v2/connections/:id/orders. Size it in `quantity` (units; Atlas
828
+ * converts to MOFSL lots / MT5 volume and fails closed on a non-multiple) or
829
+ * in `lots` (MT5 volume / MOFSL lots, sent as-is; Dhan and Kite refuse it).
830
+ * Exactly one of the two. */
831
+ interface PlaceOrderV2Body {
832
+ instrumentKey: string;
833
+ side: "BUY" | "SELL";
834
+ orderType: "MARKET" | "LIMIT" | "STOP" | "STOP_LIMIT";
835
+ quantity?: number;
836
+ lots?: number;
837
+ /** Required for LIMIT and STOP_LIMIT. */
838
+ price?: number;
839
+ /** Required for STOP and STOP_LIMIT. */
840
+ triggerPrice?: number;
841
+ /** MT5 only (capability `positionSlTp`): SL / TP the resulting position carries. */
842
+ stopLoss?: number;
843
+ takeProfit?: number;
844
+ /** Defaults to DELIVERY for equities, CARRY for everything else. */
845
+ product?: "DELIVERY" | "INTRADAY" | "CARRY" | "MTF" | "COVER" | "BRACKET";
846
+ validity?: "DAY" | "IOC" | "GTC" | "GTD" | "TTL";
847
+ /** Sanitized per broker (Dhan 30, Kite 20, MOFSL 10 chars). */
848
+ clientTag?: string;
849
+ /** Synthetic MARKET (Motilal) chase policy. Defaults { maxDriftPct: 1, maxReprices: 3, timeoutMs: 60000 }. */
850
+ chase?: {
851
+ maxDriftPct?: number;
852
+ maxReprices?: number;
853
+ timeoutMs?: number;
854
+ };
855
+ }
856
+ /** PUT /api/v2/connections/:id/orders/:orderId. At least one field. MOFSL
857
+ * requires `quantity`; MT5 pending orders accept only `price`/`triggerPrice`. */
858
+ interface ModifyOrderV2Body {
859
+ quantity?: number;
860
+ /** MT5 volume / MOFSL lots. Not with `quantity`. */
861
+ lots?: number;
862
+ price?: number;
863
+ triggerPrice?: number;
864
+ orderType?: "MARKET" | "LIMIT" | "STOP" | "STOP_LIMIT";
865
+ validity?: "DAY" | "IOC" | "GTC" | "GTD" | "TTL";
866
+ }
867
+ /** POST /api/v2/connections/:id/positions/close. Omit `quantity` and `lots`
868
+ * to flatten; omit `product` to use the one open position's product. */
869
+ interface ClosePositionV2Body {
870
+ instrumentKey: string;
871
+ /** Partial close, units. */
872
+ quantity?: number;
873
+ /** Partial close, MT5 volume / MOFSL lots. Not with `quantity`. */
874
+ lots?: number;
875
+ /** MT5 only: close this ticket rather than every ticket on the symbol. */
876
+ positionId?: string;
877
+ product?: "DELIVERY" | "INTRADAY" | "CARRY" | "MTF" | "COVER" | "BRACKET";
878
+ }
879
+ /** PUT /api/v2/connections/:id/positions/:positionId (MT5, capability
880
+ * `positionSlTp`). An omitted side keeps its current level; 0 clears it. */
881
+ interface ModifyPositionV2Body {
882
+ stopLoss?: number;
883
+ takeProfit?: number;
884
+ }
885
+ interface ModifyPositionResult {
886
+ positionId: string;
887
+ stopLoss?: number;
888
+ takeProfit?: number;
889
+ raw?: unknown;
890
+ }
891
+ interface PlaceOrderResult {
892
+ orderId: string;
893
+ connectionId: string;
894
+ instrumentKey: string;
895
+ broker: string;
896
+ /** Units. Omitted only for an MT5 order placed by `lots` on a symbol with no contractSize. */
897
+ quantity?: number;
898
+ /** MOFSL lots / MT5 volume actually sent. */
899
+ lots?: number;
900
+ /** Set when the order was synthesized as a chased LIMIT. */
901
+ synthetic?: {
902
+ restingPrice: number;
903
+ reference: number;
904
+ policy: {
905
+ maxDriftPct: number;
906
+ maxReprices: number;
907
+ timeoutMs: number;
908
+ };
909
+ };
910
+ raw?: unknown;
911
+ }
912
+ interface ModifyOrderResult {
913
+ orderId: string;
914
+ lots?: number;
915
+ raw?: unknown;
916
+ }
917
+ interface CancelOrderResult {
918
+ orderId: string;
919
+ cancelled: true;
920
+ raw?: unknown;
921
+ }
922
+ interface ClosePositionResult {
923
+ closeOrders: Array<{
924
+ orderId: string;
925
+ side?: "BUY" | "SELL";
926
+ quantity?: number;
927
+ lots?: number;
928
+ synthetic?: PlaceOrderResult["synthetic"];
929
+ }>;
930
+ raw?: unknown;
931
+ }
932
+ /** Snapshot response for v2.connections().snapshot(). Each section is either ok or error. */
933
+ interface V2Snapshot {
934
+ connectionId: string;
935
+ broker: string;
936
+ fetchedAt: string;
937
+ capabilities: BrokerCapabilities;
938
+ sections: {
939
+ orders: {
940
+ ok: true;
941
+ orders: UnifiedOrder[];
942
+ dropped: DroppedRow[];
943
+ } | {
944
+ ok: false;
945
+ error: UnifiedError;
946
+ };
947
+ positions: {
948
+ ok: true;
949
+ positions: UnifiedPosition[];
950
+ dropped: DroppedRow[];
951
+ } | {
952
+ ok: false;
953
+ error: UnifiedError;
954
+ };
955
+ holdings: {
956
+ ok: true;
957
+ holdings: UnifiedHolding[];
958
+ dropped: DroppedRow[];
959
+ } | {
960
+ ok: false;
961
+ error: UnifiedError;
962
+ };
963
+ funds: {
964
+ ok: true;
965
+ funds: UnifiedFunds;
966
+ } | {
967
+ ok: false;
968
+ error: UnifiedError;
969
+ };
970
+ trades: {
971
+ ok: true;
972
+ trades: UnifiedTrade[];
973
+ dropped: DroppedRow[];
974
+ } | {
975
+ ok: false;
976
+ error: UnifiedError;
977
+ };
978
+ profile: {
979
+ ok: true;
980
+ profile: UnifiedProfile;
981
+ } | {
982
+ ok: false;
983
+ error: UnifiedError;
984
+ };
985
+ };
986
+ }
987
+
988
+ /** @internal */
989
+ declare class BrokerSubscriptionsResource {
990
+ /** @internal */ readonly http: HttpTransport;
991
+ /** @internal */ readonly basePath: string;
992
+ constructor(http: HttpTransport, basePath: string);
993
+ subscribe(body: BrokerSubscribeBody): Promise<unknown>;
994
+ unsubscribe(body: BrokerUnsubscribeBody): Promise<unknown>;
995
+ list(): Promise<unknown>;
996
+ }
997
+ /** @internal */
998
+ declare class BrokerConnectionResource {
999
+ readonly subscriptions: BrokerSubscriptionsResource;
1000
+ /** @internal */ readonly basePath: string;
1001
+ /** @internal */ readonly http: HttpTransport;
1002
+ constructor(http: HttpTransport, brokerName: string, connectionId: string);
1003
+ placeOrder(body: BrokerOrderBody): Promise<unknown>;
1004
+ getOrders(): Promise<unknown>;
1005
+ getOrder(orderId: string): Promise<unknown>;
1006
+ modifyOrder(orderId: string, body: BrokerModifyOrderBody): Promise<unknown>;
1007
+ cancelOrder(orderId: string, body?: BrokerCancelOrderBody): Promise<unknown>;
1008
+ /** Trade book (fills). Currently served by Motilal Oswal; brokers whose
1009
+ * runner adapter doesn't implement it return an "unsupported command" error. */
1010
+ getTrades(): Promise<unknown>;
1011
+ getPositions(): Promise<unknown>;
1012
+ getHoldings(): Promise<unknown>;
1013
+ getCandles(query: BrokerCandlesQuery): Promise<unknown>;
1014
+ }
1015
+
1016
+ interface OrdersListParams {
1017
+ includeRaw?: boolean;
1018
+ }
1019
+ interface OrdersListResult {
1020
+ orders: UnifiedOrder[];
1021
+ dropped: DroppedRow[];
1022
+ }
1023
+ interface PositionsListParams {
1024
+ scope?: "NET" | "DAY";
1025
+ includeRaw?: boolean;
1026
+ }
1027
+ interface PositionsListResult {
1028
+ positions: UnifiedPosition[];
1029
+ dropped: DroppedRow[];
1030
+ scope: "NET" | "DAY";
1031
+ }
1032
+ interface HoldingsListResult {
1033
+ holdings: UnifiedHolding[];
1034
+ dropped: DroppedRow[];
1035
+ }
1036
+ interface TradesListResult {
1037
+ trades: UnifiedTrade[];
1038
+ dropped: DroppedRow[];
1039
+ }
1040
+ interface CapabilitiesResult {
1041
+ broker: string;
1042
+ capabilities: BrokerCapabilities;
1043
+ }
1044
+ declare class ConnectionsV2 {
1045
+ private readonly http;
1046
+ private readonly connectionId;
1047
+ constructor(http: HttpTransport, connectionId: string);
1048
+ orders(params?: OrdersListParams): Promise<OrdersListResult>;
1049
+ order(orderId: string, params?: {
1050
+ includeRaw?: boolean;
1051
+ }): Promise<UnifiedOrder>;
1052
+ trades(): Promise<TradesListResult>;
1053
+ positions(params?: PositionsListParams): Promise<PositionsListResult>;
1054
+ holdings(): Promise<HoldingsListResult>;
1055
+ funds(): Promise<UnifiedFunds>;
1056
+ profile(): Promise<UnifiedProfile>;
1057
+ /** MT5 only: the broker server's contract specs (contract size, volume limits, tick size…),
1058
+ * keyed to instruments where a ref exists. Held server-side for ~10 min; `symbol` filters. */
1059
+ symbols(params?: {
1060
+ symbol?: string;
1061
+ }): Promise<SymbolSpecsResult>;
1062
+ capabilities(): Promise<CapabilitiesResult>;
1063
+ snapshot(params?: {
1064
+ includeRaw?: boolean;
1065
+ }): Promise<V2Snapshot>;
1066
+ place(body: PlaceOrderV2Body, params?: {
1067
+ includeRaw?: boolean;
1068
+ }): Promise<PlaceOrderResult>;
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>;
1078
+ /** SL / TP on a live position (MT5). An omitted side keeps its level; 0 clears it. */
1079
+ modifyPosition(positionId: string, body: ModifyPositionV2Body, params?: {
1080
+ includeRaw?: boolean;
1081
+ }): Promise<ModifyPositionResult>;
1082
+ }
1083
+
1084
+ /**
1085
+ * Expert Advisors over the API-key external surface.
1086
+ *
1087
+ * Mirrors the portal /v1/eas + /v1/deployments operations under /api/external/*.
1088
+ * Account scope comes from the service key (its AtlasAccount); cross-account
1089
+ * ids return 404, never another tenant's data.
1090
+ */
1091
+ declare class EasResource {
1092
+ private readonly http;
1093
+ constructor(http: HttpTransport);
1094
+ list(): Promise<{
1095
+ items: Ea[];
1096
+ }>;
1097
+ create(body: CreateEaBody): Promise<Ea>;
1098
+ get(id: string): Promise<Ea & {
1099
+ versions: EaVersion[];
1100
+ }>;
1101
+ update(id: string, body: UpdateEaBody): Promise<Ea>;
1102
+ remove(id: string): Promise<{
1103
+ id: string;
1104
+ }>;
1105
+ listVersions(eaId: string, query?: ListEaVersionsQuery): Promise<ListEaVersionsResult>;
1106
+ /** Issue a short-lived R2 upload URL for a new .ex5/.mq5 build. */
1107
+ presignVersion(eaId: string, body: PresignEaVersionBody): Promise<PresignEaVersionResult>;
1108
+ /** Register an already-uploaded build (the r2Key returned by presignVersion). */
1109
+ registerVersion(eaId: string, body: RegisterEaVersionBody): Promise<EaVersion>;
1110
+ /** Mark a version LIVE (rollback) without re-uploading. */
1111
+ promoteVersion(eaId: string, versionId: string): Promise<{
1112
+ id: string;
1113
+ version: string;
1114
+ status: string;
1115
+ }>;
1116
+ deleteVersion(eaId: string, versionId: string): Promise<{
1117
+ id: string;
1118
+ version: string;
1119
+ }>;
1120
+ listDeployments(query?: ListDeploymentsQuery): Promise<ListDeploymentsResult>;
1121
+ /** Bind a version to a chart inside one of the caller's instances. The
1122
+ * setBlob is the .set input-override text; edit it via updateDeployment. */
1123
+ deploy(body: CreateDeploymentBody): Promise<Deployment>;
1124
+ getDeployment(id: string): Promise<Deployment>;
1125
+ updateDeployment(id: string, body: UpdateDeploymentBody): Promise<Deployment>;
1126
+ removeDeployment(id: string): Promise<{
1127
+ id: string;
1128
+ }>;
1129
+ }
1130
+
1131
+ declare class InstancesResource {
1132
+ private readonly http;
1133
+ constructor(http: HttpTransport);
1134
+ list(query?: ListInstancesQuery): Promise<AtlasInstance[]>;
1135
+ get(id: string): Promise<AtlasInstance>;
1136
+ getByExternalRef(ref: string): Promise<AtlasInstance>;
1137
+ getByExternalRefs(refs: string[]): Promise<AtlasInstance[]>;
1138
+ create(body: CreateAtlasInstanceBody): Promise<AtlasInstance>;
1139
+ update(id: string, body: UpdateAtlasInstanceBody): Promise<AtlasInstance>;
1140
+ /**
1141
+ * Wind an instance down: the host runner kills the terminal process and
1142
+ * deletes the instance folder. Credentials stay stored, so the instance
1143
+ * can be re-enabled later. Returns the updated instance.
1144
+ */
1145
+ disable(id: string): Promise<AtlasInstance>;
1146
+ /**
1147
+ * Re-enable a wound-down instance: resets it to PENDING so the runner
1148
+ * redeploys it fresh. Returns the updated instance.
1149
+ */
1150
+ enable(id: string): Promise<AtlasInstance>;
1151
+ delete(id: string): Promise<void>;
1152
+ }
1153
+
1154
+ interface InstrumentListParams {
1155
+ exchange?: string;
1156
+ segment?: string;
1157
+ symbol?: string;
1158
+ q?: string;
1159
+ active?: boolean;
1160
+ limit?: number;
1161
+ cursor?: string;
1162
+ }
1163
+ interface InstrumentListResult {
1164
+ instruments: UnifiedInstrument[];
1165
+ nextCursor: string | null;
1166
+ }
1167
+ interface ResolveInstrumentParams {
1168
+ broker: "dhan" | "motilal" | "kite" | "mt5";
1169
+ refId: string;
1170
+ segment?: string;
1171
+ }
1172
+ declare class InstrumentsV2 {
1173
+ private readonly http;
1174
+ constructor(http: HttpTransport);
1175
+ list(params?: InstrumentListParams): Promise<InstrumentListResult>;
1176
+ get(instrumentKey: string): Promise<UnifiedInstrument>;
1177
+ resolve(params: ResolveInstrumentParams): Promise<UnifiedInstrument>;
1178
+ }
1179
+
1180
+ interface MarketCandlesParams {
1181
+ instrumentKey: string;
1182
+ interval: UnifiedInterval;
1183
+ /** ISO 8601 or Date. */
1184
+ from: string | Date;
1185
+ to: string | Date;
1186
+ /** FX only: which MT5 connection serves the history (default: any running one you own). */
1187
+ connectionId?: string;
1188
+ }
1189
+ interface MarketQuotesResult {
1190
+ ticks: UnifiedTick[];
1191
+ unresolved: Array<{
1192
+ instrumentKey: string;
1193
+ code: "VALIDATION" | "INSTRUMENT_UNRESOLVED";
1194
+ reason: string;
1195
+ }>;
1196
+ }
1197
+ interface MarketCandlesResult {
1198
+ instrumentKey: string;
1199
+ interval: UnifiedInterval;
1200
+ source: "dhan" | "mt5";
1201
+ candles: UnifiedCandle[];
1202
+ }
1203
+ /** Connection-independent market data (`/api/v2/market/*`). NSE/BSE keys
1204
+ * are served by the Atlas data vendor feed, FX keys by an MT5 connection. */
1205
+ declare class MarketV2 {
1206
+ private readonly http;
1207
+ constructor(http: HttpTransport);
1208
+ /** Latest tick. A vendor key nobody is watching is subscribed and read
1209
+ * once from the vendor's REST endpoint, so this answers with a
1210
+ * `mode: "LTP"` snapshot rather than a retry-later 404. */
1211
+ quote(instrumentKey: string): Promise<UnifiedTick>;
1212
+ /** Latest tick for up to 200 keys, with the cold ones read in one vendor
1213
+ * call. `unresolved` names the keys that could not be priced and why —
1214
+ * it is never silently short. */
1215
+ quotes(instrumentKeys: string[]): Promise<MarketQuotesResult>;
1216
+ candles(params: MarketCandlesParams): Promise<MarketCandlesResult>;
1217
+ /** Option expiries for an index or equity underlying (`NSE:IDX:NIFTY`, `NSE:EQ:RELIANCE`), served by the vendor feed. */
1218
+ expiries(underlyingKey: string): Promise<UnifiedOptionExpiries>;
1219
+ /** Full option chain for one expiry (`YYYY-MM-DD`). Every leg carries its
1220
+ * canonical instrumentKey. Identical calls within ~3 s share one vendor request. */
1221
+ optionChain(underlyingKey: string, expiry: string): Promise<UnifiedOptionChain>;
1222
+ }
1223
+
1224
+ declare class ServiceKeysResource {
1225
+ private readonly http;
1226
+ constructor(http: HttpTransport);
1227
+ list(accountId: string, query?: {
1228
+ isActive?: boolean;
1229
+ }): Promise<ServiceKey[]>;
1230
+ create(accountId: string, body: CreateServiceKeyBody): Promise<ServiceKeyWithRaw>;
1231
+ update(keyId: string, body: UpdateServiceKeyBody): Promise<ServiceKey>;
1232
+ delete(keyId: string): Promise<void>;
1233
+ regenerate(keyId: string): Promise<ServiceKeyWithRaw>;
1234
+ }
1235
+
1236
+ declare class SubscriptionsResource {
1237
+ private readonly http;
1238
+ constructor(http: HttpTransport);
1239
+ private path;
1240
+ subscribeTick(instanceId: string, body: SubscribeTickBody): Promise<unknown>;
1241
+ unsubscribeTick(instanceId: string, body?: UnsubscribeTickBody): Promise<unknown>;
1242
+ getTickSubscriptions(instanceId: string): Promise<TickSubscriptions>;
1243
+ subscribeCandle(instanceId: string, body: SubscribeCandleBody): Promise<unknown>;
1244
+ unsubscribeCandle(instanceId: string, body?: UnsubscribeCandleBody): Promise<unknown>;
1245
+ getCandleSubscriptions(instanceId: string): Promise<CandleSubscriptions>;
1246
+ }
1247
+
1248
+ declare class TradingResource {
1249
+ private readonly http;
1250
+ constructor(http: HttpTransport);
1251
+ private path;
1252
+ placeOrder(accountId: string, body: PlaceOrderBody): Promise<Order>;
1253
+ getOrders(accountId: string): Promise<Order[]>;
1254
+ cancelOrder(accountId: string, ticket: number): Promise<void>;
1255
+ getPositions(accountId: string): Promise<Position[]>;
1256
+ getPosition(accountId: string, ticket: number): Promise<Position>;
1257
+ modifyPosition(accountId: string, ticket: number, body: ModifyPositionBody): Promise<unknown>;
1258
+ closePosition(accountId: string, ticket: number, body?: ClosePositionBody): Promise<unknown>;
1259
+ closeBySymbol(accountId: string, body: CloseBySymbolBody): Promise<unknown>;
1260
+ getPrice(accountId: string, symbol: string): Promise<Price>;
1261
+ getSymbols(accountId: string): Promise<string[]>;
1262
+ getAccountInfo(accountId: string): Promise<AccountInfo>;
1263
+ getCandles(accountId: string, query: GetCandlesQuery): Promise<Candle[]>;
1264
+ calculateMargin(accountId: string, body: CalculateMarginBody): Promise<MarginResult>;
1265
+ }
1266
+
1267
+ interface AtlasClientOptions {
1268
+ baseUrl: string;
1269
+ apiKey: string;
1270
+ timeoutMs?: number;
1271
+ maxRetries?: number;
1272
+ logger?: AtlasLogger;
1273
+ }
1274
+ declare class AtlasClient {
1275
+ readonly instances: InstancesResource;
1276
+ readonly eas: EasResource;
1277
+ readonly trading: TradingResource;
1278
+ readonly subscriptions: SubscriptionsResource;
1279
+ readonly serviceKeys: ServiceKeysResource;
1280
+ readonly v2: {
1281
+ instruments: InstrumentsV2;
1282
+ market: MarketV2;
1283
+ connections: (connectionId: string) => ConnectionsV2;
1284
+ };
1285
+ private readonly http;
1286
+ private readonly brokersResource;
1287
+ constructor(options: AtlasClientOptions);
1288
+ broker(brokerName: string, connectionId: string): BrokerConnectionResource;
1289
+ }
1290
+
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
+ interface AtlasWebSocketOptions {
1314
+ baseUrl: string;
1315
+ apiKey: string;
1316
+ clientName?: string;
1317
+ autoReconnect?: boolean;
1318
+ reconnectDelayMs?: number;
1319
+ maxReconnectAttempts?: number;
1320
+ }
1321
+ type WSEventMap = {
1322
+ tick: [MT5Tick];
1323
+ candle: [MT5Candle];
1324
+ broker_tick: [BrokerTick];
1325
+ broker_order_update: [BrokerOrderUpdate];
1326
+ "market.tick": [MarketTickMessage];
1327
+ "market.candle": [MarketCandleMessage];
1328
+ "trading.order": [TradingOrderMessage];
1329
+ connected: [];
1330
+ disconnected: [string];
1331
+ error: [Error];
1332
+ };
1333
+ declare class AtlasWebSocket extends EventEmitter {
1334
+ private ws;
1335
+ private authenticated;
1336
+ private reconnectAttempts;
1337
+ private reconnectTimer;
1338
+ private activeSubscriptions;
1339
+ private readonly url;
1340
+ private readonly apiKey;
1341
+ private readonly clientName?;
1342
+ private readonly autoReconnect;
1343
+ private readonly reconnectDelayMs;
1344
+ private readonly maxReconnectAttempts;
1345
+ private intentionalClose;
1346
+ constructor(options: AtlasWebSocketOptions);
1347
+ connect(): Promise<void>;
1348
+ disconnect(): void;
1349
+ subscribe(options: WSSubscribeOptions): void;
1350
+ unsubscribe(channels: WSChannel[]): void;
1351
+ get isConnected(): boolean;
1352
+ private handleMessage;
1353
+ private sendJson;
1354
+ private scheduleReconnect;
1355
+ on<K extends keyof WSEventMap>(event: K, listener: (...args: WSEventMap[K]) => void): this;
1356
+ once<K extends keyof WSEventMap>(event: K, listener: (...args: WSEventMap[K]) => void): this;
1357
+ off<K extends keyof WSEventMap>(event: K, listener: (...args: WSEventMap[K]) => void): this;
1358
+ emit<K extends keyof WSEventMap>(event: K, ...args: WSEventMap[K]): boolean;
1359
+ }
1360
+
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 };