-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
73 lines (58 loc) · 1.41 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const Net = require('net');
const Fix = require('./fix.js');
const tls = require('tls');
const tx2 = require('tx2');
function Config() {
this.configType = 'ClientConfig'
}
Config.prototype.setParams=function(host, port, apiKey, privateKey, sslEnabled){
this.host = host
this.port = port
this.apiKey = apiKey
this.privateKey = privateKey
this.sslEnabled = sslEnabled
if (sslEnabled)
this.tlsOption='TLSv1_2_method'
else
this.tlsOption='none'
this.connectionOptions = {
secureProtocol: this.tlsOption
}
};
Config.prototype.getHost=function(){
return this.host;
};
Config.prototype.getPort=function(){
return this.port;
};
Config.prototype.getApiKey=function(){
return this.apiKey;
};
Config.prototype.getPrivateKey=function(){
return this.privateKey;
};
Config.prototype.getSslEnabled=function(){
return this.sslEnabled;
};
Config.prototype.getTlsOption=function(){
return this.tlsOption;
}
Config.prototype.connect=function(msg, logger){
if (this.sslEnabled){
var connection = tls.connect(this.port, this.host,
this.connectionOptions, function() {
connection.write(msg);
logger.write("Outbound",Fix.read(msg))
});
return connection;
} else {
var connection = new Net.Socket();
connection.connect(this.port, this.host,
function() {
connection.write(msg);
logger.write("Outbound",Fix.read(msg))
});
return connection;
}
}
module.exports=Config