@danielgroen/dxtrade-api 1.0.23 → 1.0.24

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 CHANGED
@@ -29,6 +29,8 @@ npm install dxtrade-api
29
29
  - [x] OHLC / price bar data
30
30
  - [x] PnL assessments
31
31
  - [x] Multi-broker support (FTMO, Eightcap, Lark Funding)
32
+ - [x] Persistent WebSocket with `connect()`
33
+ - [x] Real-time position streaming
32
34
  - [x] Full TypeScript support
33
35
  - [ ] Batch orders
34
36
  - [ ] Modify existing orders
@@ -46,12 +48,13 @@ const client = new DxtradeClient({
46
48
  accountId: "optional_account_id",
47
49
  });
48
50
 
51
+ // connect() = auth + persistent WebSocket (recommended)
49
52
  await client.connect();
50
53
 
51
- const suggestions = await client.getSymbolSuggestions("EURUSD");
54
+ const suggestions = await client.symbols.search("EURUSD");
52
55
  const symbol = suggestions[0];
53
56
 
54
- const order = await client.submitOrder({
57
+ const order = await client.orders.submit({
55
58
  symbol: symbol.name,
56
59
  side: SIDE.BUY,
57
60
  quantity: 0.01,
@@ -60,6 +63,18 @@ const order = await client.submitOrder({
60
63
  });
61
64
 
62
65
  console.log(`Order ${order.orderId}: ${order.status}`);
66
+ client.disconnect();
67
+ ```
68
+
69
+ ## Connection Modes
70
+
71
+ ```ts
72
+ // Persistent WebSocket (recommended) — reuses one WS for all data, enables streaming
73
+ await client.connect();
74
+ client.disconnect(); // when done
75
+
76
+ // Lightweight — auth only, each data call opens a temporary WebSocket
77
+ await client.auth();
63
78
  ```
64
79
 
65
80
  ## Configuration
@@ -89,42 +104,51 @@ BROKER.FTMO // "https://dxtrade.ftmo.com"
89
104
 
90
105
  ### Session
91
106
 
92
- - `client.connect()` — Login, fetch CSRF, WebSocket handshake, optional account switch
107
+ - `client.connect()` — Auth + persistent WebSocket. Recommended for most use cases.
108
+ - `client.auth()` — Lightweight: login, fetch CSRF, WebSocket handshake, optional account switch. No persistent WS.
109
+ - `client.disconnect()` — Close the persistent WebSocket connection
93
110
  - `client.login()` — Authenticate with broker
94
111
  - `client.fetchCsrf()` — Fetch CSRF token from broker page
95
112
  - `client.switchAccount(accountId)` — Switch to a specific account
96
113
 
97
- ### Market Data
114
+ ### Positions
115
+
116
+ - `client.positions.get()` — Get all open positions
117
+ - `client.positions.close(params)` — Close a position (supports partial closes via the quantity field)
118
+ - `client.positions.closeAll()` — Close all open positions with market orders
119
+ - `client.positions.metrics()` — Get position-level P&L metrics
120
+ - `client.positions.stream(callback)` — Stream real-time position updates (requires `connect()`). Returns an unsubscribe function.
98
121
 
99
- - `client.getSymbolSuggestions(text)` — Search for symbols
100
- - `client.getSymbolInfo(symbol)` — Get instrument info (volume limits, lot size)
101
- - `client.getSymbolLimits()` — Get order size limits and stop/limit distances for all symbols
102
- - `client.getInstruments(params?)` — Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`)
103
- - `client.getOHLC(params)` — Fetch OHLC price bars for a symbol (resolution, range, maxBars, priceField)
122
+ ### Orders
104
123
 
105
- ### Trading
124
+ - `client.orders.get()` — Get all pending/open orders
125
+ - `client.orders.submit(params)` — Submit an order and wait for WebSocket confirmation
126
+ - `client.orders.cancel(orderChainId)` — Cancel a single pending order
127
+ - `client.orders.cancelAll()` — Cancel all pending orders
106
128
 
107
- - `client.submitOrder(params)` — Submit an order and wait for WebSocket confirmation
108
- - `client.getOrders()` — Get all pending/open orders via WebSocket
109
- - `client.cancelOrder(orderChainId)` — Cancel a single pending order
110
- - `client.cancelAllOrders()` — Cancel all pending orders
129
+ ### Account
111
130
 
112
- ### Positions
131
+ - `client.account.metrics()` — Get account metrics (equity, balance, margin, open P&L, etc.)
132
+ - `client.account.tradeJournal({ from, to })` — Fetch trade journal entries for a date range (Unix timestamps)
133
+ - `client.account.tradeHistory({ from, to })` — Fetch trade history for a date range (Unix timestamps)
113
134
 
114
- - `client.getPositions()` — Get all open positions via WebSocket
115
- - `client.closePosition(params)` — Close a position (supports partial closes via the quantity field)
116
- - `client.closeAllPositions()` — Close all open positions with market orders
117
- - `client.getPositionMetrics()` — Get position-level P&L metrics via WebSocket
135
+ ### Symbols
118
136
 
119
- ### Account
137
+ - `client.symbols.search(text)` — Search for symbols
138
+ - `client.symbols.info(symbol)` — Get instrument info (volume limits, lot size)
139
+ - `client.symbols.limits()` — Get order size limits and stop/limit distances for all symbols
140
+
141
+ ### Instruments
142
+
143
+ - `client.instruments.get(params?)` — Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`)
144
+
145
+ ### OHLC
120
146
 
121
- - `client.getAccountMetrics()` — Get account metrics (equity, balance, margin, open P&L, etc.)
122
- - `client.getTradeJournal({ from, to })` — Fetch trade journal entries for a date range (Unix timestamps)
123
- - `client.getTradeHistory({ from, to })` — Fetch trade history for a date range (Unix timestamps)
147
+ - `client.ohlc.get(params)` — Fetch OHLC price bars for a symbol (resolution, range, maxBars, priceField)
124
148
 
125
- ### Analytics
149
+ ### Assessments
126
150
 
127
- - `client.getAssessments(params)` — Fetch PnL assessments for a date range
151
+ - `client.assessments.get(params)` — Fetch PnL assessments for a date range
128
152
 
129
153
  ## Enums
130
154
 
@@ -157,23 +181,23 @@ const client = new DxtradeClient({
157
181
  ```bash
158
182
  cp .env.example .env # fill in credentials
159
183
  npm run example:connect
160
- npm run example:order
161
- npm run example:orders
162
- npm run example:positions
163
- npm run example:close-position
164
- npm run example:close-all-positions
165
- npm run example:position-metrics
166
- npm run example:assessments
167
- npm run example:assessments:btc
168
- npm run example:account
169
- npm run example:instruments
170
- npm run example:ohlc
171
- npm run example:instruments:forex
172
- npm run example:symbol
173
- npm run example:symbol:btc
174
- npm run example:trade-journal
175
- npm run example:trade-history
176
184
  npm run example:debug
185
+ npm run example:positions:get
186
+ npm run example:positions:close
187
+ npm run example:positions:close-all
188
+ npm run example:positions:metrics
189
+ npm run example:positions:stream
190
+ npm run example:orders:submit
191
+ npm run example:account:metrics
192
+ npm run example:account:trade-journal
193
+ npm run example:account:trade-history
194
+ npm run example:symbols:info
195
+ npm run example:symbols:info:btc
196
+ npm run example:instruments:get
197
+ npm run example:instruments:get:forex
198
+ npm run example:ohlc:get
199
+ npm run example:assessments:get
200
+ npm run example:assessments:get:btc
177
201
  ```
178
202
 
179
203
  ## DXtrade API Docs
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { EventEmitter } from 'events';
2
+
1
3
  declare const BROKER: {
2
4
  readonly LARKFUNDING: "https://trade.gooeytrade.com";
3
5
  readonly EIGHTCAP: "https://trader.dx-eightcap.com";
@@ -74,7 +76,10 @@ declare enum ERROR {
74
76
  ACCOUNT_POSITIONS_ERROR = "ACCOUNT_POSITIONS_ERROR",
75
77
  TRADE_JOURNAL_ERROR = "TRADE_JOURNAL_ERROR",
76
78
  TRADE_HISTORY_ERROR = "TRADE_HISTORY_ERROR",
77
- ASSESSMENTS_ERROR = "ASSESSMENTS_ERROR"
79
+ ASSESSMENTS_ERROR = "ASSESSMENTS_ERROR",
80
+ RATE_LIMITED = "RATE_LIMITED",
81
+ WS_MANAGER_ERROR = "WS_MANAGER_ERROR",
82
+ STREAM_REQUIRES_CONNECT = "STREAM_REQUIRES_CONNECT"
78
83
  }
79
84
  declare enum WS_MESSAGE {
80
85
  ACCOUNT_METRICS = "ACCOUNT_METRICS",
@@ -209,6 +214,16 @@ declare namespace Order {
209
214
  }
210
215
  }
211
216
 
217
+ declare class WsManager extends EventEmitter {
218
+ private _ws;
219
+ private _cache;
220
+ connect(wsUrl: string, cookieStr: string, debug?: boolean | string): Promise<void>;
221
+ waitFor<T>(type: string, timeout?: number): Promise<T>;
222
+ getCached<T>(type: string): T | undefined;
223
+ close(): void;
224
+ get isConnected(): boolean;
225
+ }
226
+
212
227
  interface DxtradeConfig {
213
228
  username: string;
214
229
  password: string;
@@ -226,6 +241,20 @@ interface DxtradeCallbacks {
226
241
  onOrderPlaced?: (order: Order.Response) => void;
227
242
  onOrderUpdate?: (order: Order.Update) => void;
228
243
  }
244
+ interface ClientContext {
245
+ config: DxtradeConfig;
246
+ callbacks: DxtradeCallbacks;
247
+ cookies: Record<string, string>;
248
+ csrf: string | null;
249
+ accountId: string | null;
250
+ atmosphereId: string | null;
251
+ wsManager: WsManager | null;
252
+ broker: keyof typeof BROKER;
253
+ retries: number;
254
+ debug: boolean | string;
255
+ ensureSession(): void;
256
+ throwError(code: string, message: string): never;
257
+ }
229
258
 
230
259
  interface WsPayload {
231
260
  accountId: string | null;
@@ -409,68 +438,46 @@ declare namespace Symbol {
409
438
  }
410
439
  }
411
440
 
412
- /**
413
- * Client for interacting with the DXtrade trading API.
414
- *
415
- * @example
416
- * ```ts
417
- * import { DxtradeClient, ORDER_TYPE, SIDE, BROKER } from "dxtrade-api";
418
- *
419
- * const client = new DxtradeClient({
420
- * username: "your_username",
421
- * password: "your_password",
422
- * broker: BROKER.FTMO,
423
- * });
424
- *
425
- * await client.connect();
426
- * ```
427
- */
428
- declare class DxtradeClient {
441
+ declare class PositionsDomain {
429
442
  private _ctx;
430
- constructor(config: DxtradeConfig);
431
- /** Authenticate with the broker using username and password. */
432
- login(): Promise<void>;
433
- /** Fetch the CSRF token required for authenticated requests. */
434
- fetchCsrf(): Promise<void>;
435
- /** Switch to a specific trading account by ID. */
436
- switchAccount(accountId: string): Promise<void>;
437
- /** Connect to the broker: login, fetch CSRF, WebSocket handshake, and optional account switch. */
438
- connect(): Promise<void>;
439
- /** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
440
- getSymbolSuggestions(text: string): Promise<Symbol.Suggestion[]>;
441
- /** Get detailed instrument info for a symbol, including volume limits and lot size. */
442
- getSymbolInfo(symbol: string): Promise<Symbol.Info>;
443
- /** Get order size limits and stop/limit distances for all symbols. */
444
- getSymbolLimits(): Promise<Symbol.Limits[]>;
443
+ constructor(_ctx: ClientContext);
444
+ /** Get all open positions via WebSocket. */
445
+ get(): Promise<Position.Get[]>;
446
+ /** Close a position. Supports partial closes by specifying a quantity smaller than the full position size. */
447
+ close(params: Position.Close): Promise<void>;
448
+ /** Close all open positions with market orders. */
449
+ closeAll(): Promise<void>;
450
+ /** Get position-level P&L metrics via WebSocket. */
451
+ metrics(): Promise<Position.Metrics[]>;
452
+ /** Stream real-time position updates. Requires connect(). Returns unsubscribe function. */
453
+ stream(callback: (positions: Position.Get[]) => void): () => void;
454
+ }
455
+ declare class OrdersDomain {
456
+ private _ctx;
457
+ constructor(_ctx: ClientContext);
458
+ /** Get all pending/open orders via WebSocket. */
459
+ get(): Promise<Order.Get[]>;
445
460
  /**
446
461
  * Submit a trading order and wait for WebSocket confirmation.
447
462
  * Supports market, limit, and stop orders with optional stop loss and take profit.
448
463
  */
449
- submitOrder(params: Order.SubmitParams): Promise<Order.Update>;
450
- /** Get all pending/open orders via WebSocket. */
451
- getOrders(): Promise<Order.Get[]>;
464
+ submit(params: Order.SubmitParams): Promise<Order.Update>;
452
465
  /** Cancel a single pending order by its order chain ID. */
453
- cancelOrder(orderChainId: number): Promise<void>;
466
+ cancel(orderChainId: number): Promise<void>;
454
467
  /** Cancel all pending orders. */
455
- cancelAllOrders(): Promise<void>;
468
+ cancelAll(): Promise<void>;
469
+ }
470
+ declare class AccountDomain {
471
+ private _ctx;
472
+ constructor(_ctx: ClientContext);
456
473
  /** Get account metrics including equity, balance, margin, and open P&L. */
457
- getAccountMetrics(): Promise<Account.Metrics>;
458
- /** Get all open positions via WebSocket. */
459
- getPositions(): Promise<Position.Get[]>;
460
- /**
461
- * Close a position. Supports partial closes by specifying a quantity smaller than the full position size.
462
- */
463
- closePosition(position: Position.Close): Promise<void>;
464
- /** Close all open positions with market orders. */
465
- closeAllPositions(): Promise<void>;
466
- /** Get position-level P&L metrics via WebSocket. */
467
- getPositionMetrics(): Promise<Position.Metrics[]>;
474
+ metrics(): Promise<Account.Metrics>;
468
475
  /**
469
476
  * Fetch trade journal entries for a date range.
470
477
  * @param params.from - Start timestamp (Unix ms)
471
478
  * @param params.to - End timestamp (Unix ms)
472
479
  */
473
- getTradeJournal(params: {
480
+ tradeJournal(params: {
474
481
  from: number;
475
482
  to: number;
476
483
  }): Promise<any>;
@@ -479,14 +486,30 @@ declare class DxtradeClient {
479
486
  * @param params.from - Start timestamp (Unix ms)
480
487
  * @param params.to - End timestamp (Unix ms)
481
488
  */
482
- getTradeHistory(params: {
489
+ tradeHistory(params: {
483
490
  from: number;
484
491
  to: number;
485
492
  }): Promise<Account.TradeHistory[]>;
493
+ }
494
+ declare class SymbolsDomain {
495
+ private _ctx;
496
+ constructor(_ctx: ClientContext);
497
+ /** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
498
+ search(text: string): Promise<Symbol.Suggestion[]>;
499
+ /** Get detailed instrument info for a symbol, including volume limits and lot size. */
500
+ info(symbol: string): Promise<Symbol.Info>;
501
+ /** Get order size limits and stop/limit distances for all symbols. */
502
+ limits(): Promise<Symbol.Limits[]>;
503
+ }
504
+ declare class InstrumentsDomain {
505
+ private _ctx;
506
+ constructor(_ctx: ClientContext);
486
507
  /** Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`). */
487
- getInstruments(params?: Partial<Instrument.Info>): Promise<Instrument.Info[]>;
488
- /** Fetch PnL assessments for an instrument within a date range. */
489
- getAssessments(params: Assessments.Params): Promise<Assessments.Response>;
508
+ get(params?: Partial<Instrument.Info>): Promise<Instrument.Info[]>;
509
+ }
510
+ declare class OhlcDomain {
511
+ private _ctx;
512
+ constructor(_ctx: ClientContext);
490
513
  /**
491
514
  * Fetch OHLC price bars for a symbol.
492
515
  * @param params.symbol - Instrument symbol (e.g. "EURUSD")
@@ -495,7 +518,59 @@ declare class DxtradeClient {
495
518
  * @param params.maxBars - Maximum bars to return (default: 3500)
496
519
  * @param params.priceField - "bid" or "ask" (default: "bid")
497
520
  */
498
- getOHLC(params: OHLC.Params): Promise<OHLC.Bar[]>;
521
+ get(params: OHLC.Params): Promise<OHLC.Bar[]>;
522
+ }
523
+ declare class AssessmentsDomain {
524
+ private _ctx;
525
+ constructor(_ctx: ClientContext);
526
+ /** Fetch PnL assessments for an instrument within a date range. */
527
+ get(params: Assessments.Params): Promise<Assessments.Response>;
528
+ }
529
+ /**
530
+ * Client for interacting with the DXtrade trading API.
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * import { DxtradeClient, ORDER_TYPE, SIDE, BROKER } from "dxtrade-api";
535
+ *
536
+ * const client = new DxtradeClient({
537
+ * username: "your_username",
538
+ * password: "your_password",
539
+ * broker: BROKER.FTMO,
540
+ * });
541
+ *
542
+ * await client.connect();
543
+ * ```
544
+ */
545
+ declare class DxtradeClient {
546
+ private _ctx;
547
+ /** Position operations: get, close, metrics, streaming. */
548
+ readonly positions: PositionsDomain;
549
+ /** Order operations: get, submit, cancel. */
550
+ readonly orders: OrdersDomain;
551
+ /** Account operations: metrics, trade journal, trade history. */
552
+ readonly account: AccountDomain;
553
+ /** Symbol operations: search, info, limits. */
554
+ readonly symbols: SymbolsDomain;
555
+ /** Instrument operations: get (with optional filtering). */
556
+ readonly instruments: InstrumentsDomain;
557
+ /** OHLC price bar operations: get. */
558
+ readonly ohlc: OhlcDomain;
559
+ /** PnL assessment operations: get. */
560
+ readonly assessments: AssessmentsDomain;
561
+ constructor(config: DxtradeConfig);
562
+ /** Authenticate with the broker using username and password. */
563
+ login(): Promise<void>;
564
+ /** Fetch the CSRF token required for authenticated requests. */
565
+ fetchCsrf(): Promise<void>;
566
+ /** Switch to a specific trading account by ID. */
567
+ switchAccount(accountId: string): Promise<void>;
568
+ /** Authenticate and establish a session: login, fetch CSRF, WebSocket handshake, and optional account switch. */
569
+ auth(): Promise<void>;
570
+ /** Connect to the broker with a persistent WebSocket: auth + persistent WS for data reuse and streaming. */
571
+ connect(): Promise<void>;
572
+ /** Close the persistent WebSocket connection. */
573
+ disconnect(): void;
499
574
  }
500
575
 
501
576
  export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ERROR, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { EventEmitter } from 'events';
2
+
1
3
  declare const BROKER: {
2
4
  readonly LARKFUNDING: "https://trade.gooeytrade.com";
3
5
  readonly EIGHTCAP: "https://trader.dx-eightcap.com";
@@ -74,7 +76,10 @@ declare enum ERROR {
74
76
  ACCOUNT_POSITIONS_ERROR = "ACCOUNT_POSITIONS_ERROR",
75
77
  TRADE_JOURNAL_ERROR = "TRADE_JOURNAL_ERROR",
76
78
  TRADE_HISTORY_ERROR = "TRADE_HISTORY_ERROR",
77
- ASSESSMENTS_ERROR = "ASSESSMENTS_ERROR"
79
+ ASSESSMENTS_ERROR = "ASSESSMENTS_ERROR",
80
+ RATE_LIMITED = "RATE_LIMITED",
81
+ WS_MANAGER_ERROR = "WS_MANAGER_ERROR",
82
+ STREAM_REQUIRES_CONNECT = "STREAM_REQUIRES_CONNECT"
78
83
  }
79
84
  declare enum WS_MESSAGE {
80
85
  ACCOUNT_METRICS = "ACCOUNT_METRICS",
@@ -209,6 +214,16 @@ declare namespace Order {
209
214
  }
210
215
  }
211
216
 
217
+ declare class WsManager extends EventEmitter {
218
+ private _ws;
219
+ private _cache;
220
+ connect(wsUrl: string, cookieStr: string, debug?: boolean | string): Promise<void>;
221
+ waitFor<T>(type: string, timeout?: number): Promise<T>;
222
+ getCached<T>(type: string): T | undefined;
223
+ close(): void;
224
+ get isConnected(): boolean;
225
+ }
226
+
212
227
  interface DxtradeConfig {
213
228
  username: string;
214
229
  password: string;
@@ -226,6 +241,20 @@ interface DxtradeCallbacks {
226
241
  onOrderPlaced?: (order: Order.Response) => void;
227
242
  onOrderUpdate?: (order: Order.Update) => void;
228
243
  }
244
+ interface ClientContext {
245
+ config: DxtradeConfig;
246
+ callbacks: DxtradeCallbacks;
247
+ cookies: Record<string, string>;
248
+ csrf: string | null;
249
+ accountId: string | null;
250
+ atmosphereId: string | null;
251
+ wsManager: WsManager | null;
252
+ broker: keyof typeof BROKER;
253
+ retries: number;
254
+ debug: boolean | string;
255
+ ensureSession(): void;
256
+ throwError(code: string, message: string): never;
257
+ }
229
258
 
230
259
  interface WsPayload {
231
260
  accountId: string | null;
@@ -409,68 +438,46 @@ declare namespace Symbol {
409
438
  }
410
439
  }
411
440
 
412
- /**
413
- * Client for interacting with the DXtrade trading API.
414
- *
415
- * @example
416
- * ```ts
417
- * import { DxtradeClient, ORDER_TYPE, SIDE, BROKER } from "dxtrade-api";
418
- *
419
- * const client = new DxtradeClient({
420
- * username: "your_username",
421
- * password: "your_password",
422
- * broker: BROKER.FTMO,
423
- * });
424
- *
425
- * await client.connect();
426
- * ```
427
- */
428
- declare class DxtradeClient {
441
+ declare class PositionsDomain {
429
442
  private _ctx;
430
- constructor(config: DxtradeConfig);
431
- /** Authenticate with the broker using username and password. */
432
- login(): Promise<void>;
433
- /** Fetch the CSRF token required for authenticated requests. */
434
- fetchCsrf(): Promise<void>;
435
- /** Switch to a specific trading account by ID. */
436
- switchAccount(accountId: string): Promise<void>;
437
- /** Connect to the broker: login, fetch CSRF, WebSocket handshake, and optional account switch. */
438
- connect(): Promise<void>;
439
- /** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
440
- getSymbolSuggestions(text: string): Promise<Symbol.Suggestion[]>;
441
- /** Get detailed instrument info for a symbol, including volume limits and lot size. */
442
- getSymbolInfo(symbol: string): Promise<Symbol.Info>;
443
- /** Get order size limits and stop/limit distances for all symbols. */
444
- getSymbolLimits(): Promise<Symbol.Limits[]>;
443
+ constructor(_ctx: ClientContext);
444
+ /** Get all open positions via WebSocket. */
445
+ get(): Promise<Position.Get[]>;
446
+ /** Close a position. Supports partial closes by specifying a quantity smaller than the full position size. */
447
+ close(params: Position.Close): Promise<void>;
448
+ /** Close all open positions with market orders. */
449
+ closeAll(): Promise<void>;
450
+ /** Get position-level P&L metrics via WebSocket. */
451
+ metrics(): Promise<Position.Metrics[]>;
452
+ /** Stream real-time position updates. Requires connect(). Returns unsubscribe function. */
453
+ stream(callback: (positions: Position.Get[]) => void): () => void;
454
+ }
455
+ declare class OrdersDomain {
456
+ private _ctx;
457
+ constructor(_ctx: ClientContext);
458
+ /** Get all pending/open orders via WebSocket. */
459
+ get(): Promise<Order.Get[]>;
445
460
  /**
446
461
  * Submit a trading order and wait for WebSocket confirmation.
447
462
  * Supports market, limit, and stop orders with optional stop loss and take profit.
448
463
  */
449
- submitOrder(params: Order.SubmitParams): Promise<Order.Update>;
450
- /** Get all pending/open orders via WebSocket. */
451
- getOrders(): Promise<Order.Get[]>;
464
+ submit(params: Order.SubmitParams): Promise<Order.Update>;
452
465
  /** Cancel a single pending order by its order chain ID. */
453
- cancelOrder(orderChainId: number): Promise<void>;
466
+ cancel(orderChainId: number): Promise<void>;
454
467
  /** Cancel all pending orders. */
455
- cancelAllOrders(): Promise<void>;
468
+ cancelAll(): Promise<void>;
469
+ }
470
+ declare class AccountDomain {
471
+ private _ctx;
472
+ constructor(_ctx: ClientContext);
456
473
  /** Get account metrics including equity, balance, margin, and open P&L. */
457
- getAccountMetrics(): Promise<Account.Metrics>;
458
- /** Get all open positions via WebSocket. */
459
- getPositions(): Promise<Position.Get[]>;
460
- /**
461
- * Close a position. Supports partial closes by specifying a quantity smaller than the full position size.
462
- */
463
- closePosition(position: Position.Close): Promise<void>;
464
- /** Close all open positions with market orders. */
465
- closeAllPositions(): Promise<void>;
466
- /** Get position-level P&L metrics via WebSocket. */
467
- getPositionMetrics(): Promise<Position.Metrics[]>;
474
+ metrics(): Promise<Account.Metrics>;
468
475
  /**
469
476
  * Fetch trade journal entries for a date range.
470
477
  * @param params.from - Start timestamp (Unix ms)
471
478
  * @param params.to - End timestamp (Unix ms)
472
479
  */
473
- getTradeJournal(params: {
480
+ tradeJournal(params: {
474
481
  from: number;
475
482
  to: number;
476
483
  }): Promise<any>;
@@ -479,14 +486,30 @@ declare class DxtradeClient {
479
486
  * @param params.from - Start timestamp (Unix ms)
480
487
  * @param params.to - End timestamp (Unix ms)
481
488
  */
482
- getTradeHistory(params: {
489
+ tradeHistory(params: {
483
490
  from: number;
484
491
  to: number;
485
492
  }): Promise<Account.TradeHistory[]>;
493
+ }
494
+ declare class SymbolsDomain {
495
+ private _ctx;
496
+ constructor(_ctx: ClientContext);
497
+ /** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
498
+ search(text: string): Promise<Symbol.Suggestion[]>;
499
+ /** Get detailed instrument info for a symbol, including volume limits and lot size. */
500
+ info(symbol: string): Promise<Symbol.Info>;
501
+ /** Get order size limits and stop/limit distances for all symbols. */
502
+ limits(): Promise<Symbol.Limits[]>;
503
+ }
504
+ declare class InstrumentsDomain {
505
+ private _ctx;
506
+ constructor(_ctx: ClientContext);
486
507
  /** Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`). */
487
- getInstruments(params?: Partial<Instrument.Info>): Promise<Instrument.Info[]>;
488
- /** Fetch PnL assessments for an instrument within a date range. */
489
- getAssessments(params: Assessments.Params): Promise<Assessments.Response>;
508
+ get(params?: Partial<Instrument.Info>): Promise<Instrument.Info[]>;
509
+ }
510
+ declare class OhlcDomain {
511
+ private _ctx;
512
+ constructor(_ctx: ClientContext);
490
513
  /**
491
514
  * Fetch OHLC price bars for a symbol.
492
515
  * @param params.symbol - Instrument symbol (e.g. "EURUSD")
@@ -495,7 +518,59 @@ declare class DxtradeClient {
495
518
  * @param params.maxBars - Maximum bars to return (default: 3500)
496
519
  * @param params.priceField - "bid" or "ask" (default: "bid")
497
520
  */
498
- getOHLC(params: OHLC.Params): Promise<OHLC.Bar[]>;
521
+ get(params: OHLC.Params): Promise<OHLC.Bar[]>;
522
+ }
523
+ declare class AssessmentsDomain {
524
+ private _ctx;
525
+ constructor(_ctx: ClientContext);
526
+ /** Fetch PnL assessments for an instrument within a date range. */
527
+ get(params: Assessments.Params): Promise<Assessments.Response>;
528
+ }
529
+ /**
530
+ * Client for interacting with the DXtrade trading API.
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * import { DxtradeClient, ORDER_TYPE, SIDE, BROKER } from "dxtrade-api";
535
+ *
536
+ * const client = new DxtradeClient({
537
+ * username: "your_username",
538
+ * password: "your_password",
539
+ * broker: BROKER.FTMO,
540
+ * });
541
+ *
542
+ * await client.connect();
543
+ * ```
544
+ */
545
+ declare class DxtradeClient {
546
+ private _ctx;
547
+ /** Position operations: get, close, metrics, streaming. */
548
+ readonly positions: PositionsDomain;
549
+ /** Order operations: get, submit, cancel. */
550
+ readonly orders: OrdersDomain;
551
+ /** Account operations: metrics, trade journal, trade history. */
552
+ readonly account: AccountDomain;
553
+ /** Symbol operations: search, info, limits. */
554
+ readonly symbols: SymbolsDomain;
555
+ /** Instrument operations: get (with optional filtering). */
556
+ readonly instruments: InstrumentsDomain;
557
+ /** OHLC price bar operations: get. */
558
+ readonly ohlc: OhlcDomain;
559
+ /** PnL assessment operations: get. */
560
+ readonly assessments: AssessmentsDomain;
561
+ constructor(config: DxtradeConfig);
562
+ /** Authenticate with the broker using username and password. */
563
+ login(): Promise<void>;
564
+ /** Fetch the CSRF token required for authenticated requests. */
565
+ fetchCsrf(): Promise<void>;
566
+ /** Switch to a specific trading account by ID. */
567
+ switchAccount(accountId: string): Promise<void>;
568
+ /** Authenticate and establish a session: login, fetch CSRF, WebSocket handshake, and optional account switch. */
569
+ auth(): Promise<void>;
570
+ /** Connect to the broker with a persistent WebSocket: auth + persistent WS for data reuse and streaming. */
571
+ connect(): Promise<void>;
572
+ /** Close the persistent WebSocket connection. */
573
+ disconnect(): void;
499
574
  }
500
575
 
501
576
  export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ERROR, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints };