fyers-api-v3 1.4.1 → 1.4.2
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/HSM/datasocket.min.js +1 -1
- package/HSM/mapper.js +220 -220
- package/HSM_Package/hslib.js +4 -4
- package/README.md +171 -171
- package/apiService/apiService.js +1026 -1026
- package/config/config.js +30 -30
- package/errorHandler/errorHandler.js +36 -36
- package/index.js +11 -11
- package/logger/log.js +61 -61
- package/obfuscate.js +24 -24
- package/ordersocket/fyersSocket.js +325 -325
- package/ordersocket/mapper.js +78 -78
- package/package.json +25 -25
- package/sample/api.js +45 -45
- package/sample/datasocket.js +24 -24
- package/sample/ordersocket.js +29 -29
- package/sample/tbtsocket.js +25 -25
- package/tbtsocket/models.js +172 -172
- package/tbtsocket/msg.js +5163 -5163
- package/tbtsocket/tbtSocket.js +338 -338
package/tbtsocket/models.js
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
// Import protobufjs (make sure you've installed it: npm install protobufjs)
|
|
2
|
-
const protobuf = require('protobufjs');
|
|
3
|
-
|
|
4
|
-
const SubscriptionModes = Object.freeze({
|
|
5
|
-
DEPTH: 'depth',
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
class Depth {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.tbq = 0;
|
|
11
|
-
this.tsq = 0;
|
|
12
|
-
this.bidprice = new Array(50).fill(0.0);
|
|
13
|
-
this.askprice = new Array(50).fill(0.0);
|
|
14
|
-
this.bidqty = new Array(50).fill(0);
|
|
15
|
-
this.askqty = new Array(50).fill(0);
|
|
16
|
-
this.bidordn = new Array(50).fill(0);
|
|
17
|
-
this.askordn = new Array(50).fill(0);
|
|
18
|
-
this.snapshot = false;
|
|
19
|
-
this.timestamp = 0;
|
|
20
|
-
this.sendtime = 0;
|
|
21
|
-
this.seqNo = 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
toString() {
|
|
25
|
-
return `Depth{ts: ${this.timestamp}, send_ts: ${this.sendtime}, tbq: ${this.tbq}, tsq: ${this.tsq}, ` +
|
|
26
|
-
`bidprice: ${this.bidprice}, askprice: ${this.askprice}, ` +
|
|
27
|
-
`bidqty: ${this.bidqty}, askqty: ${this.askqty}, ` +
|
|
28
|
-
`bidordn: ${this.bidordn}, askordn: ${this.askordn}, ` +
|
|
29
|
-
`snapshot: ${this.snapshot}, sNo: ${this.seqNo} }`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Adds depth data from a protobuf message.
|
|
34
|
-
* @param {Object} currdata - The protobuf message.
|
|
35
|
-
* @param {boolean} isSnapshot - Whether this is a snapshot.
|
|
36
|
-
*/
|
|
37
|
-
_addDepth(currdata, isSnapshot) {
|
|
38
|
-
// Check if the 'depth' field exists.
|
|
39
|
-
if (currdata.depth != null) {
|
|
40
|
-
this.snapshot = isSnapshot;
|
|
41
|
-
|
|
42
|
-
// Using wrapper types, so the values are in the `value` property.
|
|
43
|
-
if (currdata.depth.tbq != null) {
|
|
44
|
-
this.tbq = currdata.depth.tbq.value / 1;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (currdata.depth.tsq != null) {
|
|
48
|
-
this.tsq = currdata.depth.tsq.value / 1;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Process asks if present.
|
|
52
|
-
if (Array.isArray(currdata.depth.asks)) {
|
|
53
|
-
currdata.depth.asks.forEach((ask, i) => {
|
|
54
|
-
if (ask.price != null) {
|
|
55
|
-
this.askprice[i] = ask.price.value / 100;
|
|
56
|
-
}
|
|
57
|
-
if (ask.qty != null) {
|
|
58
|
-
this.askqty[i] = ask.qty.value;
|
|
59
|
-
}
|
|
60
|
-
if (ask.nord != null) {
|
|
61
|
-
this.askordn[i] = ask.nord.value;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Process bids if present.
|
|
67
|
-
if (Array.isArray(currdata.depth.bids)) {
|
|
68
|
-
currdata.depth.bids.forEach((bid, i) => {
|
|
69
|
-
if (bid.price != null) {
|
|
70
|
-
this.bidprice[i] = bid.price.value / 100;
|
|
71
|
-
}
|
|
72
|
-
if (bid.qty != null) {
|
|
73
|
-
this.bidqty[i] = bid.qty.value;
|
|
74
|
-
}
|
|
75
|
-
if (bid.nord != null) {
|
|
76
|
-
this.bidordn[i] = bid.nord.value;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Process other fields (assuming wrapper types)
|
|
82
|
-
if (currdata.feedTime != null ) {
|
|
83
|
-
this.timestamp = currdata.feedTime.value / 1;
|
|
84
|
-
}
|
|
85
|
-
if (currdata.sendTime != null ) {
|
|
86
|
-
this.sendtime = currdata.sendTime.value / 1;
|
|
87
|
-
}
|
|
88
|
-
this.seqNo = currdata.sequenceNo / 1;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
class SubscriptionInfo {
|
|
94
|
-
constructor() {
|
|
95
|
-
this._symbols = {}; // Stores channel-wise symbol sets
|
|
96
|
-
this._modeInfo = {}; // Stores channel-wise subscription modes
|
|
97
|
-
this._activeChannels = new Set(); // Stores active channels
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
subscribe(symbols, channelNo, mode) {
|
|
101
|
-
if (this._symbols[channelNo]) {
|
|
102
|
-
this._symbols[channelNo] = new Set([...this._symbols[channelNo], ...symbols]);
|
|
103
|
-
} else {
|
|
104
|
-
this._symbols[channelNo] = new Set(symbols);
|
|
105
|
-
}
|
|
106
|
-
this._modeInfo[channelNo] = mode;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
unsubscribe(symbols, channelNo) {
|
|
110
|
-
if (this._symbols[channelNo]) {
|
|
111
|
-
symbols.forEach(symbol => this._symbols[channelNo].delete(symbol));
|
|
112
|
-
if (this._symbols[channelNo].size === 0) {
|
|
113
|
-
delete this._symbols[channelNo];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
updateChannels(pauseChannels, resumeChannels) {
|
|
119
|
-
pauseChannels.forEach(channel => this._activeChannels.delete(channel));
|
|
120
|
-
resumeChannels.forEach(channel => this._activeChannels.add(channel));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
updateMode(modeConfig) {
|
|
124
|
-
Object.entries(modeConfig).forEach(([channelNo, mode]) => {
|
|
125
|
-
this._modeInfo[channelNo] = mode;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
getSymbolsInfo(channelNo) {
|
|
130
|
-
return this._symbols[channelNo] || new Set();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getModeInfo(channelNo) {
|
|
134
|
-
return this._modeInfo[channelNo] || null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
getChannelInfo() {
|
|
138
|
-
return this._activeChannels;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
class DataStore {
|
|
143
|
-
constructor() {
|
|
144
|
-
this.depth = {}; // Stores depth data by symbol
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
updateDepth(packet, cb, diffOnly) {
|
|
148
|
-
if (packet.feeds) {
|
|
149
|
-
Object.entries(packet.feeds).forEach(([_, value]) => {
|
|
150
|
-
const symbol = value.ticker;
|
|
151
|
-
|
|
152
|
-
if (!this.depth[symbol]) {
|
|
153
|
-
this.depth[symbol] = new Depth();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (!diffOnly) {
|
|
157
|
-
this.depth[symbol]._addDepth(value, packet.snapshot);
|
|
158
|
-
if (cb) cb(symbol, this.depth[symbol]);
|
|
159
|
-
} else {
|
|
160
|
-
const depth = new Depth();
|
|
161
|
-
depth._addDepth(value, packet.snapshot);
|
|
162
|
-
if (cb) cb(symbol, depth);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
module.exports.DataStore = DataStore;
|
|
170
|
-
module.exports.SubscriptionInfo = SubscriptionInfo;
|
|
171
|
-
module.exports.Depth = Depth;
|
|
172
|
-
module.exports.SubscriptionModes = SubscriptionModes;
|
|
1
|
+
// Import protobufjs (make sure you've installed it: npm install protobufjs)
|
|
2
|
+
const protobuf = require('protobufjs');
|
|
3
|
+
|
|
4
|
+
const SubscriptionModes = Object.freeze({
|
|
5
|
+
DEPTH: 'depth',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class Depth {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.tbq = 0;
|
|
11
|
+
this.tsq = 0;
|
|
12
|
+
this.bidprice = new Array(50).fill(0.0);
|
|
13
|
+
this.askprice = new Array(50).fill(0.0);
|
|
14
|
+
this.bidqty = new Array(50).fill(0);
|
|
15
|
+
this.askqty = new Array(50).fill(0);
|
|
16
|
+
this.bidordn = new Array(50).fill(0);
|
|
17
|
+
this.askordn = new Array(50).fill(0);
|
|
18
|
+
this.snapshot = false;
|
|
19
|
+
this.timestamp = 0;
|
|
20
|
+
this.sendtime = 0;
|
|
21
|
+
this.seqNo = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toString() {
|
|
25
|
+
return `Depth{ts: ${this.timestamp}, send_ts: ${this.sendtime}, tbq: ${this.tbq}, tsq: ${this.tsq}, ` +
|
|
26
|
+
`bidprice: ${this.bidprice}, askprice: ${this.askprice}, ` +
|
|
27
|
+
`bidqty: ${this.bidqty}, askqty: ${this.askqty}, ` +
|
|
28
|
+
`bidordn: ${this.bidordn}, askordn: ${this.askordn}, ` +
|
|
29
|
+
`snapshot: ${this.snapshot}, sNo: ${this.seqNo} }`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Adds depth data from a protobuf message.
|
|
34
|
+
* @param {Object} currdata - The protobuf message.
|
|
35
|
+
* @param {boolean} isSnapshot - Whether this is a snapshot.
|
|
36
|
+
*/
|
|
37
|
+
_addDepth(currdata, isSnapshot) {
|
|
38
|
+
// Check if the 'depth' field exists.
|
|
39
|
+
if (currdata.depth != null) {
|
|
40
|
+
this.snapshot = isSnapshot;
|
|
41
|
+
|
|
42
|
+
// Using wrapper types, so the values are in the `value` property.
|
|
43
|
+
if (currdata.depth.tbq != null) {
|
|
44
|
+
this.tbq = currdata.depth.tbq.value / 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (currdata.depth.tsq != null) {
|
|
48
|
+
this.tsq = currdata.depth.tsq.value / 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Process asks if present.
|
|
52
|
+
if (Array.isArray(currdata.depth.asks)) {
|
|
53
|
+
currdata.depth.asks.forEach((ask, i) => {
|
|
54
|
+
if (ask.price != null) {
|
|
55
|
+
this.askprice[i] = ask.price.value / 100;
|
|
56
|
+
}
|
|
57
|
+
if (ask.qty != null) {
|
|
58
|
+
this.askqty[i] = ask.qty.value;
|
|
59
|
+
}
|
|
60
|
+
if (ask.nord != null) {
|
|
61
|
+
this.askordn[i] = ask.nord.value;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Process bids if present.
|
|
67
|
+
if (Array.isArray(currdata.depth.bids)) {
|
|
68
|
+
currdata.depth.bids.forEach((bid, i) => {
|
|
69
|
+
if (bid.price != null) {
|
|
70
|
+
this.bidprice[i] = bid.price.value / 100;
|
|
71
|
+
}
|
|
72
|
+
if (bid.qty != null) {
|
|
73
|
+
this.bidqty[i] = bid.qty.value;
|
|
74
|
+
}
|
|
75
|
+
if (bid.nord != null) {
|
|
76
|
+
this.bidordn[i] = bid.nord.value;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Process other fields (assuming wrapper types)
|
|
82
|
+
if (currdata.feedTime != null ) {
|
|
83
|
+
this.timestamp = currdata.feedTime.value / 1;
|
|
84
|
+
}
|
|
85
|
+
if (currdata.sendTime != null ) {
|
|
86
|
+
this.sendtime = currdata.sendTime.value / 1;
|
|
87
|
+
}
|
|
88
|
+
this.seqNo = currdata.sequenceNo / 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
class SubscriptionInfo {
|
|
94
|
+
constructor() {
|
|
95
|
+
this._symbols = {}; // Stores channel-wise symbol sets
|
|
96
|
+
this._modeInfo = {}; // Stores channel-wise subscription modes
|
|
97
|
+
this._activeChannels = new Set(); // Stores active channels
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
subscribe(symbols, channelNo, mode) {
|
|
101
|
+
if (this._symbols[channelNo]) {
|
|
102
|
+
this._symbols[channelNo] = new Set([...this._symbols[channelNo], ...symbols]);
|
|
103
|
+
} else {
|
|
104
|
+
this._symbols[channelNo] = new Set(symbols);
|
|
105
|
+
}
|
|
106
|
+
this._modeInfo[channelNo] = mode;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
unsubscribe(symbols, channelNo) {
|
|
110
|
+
if (this._symbols[channelNo]) {
|
|
111
|
+
symbols.forEach(symbol => this._symbols[channelNo].delete(symbol));
|
|
112
|
+
if (this._symbols[channelNo].size === 0) {
|
|
113
|
+
delete this._symbols[channelNo];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
updateChannels(pauseChannels, resumeChannels) {
|
|
119
|
+
pauseChannels.forEach(channel => this._activeChannels.delete(channel));
|
|
120
|
+
resumeChannels.forEach(channel => this._activeChannels.add(channel));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
updateMode(modeConfig) {
|
|
124
|
+
Object.entries(modeConfig).forEach(([channelNo, mode]) => {
|
|
125
|
+
this._modeInfo[channelNo] = mode;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getSymbolsInfo(channelNo) {
|
|
130
|
+
return this._symbols[channelNo] || new Set();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getModeInfo(channelNo) {
|
|
134
|
+
return this._modeInfo[channelNo] || null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getChannelInfo() {
|
|
138
|
+
return this._activeChannels;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
class DataStore {
|
|
143
|
+
constructor() {
|
|
144
|
+
this.depth = {}; // Stores depth data by symbol
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
updateDepth(packet, cb, diffOnly) {
|
|
148
|
+
if (packet.feeds) {
|
|
149
|
+
Object.entries(packet.feeds).forEach(([_, value]) => {
|
|
150
|
+
const symbol = value.ticker;
|
|
151
|
+
|
|
152
|
+
if (!this.depth[symbol]) {
|
|
153
|
+
this.depth[symbol] = new Depth();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!diffOnly) {
|
|
157
|
+
this.depth[symbol]._addDepth(value, packet.snapshot);
|
|
158
|
+
if (cb) cb(symbol, this.depth[symbol]);
|
|
159
|
+
} else {
|
|
160
|
+
const depth = new Depth();
|
|
161
|
+
depth._addDepth(value, packet.snapshot);
|
|
162
|
+
if (cb) cb(symbol, depth);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports.DataStore = DataStore;
|
|
170
|
+
module.exports.SubscriptionInfo = SubscriptionInfo;
|
|
171
|
+
module.exports.Depth = Depth;
|
|
172
|
+
module.exports.SubscriptionModes = SubscriptionModes;
|