@pipsend/sdk 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +70 -11
- package/dist/index.d.ts +70 -11
- package/dist/index.js +59 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -18,7 +18,7 @@ interface WebSocketConfig {
|
|
|
18
18
|
/**
|
|
19
19
|
* Available WebSocket channels for subscription
|
|
20
20
|
*/
|
|
21
|
-
type WebSocketChannel = 'positions:new' | 'positions:closed' | 'positions:updated' | 'accounts:balance';
|
|
21
|
+
type WebSocketChannel = 'positions:new' | 'positions:closed' | 'positions:updated' | 'accounts:balance' | 'account_metrics';
|
|
22
22
|
/**
|
|
23
23
|
* WebSocket operation types from server
|
|
24
24
|
*/
|
|
@@ -79,21 +79,27 @@ interface PositionEvent {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Balance update event
|
|
82
|
+
* Balance update event (account metrics)
|
|
83
83
|
*/
|
|
84
84
|
interface BalanceEvent {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
metrics: {
|
|
86
|
+
balance: number;
|
|
87
|
+
equity: number;
|
|
88
|
+
margin: number;
|
|
89
|
+
free_margin: number;
|
|
90
|
+
margin_level: number;
|
|
91
|
+
total_pnl: number;
|
|
92
|
+
leverage: number;
|
|
93
|
+
currency: string;
|
|
94
|
+
};
|
|
95
|
+
ts: number;
|
|
96
|
+
type: 'account_metrics';
|
|
97
|
+
login?: number;
|
|
92
98
|
}
|
|
93
99
|
/**
|
|
94
100
|
* WebSocket event types (internal)
|
|
95
101
|
*/
|
|
96
|
-
type WebSocketEventType = 'position:opened' | 'position:closed' | 'position:updated' | 'balance:updated' | 'connected' | 'disconnected' | 'error' | 'subscription_success' | 'unsubscription_success' | '*';
|
|
102
|
+
type WebSocketEventType = 'position:opened' | 'position:closed' | 'position:updated' | 'balance:updated' | 'account:metrics' | 'connected' | 'disconnected' | 'error' | 'subscription_success' | 'unsubscription_success' | '*';
|
|
97
103
|
/**
|
|
98
104
|
* @deprecated Use PositionEvent instead
|
|
99
105
|
*/
|
|
@@ -369,6 +375,37 @@ interface AccountStatusResponse {
|
|
|
369
375
|
status_code: 'SUCCESS';
|
|
370
376
|
data: AccountStatus;
|
|
371
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* Account permission types
|
|
380
|
+
*/
|
|
381
|
+
type AccountPermission = 'RIGHT_ENABLED' | 'RIGHT_LOGIN_ENABLED' | 'RIGHT_TRADE_ENABLED' | 'RIGHT_EA_ENABLED' | 'RIGHT_READONLY' | 'RIGHT_API_ACCESS_ENABLED' | 'RIGHT_BALANCE_READONLY' | 'RIGHT_DEPOSIT_ENABLED' | 'RIGHT_WITHDRAW_ENABLED' | 'RIGHT_PUSH_NOTIFICATIONS_ENABLED' | 'RIGHT_FORCE_PASSWORD_RESET';
|
|
382
|
+
/**
|
|
383
|
+
* Account rights/permissions
|
|
384
|
+
*/
|
|
385
|
+
interface AccountRights {
|
|
386
|
+
/** Account login */
|
|
387
|
+
login: number;
|
|
388
|
+
/** List of active permissions */
|
|
389
|
+
rights: string[];
|
|
390
|
+
/** Bitmask representation of permissions */
|
|
391
|
+
rights_mask: number;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Update account rights request
|
|
395
|
+
*/
|
|
396
|
+
interface UpdateRightsRequest {
|
|
397
|
+
/** List of permissions to set (replaces all existing permissions) */
|
|
398
|
+
rights: string[];
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Update account rights response
|
|
402
|
+
*/
|
|
403
|
+
interface UpdateRightsResponse {
|
|
404
|
+
/** Account login */
|
|
405
|
+
login: number;
|
|
406
|
+
/** Updated list of permissions */
|
|
407
|
+
rights: string[];
|
|
408
|
+
}
|
|
372
409
|
|
|
373
410
|
/**
|
|
374
411
|
* Trading Group types
|
|
@@ -1139,6 +1176,20 @@ declare class AccountsAPI {
|
|
|
1139
1176
|
* The adjustment is relative: amount is added or subtracted from current value
|
|
1140
1177
|
*/
|
|
1141
1178
|
balance(login: number, request: AdjustBalanceRequest): Promise<AdjustBalanceResponse>;
|
|
1179
|
+
/**
|
|
1180
|
+
* Get account permissions
|
|
1181
|
+
* @param login - Account login
|
|
1182
|
+
* @returns Account permissions
|
|
1183
|
+
*/
|
|
1184
|
+
getRights(login: number): Promise<AccountRights>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Update account permissions
|
|
1187
|
+
* IMPORTANT: This replaces all existing permissions
|
|
1188
|
+
* @param login - Account login
|
|
1189
|
+
* @param data - Permissions to set
|
|
1190
|
+
* @returns Updated permissions
|
|
1191
|
+
*/
|
|
1192
|
+
updateRights(login: number, data: UpdateRightsRequest): Promise<UpdateRightsResponse>;
|
|
1142
1193
|
}
|
|
1143
1194
|
|
|
1144
1195
|
/**
|
|
@@ -1420,6 +1471,10 @@ declare class PipsendClient {
|
|
|
1420
1471
|
* Listens to balance updated events
|
|
1421
1472
|
*/
|
|
1422
1473
|
onBalanceUpdated: (callback: WebSocketCallback<BalanceEvent>) => void;
|
|
1474
|
+
/**
|
|
1475
|
+
* Listens to account metrics events (replaces balance updates)
|
|
1476
|
+
*/
|
|
1477
|
+
onAccountMetrics: (callback: WebSocketCallback<BalanceEvent>) => void;
|
|
1423
1478
|
/**
|
|
1424
1479
|
* @deprecated Use onPositionUpdated instead
|
|
1425
1480
|
*/
|
|
@@ -1448,6 +1503,10 @@ declare class PipsendClient {
|
|
|
1448
1503
|
* Listens to error events
|
|
1449
1504
|
*/
|
|
1450
1505
|
onError: (callback: WebSocketCallback) => void;
|
|
1506
|
+
/**
|
|
1507
|
+
* Registers a custom event listener
|
|
1508
|
+
*/
|
|
1509
|
+
on: (event: string, callback: WebSocketCallback) => void;
|
|
1451
1510
|
/**
|
|
1452
1511
|
* Removes event listener
|
|
1453
1512
|
*/
|
|
@@ -1490,4 +1549,4 @@ declare const sdk: {
|
|
|
1490
1549
|
PipsendClient: typeof PipsendClient;
|
|
1491
1550
|
};
|
|
1492
1551
|
|
|
1493
|
-
export { type Account, type AccountStatistics, type AccountStatisticsParams, type AccountsListParams, type AuthResponse, AuthenticationError, type BalanceUpdate, type CalculateProfitRequest, type CalculateProfitResponse, type Candle, type CandlesParams, type ChangePasswordRequest, type CheckMarginRequest, type CheckMarginResponse, type CloseTradeRequest, type CloseTradeResponse, ConfigurationError, type Group, type GroupsParams, type HealthCheckResponse, type ModifyTradeRequest, type ModifyTradeResponse, type OpenTradeRequest, type OpenTradeResponse, type Order, type OrderData, type OrderStatistics, type OrderUpdate, type OrdersListParams, type PaginatedResponse, type PaginationParams, PipsendClient, type PipsendConfig, PipsendError, type Position, type PositionStatistics, type PositionUpdate, type PositionsListParams, type PriceUpdate, type Symbol, type SymbolsParams, type TokenInfo, type TradingGroup, type TradingGroupStatistics, type TradingGroupsListParams, type UpdateOrderRequest, type UpdatePositionRequest, type WebSocketCallback, type WebSocketConfig, WebSocketError, type WebSocketEventType, type WebSocketMessage, createClient, sdk as default };
|
|
1552
|
+
export { type Account, type AccountPermission, type AccountRights, type AccountStatistics, type AccountStatisticsParams, type AccountsListParams, type AuthResponse, AuthenticationError, type BalanceUpdate, type CalculateProfitRequest, type CalculateProfitResponse, type Candle, type CandlesParams, type ChangePasswordRequest, type CheckMarginRequest, type CheckMarginResponse, type CloseTradeRequest, type CloseTradeResponse, ConfigurationError, type Group, type GroupsParams, type HealthCheckResponse, type ModifyTradeRequest, type ModifyTradeResponse, type OpenTradeRequest, type OpenTradeResponse, type Order, type OrderData, type OrderStatistics, type OrderUpdate, type OrdersListParams, type PaginatedResponse, type PaginationParams, PipsendClient, type PipsendConfig, PipsendError, type Position, type PositionStatistics, type PositionUpdate, type PositionsListParams, type PriceUpdate, type Symbol, type SymbolsParams, type TokenInfo, type TradingGroup, type TradingGroupStatistics, type TradingGroupsListParams, type UpdateOrderRequest, type UpdatePositionRequest, type UpdateRightsRequest, type UpdateRightsResponse, type WebSocketCallback, type WebSocketConfig, WebSocketError, type WebSocketEventType, type WebSocketMessage, createClient, sdk as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface WebSocketConfig {
|
|
|
18
18
|
/**
|
|
19
19
|
* Available WebSocket channels for subscription
|
|
20
20
|
*/
|
|
21
|
-
type WebSocketChannel = 'positions:new' | 'positions:closed' | 'positions:updated' | 'accounts:balance';
|
|
21
|
+
type WebSocketChannel = 'positions:new' | 'positions:closed' | 'positions:updated' | 'accounts:balance' | 'account_metrics';
|
|
22
22
|
/**
|
|
23
23
|
* WebSocket operation types from server
|
|
24
24
|
*/
|
|
@@ -79,21 +79,27 @@ interface PositionEvent {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Balance update event
|
|
82
|
+
* Balance update event (account metrics)
|
|
83
83
|
*/
|
|
84
84
|
interface BalanceEvent {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
metrics: {
|
|
86
|
+
balance: number;
|
|
87
|
+
equity: number;
|
|
88
|
+
margin: number;
|
|
89
|
+
free_margin: number;
|
|
90
|
+
margin_level: number;
|
|
91
|
+
total_pnl: number;
|
|
92
|
+
leverage: number;
|
|
93
|
+
currency: string;
|
|
94
|
+
};
|
|
95
|
+
ts: number;
|
|
96
|
+
type: 'account_metrics';
|
|
97
|
+
login?: number;
|
|
92
98
|
}
|
|
93
99
|
/**
|
|
94
100
|
* WebSocket event types (internal)
|
|
95
101
|
*/
|
|
96
|
-
type WebSocketEventType = 'position:opened' | 'position:closed' | 'position:updated' | 'balance:updated' | 'connected' | 'disconnected' | 'error' | 'subscription_success' | 'unsubscription_success' | '*';
|
|
102
|
+
type WebSocketEventType = 'position:opened' | 'position:closed' | 'position:updated' | 'balance:updated' | 'account:metrics' | 'connected' | 'disconnected' | 'error' | 'subscription_success' | 'unsubscription_success' | '*';
|
|
97
103
|
/**
|
|
98
104
|
* @deprecated Use PositionEvent instead
|
|
99
105
|
*/
|
|
@@ -369,6 +375,37 @@ interface AccountStatusResponse {
|
|
|
369
375
|
status_code: 'SUCCESS';
|
|
370
376
|
data: AccountStatus;
|
|
371
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* Account permission types
|
|
380
|
+
*/
|
|
381
|
+
type AccountPermission = 'RIGHT_ENABLED' | 'RIGHT_LOGIN_ENABLED' | 'RIGHT_TRADE_ENABLED' | 'RIGHT_EA_ENABLED' | 'RIGHT_READONLY' | 'RIGHT_API_ACCESS_ENABLED' | 'RIGHT_BALANCE_READONLY' | 'RIGHT_DEPOSIT_ENABLED' | 'RIGHT_WITHDRAW_ENABLED' | 'RIGHT_PUSH_NOTIFICATIONS_ENABLED' | 'RIGHT_FORCE_PASSWORD_RESET';
|
|
382
|
+
/**
|
|
383
|
+
* Account rights/permissions
|
|
384
|
+
*/
|
|
385
|
+
interface AccountRights {
|
|
386
|
+
/** Account login */
|
|
387
|
+
login: number;
|
|
388
|
+
/** List of active permissions */
|
|
389
|
+
rights: string[];
|
|
390
|
+
/** Bitmask representation of permissions */
|
|
391
|
+
rights_mask: number;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Update account rights request
|
|
395
|
+
*/
|
|
396
|
+
interface UpdateRightsRequest {
|
|
397
|
+
/** List of permissions to set (replaces all existing permissions) */
|
|
398
|
+
rights: string[];
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Update account rights response
|
|
402
|
+
*/
|
|
403
|
+
interface UpdateRightsResponse {
|
|
404
|
+
/** Account login */
|
|
405
|
+
login: number;
|
|
406
|
+
/** Updated list of permissions */
|
|
407
|
+
rights: string[];
|
|
408
|
+
}
|
|
372
409
|
|
|
373
410
|
/**
|
|
374
411
|
* Trading Group types
|
|
@@ -1139,6 +1176,20 @@ declare class AccountsAPI {
|
|
|
1139
1176
|
* The adjustment is relative: amount is added or subtracted from current value
|
|
1140
1177
|
*/
|
|
1141
1178
|
balance(login: number, request: AdjustBalanceRequest): Promise<AdjustBalanceResponse>;
|
|
1179
|
+
/**
|
|
1180
|
+
* Get account permissions
|
|
1181
|
+
* @param login - Account login
|
|
1182
|
+
* @returns Account permissions
|
|
1183
|
+
*/
|
|
1184
|
+
getRights(login: number): Promise<AccountRights>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Update account permissions
|
|
1187
|
+
* IMPORTANT: This replaces all existing permissions
|
|
1188
|
+
* @param login - Account login
|
|
1189
|
+
* @param data - Permissions to set
|
|
1190
|
+
* @returns Updated permissions
|
|
1191
|
+
*/
|
|
1192
|
+
updateRights(login: number, data: UpdateRightsRequest): Promise<UpdateRightsResponse>;
|
|
1142
1193
|
}
|
|
1143
1194
|
|
|
1144
1195
|
/**
|
|
@@ -1420,6 +1471,10 @@ declare class PipsendClient {
|
|
|
1420
1471
|
* Listens to balance updated events
|
|
1421
1472
|
*/
|
|
1422
1473
|
onBalanceUpdated: (callback: WebSocketCallback<BalanceEvent>) => void;
|
|
1474
|
+
/**
|
|
1475
|
+
* Listens to account metrics events (replaces balance updates)
|
|
1476
|
+
*/
|
|
1477
|
+
onAccountMetrics: (callback: WebSocketCallback<BalanceEvent>) => void;
|
|
1423
1478
|
/**
|
|
1424
1479
|
* @deprecated Use onPositionUpdated instead
|
|
1425
1480
|
*/
|
|
@@ -1448,6 +1503,10 @@ declare class PipsendClient {
|
|
|
1448
1503
|
* Listens to error events
|
|
1449
1504
|
*/
|
|
1450
1505
|
onError: (callback: WebSocketCallback) => void;
|
|
1506
|
+
/**
|
|
1507
|
+
* Registers a custom event listener
|
|
1508
|
+
*/
|
|
1509
|
+
on: (event: string, callback: WebSocketCallback) => void;
|
|
1451
1510
|
/**
|
|
1452
1511
|
* Removes event listener
|
|
1453
1512
|
*/
|
|
@@ -1490,4 +1549,4 @@ declare const sdk: {
|
|
|
1490
1549
|
PipsendClient: typeof PipsendClient;
|
|
1491
1550
|
};
|
|
1492
1551
|
|
|
1493
|
-
export { type Account, type AccountStatistics, type AccountStatisticsParams, type AccountsListParams, type AuthResponse, AuthenticationError, type BalanceUpdate, type CalculateProfitRequest, type CalculateProfitResponse, type Candle, type CandlesParams, type ChangePasswordRequest, type CheckMarginRequest, type CheckMarginResponse, type CloseTradeRequest, type CloseTradeResponse, ConfigurationError, type Group, type GroupsParams, type HealthCheckResponse, type ModifyTradeRequest, type ModifyTradeResponse, type OpenTradeRequest, type OpenTradeResponse, type Order, type OrderData, type OrderStatistics, type OrderUpdate, type OrdersListParams, type PaginatedResponse, type PaginationParams, PipsendClient, type PipsendConfig, PipsendError, type Position, type PositionStatistics, type PositionUpdate, type PositionsListParams, type PriceUpdate, type Symbol, type SymbolsParams, type TokenInfo, type TradingGroup, type TradingGroupStatistics, type TradingGroupsListParams, type UpdateOrderRequest, type UpdatePositionRequest, type WebSocketCallback, type WebSocketConfig, WebSocketError, type WebSocketEventType, type WebSocketMessage, createClient, sdk as default };
|
|
1552
|
+
export { type Account, type AccountPermission, type AccountRights, type AccountStatistics, type AccountStatisticsParams, type AccountsListParams, type AuthResponse, AuthenticationError, type BalanceUpdate, type CalculateProfitRequest, type CalculateProfitResponse, type Candle, type CandlesParams, type ChangePasswordRequest, type CheckMarginRequest, type CheckMarginResponse, type CloseTradeRequest, type CloseTradeResponse, ConfigurationError, type Group, type GroupsParams, type HealthCheckResponse, type ModifyTradeRequest, type ModifyTradeResponse, type OpenTradeRequest, type OpenTradeResponse, type Order, type OrderData, type OrderStatistics, type OrderUpdate, type OrdersListParams, type PaginatedResponse, type PaginationParams, PipsendClient, type PipsendConfig, PipsendError, type Position, type PositionStatistics, type PositionUpdate, type PositionsListParams, type PriceUpdate, type Symbol, type SymbolsParams, type TokenInfo, type TradingGroup, type TradingGroupStatistics, type TradingGroupsListParams, type UpdateOrderRequest, type UpdatePositionRequest, type UpdateRightsRequest, type UpdateRightsResponse, type WebSocketCallback, type WebSocketConfig, WebSocketError, type WebSocketEventType, type WebSocketMessage, createClient, sdk as default };
|
package/dist/index.js
CHANGED
|
@@ -134,11 +134,6 @@ var AuthManager = class {
|
|
|
134
134
|
}
|
|
135
135
|
const data = await response.json();
|
|
136
136
|
this.setTokenInfo(data);
|
|
137
|
-
console.log("\u2705 Authentication successful");
|
|
138
|
-
console.log(` User: ${data.user.first_name} ${data.user.last_name} (${data.user.email})`);
|
|
139
|
-
console.log(` Login: ${data.user.login}`);
|
|
140
|
-
console.log(` Balance: $${data.user.balance.toFixed(2)}`);
|
|
141
|
-
console.log(` Logged with: ${data.logged_with}`);
|
|
142
137
|
} catch (error) {
|
|
143
138
|
if (error instanceof AuthenticationError) {
|
|
144
139
|
throw error;
|
|
@@ -153,7 +148,6 @@ var AuthManager = class {
|
|
|
153
148
|
*/
|
|
154
149
|
async refreshToken() {
|
|
155
150
|
if (!this.tokenInfo?.refreshToken) {
|
|
156
|
-
console.log("\u26A0\uFE0F No refresh token available, performing full authentication");
|
|
157
151
|
this.tokenInfo = void 0;
|
|
158
152
|
await this.authenticate();
|
|
159
153
|
return;
|
|
@@ -167,7 +161,6 @@ var AuthManager = class {
|
|
|
167
161
|
})
|
|
168
162
|
});
|
|
169
163
|
if (!response.ok) {
|
|
170
|
-
console.log("\u26A0\uFE0F Refresh token failed, performing full authentication");
|
|
171
164
|
this.tokenInfo = void 0;
|
|
172
165
|
await this.authenticate();
|
|
173
166
|
return;
|
|
@@ -182,9 +175,7 @@ var AuthManager = class {
|
|
|
182
175
|
issuedAt: now,
|
|
183
176
|
expiresAt
|
|
184
177
|
};
|
|
185
|
-
console.log("\u2705 Token refreshed successfully");
|
|
186
178
|
} catch (error) {
|
|
187
|
-
console.error("\u274C Error refreshing token:", error);
|
|
188
179
|
this.tokenInfo = void 0;
|
|
189
180
|
await this.authenticate();
|
|
190
181
|
}
|
|
@@ -236,11 +227,9 @@ var WebSocketManager = class {
|
|
|
236
227
|
*/
|
|
237
228
|
async connect() {
|
|
238
229
|
if (this.isConnected) {
|
|
239
|
-
console.log("\u26A0\uFE0F WebSocket already connected");
|
|
240
230
|
return;
|
|
241
231
|
}
|
|
242
232
|
if (this.isReconnecting) {
|
|
243
|
-
console.log("\u26A0\uFE0F WebSocket reconnection in progress");
|
|
244
233
|
return;
|
|
245
234
|
}
|
|
246
235
|
const token = await this.authManager.ensureAuthenticated();
|
|
@@ -251,13 +240,11 @@ var WebSocketManager = class {
|
|
|
251
240
|
const WS = this.getWebSocketConstructor();
|
|
252
241
|
this.ws = new WS(wsUrl);
|
|
253
242
|
this.ws.onopen = () => {
|
|
254
|
-
console.log("\u2705 WebSocket connected");
|
|
255
243
|
this.isConnected = true;
|
|
256
244
|
this.isReconnecting = false;
|
|
257
245
|
this.reconnectAttempts = 0;
|
|
258
246
|
this.emit("connected", { timestamp: Date.now() });
|
|
259
247
|
if (this.subscribedChannels.length > 0) {
|
|
260
|
-
console.log("\u{1F504} Resubscribing to channels:", this.subscribedChannels);
|
|
261
248
|
this.subscribe(this.subscribedChannels);
|
|
262
249
|
}
|
|
263
250
|
this.startHeartbeat();
|
|
@@ -279,7 +266,6 @@ var WebSocketManager = class {
|
|
|
279
266
|
}
|
|
280
267
|
};
|
|
281
268
|
this.ws.onclose = (event) => {
|
|
282
|
-
console.log("WebSocket disconnected", event.code, event.reason);
|
|
283
269
|
this.isConnected = false;
|
|
284
270
|
this.stopHeartbeat();
|
|
285
271
|
this.emit("disconnected", {
|
|
@@ -309,14 +295,12 @@ var WebSocketManager = class {
|
|
|
309
295
|
channels
|
|
310
296
|
};
|
|
311
297
|
this.sendAction(message);
|
|
312
|
-
console.log("\u{1F4E1} Subscribed to channels:", channels);
|
|
313
298
|
}
|
|
314
299
|
/**
|
|
315
300
|
* Unsubscribes from WebSocket channels
|
|
316
301
|
*/
|
|
317
302
|
unsubscribe(channels) {
|
|
318
303
|
if (!this.isConnected) {
|
|
319
|
-
console.warn("WebSocket not connected, cannot unsubscribe");
|
|
320
304
|
return;
|
|
321
305
|
}
|
|
322
306
|
this.subscribedChannels = this.subscribedChannels.filter(
|
|
@@ -327,7 +311,6 @@ var WebSocketManager = class {
|
|
|
327
311
|
channels
|
|
328
312
|
};
|
|
329
313
|
this.sendAction(message);
|
|
330
|
-
console.log("\u{1F4E1} Unsubscribed from channels:", channels);
|
|
331
314
|
}
|
|
332
315
|
/**
|
|
333
316
|
* Registers an event listener
|
|
@@ -352,7 +335,6 @@ var WebSocketManager = class {
|
|
|
352
335
|
* Disconnects from WebSocket
|
|
353
336
|
*/
|
|
354
337
|
disconnect() {
|
|
355
|
-
console.log("\u{1F44B} Disconnecting WebSocket...");
|
|
356
338
|
this.stopHeartbeat();
|
|
357
339
|
if (this.ws) {
|
|
358
340
|
this.ws.close();
|
|
@@ -410,7 +392,6 @@ var WebSocketManager = class {
|
|
|
410
392
|
*/
|
|
411
393
|
sendAction(message) {
|
|
412
394
|
if (!this.ws || !this.isConnected) {
|
|
413
|
-
console.warn("\u26A0\uFE0F WebSocket not ready, message not sent:", message.action);
|
|
414
395
|
return;
|
|
415
396
|
}
|
|
416
397
|
try {
|
|
@@ -454,7 +435,7 @@ var WebSocketManager = class {
|
|
|
454
435
|
this.handleError(message);
|
|
455
436
|
break;
|
|
456
437
|
default:
|
|
457
|
-
|
|
438
|
+
break;
|
|
458
439
|
}
|
|
459
440
|
this.emit("*", message);
|
|
460
441
|
}
|
|
@@ -462,22 +443,18 @@ var WebSocketManager = class {
|
|
|
462
443
|
* Handles connected message from server
|
|
463
444
|
*/
|
|
464
445
|
handleConnected(message) {
|
|
465
|
-
console.log("\u2705 WebSocket connected:", message.data.message);
|
|
466
|
-
console.log(" Available channels:", message.data.available_channels);
|
|
467
446
|
this.emit("connected", message.data);
|
|
468
447
|
}
|
|
469
448
|
/**
|
|
470
449
|
* Handles subscription success
|
|
471
450
|
*/
|
|
472
451
|
handleSubscriptionSuccess(message) {
|
|
473
|
-
console.log("\u2705 Subscription successful:", message.data.subscribed);
|
|
474
452
|
this.emit("subscription_success", message.data);
|
|
475
453
|
}
|
|
476
454
|
/**
|
|
477
455
|
* Handles unsubscription success
|
|
478
456
|
*/
|
|
479
457
|
handleUnsubscriptionSuccess(message) {
|
|
480
|
-
console.log("\u2705 Unsubscription successful:", message.data.unsubscribed);
|
|
481
458
|
this.emit("unsubscription_success", message.data);
|
|
482
459
|
}
|
|
483
460
|
/**
|
|
@@ -497,11 +474,27 @@ var WebSocketManager = class {
|
|
|
497
474
|
case "position.updated":
|
|
498
475
|
this.emit("position:updated", eventData);
|
|
499
476
|
break;
|
|
477
|
+
case "account_metrics":
|
|
478
|
+
const balanceEvent = eventData;
|
|
479
|
+
if (message.topic?.startsWith("balance:")) {
|
|
480
|
+
const loginMatch = message.topic.match(/balance:api:(\d+)/);
|
|
481
|
+
if (loginMatch) {
|
|
482
|
+
balanceEvent.login = parseInt(loginMatch[1], 10);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
this.emit("account:metrics", balanceEvent);
|
|
486
|
+
this.emit("balance:updated", balanceEvent);
|
|
487
|
+
break;
|
|
500
488
|
default:
|
|
501
489
|
if (message.topic?.startsWith("balance:")) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
490
|
+
const event = eventData;
|
|
491
|
+
const loginMatch = message.topic.match(/balance:api:(\d+)/);
|
|
492
|
+
if (loginMatch) {
|
|
493
|
+
event.login = parseInt(loginMatch[1], 10);
|
|
494
|
+
}
|
|
495
|
+
this.emit("balance:updated", event);
|
|
496
|
+
} else if (message.topic?.startsWith("account_metrics")) {
|
|
497
|
+
this.emit("account:metrics", eventData);
|
|
505
498
|
}
|
|
506
499
|
}
|
|
507
500
|
}
|
|
@@ -537,18 +530,13 @@ var WebSocketManager = class {
|
|
|
537
530
|
const autoReconnect = this.config.websocket?.autoReconnect ?? true;
|
|
538
531
|
const maxAttempts = this.config.websocket?.maxReconnectAttempts ?? 5;
|
|
539
532
|
if (!autoReconnect) {
|
|
540
|
-
console.log("Auto-reconnect disabled");
|
|
541
533
|
return;
|
|
542
534
|
}
|
|
543
535
|
if (this.reconnectAttempts >= maxAttempts) {
|
|
544
|
-
console.log(`\u274C Max reconnection attempts (${maxAttempts}) reached. Giving up.`);
|
|
545
536
|
this.emit("error", new WebSocketError("Max reconnection attempts reached"));
|
|
546
537
|
return;
|
|
547
538
|
}
|
|
548
539
|
const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 3e4);
|
|
549
|
-
console.log(
|
|
550
|
-
`\u{1F504} Reconnecting in ${delay}ms (attempt ${this.reconnectAttempts + 1}/${maxAttempts})...`
|
|
551
|
-
);
|
|
552
540
|
this.isReconnecting = true;
|
|
553
541
|
setTimeout(() => {
|
|
554
542
|
this.reconnectAttempts++;
|
|
@@ -765,6 +753,27 @@ var AccountsAPI = class {
|
|
|
765
753
|
async balance(login, request) {
|
|
766
754
|
return this.http.put(`/api/v1/accounts/${login}/adjust`, request);
|
|
767
755
|
}
|
|
756
|
+
/**
|
|
757
|
+
* Get account permissions
|
|
758
|
+
* @param login - Account login
|
|
759
|
+
* @returns Account permissions
|
|
760
|
+
*/
|
|
761
|
+
async getRights(login) {
|
|
762
|
+
return this.http.get(`/api/v1/accounts/${login}/rights`);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Update account permissions
|
|
766
|
+
* IMPORTANT: This replaces all existing permissions
|
|
767
|
+
* @param login - Account login
|
|
768
|
+
* @param data - Permissions to set
|
|
769
|
+
* @returns Updated permissions
|
|
770
|
+
*/
|
|
771
|
+
async updateRights(login, data) {
|
|
772
|
+
return this.http.put(
|
|
773
|
+
`/api/v1/accounts/${login}/rights`,
|
|
774
|
+
data
|
|
775
|
+
);
|
|
776
|
+
}
|
|
768
777
|
};
|
|
769
778
|
|
|
770
779
|
// src/api/trading-groups.ts
|
|
@@ -1122,6 +1131,15 @@ var PipsendClient = class {
|
|
|
1122
1131
|
}
|
|
1123
1132
|
this.wsManager.on("balance:updated", callback);
|
|
1124
1133
|
},
|
|
1134
|
+
/**
|
|
1135
|
+
* Listens to account metrics events (replaces balance updates)
|
|
1136
|
+
*/
|
|
1137
|
+
onAccountMetrics: (callback) => {
|
|
1138
|
+
if (!this.wsManager) {
|
|
1139
|
+
throw new WebSocketError("WebSocket not enabled");
|
|
1140
|
+
}
|
|
1141
|
+
this.wsManager.on("account:metrics", callback);
|
|
1142
|
+
},
|
|
1125
1143
|
// Legacy methods (deprecated but kept for compatibility)
|
|
1126
1144
|
/**
|
|
1127
1145
|
* @deprecated Use onPositionUpdated instead
|
|
@@ -1190,6 +1208,15 @@ var PipsendClient = class {
|
|
|
1190
1208
|
}
|
|
1191
1209
|
this.wsManager.on("error", callback);
|
|
1192
1210
|
},
|
|
1211
|
+
/**
|
|
1212
|
+
* Registers a custom event listener
|
|
1213
|
+
*/
|
|
1214
|
+
on: (event, callback) => {
|
|
1215
|
+
if (!this.wsManager) {
|
|
1216
|
+
throw new WebSocketError("WebSocket not enabled");
|
|
1217
|
+
}
|
|
1218
|
+
this.wsManager.on(event, callback);
|
|
1219
|
+
},
|
|
1193
1220
|
/**
|
|
1194
1221
|
* Removes event listener
|
|
1195
1222
|
*/
|