xts-interactive-api-ip 0.0.0-stage → 3.0.3
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/LICENSE +22 -0
- package/README.md +303 -2
- package/examples/config/config.json +6 -0
- package/examples/interactiveTestClient.js +377 -0
- package/lib/config/app/config.json +4 -0
- package/lib/config/app/settings.json +28 -0
- package/lib/customError.js +27 -0
- package/lib/index.js +5 -0
- package/lib/interactiveRestAPI.js +1006 -0
- package/lib/interactiveSocket.js +355 -0
- package/lib/logger.js +125 -0
- package/lib/request.js +80 -0
- package/package.json +41 -4
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
var socketIoClient = require('socket.io-client');
|
|
2
|
+
var settings = require('./config/app/settings.json');
|
|
3
|
+
var events = require('events');
|
|
4
|
+
var logger = require('./logger');
|
|
5
|
+
var config = require('./config/app/config.json');
|
|
6
|
+
var https = require('https');
|
|
7
|
+
var http = require('http');
|
|
8
|
+
|
|
9
|
+
module.exports = class XTSEmitter {
|
|
10
|
+
/**
|
|
11
|
+
* Constructs an XTSEmitter instance to enable data transfer via socket related events.
|
|
12
|
+
*
|
|
13
|
+
* @constructor
|
|
14
|
+
*
|
|
15
|
+
* @param {String} url
|
|
16
|
+
* url parameter is used to connect to the particular server.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
constructor(url, localIP) {
|
|
20
|
+
this.url = url === undefined ? config.url : url;
|
|
21
|
+
this.socketMD = {
|
|
22
|
+
isConnected: false,
|
|
23
|
+
socketMarketData: null,
|
|
24
|
+
interval: null,
|
|
25
|
+
};
|
|
26
|
+
this.localIP = localIP;
|
|
27
|
+
this.eventEmitter = new events.EventEmitter();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* set the token value by providing the token in the input
|
|
32
|
+
*
|
|
33
|
+
* @param {string} token
|
|
34
|
+
* token parameter will be generated after successful login and will be used in other private API's
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
set token(token) {
|
|
38
|
+
this._token = token;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns the token generated after successful logIn
|
|
43
|
+
*
|
|
44
|
+
*
|
|
45
|
+
* @return
|
|
46
|
+
* the value of token generated after successful logIn
|
|
47
|
+
*/
|
|
48
|
+
get token() {
|
|
49
|
+
return this._token;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* set the userID value by providing the userID in the input
|
|
54
|
+
*
|
|
55
|
+
* @param {string} userID
|
|
56
|
+
* userID for the particular user
|
|
57
|
+
*/
|
|
58
|
+
set userID(userID) {
|
|
59
|
+
this._userID = userID;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns userID for the particular user
|
|
64
|
+
*
|
|
65
|
+
*
|
|
66
|
+
* @return
|
|
67
|
+
* the userID for the particular user
|
|
68
|
+
*/
|
|
69
|
+
get userID() {
|
|
70
|
+
return this._userID;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* set the url value by providing the url in the input
|
|
75
|
+
*
|
|
76
|
+
* @param {string} url
|
|
77
|
+
* url parameter is used to connect to the particular server.
|
|
78
|
+
*/
|
|
79
|
+
set url(url) {
|
|
80
|
+
this._url = url;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns url used to connect to the particular server.
|
|
85
|
+
*
|
|
86
|
+
*
|
|
87
|
+
* @return
|
|
88
|
+
* the url used to connect to the particular server.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
get url() {
|
|
92
|
+
return this._url;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* set the localIP value by providing the localIP in the input
|
|
96
|
+
*
|
|
97
|
+
* @param {string} localIP
|
|
98
|
+
* localIP parameter is used to bind the socket connection to a specific local IP address.
|
|
99
|
+
*/
|
|
100
|
+
set localIP(localIP) {
|
|
101
|
+
this._localIP = localIP;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns localIP used to bind the socket connection.
|
|
105
|
+
*
|
|
106
|
+
*
|
|
107
|
+
* @return
|
|
108
|
+
* the localIP used to bind the socket connection to a specific local IP address.
|
|
109
|
+
*/
|
|
110
|
+
get localIP() {
|
|
111
|
+
return this._localIP;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Initalizes the socket by accepting userID and token as input parameters
|
|
115
|
+
*
|
|
116
|
+
* @param {Object} reqObject request object.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} reqObject.userID
|
|
119
|
+
* userID for the particular user.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} reqObject.token
|
|
122
|
+
* token parameter will be generated after successful login and will be used in other private API's
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
init(reqObject) {
|
|
126
|
+
this.userID = reqObject.userID;
|
|
127
|
+
this.token = reqObject.token;
|
|
128
|
+
|
|
129
|
+
if (this.socketMD.socketMarketData) {
|
|
130
|
+
this.socketMD.socketMarketData.destroy();
|
|
131
|
+
delete this.socketMD.socketMarketData;
|
|
132
|
+
this.socketMD.socketMarketData = null;
|
|
133
|
+
}
|
|
134
|
+
// path: "/interactive/socket.io",
|
|
135
|
+
|
|
136
|
+
let socketOptions = {
|
|
137
|
+
path: '/interactive/socket.io',
|
|
138
|
+
reconnection: false,
|
|
139
|
+
query: { token: this.token, userID: this.userID, apiType: 'INTERACTIVE' }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (this.localIP) {
|
|
143
|
+
const agentOptions = { localAddress: this.localIP };
|
|
144
|
+
socketOptions.agent = this.url.startsWith('https')
|
|
145
|
+
? new https.Agent(agentOptions)
|
|
146
|
+
: new http.Agent(agentOptions);
|
|
147
|
+
|
|
148
|
+
// For socket.io-client v2.x, also set transportOptions
|
|
149
|
+
socketOptions.transportOptions = {
|
|
150
|
+
polling: {
|
|
151
|
+
extraHeaders: {}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
logger.logFile('Socket connection will use local IP: ' + this.localIP);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.socketMD.socketMarketData = socketIoClient(this.url, socketOptions);
|
|
159
|
+
logger.logFile(
|
|
160
|
+
'socket is initialized with the following parameters url ' +
|
|
161
|
+
this.url +
|
|
162
|
+
' token ' +
|
|
163
|
+
this.token +
|
|
164
|
+
' userID ' +
|
|
165
|
+
this.userID
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Listener of the connect event via socket and emit the connect event via event Emitter
|
|
170
|
+
*
|
|
171
|
+
*
|
|
172
|
+
* @event connect
|
|
173
|
+
*/
|
|
174
|
+
this.socketMD.socketMarketData.on(settings.socket.connect, (data) => {
|
|
175
|
+
this.socketMD.isConnected = true;
|
|
176
|
+
console.info('socket connected successfully');
|
|
177
|
+
this.eventEmitter.emit(settings.socket.connect, data);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Listener of the joined event via socket and emit the joined event via event Emitter
|
|
182
|
+
*
|
|
183
|
+
*
|
|
184
|
+
* @event joined
|
|
185
|
+
*/
|
|
186
|
+
this.socketMD.socketMarketData.on(settings.socket.joined, (data) => {
|
|
187
|
+
console.info('socket joined successfully');
|
|
188
|
+
this.eventEmitter.emit(settings.socket.joined, data);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Listener of the error event via socket and emit the error event via event Emitter
|
|
193
|
+
*
|
|
194
|
+
*
|
|
195
|
+
* @event error
|
|
196
|
+
*/
|
|
197
|
+
this.socketMD.socketMarketData.on(settings.socket.error, (data) => {
|
|
198
|
+
console.info('socket error occurred');
|
|
199
|
+
this.eventEmitter.emit(settings.socket.error, data);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Listener of the disconnect event via socket and emit the disconnect event via event Emitter
|
|
204
|
+
*
|
|
205
|
+
*
|
|
206
|
+
* @event disconnect
|
|
207
|
+
*/
|
|
208
|
+
this.socketMD.socketMarketData.on(settings.socket.disconnect, (data) => {
|
|
209
|
+
console.info('socket got disconnected');
|
|
210
|
+
|
|
211
|
+
this.socketMD.isConnected = false;
|
|
212
|
+
this.socketMD.interval = setInterval(() => {
|
|
213
|
+
if (this.socketMD.isConnected) {
|
|
214
|
+
clearInterval(this.socketMD.interval);
|
|
215
|
+
this.socketMD.interval = null;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
let reqObject = {
|
|
219
|
+
userID: this.userID,
|
|
220
|
+
token: this.token,
|
|
221
|
+
};
|
|
222
|
+
this.init(reqObject);
|
|
223
|
+
}, 5000);
|
|
224
|
+
|
|
225
|
+
this.eventEmitter.emit(settings.socket.disconnect, data);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Listener of the order event via socket and emit the order event via event Emitter
|
|
230
|
+
*
|
|
231
|
+
*
|
|
232
|
+
* @event order
|
|
233
|
+
*/
|
|
234
|
+
this.socketMD.socketMarketData.on(settings.socket.order, (data) => {
|
|
235
|
+
console.info('inside order response channel');
|
|
236
|
+
this.eventEmitter.emit(settings.socket.order, data);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Listener of the trade event via socket and emit the trade event via event Emitter
|
|
241
|
+
*
|
|
242
|
+
*
|
|
243
|
+
* @event trade
|
|
244
|
+
*/
|
|
245
|
+
this.socketMD.socketMarketData.on(settings.socket.trade, (data) => {
|
|
246
|
+
console.info('inside trade response channel');
|
|
247
|
+
this.eventEmitter.emit(settings.socket.trade, data);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Listener of the position event via socket and emit the position event via event Emitter
|
|
252
|
+
*
|
|
253
|
+
*
|
|
254
|
+
* @event position
|
|
255
|
+
*/
|
|
256
|
+
this.socketMD.socketMarketData.on(settings.socket.position, (data) => {
|
|
257
|
+
console.info('inside positions response channel');
|
|
258
|
+
this.eventEmitter.emit(settings.socket.position, data);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Listener of the logout event via socket and emit the logout event via event Emitter
|
|
263
|
+
*
|
|
264
|
+
*
|
|
265
|
+
* @event logout
|
|
266
|
+
*/
|
|
267
|
+
this.socketMD.socketMarketData.on(settings.socket.logout, (data) => {
|
|
268
|
+
console.info('socket logout successfully');
|
|
269
|
+
this.eventEmitter.emit(settings.socket.logout, data);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* connect listener for event emitter
|
|
275
|
+
*
|
|
276
|
+
*/
|
|
277
|
+
onConnect(fn) {
|
|
278
|
+
this.eventEmitter.on(settings.socket.connect, (data) => {
|
|
279
|
+
fn(data);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* joined listener for event emitter
|
|
285
|
+
*
|
|
286
|
+
*/
|
|
287
|
+
onJoined(fn) {
|
|
288
|
+
this.eventEmitter.on(settings.socket.joined, (data) => {
|
|
289
|
+
fn(data);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* error listener for event emitter
|
|
295
|
+
*
|
|
296
|
+
*/
|
|
297
|
+
onError(fn) {
|
|
298
|
+
this.eventEmitter.on(settings.socket.error, (data) => {
|
|
299
|
+
fn(data);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* disconnect listener for event emitter
|
|
305
|
+
*
|
|
306
|
+
*/
|
|
307
|
+
onDisconnect(fn) {
|
|
308
|
+
this.eventEmitter.on(settings.socket.disconnect, (data) => {
|
|
309
|
+
fn(data);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* order listener for event emitter
|
|
315
|
+
*
|
|
316
|
+
*/
|
|
317
|
+
onOrder(fn) {
|
|
318
|
+
this.eventEmitter.on(settings.socket.order, (data) => {
|
|
319
|
+
let orderObject = JSON.parse(data);
|
|
320
|
+
fn(orderObject);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* trade listener for event emitter
|
|
326
|
+
*
|
|
327
|
+
*/
|
|
328
|
+
onTrade(fn) {
|
|
329
|
+
this.eventEmitter.on(settings.socket.trade, (data) => {
|
|
330
|
+
let tradeObject = JSON.parse(data);
|
|
331
|
+
fn(tradeObject);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* position listener for event emitter
|
|
337
|
+
*
|
|
338
|
+
*/
|
|
339
|
+
onPosition(fn) {
|
|
340
|
+
this.eventEmitter.on(settings.socket.position, (data) => {
|
|
341
|
+
let positionObject = JSON.parse(data);
|
|
342
|
+
fn(positionObject);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* logout listener for event emitter
|
|
348
|
+
*
|
|
349
|
+
*/
|
|
350
|
+
onLogout(fn) {
|
|
351
|
+
this.eventEmitter.on(settings.socket.logout, (data) => {
|
|
352
|
+
fn(data);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
};
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var settings = require('./config/app/settings.json');
|
|
3
|
+
var config = require('./config/app/config.json');
|
|
4
|
+
|
|
5
|
+
Date.prototype.getMonthFormatted = function () {
|
|
6
|
+
var month = this.getMonth() + 1;
|
|
7
|
+
return month < 10 ? '0' + month : '' + month;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
Date.prototype.getMonthFormattedString = function () {
|
|
11
|
+
switch (this.getMonth()) {
|
|
12
|
+
case 0:
|
|
13
|
+
return 'Jan';
|
|
14
|
+
case 1:
|
|
15
|
+
return 'Feb';
|
|
16
|
+
case 2:
|
|
17
|
+
return 'Mar';
|
|
18
|
+
case 3:
|
|
19
|
+
return 'Apr';
|
|
20
|
+
case 4:
|
|
21
|
+
return 'May';
|
|
22
|
+
case 5:
|
|
23
|
+
return 'Jun';
|
|
24
|
+
case 6:
|
|
25
|
+
return 'Jul';
|
|
26
|
+
case 7:
|
|
27
|
+
return 'Aug';
|
|
28
|
+
case 8:
|
|
29
|
+
return 'Sep';
|
|
30
|
+
case 9:
|
|
31
|
+
return 'Oct';
|
|
32
|
+
case 10:
|
|
33
|
+
return 'Nov';
|
|
34
|
+
case 11:
|
|
35
|
+
return 'Dec';
|
|
36
|
+
}
|
|
37
|
+
return month < 10 ? '0' + month : '' + month;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Date.prototype.getDayFormatted = function () {
|
|
41
|
+
var day = this.getDate();
|
|
42
|
+
return day < 10 ? '0' + day : '' + day;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Date.prototype.getHourFormatted = function () {
|
|
46
|
+
var hour = this.getHours();
|
|
47
|
+
return hour < 10 ? '0' + hour : '' + hour;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
Date.prototype.getMinuteFormatted = function () {
|
|
51
|
+
var minute = this.getMinutes();
|
|
52
|
+
return minute < 10 ? '0' + minute : '' + minute;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Date.prototype.getSecondFormatted = function () {
|
|
56
|
+
var second = this.getSeconds();
|
|
57
|
+
return second < 10 ? '0' + second : '' + second;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Date.prototype.getFormatedDateTime = function () {
|
|
61
|
+
return (
|
|
62
|
+
this.getDayFormatted() +
|
|
63
|
+
'/' +
|
|
64
|
+
this.getMonthFormatted() +
|
|
65
|
+
'/' +
|
|
66
|
+
this.getFullYear() +
|
|
67
|
+
' ' +
|
|
68
|
+
this.getHourFormatted() +
|
|
69
|
+
':' +
|
|
70
|
+
this.getMinuteFormatted() +
|
|
71
|
+
':' +
|
|
72
|
+
this.getSecondFormatted()
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
Date.prototype.getDateTimeFormatted = function () {
|
|
77
|
+
return `${this.getMonthFormattedString()} ${this.getDayFormatted()} ${this.getFullYear()} ${this.getHourFormatted()}:${this.getMinuteFormatted()}:${this.getSecondFormatted()}`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var dir = process.cwd() + '/logs';
|
|
81
|
+
var d = new Date();
|
|
82
|
+
var todaysDate =
|
|
83
|
+
d.getDayFormatted() + '' + d.getMonthFormatted() + '' + d.getFullYear();
|
|
84
|
+
var logFileName = dir + '/debug_' + todaysDate + '.txt';
|
|
85
|
+
var initMessage =
|
|
86
|
+
'============================================\nInitialized logger\n==================================================\n';
|
|
87
|
+
//var dir = '../logs';
|
|
88
|
+
|
|
89
|
+
module.exports.init = function () {
|
|
90
|
+
if (config.logEnabled) {
|
|
91
|
+
console.info('logger module initialized successfully!');
|
|
92
|
+
// For uncaughtException Log
|
|
93
|
+
if (!fs.existsSync(dir)) {
|
|
94
|
+
fs.mkdirSync(dir);
|
|
95
|
+
}
|
|
96
|
+
if (!fs.existsSync(logFileName)) {
|
|
97
|
+
fs.appendFile(logFileName, initMessage, function (err) {
|
|
98
|
+
if (err) {
|
|
99
|
+
// return module.exports.writeLine(enums.consoleColor.yellow + "%s" + enums.consoleColor.reset, err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
let message =
|
|
104
|
+
'============================================\n RUN the application on' +
|
|
105
|
+
new Date() +
|
|
106
|
+
'\n==================================================\n';
|
|
107
|
+
fs.appendFile(logFileName, message, function (err) {
|
|
108
|
+
if (err) {
|
|
109
|
+
//return module.exports.writeLine(enums.consoleColor.yellow + "%s" + enums.consoleColor.reset, err);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
module.exports.logFile = function (logMessage) {
|
|
117
|
+
if (config.logEnabled) {
|
|
118
|
+
logMessage = logMessage + ' \n';
|
|
119
|
+
fs.appendFile(logFileName, JSON.stringify(logMessage), function (err) {
|
|
120
|
+
if (err) {
|
|
121
|
+
// return module.exports.writeLine(enums.consoleColor.yellow + "%s" + enums.consoleColor.reset, err);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
package/lib/request.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var axios = require("axios");
|
|
2
|
+
var https = require("https");
|
|
3
|
+
var http = require("http");
|
|
4
|
+
var logger = require('./logger');
|
|
5
|
+
|
|
6
|
+
module.exports.processRequest = async function(method, url, headers, data, localIP) {
|
|
7
|
+
try {
|
|
8
|
+
var options = {
|
|
9
|
+
method: method,
|
|
10
|
+
url: url,
|
|
11
|
+
headers: {
|
|
12
|
+
"authorization": headers.authorization
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Add data for POST/PUT requests
|
|
17
|
+
if (method === "POST" || method === "PUT") {
|
|
18
|
+
options.data = data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Create HTTP/HTTPS agent with local IP binding if provided
|
|
22
|
+
if (localIP) {
|
|
23
|
+
const agentOptions = { localAddress: localIP };
|
|
24
|
+
options.httpAgent = new http.Agent(agentOptions);
|
|
25
|
+
options.httpsAgent = new https.Agent(agentOptions);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
logger.logFile("request object sent to the server");
|
|
29
|
+
logger.logFile(JSON.stringify({
|
|
30
|
+
method: options.method,
|
|
31
|
+
url: options.url,
|
|
32
|
+
headers: options.headers,
|
|
33
|
+
data: options.data,
|
|
34
|
+
localIP: localIP || 'default'
|
|
35
|
+
}));
|
|
36
|
+
console.log("Request sending:", JSON.stringify({
|
|
37
|
+
method: options.method,
|
|
38
|
+
url: options.url,
|
|
39
|
+
headers: options.headers,
|
|
40
|
+
data: options.data,
|
|
41
|
+
localIP: localIP || 'default'
|
|
42
|
+
}));
|
|
43
|
+
let response = await axios(options);
|
|
44
|
+
|
|
45
|
+
logger.logFile("request object received from the server");
|
|
46
|
+
logger.logFile(JSON.stringify(response.data));
|
|
47
|
+
|
|
48
|
+
return response.data;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const responseData = error.response?.data;
|
|
51
|
+
console.log("Error received:", JSON.stringify({
|
|
52
|
+
status: error.response?.status,
|
|
53
|
+
statusText: error.response?.statusText,
|
|
54
|
+
data: responseData || error.message
|
|
55
|
+
}));
|
|
56
|
+
logger.logFile("exception object received from the server");
|
|
57
|
+
logger.logFile(JSON.stringify({
|
|
58
|
+
status: error.response?.status,
|
|
59
|
+
statusText: error.response?.statusText,
|
|
60
|
+
data: responseData || error.message
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
if (error.response) {
|
|
64
|
+
const err = new Error(
|
|
65
|
+
responseData?.message ||
|
|
66
|
+
responseData?.description ||
|
|
67
|
+
responseData?.error ||
|
|
68
|
+
JSON.stringify(responseData) ||
|
|
69
|
+
error.message
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
err.statusCode = error.response.status;
|
|
73
|
+
err.responseData = responseData;
|
|
74
|
+
err.stack = error.stack;
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xts-interactive-api-ip",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.3",
|
|
4
|
+
"description": "Unofficial Node.js client for the Symphony Fintech XTS Interactive API with local IP binding (fork of xts-interactive-api)",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/",
|
|
8
|
+
"examples/"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"xts",
|
|
12
|
+
"xts-interactive-api",
|
|
13
|
+
"SymphonyFintech",
|
|
14
|
+
"Symphony",
|
|
15
|
+
"Fintech",
|
|
16
|
+
"trading",
|
|
17
|
+
"stockmarket",
|
|
18
|
+
"stock",
|
|
19
|
+
"Interactive",
|
|
20
|
+
"local-ip",
|
|
21
|
+
"ClientApp"
|
|
22
|
+
],
|
|
23
|
+
"author": "multyfi",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=14"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"axios": "^1.6.0",
|
|
30
|
+
"socket.io-client": "~2.2.0"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/multyfi/xts-interactive-api-ip.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/multyfi/xts-interactive-api-ip/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/multyfi/xts-interactive-api-ip#readme",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
42
|
+
}
|
|
43
|
+
}
|