@danielgroen/dxtrade-api 1.0.25 → 1.0.26
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 +2 -1
- package/dist/index.d.mts +124 -89
- package/dist/index.d.ts +124 -89
- package/dist/index.js +1063 -848
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1060 -848
- package/dist/index.mjs.map +1 -1
- package/llms.txt +2 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ BROKER.FTMO // "https://dxtrade.ftmo.com"
|
|
|
114
114
|
### Positions
|
|
115
115
|
|
|
116
116
|
- `client.positions.get()` — Get all open positions with P&L metrics merged (margin, plOpen, marketValue, etc.)
|
|
117
|
-
- `client.positions.close(
|
|
117
|
+
- `client.positions.close(positionCode, options?)` — Close a position by its position code. Returns `Position.Full` with P&L metrics. Options: `waitForClose: "stream" | "poll"`, `timeout` (ms, default 30000), `pollInterval` (ms, default 1000)
|
|
118
118
|
- `client.positions.closeAll()` — Close all open positions with market orders
|
|
119
119
|
- `client.positions.stream(callback)` — Stream real-time position updates with live P&L (requires `connect()`). Returns an unsubscribe function.
|
|
120
120
|
|
|
@@ -185,6 +185,7 @@ npm run example:debug
|
|
|
185
185
|
npm run example:positions:get
|
|
186
186
|
npm run example:positions:close
|
|
187
187
|
npm run example:positions:close-all
|
|
188
|
+
npm run example:positions:close-by-code
|
|
188
189
|
npm run example:positions:metrics
|
|
189
190
|
npm run example:positions:stream
|
|
190
191
|
npm run example:orders:submit
|
package/dist/index.d.mts
CHANGED
|
@@ -67,7 +67,9 @@ declare enum ERROR {
|
|
|
67
67
|
ORDERS_TIMEOUT = "ORDERS_TIMEOUT",
|
|
68
68
|
ORDERS_ERROR = "ORDERS_ERROR",
|
|
69
69
|
CANCEL_ORDER_ERROR = "CANCEL_ORDER_ERROR",
|
|
70
|
+
POSITION_NOT_FOUND = "POSITION_NOT_FOUND",
|
|
70
71
|
POSITION_CLOSE_ERROR = "POSITION_CLOSE_ERROR",
|
|
72
|
+
POSITION_CLOSE_TIMEOUT = "POSITION_CLOSE_TIMEOUT",
|
|
71
73
|
POSITION_METRICS_TIMEOUT = "POSITION_METRICS_TIMEOUT",
|
|
72
74
|
POSITION_METRICS_ERROR = "POSITION_METRICS_ERROR",
|
|
73
75
|
ACCOUNT_METRICS_TIMEOUT = "ACCOUNT_METRICS_TIMEOUT",
|
|
@@ -81,6 +83,19 @@ declare enum ERROR {
|
|
|
81
83
|
WS_MANAGER_ERROR = "WS_MANAGER_ERROR",
|
|
82
84
|
STREAM_REQUIRES_CONNECT = "STREAM_REQUIRES_CONNECT"
|
|
83
85
|
}
|
|
86
|
+
declare enum MESSAGE_CATEGORY {
|
|
87
|
+
TRADE_LOG = "TRADE_LOG",
|
|
88
|
+
NOTIFICATION = "NOTIFICATION"
|
|
89
|
+
}
|
|
90
|
+
declare enum MESSAGE_TYPE {
|
|
91
|
+
ORDER = "ORDER",
|
|
92
|
+
INSTRUMENT_ACTIVATED = "INSTRUMENT_ACTIVATED"
|
|
93
|
+
}
|
|
94
|
+
declare enum ORDER_STATUS {
|
|
95
|
+
PLACED = "PLACED",
|
|
96
|
+
FILLED = "FILLED",
|
|
97
|
+
REJECTED = "REJECTED"
|
|
98
|
+
}
|
|
84
99
|
declare enum WS_MESSAGE {
|
|
85
100
|
ACCOUNT_METRICS = "ACCOUNT_METRICS",
|
|
86
101
|
ACCOUNTS = "ACCOUNTS",
|
|
@@ -110,6 +125,22 @@ declare class DxtradeError extends Error {
|
|
|
110
125
|
constructor(code: string, message: string);
|
|
111
126
|
}
|
|
112
127
|
|
|
128
|
+
declare class OrdersDomain {
|
|
129
|
+
private _ctx;
|
|
130
|
+
constructor(_ctx: ClientContext);
|
|
131
|
+
/** Get all pending/open orders via WebSocket. */
|
|
132
|
+
get(timeout?: number): Promise<Order.Get[]>;
|
|
133
|
+
/** Cancel a single pending order by its order chain ID. */
|
|
134
|
+
cancel(orderChainId: number): Promise<void>;
|
|
135
|
+
/** Cancel all pending orders. */
|
|
136
|
+
cancelAll(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Submit a trading order and wait for WebSocket confirmation.
|
|
139
|
+
* Supports market, limit, and stop orders with optional stop loss and take profit.
|
|
140
|
+
*/
|
|
141
|
+
submit(params: Order.SubmitParams): Promise<Order.Update>;
|
|
142
|
+
}
|
|
143
|
+
|
|
113
144
|
declare namespace Order {
|
|
114
145
|
interface Get {
|
|
115
146
|
account: string;
|
|
@@ -159,6 +190,7 @@ declare namespace Order {
|
|
|
159
190
|
orderId: string;
|
|
160
191
|
status: string;
|
|
161
192
|
statusDescription?: string;
|
|
193
|
+
positionCode?: string;
|
|
162
194
|
[key: string]: unknown;
|
|
163
195
|
}
|
|
164
196
|
interface Model {
|
|
@@ -263,6 +295,31 @@ interface WsPayload {
|
|
|
263
295
|
type: string;
|
|
264
296
|
}
|
|
265
297
|
|
|
298
|
+
declare class AccountDomain {
|
|
299
|
+
private _ctx;
|
|
300
|
+
constructor(_ctx: ClientContext);
|
|
301
|
+
/** Get account metrics including equity, balance, margin, and open P&L. */
|
|
302
|
+
metrics(timeout?: number): Promise<Account.Metrics>;
|
|
303
|
+
/**
|
|
304
|
+
* Fetch trade history for a date range.
|
|
305
|
+
* @param params.from - Start timestamp (Unix ms)
|
|
306
|
+
* @param params.to - End timestamp (Unix ms)
|
|
307
|
+
*/
|
|
308
|
+
tradeHistory(params: {
|
|
309
|
+
from: number;
|
|
310
|
+
to: number;
|
|
311
|
+
}): Promise<Account.TradeHistory[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Fetch trade journal entries for a date range.
|
|
314
|
+
* @param params.from - Start timestamp (Unix ms)
|
|
315
|
+
* @param params.to - End timestamp (Unix ms)
|
|
316
|
+
*/
|
|
317
|
+
tradeJournal(params: {
|
|
318
|
+
from: number;
|
|
319
|
+
to: number;
|
|
320
|
+
}): Promise<any>;
|
|
321
|
+
}
|
|
322
|
+
|
|
266
323
|
declare namespace Account {
|
|
267
324
|
interface TradeHistory {
|
|
268
325
|
orderId: number;
|
|
@@ -293,6 +350,13 @@ declare namespace Account {
|
|
|
293
350
|
}
|
|
294
351
|
}
|
|
295
352
|
|
|
353
|
+
declare class AssessmentsDomain {
|
|
354
|
+
private _ctx;
|
|
355
|
+
constructor(_ctx: ClientContext);
|
|
356
|
+
/** Fetch PnL assessments for an instrument within a date range. */
|
|
357
|
+
get(params: Assessments.Params): Promise<Assessments.Response>;
|
|
358
|
+
}
|
|
359
|
+
|
|
296
360
|
declare namespace Assessments {
|
|
297
361
|
interface Params {
|
|
298
362
|
from: number;
|
|
@@ -306,6 +370,13 @@ declare namespace Assessments {
|
|
|
306
370
|
}
|
|
307
371
|
}
|
|
308
372
|
|
|
373
|
+
declare class InstrumentsDomain {
|
|
374
|
+
private _ctx;
|
|
375
|
+
constructor(_ctx: ClientContext);
|
|
376
|
+
/** Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`). */
|
|
377
|
+
get(params?: Partial<Instrument.Info>, timeout?: number): Promise<Instrument.Info[]>;
|
|
378
|
+
}
|
|
379
|
+
|
|
309
380
|
declare namespace Instrument {
|
|
310
381
|
interface Info {
|
|
311
382
|
id: number;
|
|
@@ -345,6 +416,22 @@ declare namespace Instrument {
|
|
|
345
416
|
}
|
|
346
417
|
}
|
|
347
418
|
|
|
419
|
+
declare class OhlcDomain {
|
|
420
|
+
private _ctx;
|
|
421
|
+
constructor(_ctx: ClientContext);
|
|
422
|
+
/** Stream real-time OHLC bar updates. Requires connect(). Returns unsubscribe function. */
|
|
423
|
+
stream(params: OHLC.Params, callback: (bars: OHLC.Bar[]) => void): Promise<() => void>;
|
|
424
|
+
/**
|
|
425
|
+
* Fetch OHLC price bars for a symbol.
|
|
426
|
+
* @param params.symbol - Instrument symbol (e.g. "EURUSD")
|
|
427
|
+
* @param params.resolution - Bar period in seconds (default: 60 = 1 min)
|
|
428
|
+
* @param params.range - Lookback window in seconds (default: 432000 = 5 days)
|
|
429
|
+
* @param params.maxBars - Maximum bars to return (default: 3500)
|
|
430
|
+
* @param params.priceField - "bid" or "ask" (default: "bid")
|
|
431
|
+
*/
|
|
432
|
+
get(params: OHLC.Params, timeout?: number): Promise<OHLC.Bar[]>;
|
|
433
|
+
}
|
|
434
|
+
|
|
348
435
|
declare namespace OHLC {
|
|
349
436
|
interface Params {
|
|
350
437
|
/** Symbol to fetch bars for (e.g. "EURUSD"). */
|
|
@@ -370,6 +457,22 @@ declare namespace OHLC {
|
|
|
370
457
|
}
|
|
371
458
|
}
|
|
372
459
|
|
|
460
|
+
declare class PositionsDomain {
|
|
461
|
+
private _ctx;
|
|
462
|
+
constructor(_ctx: ClientContext);
|
|
463
|
+
/** Stream real-time position updates with P&L metrics. Requires connect(). Returns unsubscribe function. */
|
|
464
|
+
stream(callback: (positions: Position.Full[]) => void): () => void;
|
|
465
|
+
/** Get all open positions with P&L metrics merged. */
|
|
466
|
+
get(): Promise<Position.Full[]>;
|
|
467
|
+
/** Close all open positions with market orders. */
|
|
468
|
+
closeAll(): Promise<void>;
|
|
469
|
+
/** Close a position by its position code. Returns the position with P&L metrics. Optionally wait for close confirmation via `waitForClose: "stream" | "poll"`. */
|
|
470
|
+
close(positionCode: string, options?: Position.CloseOptions): Promise<Position.Full>;
|
|
471
|
+
private _waitForCloseStream;
|
|
472
|
+
private _waitForClosePoll;
|
|
473
|
+
private _sendCloseRequest;
|
|
474
|
+
}
|
|
475
|
+
|
|
373
476
|
declare namespace Position {
|
|
374
477
|
interface Get {
|
|
375
478
|
uid: string;
|
|
@@ -412,6 +515,14 @@ declare namespace Position {
|
|
|
412
515
|
averagePrice: number;
|
|
413
516
|
marketValue: number;
|
|
414
517
|
}
|
|
518
|
+
interface CloseOptions {
|
|
519
|
+
/** Wait for the position to disappear after closing. "stream" uses the persistent WebSocket (requires connect()), "poll" repeatedly calls getPositions(). */
|
|
520
|
+
waitForClose?: "stream" | "poll";
|
|
521
|
+
/** Timeout in ms for waitForClose (default: 30000). */
|
|
522
|
+
timeout?: number;
|
|
523
|
+
/** Poll interval in ms when using waitForClose: "poll" (default: 1000). */
|
|
524
|
+
pollInterval?: number;
|
|
525
|
+
}
|
|
415
526
|
interface Close {
|
|
416
527
|
legs: {
|
|
417
528
|
instrumentId: number;
|
|
@@ -427,6 +538,17 @@ declare namespace Position {
|
|
|
427
538
|
}
|
|
428
539
|
}
|
|
429
540
|
|
|
541
|
+
declare class SymbolsDomain {
|
|
542
|
+
private _ctx;
|
|
543
|
+
constructor(_ctx: ClientContext);
|
|
544
|
+
/** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
|
|
545
|
+
search(text: string): Promise<Symbol.Suggestion[]>;
|
|
546
|
+
/** Get detailed instrument info for a symbol, including volume limits and lot size. */
|
|
547
|
+
info(symbol: string): Promise<Symbol.Info>;
|
|
548
|
+
/** Get order size limits and stop/limit distances for all symbols. */
|
|
549
|
+
limits(timeout?: number): Promise<Symbol.Limits[]>;
|
|
550
|
+
}
|
|
551
|
+
|
|
430
552
|
declare namespace Symbol {
|
|
431
553
|
interface Suggestion {
|
|
432
554
|
id: number;
|
|
@@ -454,94 +576,6 @@ declare namespace Symbol {
|
|
|
454
576
|
}
|
|
455
577
|
}
|
|
456
578
|
|
|
457
|
-
declare class PositionsDomain {
|
|
458
|
-
private _ctx;
|
|
459
|
-
constructor(_ctx: ClientContext);
|
|
460
|
-
/** Get all open positions with P&L metrics merged. */
|
|
461
|
-
get(): Promise<Position.Full[]>;
|
|
462
|
-
/** Close a position. Supports partial closes by specifying a quantity smaller than the full position size. */
|
|
463
|
-
close(params: Position.Close): Promise<void>;
|
|
464
|
-
/** Close all open positions with market orders. */
|
|
465
|
-
closeAll(): Promise<void>;
|
|
466
|
-
/** Stream real-time position updates with P&L metrics. Requires connect(). Returns unsubscribe function. */
|
|
467
|
-
stream(callback: (positions: Position.Full[]) => void): () => void;
|
|
468
|
-
}
|
|
469
|
-
declare class OrdersDomain {
|
|
470
|
-
private _ctx;
|
|
471
|
-
constructor(_ctx: ClientContext);
|
|
472
|
-
/** Get all pending/open orders via WebSocket. */
|
|
473
|
-
get(): Promise<Order.Get[]>;
|
|
474
|
-
/**
|
|
475
|
-
* Submit a trading order and wait for WebSocket confirmation.
|
|
476
|
-
* Supports market, limit, and stop orders with optional stop loss and take profit.
|
|
477
|
-
*/
|
|
478
|
-
submit(params: Order.SubmitParams): Promise<Order.Update>;
|
|
479
|
-
/** Cancel a single pending order by its order chain ID. */
|
|
480
|
-
cancel(orderChainId: number): Promise<void>;
|
|
481
|
-
/** Cancel all pending orders. */
|
|
482
|
-
cancelAll(): Promise<void>;
|
|
483
|
-
}
|
|
484
|
-
declare class AccountDomain {
|
|
485
|
-
private _ctx;
|
|
486
|
-
constructor(_ctx: ClientContext);
|
|
487
|
-
/** Get account metrics including equity, balance, margin, and open P&L. */
|
|
488
|
-
metrics(): Promise<Account.Metrics>;
|
|
489
|
-
/**
|
|
490
|
-
* Fetch trade journal entries for a date range.
|
|
491
|
-
* @param params.from - Start timestamp (Unix ms)
|
|
492
|
-
* @param params.to - End timestamp (Unix ms)
|
|
493
|
-
*/
|
|
494
|
-
tradeJournal(params: {
|
|
495
|
-
from: number;
|
|
496
|
-
to: number;
|
|
497
|
-
}): Promise<any>;
|
|
498
|
-
/**
|
|
499
|
-
* Fetch trade history for a date range.
|
|
500
|
-
* @param params.from - Start timestamp (Unix ms)
|
|
501
|
-
* @param params.to - End timestamp (Unix ms)
|
|
502
|
-
*/
|
|
503
|
-
tradeHistory(params: {
|
|
504
|
-
from: number;
|
|
505
|
-
to: number;
|
|
506
|
-
}): Promise<Account.TradeHistory[]>;
|
|
507
|
-
}
|
|
508
|
-
declare class SymbolsDomain {
|
|
509
|
-
private _ctx;
|
|
510
|
-
constructor(_ctx: ClientContext);
|
|
511
|
-
/** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
|
|
512
|
-
search(text: string): Promise<Symbol.Suggestion[]>;
|
|
513
|
-
/** Get detailed instrument info for a symbol, including volume limits and lot size. */
|
|
514
|
-
info(symbol: string): Promise<Symbol.Info>;
|
|
515
|
-
/** Get order size limits and stop/limit distances for all symbols. */
|
|
516
|
-
limits(): Promise<Symbol.Limits[]>;
|
|
517
|
-
}
|
|
518
|
-
declare class InstrumentsDomain {
|
|
519
|
-
private _ctx;
|
|
520
|
-
constructor(_ctx: ClientContext);
|
|
521
|
-
/** Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`). */
|
|
522
|
-
get(params?: Partial<Instrument.Info>): Promise<Instrument.Info[]>;
|
|
523
|
-
}
|
|
524
|
-
declare class OhlcDomain {
|
|
525
|
-
private _ctx;
|
|
526
|
-
constructor(_ctx: ClientContext);
|
|
527
|
-
/**
|
|
528
|
-
* Fetch OHLC price bars for a symbol.
|
|
529
|
-
* @param params.symbol - Instrument symbol (e.g. "EURUSD")
|
|
530
|
-
* @param params.resolution - Bar period in seconds (default: 60 = 1 min)
|
|
531
|
-
* @param params.range - Lookback window in seconds (default: 432000 = 5 days)
|
|
532
|
-
* @param params.maxBars - Maximum bars to return (default: 3500)
|
|
533
|
-
* @param params.priceField - "bid" or "ask" (default: "bid")
|
|
534
|
-
*/
|
|
535
|
-
get(params: OHLC.Params): Promise<OHLC.Bar[]>;
|
|
536
|
-
/** Stream real-time OHLC bar updates. Requires connect(). Returns unsubscribe function. */
|
|
537
|
-
stream(params: OHLC.Params, callback: (bars: OHLC.Bar[]) => void): Promise<() => void>;
|
|
538
|
-
}
|
|
539
|
-
declare class AssessmentsDomain {
|
|
540
|
-
private _ctx;
|
|
541
|
-
constructor(_ctx: ClientContext);
|
|
542
|
-
/** Fetch PnL assessments for an instrument within a date range. */
|
|
543
|
-
get(params: Assessments.Params): Promise<Assessments.Response>;
|
|
544
|
-
}
|
|
545
579
|
/**
|
|
546
580
|
* Client for interacting with the DXtrade trading API.
|
|
547
581
|
*
|
|
@@ -560,6 +594,7 @@ declare class AssessmentsDomain {
|
|
|
560
594
|
*/
|
|
561
595
|
declare class DxtradeClient {
|
|
562
596
|
private _ctx;
|
|
597
|
+
private _session;
|
|
563
598
|
/** Position operations: get, close, metrics, streaming. */
|
|
564
599
|
readonly positions: PositionsDomain;
|
|
565
600
|
/** Order operations: get, submit, cancel. */
|
|
@@ -589,4 +624,4 @@ declare class DxtradeClient {
|
|
|
589
624
|
disconnect(): void;
|
|
590
625
|
}
|
|
591
626
|
|
|
592
|
-
export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ERROR, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints };
|
|
627
|
+
export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ERROR, MESSAGE_CATEGORY, MESSAGE_TYPE, ORDER_STATUS, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints };
|
package/dist/index.d.ts
CHANGED
|
@@ -67,7 +67,9 @@ declare enum ERROR {
|
|
|
67
67
|
ORDERS_TIMEOUT = "ORDERS_TIMEOUT",
|
|
68
68
|
ORDERS_ERROR = "ORDERS_ERROR",
|
|
69
69
|
CANCEL_ORDER_ERROR = "CANCEL_ORDER_ERROR",
|
|
70
|
+
POSITION_NOT_FOUND = "POSITION_NOT_FOUND",
|
|
70
71
|
POSITION_CLOSE_ERROR = "POSITION_CLOSE_ERROR",
|
|
72
|
+
POSITION_CLOSE_TIMEOUT = "POSITION_CLOSE_TIMEOUT",
|
|
71
73
|
POSITION_METRICS_TIMEOUT = "POSITION_METRICS_TIMEOUT",
|
|
72
74
|
POSITION_METRICS_ERROR = "POSITION_METRICS_ERROR",
|
|
73
75
|
ACCOUNT_METRICS_TIMEOUT = "ACCOUNT_METRICS_TIMEOUT",
|
|
@@ -81,6 +83,19 @@ declare enum ERROR {
|
|
|
81
83
|
WS_MANAGER_ERROR = "WS_MANAGER_ERROR",
|
|
82
84
|
STREAM_REQUIRES_CONNECT = "STREAM_REQUIRES_CONNECT"
|
|
83
85
|
}
|
|
86
|
+
declare enum MESSAGE_CATEGORY {
|
|
87
|
+
TRADE_LOG = "TRADE_LOG",
|
|
88
|
+
NOTIFICATION = "NOTIFICATION"
|
|
89
|
+
}
|
|
90
|
+
declare enum MESSAGE_TYPE {
|
|
91
|
+
ORDER = "ORDER",
|
|
92
|
+
INSTRUMENT_ACTIVATED = "INSTRUMENT_ACTIVATED"
|
|
93
|
+
}
|
|
94
|
+
declare enum ORDER_STATUS {
|
|
95
|
+
PLACED = "PLACED",
|
|
96
|
+
FILLED = "FILLED",
|
|
97
|
+
REJECTED = "REJECTED"
|
|
98
|
+
}
|
|
84
99
|
declare enum WS_MESSAGE {
|
|
85
100
|
ACCOUNT_METRICS = "ACCOUNT_METRICS",
|
|
86
101
|
ACCOUNTS = "ACCOUNTS",
|
|
@@ -110,6 +125,22 @@ declare class DxtradeError extends Error {
|
|
|
110
125
|
constructor(code: string, message: string);
|
|
111
126
|
}
|
|
112
127
|
|
|
128
|
+
declare class OrdersDomain {
|
|
129
|
+
private _ctx;
|
|
130
|
+
constructor(_ctx: ClientContext);
|
|
131
|
+
/** Get all pending/open orders via WebSocket. */
|
|
132
|
+
get(timeout?: number): Promise<Order.Get[]>;
|
|
133
|
+
/** Cancel a single pending order by its order chain ID. */
|
|
134
|
+
cancel(orderChainId: number): Promise<void>;
|
|
135
|
+
/** Cancel all pending orders. */
|
|
136
|
+
cancelAll(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Submit a trading order and wait for WebSocket confirmation.
|
|
139
|
+
* Supports market, limit, and stop orders with optional stop loss and take profit.
|
|
140
|
+
*/
|
|
141
|
+
submit(params: Order.SubmitParams): Promise<Order.Update>;
|
|
142
|
+
}
|
|
143
|
+
|
|
113
144
|
declare namespace Order {
|
|
114
145
|
interface Get {
|
|
115
146
|
account: string;
|
|
@@ -159,6 +190,7 @@ declare namespace Order {
|
|
|
159
190
|
orderId: string;
|
|
160
191
|
status: string;
|
|
161
192
|
statusDescription?: string;
|
|
193
|
+
positionCode?: string;
|
|
162
194
|
[key: string]: unknown;
|
|
163
195
|
}
|
|
164
196
|
interface Model {
|
|
@@ -263,6 +295,31 @@ interface WsPayload {
|
|
|
263
295
|
type: string;
|
|
264
296
|
}
|
|
265
297
|
|
|
298
|
+
declare class AccountDomain {
|
|
299
|
+
private _ctx;
|
|
300
|
+
constructor(_ctx: ClientContext);
|
|
301
|
+
/** Get account metrics including equity, balance, margin, and open P&L. */
|
|
302
|
+
metrics(timeout?: number): Promise<Account.Metrics>;
|
|
303
|
+
/**
|
|
304
|
+
* Fetch trade history for a date range.
|
|
305
|
+
* @param params.from - Start timestamp (Unix ms)
|
|
306
|
+
* @param params.to - End timestamp (Unix ms)
|
|
307
|
+
*/
|
|
308
|
+
tradeHistory(params: {
|
|
309
|
+
from: number;
|
|
310
|
+
to: number;
|
|
311
|
+
}): Promise<Account.TradeHistory[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Fetch trade journal entries for a date range.
|
|
314
|
+
* @param params.from - Start timestamp (Unix ms)
|
|
315
|
+
* @param params.to - End timestamp (Unix ms)
|
|
316
|
+
*/
|
|
317
|
+
tradeJournal(params: {
|
|
318
|
+
from: number;
|
|
319
|
+
to: number;
|
|
320
|
+
}): Promise<any>;
|
|
321
|
+
}
|
|
322
|
+
|
|
266
323
|
declare namespace Account {
|
|
267
324
|
interface TradeHistory {
|
|
268
325
|
orderId: number;
|
|
@@ -293,6 +350,13 @@ declare namespace Account {
|
|
|
293
350
|
}
|
|
294
351
|
}
|
|
295
352
|
|
|
353
|
+
declare class AssessmentsDomain {
|
|
354
|
+
private _ctx;
|
|
355
|
+
constructor(_ctx: ClientContext);
|
|
356
|
+
/** Fetch PnL assessments for an instrument within a date range. */
|
|
357
|
+
get(params: Assessments.Params): Promise<Assessments.Response>;
|
|
358
|
+
}
|
|
359
|
+
|
|
296
360
|
declare namespace Assessments {
|
|
297
361
|
interface Params {
|
|
298
362
|
from: number;
|
|
@@ -306,6 +370,13 @@ declare namespace Assessments {
|
|
|
306
370
|
}
|
|
307
371
|
}
|
|
308
372
|
|
|
373
|
+
declare class InstrumentsDomain {
|
|
374
|
+
private _ctx;
|
|
375
|
+
constructor(_ctx: ClientContext);
|
|
376
|
+
/** Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`). */
|
|
377
|
+
get(params?: Partial<Instrument.Info>, timeout?: number): Promise<Instrument.Info[]>;
|
|
378
|
+
}
|
|
379
|
+
|
|
309
380
|
declare namespace Instrument {
|
|
310
381
|
interface Info {
|
|
311
382
|
id: number;
|
|
@@ -345,6 +416,22 @@ declare namespace Instrument {
|
|
|
345
416
|
}
|
|
346
417
|
}
|
|
347
418
|
|
|
419
|
+
declare class OhlcDomain {
|
|
420
|
+
private _ctx;
|
|
421
|
+
constructor(_ctx: ClientContext);
|
|
422
|
+
/** Stream real-time OHLC bar updates. Requires connect(). Returns unsubscribe function. */
|
|
423
|
+
stream(params: OHLC.Params, callback: (bars: OHLC.Bar[]) => void): Promise<() => void>;
|
|
424
|
+
/**
|
|
425
|
+
* Fetch OHLC price bars for a symbol.
|
|
426
|
+
* @param params.symbol - Instrument symbol (e.g. "EURUSD")
|
|
427
|
+
* @param params.resolution - Bar period in seconds (default: 60 = 1 min)
|
|
428
|
+
* @param params.range - Lookback window in seconds (default: 432000 = 5 days)
|
|
429
|
+
* @param params.maxBars - Maximum bars to return (default: 3500)
|
|
430
|
+
* @param params.priceField - "bid" or "ask" (default: "bid")
|
|
431
|
+
*/
|
|
432
|
+
get(params: OHLC.Params, timeout?: number): Promise<OHLC.Bar[]>;
|
|
433
|
+
}
|
|
434
|
+
|
|
348
435
|
declare namespace OHLC {
|
|
349
436
|
interface Params {
|
|
350
437
|
/** Symbol to fetch bars for (e.g. "EURUSD"). */
|
|
@@ -370,6 +457,22 @@ declare namespace OHLC {
|
|
|
370
457
|
}
|
|
371
458
|
}
|
|
372
459
|
|
|
460
|
+
declare class PositionsDomain {
|
|
461
|
+
private _ctx;
|
|
462
|
+
constructor(_ctx: ClientContext);
|
|
463
|
+
/** Stream real-time position updates with P&L metrics. Requires connect(). Returns unsubscribe function. */
|
|
464
|
+
stream(callback: (positions: Position.Full[]) => void): () => void;
|
|
465
|
+
/** Get all open positions with P&L metrics merged. */
|
|
466
|
+
get(): Promise<Position.Full[]>;
|
|
467
|
+
/** Close all open positions with market orders. */
|
|
468
|
+
closeAll(): Promise<void>;
|
|
469
|
+
/** Close a position by its position code. Returns the position with P&L metrics. Optionally wait for close confirmation via `waitForClose: "stream" | "poll"`. */
|
|
470
|
+
close(positionCode: string, options?: Position.CloseOptions): Promise<Position.Full>;
|
|
471
|
+
private _waitForCloseStream;
|
|
472
|
+
private _waitForClosePoll;
|
|
473
|
+
private _sendCloseRequest;
|
|
474
|
+
}
|
|
475
|
+
|
|
373
476
|
declare namespace Position {
|
|
374
477
|
interface Get {
|
|
375
478
|
uid: string;
|
|
@@ -412,6 +515,14 @@ declare namespace Position {
|
|
|
412
515
|
averagePrice: number;
|
|
413
516
|
marketValue: number;
|
|
414
517
|
}
|
|
518
|
+
interface CloseOptions {
|
|
519
|
+
/** Wait for the position to disappear after closing. "stream" uses the persistent WebSocket (requires connect()), "poll" repeatedly calls getPositions(). */
|
|
520
|
+
waitForClose?: "stream" | "poll";
|
|
521
|
+
/** Timeout in ms for waitForClose (default: 30000). */
|
|
522
|
+
timeout?: number;
|
|
523
|
+
/** Poll interval in ms when using waitForClose: "poll" (default: 1000). */
|
|
524
|
+
pollInterval?: number;
|
|
525
|
+
}
|
|
415
526
|
interface Close {
|
|
416
527
|
legs: {
|
|
417
528
|
instrumentId: number;
|
|
@@ -427,6 +538,17 @@ declare namespace Position {
|
|
|
427
538
|
}
|
|
428
539
|
}
|
|
429
540
|
|
|
541
|
+
declare class SymbolsDomain {
|
|
542
|
+
private _ctx;
|
|
543
|
+
constructor(_ctx: ClientContext);
|
|
544
|
+
/** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
|
|
545
|
+
search(text: string): Promise<Symbol.Suggestion[]>;
|
|
546
|
+
/** Get detailed instrument info for a symbol, including volume limits and lot size. */
|
|
547
|
+
info(symbol: string): Promise<Symbol.Info>;
|
|
548
|
+
/** Get order size limits and stop/limit distances for all symbols. */
|
|
549
|
+
limits(timeout?: number): Promise<Symbol.Limits[]>;
|
|
550
|
+
}
|
|
551
|
+
|
|
430
552
|
declare namespace Symbol {
|
|
431
553
|
interface Suggestion {
|
|
432
554
|
id: number;
|
|
@@ -454,94 +576,6 @@ declare namespace Symbol {
|
|
|
454
576
|
}
|
|
455
577
|
}
|
|
456
578
|
|
|
457
|
-
declare class PositionsDomain {
|
|
458
|
-
private _ctx;
|
|
459
|
-
constructor(_ctx: ClientContext);
|
|
460
|
-
/** Get all open positions with P&L metrics merged. */
|
|
461
|
-
get(): Promise<Position.Full[]>;
|
|
462
|
-
/** Close a position. Supports partial closes by specifying a quantity smaller than the full position size. */
|
|
463
|
-
close(params: Position.Close): Promise<void>;
|
|
464
|
-
/** Close all open positions with market orders. */
|
|
465
|
-
closeAll(): Promise<void>;
|
|
466
|
-
/** Stream real-time position updates with P&L metrics. Requires connect(). Returns unsubscribe function. */
|
|
467
|
-
stream(callback: (positions: Position.Full[]) => void): () => void;
|
|
468
|
-
}
|
|
469
|
-
declare class OrdersDomain {
|
|
470
|
-
private _ctx;
|
|
471
|
-
constructor(_ctx: ClientContext);
|
|
472
|
-
/** Get all pending/open orders via WebSocket. */
|
|
473
|
-
get(): Promise<Order.Get[]>;
|
|
474
|
-
/**
|
|
475
|
-
* Submit a trading order and wait for WebSocket confirmation.
|
|
476
|
-
* Supports market, limit, and stop orders with optional stop loss and take profit.
|
|
477
|
-
*/
|
|
478
|
-
submit(params: Order.SubmitParams): Promise<Order.Update>;
|
|
479
|
-
/** Cancel a single pending order by its order chain ID. */
|
|
480
|
-
cancel(orderChainId: number): Promise<void>;
|
|
481
|
-
/** Cancel all pending orders. */
|
|
482
|
-
cancelAll(): Promise<void>;
|
|
483
|
-
}
|
|
484
|
-
declare class AccountDomain {
|
|
485
|
-
private _ctx;
|
|
486
|
-
constructor(_ctx: ClientContext);
|
|
487
|
-
/** Get account metrics including equity, balance, margin, and open P&L. */
|
|
488
|
-
metrics(): Promise<Account.Metrics>;
|
|
489
|
-
/**
|
|
490
|
-
* Fetch trade journal entries for a date range.
|
|
491
|
-
* @param params.from - Start timestamp (Unix ms)
|
|
492
|
-
* @param params.to - End timestamp (Unix ms)
|
|
493
|
-
*/
|
|
494
|
-
tradeJournal(params: {
|
|
495
|
-
from: number;
|
|
496
|
-
to: number;
|
|
497
|
-
}): Promise<any>;
|
|
498
|
-
/**
|
|
499
|
-
* Fetch trade history for a date range.
|
|
500
|
-
* @param params.from - Start timestamp (Unix ms)
|
|
501
|
-
* @param params.to - End timestamp (Unix ms)
|
|
502
|
-
*/
|
|
503
|
-
tradeHistory(params: {
|
|
504
|
-
from: number;
|
|
505
|
-
to: number;
|
|
506
|
-
}): Promise<Account.TradeHistory[]>;
|
|
507
|
-
}
|
|
508
|
-
declare class SymbolsDomain {
|
|
509
|
-
private _ctx;
|
|
510
|
-
constructor(_ctx: ClientContext);
|
|
511
|
-
/** Search for symbols matching the given text (e.g. "EURUSD", "BTC"). */
|
|
512
|
-
search(text: string): Promise<Symbol.Suggestion[]>;
|
|
513
|
-
/** Get detailed instrument info for a symbol, including volume limits and lot size. */
|
|
514
|
-
info(symbol: string): Promise<Symbol.Info>;
|
|
515
|
-
/** Get order size limits and stop/limit distances for all symbols. */
|
|
516
|
-
limits(): Promise<Symbol.Limits[]>;
|
|
517
|
-
}
|
|
518
|
-
declare class InstrumentsDomain {
|
|
519
|
-
private _ctx;
|
|
520
|
-
constructor(_ctx: ClientContext);
|
|
521
|
-
/** Get all available instruments, optionally filtered by partial match (e.g. `{ type: "FOREX" }`). */
|
|
522
|
-
get(params?: Partial<Instrument.Info>): Promise<Instrument.Info[]>;
|
|
523
|
-
}
|
|
524
|
-
declare class OhlcDomain {
|
|
525
|
-
private _ctx;
|
|
526
|
-
constructor(_ctx: ClientContext);
|
|
527
|
-
/**
|
|
528
|
-
* Fetch OHLC price bars for a symbol.
|
|
529
|
-
* @param params.symbol - Instrument symbol (e.g. "EURUSD")
|
|
530
|
-
* @param params.resolution - Bar period in seconds (default: 60 = 1 min)
|
|
531
|
-
* @param params.range - Lookback window in seconds (default: 432000 = 5 days)
|
|
532
|
-
* @param params.maxBars - Maximum bars to return (default: 3500)
|
|
533
|
-
* @param params.priceField - "bid" or "ask" (default: "bid")
|
|
534
|
-
*/
|
|
535
|
-
get(params: OHLC.Params): Promise<OHLC.Bar[]>;
|
|
536
|
-
/** Stream real-time OHLC bar updates. Requires connect(). Returns unsubscribe function. */
|
|
537
|
-
stream(params: OHLC.Params, callback: (bars: OHLC.Bar[]) => void): Promise<() => void>;
|
|
538
|
-
}
|
|
539
|
-
declare class AssessmentsDomain {
|
|
540
|
-
private _ctx;
|
|
541
|
-
constructor(_ctx: ClientContext);
|
|
542
|
-
/** Fetch PnL assessments for an instrument within a date range. */
|
|
543
|
-
get(params: Assessments.Params): Promise<Assessments.Response>;
|
|
544
|
-
}
|
|
545
579
|
/**
|
|
546
580
|
* Client for interacting with the DXtrade trading API.
|
|
547
581
|
*
|
|
@@ -560,6 +594,7 @@ declare class AssessmentsDomain {
|
|
|
560
594
|
*/
|
|
561
595
|
declare class DxtradeClient {
|
|
562
596
|
private _ctx;
|
|
597
|
+
private _session;
|
|
563
598
|
/** Position operations: get, close, metrics, streaming. */
|
|
564
599
|
readonly positions: PositionsDomain;
|
|
565
600
|
/** Order operations: get, submit, cancel. */
|
|
@@ -589,4 +624,4 @@ declare class DxtradeClient {
|
|
|
589
624
|
disconnect(): void;
|
|
590
625
|
}
|
|
591
626
|
|
|
592
|
-
export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ERROR, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints };
|
|
627
|
+
export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ERROR, MESSAGE_CATEGORY, MESSAGE_TYPE, ORDER_STATUS, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints };
|