@danielgroen/dxtrade-api 1.0.7 → 1.0.8

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
@@ -1,9 +1,9 @@
1
- # DXTrade API
1
+ # DXtrade API
2
2
 
3
3
  <!-- create image from ./public/logo-dxtrade.svg -->
4
- [![DXTrade API](https://raw.githubusercontent.com/danielgroen/dxtrade-api/master/public/logo-dxtrade.svg)](https://demo.dx.trade/developers/#/)
4
+ [![DXtrade API](https://raw.githubusercontent.com/danielgroen/dxtrade-api/master/public/logo-dxtrade.svg)](https://demo.dx.trade/developers/#/)
5
5
 
6
- TypeScript client library for the DXTrade trading API based upon Nodejs.
6
+ TypeScript client library for the DXtrade trading API based upon Nodejs.
7
7
 
8
8
  ## Install
9
9
 
@@ -19,7 +19,7 @@ import { DxtradeClient, OrderType, OrderSide, BROKER } from "dxtrade-api";
19
19
  const client = new DxtradeClient({
20
20
  username: "your_username",
21
21
  password: "your_password",
22
- broker: "lark",
22
+ broker: "larkfunding",
23
23
  accountId: "optional_account_id",
24
24
  });
25
25
 
@@ -43,9 +43,9 @@ console.log(`Order ${order.orderId}: ${order.status}`);
43
43
 
44
44
  | Option | Type | Required | Description |
45
45
  |---|---|---|---|
46
- | `username` | `string` | Yes | DXTrade account username |
47
- | `password` | `string` | Yes | DXTrade account password |
48
- | `broker` | `string` | Yes | Broker identifier (e.g. `"lark"`, `"eightcap"`) |
46
+ | `username` | `string` | Yes | DXtrade account username |
47
+ | `password` | `string` | Yes | DXtrade account password |
48
+ | `broker` | `string` | Yes | Broker identifier (e.g. `"larkfunding"`, `"eightcap"`) |
49
49
  | `accountId` | `string` | No | Account ID to auto-switch after login |
50
50
  | `brokerUrls` | `Record<string, string>` | No | Custom broker URL mapping |
51
51
  | `retries` | `number` | No | Retry count for failed requests (default: 3) |
@@ -106,7 +106,7 @@ npm run example:order
106
106
  npm run example:assessments
107
107
  ```
108
108
 
109
- ## DXTrade API Docs
109
+ ## DXtrade API Docs
110
110
 
111
111
  https://demo.dx.trade/developers/#/
112
112
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  declare const BROKER: {
2
- readonly LARK: "https://trade.gooeytrade.com";
2
+ readonly LARKFUNDING: "https://trade.gooeytrade.com";
3
3
  readonly EIGHTCAP: "https://trader.dx-eightcap.com";
4
4
  };
5
5
  declare function resolveBrokerUrl(broker: string, customUrls?: Record<string, string>): string;
@@ -27,103 +27,180 @@ declare enum ACTION {
27
27
  OPENING = "OPENING",
28
28
  CLOSING = "CLOSING"
29
29
  }
30
+ declare enum TIF {
31
+ GTC = "GTC",
32
+ DAY = "DAY",
33
+ GTD = "GTD"
34
+ }
35
+ declare enum WS_MESSAGE {
36
+ ACCOUNTS = "ACCOUNTS",
37
+ AVAILABLE_WATCHLISTS = "AVAILABLE_WATCHLISTS",
38
+ MESSAGE = "MESSAGE",
39
+ ORDERS = "ORDERS",
40
+ POSITIONS = "POSITIONS",
41
+ POSITION_CASH_TRANSFERS = "POSITION_CASH_TRANSFERS",
42
+ PRIVATE_LAYOUT_NAMES = "PRIVATE_LAYOUT_NAMES",
43
+ SHARED_PROPERTIES_MESSAGE = "SHARED_PROPERTIES_MESSAGE",
44
+ USER_LOGIN_INFO = "USER_LOGIN_INFO"
45
+ }
30
46
 
31
47
  declare class DxtradeError extends Error {
32
48
  code: string;
33
49
  constructor(code: string, message: string);
34
50
  }
35
51
 
36
- interface SubmitOrderParams$1 {
37
- symbol: string;
38
- side: SIDE;
39
- quantity: number;
40
- orderType: ORDER_TYPE;
41
- price?: number;
42
- instrumentId?: number;
43
- stopLoss?: StopLossParams;
44
- takeProfit?: TakeProfitParams;
45
- positionEffect?: ACTION;
46
- }
47
- interface StopLossParams {
48
- price?: number;
49
- offset?: number;
50
- }
51
- interface TakeProfitParams {
52
- price?: number;
53
- offset?: number;
54
- }
55
- interface OrderResponse {
56
- status: number;
57
- data: unknown;
58
- }
59
- interface OrderUpdate$1 {
60
- orderId: string;
61
- status: string;
62
- statusDescription?: string;
63
- [key: string]: unknown;
52
+ declare namespace Order {
53
+ interface SubmitParams {
54
+ symbol: string;
55
+ side: SIDE;
56
+ quantity: number;
57
+ orderType: ORDER_TYPE;
58
+ orderCode?: string;
59
+ price?: number;
60
+ instrumentId?: number;
61
+ positionEffect?: ACTION;
62
+ positionCode?: string;
63
+ tif?: TIF;
64
+ expireDate?: string;
65
+ stopLoss?: StopLoss;
66
+ takeProfit?: TakeProfit;
67
+ metadata?: Record<string, string>;
68
+ }
69
+ interface StopLoss {
70
+ price?: number;
71
+ offset?: number;
72
+ }
73
+ interface TakeProfit {
74
+ price?: number;
75
+ offset?: number;
76
+ }
77
+ interface Response {
78
+ orderId: number;
79
+ updateOrderId: number;
80
+ }
81
+ interface Update {
82
+ orderId: string;
83
+ status: string;
84
+ statusDescription?: string;
85
+ [key: string]: unknown;
86
+ }
87
+ interface Model {
88
+ account: string;
89
+ orderId: number;
90
+ orderCode: string;
91
+ version: number;
92
+ clientOrderId: string;
93
+ actionCode: string;
94
+ legCount: number;
95
+ type: ORDER_TYPE;
96
+ instrument: string;
97
+ status: string;
98
+ finalStatus: boolean;
99
+ legs: Leg[];
100
+ side: SIDE;
101
+ tif: TIF;
102
+ priceOffset?: number;
103
+ priceLink?: "TRIGGERED_STOP" | "TRIGGERED_LIMIT";
104
+ expireDate?: string;
105
+ marginRate?: number;
106
+ issueTime: string;
107
+ transactionTime: string;
108
+ links?: Link[];
109
+ executions?: Execution[];
110
+ cashTransactions?: CashTransaction[];
111
+ audit?: Audit;
112
+ }
113
+ interface Leg {
114
+ instrument: string;
115
+ positionEffect?: ACTION;
116
+ positionCode?: string;
117
+ price?: number;
118
+ legRatio: number;
119
+ quantity: number;
120
+ filledQuantity: number;
121
+ remainingQuantity: number;
122
+ averagePrice: number;
123
+ }
124
+ interface Link {
125
+ linkType: "PARENT" | "CHILD" | "OCO";
126
+ linkedOrder: string;
127
+ linkedClientOrderId: string;
128
+ }
129
+ interface Execution {
130
+ [key: string]: unknown;
131
+ }
132
+ interface CashTransaction {
133
+ [key: string]: unknown;
134
+ }
135
+ interface Audit {
136
+ IP?: string;
137
+ userAgent?: string;
138
+ }
64
139
  }
65
140
 
66
- interface DxtradeConfig$1 {
141
+ interface DxtradeConfig {
67
142
  username: string;
68
143
  password: string;
69
144
  broker: string;
70
145
  accountId?: string;
71
146
  brokerUrls?: Record<string, string>;
72
147
  retries?: number;
73
- debug?: boolean;
148
+ debug?: boolean | string;
74
149
  callbacks?: DxtradeCallbacks;
75
150
  }
76
151
  interface DxtradeCallbacks {
77
152
  onError?: (error: DxtradeError) => void;
78
153
  onLogin?: () => void;
79
154
  onAccountSwitch?: (accountId: string) => void;
80
- onOrderPlaced?: (order: OrderResponse) => void;
81
- onOrderUpdate?: (order: OrderUpdate$1) => void;
155
+ onOrderPlaced?: (order: Order.Response) => void;
156
+ onOrderUpdate?: (order: Order.Update) => void;
82
157
  }
83
158
 
84
- interface SymbolSuggestion$1 {
85
- id: number;
86
- name: string;
87
- [key: string]: unknown;
88
- }
89
- interface SymbolInfo$1 {
90
- maxVolume: number;
91
- minVolume: number;
92
- volumeStep: number;
93
- lotSize: number;
94
- [key: string]: unknown;
159
+ interface WsPayload {
160
+ accountId: string | null;
161
+ body: unknown;
162
+ type: string;
95
163
  }
96
164
 
97
- interface AssessmentsParams$1 {
98
- from: number;
99
- to: number;
100
- instrument: string;
101
- subtype?: string | null;
165
+ declare namespace Symbol {
166
+ interface Suggestion {
167
+ id: number;
168
+ name: string;
169
+ [key: string]: unknown;
170
+ }
171
+ interface Info {
172
+ maxVolume: number;
173
+ minVolume: number;
174
+ volumeStep: number;
175
+ lotSize: number;
176
+ [key: string]: unknown;
177
+ }
102
178
  }
103
- interface AssessmentsResponse$1 {
104
- totalPL?: number;
105
- [key: string]: unknown;
179
+
180
+ declare namespace Assessments {
181
+ interface Params {
182
+ from: number;
183
+ to: number;
184
+ instrument: string;
185
+ subtype?: string | null;
186
+ }
187
+ interface Response {
188
+ totalPL?: number;
189
+ [key: string]: unknown;
190
+ }
106
191
  }
107
192
 
108
193
  declare class DxtradeClient {
109
- private config;
110
- private callbacks;
111
- private cookies;
112
- private csrf;
113
- private baseUrl;
114
- private retries;
115
- private debug;
194
+ private _ctx;
116
195
  constructor(config: DxtradeConfig);
117
196
  login(): Promise<void>;
118
197
  fetchCsrf(): Promise<void>;
119
198
  switchAccount(accountId: string): Promise<void>;
120
- getSymbolSuggestions(text: string): Promise<SymbolSuggestion[]>;
121
- getSymbolInfo(symbol: string): Promise<SymbolInfo>;
122
- submitOrder(params: SubmitOrderParams): Promise<OrderUpdate>;
123
- getAssessments(params: AssessmentsParams): Promise<AssessmentsResponse>;
124
199
  connect(): Promise<void>;
125
- private ensureSession;
126
- private throwError;
200
+ getSymbolSuggestions(text: string): Promise<Symbol.Suggestion[]>;
201
+ getSymbolInfo(symbol: string): Promise<Symbol.Info>;
202
+ submitOrder(params: Order.SubmitParams): Promise<Order.Update>;
203
+ getAssessments(params: Assessments.Params): Promise<Assessments.Response>;
127
204
  }
128
205
 
129
- export { ACTION, type AssessmentsParams$1 as AssessmentsParams, type AssessmentsResponse$1 as AssessmentsResponse, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig$1 as DxtradeConfig, DxtradeError, ORDER_TYPE, type OrderResponse, type OrderUpdate$1 as OrderUpdate, SIDE, type StopLossParams, type SubmitOrderParams$1 as SubmitOrderParams, type SymbolInfo$1 as SymbolInfo, type SymbolSuggestion$1 as SymbolSuggestion, type TakeProfitParams, endpoints, resolveBrokerUrl };
206
+ export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints, resolveBrokerUrl };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  declare const BROKER: {
2
- readonly LARK: "https://trade.gooeytrade.com";
2
+ readonly LARKFUNDING: "https://trade.gooeytrade.com";
3
3
  readonly EIGHTCAP: "https://trader.dx-eightcap.com";
4
4
  };
5
5
  declare function resolveBrokerUrl(broker: string, customUrls?: Record<string, string>): string;
@@ -27,103 +27,180 @@ declare enum ACTION {
27
27
  OPENING = "OPENING",
28
28
  CLOSING = "CLOSING"
29
29
  }
30
+ declare enum TIF {
31
+ GTC = "GTC",
32
+ DAY = "DAY",
33
+ GTD = "GTD"
34
+ }
35
+ declare enum WS_MESSAGE {
36
+ ACCOUNTS = "ACCOUNTS",
37
+ AVAILABLE_WATCHLISTS = "AVAILABLE_WATCHLISTS",
38
+ MESSAGE = "MESSAGE",
39
+ ORDERS = "ORDERS",
40
+ POSITIONS = "POSITIONS",
41
+ POSITION_CASH_TRANSFERS = "POSITION_CASH_TRANSFERS",
42
+ PRIVATE_LAYOUT_NAMES = "PRIVATE_LAYOUT_NAMES",
43
+ SHARED_PROPERTIES_MESSAGE = "SHARED_PROPERTIES_MESSAGE",
44
+ USER_LOGIN_INFO = "USER_LOGIN_INFO"
45
+ }
30
46
 
31
47
  declare class DxtradeError extends Error {
32
48
  code: string;
33
49
  constructor(code: string, message: string);
34
50
  }
35
51
 
36
- interface SubmitOrderParams$1 {
37
- symbol: string;
38
- side: SIDE;
39
- quantity: number;
40
- orderType: ORDER_TYPE;
41
- price?: number;
42
- instrumentId?: number;
43
- stopLoss?: StopLossParams;
44
- takeProfit?: TakeProfitParams;
45
- positionEffect?: ACTION;
46
- }
47
- interface StopLossParams {
48
- price?: number;
49
- offset?: number;
50
- }
51
- interface TakeProfitParams {
52
- price?: number;
53
- offset?: number;
54
- }
55
- interface OrderResponse {
56
- status: number;
57
- data: unknown;
58
- }
59
- interface OrderUpdate$1 {
60
- orderId: string;
61
- status: string;
62
- statusDescription?: string;
63
- [key: string]: unknown;
52
+ declare namespace Order {
53
+ interface SubmitParams {
54
+ symbol: string;
55
+ side: SIDE;
56
+ quantity: number;
57
+ orderType: ORDER_TYPE;
58
+ orderCode?: string;
59
+ price?: number;
60
+ instrumentId?: number;
61
+ positionEffect?: ACTION;
62
+ positionCode?: string;
63
+ tif?: TIF;
64
+ expireDate?: string;
65
+ stopLoss?: StopLoss;
66
+ takeProfit?: TakeProfit;
67
+ metadata?: Record<string, string>;
68
+ }
69
+ interface StopLoss {
70
+ price?: number;
71
+ offset?: number;
72
+ }
73
+ interface TakeProfit {
74
+ price?: number;
75
+ offset?: number;
76
+ }
77
+ interface Response {
78
+ orderId: number;
79
+ updateOrderId: number;
80
+ }
81
+ interface Update {
82
+ orderId: string;
83
+ status: string;
84
+ statusDescription?: string;
85
+ [key: string]: unknown;
86
+ }
87
+ interface Model {
88
+ account: string;
89
+ orderId: number;
90
+ orderCode: string;
91
+ version: number;
92
+ clientOrderId: string;
93
+ actionCode: string;
94
+ legCount: number;
95
+ type: ORDER_TYPE;
96
+ instrument: string;
97
+ status: string;
98
+ finalStatus: boolean;
99
+ legs: Leg[];
100
+ side: SIDE;
101
+ tif: TIF;
102
+ priceOffset?: number;
103
+ priceLink?: "TRIGGERED_STOP" | "TRIGGERED_LIMIT";
104
+ expireDate?: string;
105
+ marginRate?: number;
106
+ issueTime: string;
107
+ transactionTime: string;
108
+ links?: Link[];
109
+ executions?: Execution[];
110
+ cashTransactions?: CashTransaction[];
111
+ audit?: Audit;
112
+ }
113
+ interface Leg {
114
+ instrument: string;
115
+ positionEffect?: ACTION;
116
+ positionCode?: string;
117
+ price?: number;
118
+ legRatio: number;
119
+ quantity: number;
120
+ filledQuantity: number;
121
+ remainingQuantity: number;
122
+ averagePrice: number;
123
+ }
124
+ interface Link {
125
+ linkType: "PARENT" | "CHILD" | "OCO";
126
+ linkedOrder: string;
127
+ linkedClientOrderId: string;
128
+ }
129
+ interface Execution {
130
+ [key: string]: unknown;
131
+ }
132
+ interface CashTransaction {
133
+ [key: string]: unknown;
134
+ }
135
+ interface Audit {
136
+ IP?: string;
137
+ userAgent?: string;
138
+ }
64
139
  }
65
140
 
66
- interface DxtradeConfig$1 {
141
+ interface DxtradeConfig {
67
142
  username: string;
68
143
  password: string;
69
144
  broker: string;
70
145
  accountId?: string;
71
146
  brokerUrls?: Record<string, string>;
72
147
  retries?: number;
73
- debug?: boolean;
148
+ debug?: boolean | string;
74
149
  callbacks?: DxtradeCallbacks;
75
150
  }
76
151
  interface DxtradeCallbacks {
77
152
  onError?: (error: DxtradeError) => void;
78
153
  onLogin?: () => void;
79
154
  onAccountSwitch?: (accountId: string) => void;
80
- onOrderPlaced?: (order: OrderResponse) => void;
81
- onOrderUpdate?: (order: OrderUpdate$1) => void;
155
+ onOrderPlaced?: (order: Order.Response) => void;
156
+ onOrderUpdate?: (order: Order.Update) => void;
82
157
  }
83
158
 
84
- interface SymbolSuggestion$1 {
85
- id: number;
86
- name: string;
87
- [key: string]: unknown;
88
- }
89
- interface SymbolInfo$1 {
90
- maxVolume: number;
91
- minVolume: number;
92
- volumeStep: number;
93
- lotSize: number;
94
- [key: string]: unknown;
159
+ interface WsPayload {
160
+ accountId: string | null;
161
+ body: unknown;
162
+ type: string;
95
163
  }
96
164
 
97
- interface AssessmentsParams$1 {
98
- from: number;
99
- to: number;
100
- instrument: string;
101
- subtype?: string | null;
165
+ declare namespace Symbol {
166
+ interface Suggestion {
167
+ id: number;
168
+ name: string;
169
+ [key: string]: unknown;
170
+ }
171
+ interface Info {
172
+ maxVolume: number;
173
+ minVolume: number;
174
+ volumeStep: number;
175
+ lotSize: number;
176
+ [key: string]: unknown;
177
+ }
102
178
  }
103
- interface AssessmentsResponse$1 {
104
- totalPL?: number;
105
- [key: string]: unknown;
179
+
180
+ declare namespace Assessments {
181
+ interface Params {
182
+ from: number;
183
+ to: number;
184
+ instrument: string;
185
+ subtype?: string | null;
186
+ }
187
+ interface Response {
188
+ totalPL?: number;
189
+ [key: string]: unknown;
190
+ }
106
191
  }
107
192
 
108
193
  declare class DxtradeClient {
109
- private config;
110
- private callbacks;
111
- private cookies;
112
- private csrf;
113
- private baseUrl;
114
- private retries;
115
- private debug;
194
+ private _ctx;
116
195
  constructor(config: DxtradeConfig);
117
196
  login(): Promise<void>;
118
197
  fetchCsrf(): Promise<void>;
119
198
  switchAccount(accountId: string): Promise<void>;
120
- getSymbolSuggestions(text: string): Promise<SymbolSuggestion[]>;
121
- getSymbolInfo(symbol: string): Promise<SymbolInfo>;
122
- submitOrder(params: SubmitOrderParams): Promise<OrderUpdate>;
123
- getAssessments(params: AssessmentsParams): Promise<AssessmentsResponse>;
124
199
  connect(): Promise<void>;
125
- private ensureSession;
126
- private throwError;
200
+ getSymbolSuggestions(text: string): Promise<Symbol.Suggestion[]>;
201
+ getSymbolInfo(symbol: string): Promise<Symbol.Info>;
202
+ submitOrder(params: Order.SubmitParams): Promise<Order.Update>;
203
+ getAssessments(params: Assessments.Params): Promise<Assessments.Response>;
127
204
  }
128
205
 
129
- export { ACTION, type AssessmentsParams$1 as AssessmentsParams, type AssessmentsResponse$1 as AssessmentsResponse, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig$1 as DxtradeConfig, DxtradeError, ORDER_TYPE, type OrderResponse, type OrderUpdate$1 as OrderUpdate, SIDE, type StopLossParams, type SubmitOrderParams$1 as SubmitOrderParams, type SymbolInfo$1 as SymbolInfo, type SymbolSuggestion$1 as SymbolSuggestion, type TakeProfitParams, endpoints, resolveBrokerUrl };
206
+ export { ACTION, BROKER, type DxtradeCallbacks, DxtradeClient, type DxtradeConfig, DxtradeError, ORDER_TYPE, SIDE, TIF, WS_MESSAGE, type WsPayload, endpoints, resolveBrokerUrl };