jspurefix 5.11.2 → 5.11.4

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.
Files changed (104) hide show
  1. package/.gitattributes +4 -0
  2. package/dist/buffer/index.d.ts +6 -0
  3. package/dist/buffer/index.js +6 -0
  4. package/dist/buffer/index.js.map +1 -1
  5. package/dist/collections/index.d.ts +1 -0
  6. package/dist/collections/index.js +16 -0
  7. package/dist/collections/index.js.map +1 -1
  8. package/dist/config/winston-logger.js +2 -0
  9. package/dist/config/winston-logger.js.map +1 -1
  10. package/dist/dictionary/contained/index.d.ts +3 -0
  11. package/dist/dictionary/contained/index.js +3 -0
  12. package/dist/dictionary/contained/index.js.map +1 -1
  13. package/dist/dictionary/index.d.ts +5 -0
  14. package/dist/dictionary/index.js +5 -0
  15. package/dist/dictionary/index.js.map +1 -1
  16. package/dist/generator/applicability.d.ts +3 -0
  17. package/dist/generator/applicability.js +48 -0
  18. package/dist/generator/applicability.js.map +1 -0
  19. package/dist/generator/case-builder.d.ts +34 -0
  20. package/dist/generator/case-builder.js +111 -0
  21. package/dist/generator/case-builder.js.map +1 -0
  22. package/dist/generator/corpus-store.d.ts +43 -0
  23. package/dist/generator/corpus-store.js +115 -0
  24. package/dist/generator/corpus-store.js.map +1 -0
  25. package/dist/generator/index.d.ts +12 -0
  26. package/dist/generator/index.js +29 -0
  27. package/dist/generator/index.js.map +1 -0
  28. package/dist/generator/instrument-universe.d.ts +54 -0
  29. package/dist/generator/instrument-universe.js +286 -0
  30. package/dist/generator/instrument-universe.js.map +1 -0
  31. package/dist/generator/layout.d.ts +46 -0
  32. package/dist/generator/layout.js +208 -0
  33. package/dist/generator/layout.js.map +1 -0
  34. package/dist/generator/market-context.d.ts +64 -0
  35. package/dist/generator/market-context.js +119 -0
  36. package/dist/generator/market-context.js.map +1 -0
  37. package/dist/generator/outcome.d.ts +16 -0
  38. package/dist/generator/outcome.js +71 -0
  39. package/dist/generator/outcome.js.map +1 -0
  40. package/dist/generator/realistic-generator.d.ts +53 -0
  41. package/dist/generator/realistic-generator.js +275 -0
  42. package/dist/generator/realistic-generator.js.map +1 -0
  43. package/dist/generator/rng.d.ts +12 -0
  44. package/dist/generator/rng.js +60 -0
  45. package/dist/generator/rng.js.map +1 -0
  46. package/dist/generator/scatter.d.ts +50 -0
  47. package/dist/generator/scatter.js +285 -0
  48. package/dist/generator/scatter.js.map +1 -0
  49. package/dist/generator/scenarios.d.ts +13 -0
  50. package/dist/generator/scenarios.js +139 -0
  51. package/dist/generator/scenarios.js.map +1 -0
  52. package/dist/generator/value-conventions.d.ts +15 -0
  53. package/dist/generator/value-conventions.js +217 -0
  54. package/dist/generator/value-conventions.js.map +1 -0
  55. package/dist/index.d.ts +6 -0
  56. package/dist/index.js +4 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/jsfix-cmd.d.ts +5 -0
  59. package/dist/jsfix-cmd.js +161 -0
  60. package/dist/jsfix-cmd.js.map +1 -1
  61. package/dist/store/fix-msg-ascii-store-resend.js +2 -2
  62. package/dist/store/fix-msg-ascii-store-resend.js.map +1 -1
  63. package/dist/store/fix-msg-store-record.d.ts +1 -1
  64. package/dist/store/fix-msg-store-record.js.map +1 -1
  65. package/dist/store/index.d.ts +1 -0
  66. package/dist/store/index.js +1 -0
  67. package/dist/store/index.js.map +1 -1
  68. package/dist/transport/index.d.ts +7 -0
  69. package/dist/transport/index.js +7 -0
  70. package/dist/transport/index.js.map +1 -1
  71. package/dist/transport/session/index.d.ts +1 -0
  72. package/dist/transport/session/index.js +1 -0
  73. package/dist/transport/session/index.js.map +1 -1
  74. package/docs/generated-cases.md +237 -0
  75. package/docs/instrumentation.md +14 -0
  76. package/docs/scattered-components.md +60 -5
  77. package/jsfix.test_client.txt +62 -62
  78. package/jsfix.test_server.txt +72 -72
  79. package/package.json +5 -2
  80. package/src/buffer/index.ts +6 -0
  81. package/src/collections/index.ts +1 -1
  82. package/src/config/winston-logger.ts +8 -0
  83. package/src/dictionary/contained/index.ts +3 -0
  84. package/src/dictionary/index.ts +5 -0
  85. package/src/generator/applicability.ts +87 -0
  86. package/src/generator/case-builder.ts +167 -0
  87. package/src/generator/corpus-store.ts +166 -0
  88. package/src/generator/index.ts +12 -0
  89. package/src/generator/instrument-universe.ts +347 -0
  90. package/src/generator/layout.ts +279 -0
  91. package/src/generator/market-context.ts +207 -0
  92. package/src/generator/outcome.ts +102 -0
  93. package/src/generator/realistic-generator.ts +404 -0
  94. package/src/generator/rng.ts +92 -0
  95. package/src/generator/scatter.ts +432 -0
  96. package/src/generator/scenarios.ts +167 -0
  97. package/src/generator/value-conventions.ts +295 -0
  98. package/src/index.ts +12 -0
  99. package/src/jsfix-cmd.ts +204 -0
  100. package/src/store/fix-msg-ascii-store-resend.ts +2 -1
  101. package/src/store/fix-msg-store-record.ts +4 -1
  102. package/src/store/index.ts +1 -0
  103. package/src/transport/index.ts +10 -0
  104. package/src/transport/session/index.ts +1 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./rng"), exports);
18
+ __exportStar(require("./instrument-universe"), exports);
19
+ __exportStar(require("./market-context"), exports);
20
+ __exportStar(require("./value-conventions"), exports);
21
+ __exportStar(require("./realistic-generator"), exports);
22
+ __exportStar(require("./applicability"), exports);
23
+ __exportStar(require("./scenarios"), exports);
24
+ __exportStar(require("./layout"), exports);
25
+ __exportStar(require("./scatter"), exports);
26
+ __exportStar(require("./outcome"), exports);
27
+ __exportStar(require("./case-builder"), exports);
28
+ __exportStar(require("./corpus-store"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,wDAAqC;AACrC,mDAAgC;AAChC,sDAAmC;AACnC,wDAAqC;AACrC,kDAA+B;AAC/B,8CAA2B;AAC3B,2CAAwB;AACxB,4CAAyB;AACzB,4CAAyB;AACzB,iDAA8B;AAC9B,iDAA8B","sourcesContent":["export * from './rng'\nexport * from './instrument-universe'\nexport * from './market-context'\nexport * from './value-conventions'\nexport * from './realistic-generator'\nexport * from './applicability'\nexport * from './scenarios'\nexport * from './layout'\nexport * from './scatter'\nexport * from './outcome'\nexport * from './case-builder'\nexport * from './corpus-store'\n"]}
@@ -0,0 +1,54 @@
1
+ import { Rng } from './rng';
2
+ export declare enum AssetClass {
3
+ Equity = "equity",
4
+ Future = "future",
5
+ Option = "option",
6
+ Spread = "spread",
7
+ Fx = "fx",
8
+ Bond = "bond"
9
+ }
10
+ export interface ILegSpec {
11
+ readonly symbol: string;
12
+ readonly securityId: string;
13
+ readonly securityIdSource: string;
14
+ readonly securityType: string;
15
+ readonly maturityMonthYear?: string;
16
+ readonly side: string;
17
+ readonly ratio: number;
18
+ readonly refPx: number;
19
+ }
20
+ export interface IInstrumentSpec {
21
+ readonly name: string;
22
+ readonly assetClass: AssetClass;
23
+ readonly symbol: string;
24
+ readonly securityId: string;
25
+ readonly securityIdSource: string;
26
+ readonly securityExchange: string;
27
+ readonly securityType: string;
28
+ readonly cfiCode: string;
29
+ readonly currency: string;
30
+ readonly refPx: number;
31
+ readonly tick: number;
32
+ readonly lotSize: number;
33
+ readonly contractMultiplier?: number;
34
+ readonly maturityMonthYear?: string;
35
+ readonly maturityDate?: string;
36
+ readonly strikePrice?: number;
37
+ readonly putOrCall?: number;
38
+ readonly product?: number;
39
+ readonly legs?: readonly ILegSpec[];
40
+ }
41
+ declare function byClass(assetClass: AssetClass): readonly IInstrumentSpec[];
42
+ export declare const InstrumentUniverse: {
43
+ equities: readonly IInstrumentSpec[];
44
+ futures: readonly IInstrumentSpec[];
45
+ options: readonly IInstrumentSpec[];
46
+ fx: readonly IInstrumentSpec[];
47
+ bonds: readonly IInstrumentSpec[];
48
+ spreads: readonly IInstrumentSpec[];
49
+ all: readonly IInstrumentSpec[];
50
+ byClass: typeof byClass;
51
+ byName(name: string): IInstrumentSpec | undefined;
52
+ choose(rng: Rng, assetClass?: AssetClass): IInstrumentSpec;
53
+ };
54
+ export {};
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstrumentUniverse = exports.AssetClass = void 0;
4
+ var AssetClass;
5
+ (function (AssetClass) {
6
+ AssetClass["Equity"] = "equity";
7
+ AssetClass["Future"] = "future";
8
+ AssetClass["Option"] = "option";
9
+ AssetClass["Spread"] = "spread";
10
+ AssetClass["Fx"] = "fx";
11
+ AssetClass["Bond"] = "bond";
12
+ })(AssetClass || (exports.AssetClass = AssetClass = {}));
13
+ const equities = [
14
+ {
15
+ name: 'Apple Inc',
16
+ assetClass: AssetClass.Equity,
17
+ symbol: 'AAPL',
18
+ securityId: 'US0378331005',
19
+ securityIdSource: '4',
20
+ securityExchange: 'XNAS',
21
+ securityType: 'CS',
22
+ cfiCode: 'ESVUFR',
23
+ currency: 'USD',
24
+ refPx: 214.5,
25
+ tick: 0.01,
26
+ lotSize: 100,
27
+ product: 5
28
+ },
29
+ {
30
+ name: 'Vodafone Group',
31
+ assetClass: AssetClass.Equity,
32
+ symbol: 'VOD.L',
33
+ securityId: 'GB00BH4HKS39',
34
+ securityIdSource: '4',
35
+ securityExchange: 'XLON',
36
+ securityType: 'CS',
37
+ cfiCode: 'ESVUFR',
38
+ currency: 'GBP',
39
+ refPx: 0.762,
40
+ tick: 0.0001,
41
+ lotSize: 1000,
42
+ product: 5
43
+ },
44
+ {
45
+ name: 'SAP SE',
46
+ assetClass: AssetClass.Equity,
47
+ symbol: 'SAP',
48
+ securityId: 'DE0007164600',
49
+ securityIdSource: '4',
50
+ securityExchange: 'XETR',
51
+ securityType: 'CS',
52
+ cfiCode: 'ESVUFR',
53
+ currency: 'EUR',
54
+ refPx: 196.3,
55
+ tick: 0.01,
56
+ lotSize: 100,
57
+ product: 5
58
+ }
59
+ ];
60
+ const futures = [
61
+ {
62
+ name: 'ICE Brent Crude Jan26',
63
+ assetClass: AssetClass.Future,
64
+ symbol: 'BRN',
65
+ securityId: 'BRN FMF0026!',
66
+ securityIdSource: '8',
67
+ securityExchange: 'IFEU',
68
+ securityType: 'FUT',
69
+ cfiCode: 'FCEPSX',
70
+ currency: 'USD',
71
+ refPx: 71.35,
72
+ tick: 0.01,
73
+ lotSize: 1,
74
+ contractMultiplier: 1000,
75
+ maturityMonthYear: '202601',
76
+ maturityDate: '20251130',
77
+ product: 2
78
+ },
79
+ {
80
+ name: 'ICE Low Sulphur Gasoil Feb26',
81
+ assetClass: AssetClass.Future,
82
+ symbol: 'GAS',
83
+ securityId: 'GAS FMG0026!',
84
+ securityIdSource: '8',
85
+ securityExchange: 'IFEU',
86
+ securityType: 'FUT',
87
+ cfiCode: 'FCEPSX',
88
+ currency: 'USD',
89
+ refPx: 668.25,
90
+ tick: 0.25,
91
+ lotSize: 1,
92
+ contractMultiplier: 100,
93
+ maturityMonthYear: '202602',
94
+ maturityDate: '20260112',
95
+ product: 2
96
+ },
97
+ {
98
+ name: 'CME E-mini S and P 500 Dec25',
99
+ assetClass: AssetClass.Future,
100
+ symbol: 'ES',
101
+ securityId: 'ESZ5',
102
+ securityIdSource: '8',
103
+ securityExchange: 'XCME',
104
+ securityType: 'FUT',
105
+ cfiCode: 'FFICSX',
106
+ currency: 'USD',
107
+ refPx: 6042.25,
108
+ tick: 0.25,
109
+ lotSize: 1,
110
+ contractMultiplier: 50,
111
+ maturityMonthYear: '202512',
112
+ maturityDate: '20251219',
113
+ product: 5
114
+ }
115
+ ];
116
+ const options = [
117
+ {
118
+ name: 'CME E-mini Dec25 6000 Call',
119
+ assetClass: AssetClass.Option,
120
+ symbol: 'ES',
121
+ securityId: 'ESZ5 C6000',
122
+ securityIdSource: '8',
123
+ securityExchange: 'XCME',
124
+ securityType: 'OPT',
125
+ cfiCode: 'OCEFCS',
126
+ currency: 'USD',
127
+ refPx: 118.75,
128
+ tick: 0.25,
129
+ lotSize: 1,
130
+ contractMultiplier: 50,
131
+ maturityMonthYear: '202512',
132
+ maturityDate: '20251219',
133
+ strikePrice: 6000,
134
+ putOrCall: 1,
135
+ product: 5
136
+ }
137
+ ];
138
+ const fx = [
139
+ {
140
+ name: 'EUR/USD spot',
141
+ assetClass: AssetClass.Fx,
142
+ symbol: 'EUR/USD',
143
+ securityId: 'EURUSD',
144
+ securityIdSource: '8',
145
+ securityExchange: 'XOFF',
146
+ securityType: 'FXSPOT',
147
+ cfiCode: 'MRCXXX',
148
+ currency: 'EUR',
149
+ refPx: 1.0842,
150
+ tick: 0.00005,
151
+ lotSize: 1000000,
152
+ product: 4
153
+ }
154
+ ];
155
+ const bonds = [
156
+ {
157
+ name: 'US Treasury 4.25 Nov 2034',
158
+ assetClass: AssetClass.Bond,
159
+ symbol: 'T 4.25 11/34',
160
+ securityId: 'US91282CLW12',
161
+ securityIdSource: '4',
162
+ securityExchange: 'XOFF',
163
+ securityType: 'TBOND',
164
+ cfiCode: 'DBFUFR',
165
+ currency: 'USD',
166
+ refPx: 99.421875,
167
+ tick: 0.015625,
168
+ lotSize: 1000,
169
+ maturityDate: '20341115',
170
+ product: 6
171
+ }
172
+ ];
173
+ const spreads = [
174
+ {
175
+ name: 'ICE Brent Jan26/Feb26 calendar spread',
176
+ assetClass: AssetClass.Spread,
177
+ symbol: 'BRN',
178
+ securityId: 'BRN JAN26-FEB26',
179
+ securityIdSource: '8',
180
+ securityExchange: 'IFEU',
181
+ securityType: 'MLEG',
182
+ cfiCode: 'FMEPSX',
183
+ currency: 'USD',
184
+ refPx: 0.34,
185
+ tick: 0.01,
186
+ lotSize: 1,
187
+ contractMultiplier: 1000,
188
+ maturityMonthYear: '202601',
189
+ product: 2,
190
+ legs: [
191
+ {
192
+ symbol: 'BRN',
193
+ securityId: 'BRN FMF0026!',
194
+ securityIdSource: '8',
195
+ securityType: 'FUT',
196
+ maturityMonthYear: '202601',
197
+ side: '1',
198
+ ratio: 1,
199
+ refPx: 71.35
200
+ },
201
+ {
202
+ symbol: 'BRN',
203
+ securityId: 'BRN FMG0026!',
204
+ securityIdSource: '8',
205
+ securityType: 'FUT',
206
+ maturityMonthYear: '202602',
207
+ side: '2',
208
+ ratio: 1,
209
+ refPx: 71.01
210
+ }
211
+ ]
212
+ },
213
+ {
214
+ name: 'ICE Brent/Gasoil crack spread',
215
+ assetClass: AssetClass.Spread,
216
+ symbol: 'BRNGAS',
217
+ securityId: 'BRN-GAS CRACK',
218
+ securityIdSource: '8',
219
+ securityExchange: 'IFEU',
220
+ securityType: 'MLEG',
221
+ cfiCode: 'FMEPSX',
222
+ currency: 'USD',
223
+ refPx: 12.68,
224
+ tick: 0.01,
225
+ lotSize: 1,
226
+ contractMultiplier: 1000,
227
+ maturityMonthYear: '202602',
228
+ product: 2,
229
+ legs: [
230
+ {
231
+ symbol: 'GAS',
232
+ securityId: 'GAS FMG0026!',
233
+ securityIdSource: '8',
234
+ securityType: 'FUT',
235
+ maturityMonthYear: '202602',
236
+ side: '1',
237
+ ratio: 1,
238
+ refPx: 668.25
239
+ },
240
+ {
241
+ symbol: 'BRN',
242
+ securityId: 'BRN FMG0026!',
243
+ securityIdSource: '8',
244
+ securityType: 'FUT',
245
+ maturityMonthYear: '202602',
246
+ side: '2',
247
+ ratio: 1,
248
+ refPx: 71.2
249
+ }
250
+ ]
251
+ }
252
+ ];
253
+ function byClass(assetClass) {
254
+ switch (assetClass) {
255
+ case AssetClass.Equity: return equities;
256
+ case AssetClass.Future: return futures;
257
+ case AssetClass.Option: return options;
258
+ case AssetClass.Fx: return fx;
259
+ case AssetClass.Bond: return bonds;
260
+ case AssetClass.Spread: return spreads;
261
+ default: return equities;
262
+ }
263
+ }
264
+ const all = [
265
+ ...equities, ...futures, ...options, ...fx, ...bonds, ...spreads
266
+ ];
267
+ exports.InstrumentUniverse = {
268
+ equities,
269
+ futures,
270
+ options,
271
+ fx,
272
+ bonds,
273
+ spreads,
274
+ all,
275
+ byClass,
276
+ byName(name) {
277
+ const lower = name.toLowerCase();
278
+ return all.find(i => i.symbol.toLowerCase() === lower ||
279
+ i.securityId.toLowerCase() === lower ||
280
+ i.name.toLowerCase() === lower);
281
+ },
282
+ choose(rng, assetClass) {
283
+ return rng.pick(assetClass ? byClass(assetClass) : all);
284
+ }
285
+ };
286
+ //# sourceMappingURL=instrument-universe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrument-universe.js","sourceRoot":"","sources":["../../src/generator/instrument-universe.ts"],"names":[],"mappings":";;;AAcA,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;IACjB,+BAAiB,CAAA;IACjB,uBAAS,CAAA;IACT,2BAAa,CAAA;AACf,CAAC,EAPW,UAAU,0BAAV,UAAU,QAOrB;AAoCD,MAAM,QAAQ,GAA+B;IAC3C;QACE,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,UAAU,CAAC,MAAM;QAC7B,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,cAAc;QAC1B,gBAAgB,EAAE,GAAG;QACrB,gBAAgB,EAAE,MAAM;QACxB,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,QAAQ;QACjB,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,I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AAQ,EAAE,UAAuB;QACvC,OAAO,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACzD,CAAC;CACF,CAAA","sourcesContent":["import { Rng } from './rng'\n\n/**\n * A small book of instruments that read like instruments.\n *\n * The point is not coverage - it is that a generated message can be scanned by eye and\n * recognised. `55=BRN` with `541=20251231` and `44=71.35` is a Brent future at a\n * plausible price; `55=Lorem` with `44=-4534.7` is noise that happens to encode.\n *\n * Prices carry a tick and a lot size so quantities and prices agree with the contract\n * they claim to be, and a spread carries its legs so a multileg message can be built\n * with parent and legs that actually correspond.\n */\n\nexport enum AssetClass {\n Equity = 'equity',\n Future = 'future',\n Option = 'option',\n Spread = 'spread',\n Fx = 'fx',\n Bond = 'bond'\n}\n\nexport interface ILegSpec {\n readonly symbol: string\n readonly securityId: string\n readonly securityIdSource: string\n readonly securityType: string\n readonly maturityMonthYear?: string\n readonly side: string\n readonly ratio: number\n readonly refPx: number\n}\n\nexport interface IInstrumentSpec {\n readonly name: string\n readonly assetClass: AssetClass\n readonly symbol: string\n readonly securityId: string\n /** 1 CUSIP, 2 SEDOL, 4 ISIN, 8 exchange symbol, 9 CTA */\n readonly securityIdSource: string\n readonly securityExchange: string\n readonly securityType: string\n readonly cfiCode: string\n readonly currency: string\n readonly refPx: number\n readonly tick: number\n readonly lotSize: number\n readonly contractMultiplier?: number\n readonly maturityMonthYear?: string\n readonly maturityDate?: string\n readonly strikePrice?: number\n readonly putOrCall?: number\n readonly product?: number\n readonly legs?: readonly ILegSpec[]\n}\n\nconst equities: readonly IInstrumentSpec[] = [\n {\n name: 'Apple Inc',\n assetClass: AssetClass.Equity,\n symbol: 'AAPL',\n securityId: 'US0378331005',\n securityIdSource: '4',\n securityExchange: 'XNAS',\n securityType: 'CS',\n cfiCode: 'ESVUFR',\n currency: 'USD',\n refPx: 214.5,\n tick: 0.01,\n lotSize: 100,\n product: 5\n },\n {\n name: 'Vodafone Group',\n assetClass: AssetClass.Equity,\n symbol: 'VOD.L',\n securityId: 'GB00BH4HKS39',\n securityIdSource: '4',\n securityExchange: 'XLON',\n securityType: 'CS',\n cfiCode: 'ESVUFR',\n currency: 'GBP',\n refPx: 0.762,\n tick: 0.0001,\n lotSize: 1000,\n product: 5\n },\n {\n name: 'SAP SE',\n assetClass: AssetClass.Equity,\n symbol: 'SAP',\n securityId: 'DE0007164600',\n securityIdSource: '4',\n securityExchange: 'XETR',\n securityType: 'CS',\n cfiCode: 'ESVUFR',\n currency: 'EUR',\n refPx: 196.3,\n tick: 0.01,\n lotSize: 100,\n product: 5\n }\n]\n\nconst futures: readonly IInstrumentSpec[] = [\n {\n name: 'ICE Brent Crude Jan26',\n assetClass: AssetClass.Future,\n symbol: 'BRN',\n securityId: 'BRN FMF0026!',\n securityIdSource: '8',\n securityExchange: 'IFEU',\n securityType: 'FUT',\n cfiCode: 'FCEPSX',\n currency: 'USD',\n refPx: 71.35,\n tick: 0.01,\n lotSize: 1,\n contractMultiplier: 1000,\n maturityMonthYear: '202601',\n maturityDate: '20251130',\n product: 2\n },\n {\n name: 'ICE Low Sulphur Gasoil Feb26',\n assetClass: AssetClass.Future,\n symbol: 'GAS',\n securityId: 'GAS FMG0026!',\n securityIdSource: '8',\n securityExchange: 'IFEU',\n securityType: 'FUT',\n cfiCode: 'FCEPSX',\n currency: 'USD',\n refPx: 668.25,\n tick: 0.25,\n lotSize: 1,\n contractMultiplier: 100,\n maturityMonthYear: '202602',\n maturityDate: '20260112',\n product: 2\n },\n {\n name: 'CME E-mini S and P 500 Dec25',\n assetClass: AssetClass.Future,\n symbol: 'ES',\n securityId: 'ESZ5',\n securityIdSource: '8',\n securityExchange: 'XCME',\n securityType: 'FUT',\n cfiCode: 'FFICSX',\n currency: 'USD',\n refPx: 6042.25,\n tick: 0.25,\n lotSize: 1,\n contractMultiplier: 50,\n maturityMonthYear: '202512',\n maturityDate: '20251219',\n product: 5\n }\n]\n\nconst options: readonly IInstrumentSpec[] = [\n {\n name: 'CME E-mini Dec25 6000 Call',\n assetClass: AssetClass.Option,\n symbol: 'ES',\n securityId: 'ESZ5 C6000',\n securityIdSource: '8',\n securityExchange: 'XCME',\n securityType: 'OPT',\n cfiCode: 'OCEFCS',\n currency: 'USD',\n refPx: 118.75,\n tick: 0.25,\n lotSize: 1,\n contractMultiplier: 50,\n maturityMonthYear: '202512',\n maturityDate: '20251219',\n strikePrice: 6000,\n putOrCall: 1,\n product: 5\n }\n]\n\nconst fx: readonly IInstrumentSpec[] = [\n {\n name: 'EUR/USD spot',\n assetClass: AssetClass.Fx,\n symbol: 'EUR/USD',\n securityId: 'EURUSD',\n securityIdSource: '8',\n securityExchange: 'XOFF',\n securityType: 'FXSPOT',\n cfiCode: 'MRCXXX',\n currency: 'EUR',\n refPx: 1.0842,\n tick: 0.00005,\n lotSize: 1000000,\n product: 4\n }\n]\n\nconst bonds: readonly IInstrumentSpec[] = [\n {\n name: 'US Treasury 4.25 Nov 2034',\n assetClass: AssetClass.Bond,\n symbol: 'T 4.25 11/34',\n securityId: 'US91282CLW12',\n securityIdSource: '4',\n securityExchange: 'XOFF',\n securityType: 'TBOND',\n cfiCode: 'DBFUFR',\n currency: 'USD',\n refPx: 99.421875,\n tick: 0.015625,\n lotSize: 1000,\n maturityDate: '20341115',\n product: 6\n }\n]\n\n/**\n * The shape the whole scattered component exercise is really about. ICE publishes\n * calendar and crack spreads as single tradeable instruments whose fills report a parent\n * and one leg per contract, and a trade capture for one of these is where deep nesting\n * shows up in real life.\n */\nconst spreads: readonly IInstrumentSpec[] = [\n {\n name: 'ICE Brent Jan26/Feb26 calendar spread',\n assetClass: AssetClass.Spread,\n symbol: 'BRN',\n securityId: 'BRN JAN26-FEB26',\n securityIdSource: '8',\n securityExchange: 'IFEU',\n securityType: 'MLEG',\n cfiCode: 'FMEPSX',\n currency: 'USD',\n refPx: 0.34,\n tick: 0.01,\n lotSize: 1,\n contractMultiplier: 1000,\n maturityMonthYear: '202601',\n product: 2,\n legs: [\n {\n symbol: 'BRN',\n securityId: 'BRN FMF0026!',\n securityIdSource: '8',\n securityType: 'FUT',\n maturityMonthYear: '202601',\n side: '1',\n ratio: 1,\n refPx: 71.35\n },\n {\n symbol: 'BRN',\n securityId: 'BRN FMG0026!',\n securityIdSource: '8',\n securityType: 'FUT',\n maturityMonthYear: '202602',\n side: '2',\n ratio: 1,\n refPx: 71.01\n }\n ]\n },\n {\n name: 'ICE Brent/Gasoil crack spread',\n assetClass: AssetClass.Spread,\n symbol: 'BRNGAS',\n securityId: 'BRN-GAS CRACK',\n securityIdSource: '8',\n securityExchange: 'IFEU',\n securityType: 'MLEG',\n cfiCode: 'FMEPSX',\n currency: 'USD',\n refPx: 12.68,\n tick: 0.01,\n lotSize: 1,\n contractMultiplier: 1000,\n maturityMonthYear: '202602',\n product: 2,\n legs: [\n {\n symbol: 'GAS',\n securityId: 'GAS FMG0026!',\n securityIdSource: '8',\n securityType: 'FUT',\n maturityMonthYear: '202602',\n side: '1',\n ratio: 1,\n refPx: 668.25\n },\n {\n symbol: 'BRN',\n securityId: 'BRN FMG0026!',\n securityIdSource: '8',\n securityType: 'FUT',\n maturityMonthYear: '202602',\n side: '2',\n ratio: 1,\n refPx: 71.2\n }\n ]\n }\n]\n\nfunction byClass (assetClass: AssetClass): readonly IInstrumentSpec[] {\n switch (assetClass) {\n case AssetClass.Equity: return equities\n case AssetClass.Future: return futures\n case AssetClass.Option: return options\n case AssetClass.Fx: return fx\n case AssetClass.Bond: return bonds\n case AssetClass.Spread: return spreads\n default: return equities\n }\n}\n\nconst all: readonly IInstrumentSpec[] = [\n ...equities, ...futures, ...options, ...fx, ...bonds, ...spreads\n]\n\nexport const InstrumentUniverse = {\n equities,\n futures,\n options,\n fx,\n bonds,\n spreads,\n all,\n byClass,\n\n byName (name: string): IInstrumentSpec | undefined {\n const lower = name.toLowerCase()\n return all.find(i =>\n i.symbol.toLowerCase() === lower ||\n i.securityId.toLowerCase() === lower ||\n i.name.toLowerCase() === lower)\n },\n\n choose (rng: Rng, assetClass?: AssetClass): IInstrumentSpec {\n return rng.pick(assetClass ? byClass(assetClass) : all)\n }\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { ILooseObject } from '../collections/collection';
2
+ import { IContainedSet } from '../dictionary/contained';
3
+ export interface IToken {
4
+ readonly tag: number;
5
+ readonly text: string;
6
+ }
7
+ export declare enum LayoutKind {
8
+ Message = "message",
9
+ Component = "component",
10
+ Group = "group",
11
+ Instance = "instance",
12
+ Field = "field"
13
+ }
14
+ export declare class LayoutNode {
15
+ readonly kind: LayoutKind;
16
+ readonly name: string;
17
+ readonly path: string;
18
+ readonly tokenIndex: number;
19
+ readonly set: IContainedSet | null;
20
+ readonly extraTokenIndex: number;
21
+ readonly children: LayoutNode[];
22
+ constructor(kind: LayoutKind, name: string, path: string, tokenIndex?: number, set?: IContainedSet | null, extraTokenIndex?: number);
23
+ canonical(into?: number[]): number[];
24
+ get isLevel(): boolean;
25
+ }
26
+ export declare function tokenise(wire: string, delimiter: string): IToken[];
27
+ export declare function assemble(tokens: readonly IToken[], order: readonly number[], delimiter: string): string;
28
+ export interface ILayout {
29
+ readonly root: LayoutNode;
30
+ readonly tokens: readonly IToken[];
31
+ readonly bodyStart: number;
32
+ readonly bodyEnd: number;
33
+ }
34
+ export declare class Layout {
35
+ private index;
36
+ private constructor();
37
+ static build(wire: string, delimiter: string, object: ILooseObject, set: IContainedSet): ILayout;
38
+ private static expectedTags;
39
+ private static locate;
40
+ private static presentFields;
41
+ private static instancesOf;
42
+ private static lengthField;
43
+ private static lengthName;
44
+ private static lengthTag;
45
+ private walk;
46
+ }
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Layout = exports.LayoutNode = exports.LayoutKind = void 0;
4
+ exports.tokenise = tokenise;
5
+ exports.assemble = assemble;
6
+ const contained_1 = require("../dictionary/contained");
7
+ const tag_type_1 = require("../buffer/tag/tag-type");
8
+ var LayoutKind;
9
+ (function (LayoutKind) {
10
+ LayoutKind["Message"] = "message";
11
+ LayoutKind["Component"] = "component";
12
+ LayoutKind["Group"] = "group";
13
+ LayoutKind["Instance"] = "instance";
14
+ LayoutKind["Field"] = "field";
15
+ })(LayoutKind || (exports.LayoutKind = LayoutKind = {}));
16
+ class LayoutNode {
17
+ constructor(kind, name, path, tokenIndex = -1, set = null, extraTokenIndex = -1) {
18
+ this.kind = kind;
19
+ this.name = name;
20
+ this.path = path;
21
+ this.tokenIndex = tokenIndex;
22
+ this.set = set;
23
+ this.extraTokenIndex = extraTokenIndex;
24
+ this.children = [];
25
+ }
26
+ canonical(into = []) {
27
+ if (this.tokenIndex >= 0)
28
+ into.push(this.tokenIndex);
29
+ if (this.extraTokenIndex >= 0)
30
+ into.push(this.extraTokenIndex);
31
+ for (const c of this.children) {
32
+ c.canonical(into);
33
+ }
34
+ return into;
35
+ }
36
+ get isLevel() {
37
+ return this.kind === LayoutKind.Message || this.kind === LayoutKind.Instance;
38
+ }
39
+ }
40
+ exports.LayoutNode = LayoutNode;
41
+ function tokenise(wire, delimiter) {
42
+ const parts = wire.split(delimiter);
43
+ const tokens = [];
44
+ for (const p of parts) {
45
+ if (p.length === 0)
46
+ continue;
47
+ const eq = p.indexOf('=');
48
+ if (eq <= 0)
49
+ continue;
50
+ tokens.push({ tag: parseInt(p.substring(0, eq), 10), text: p });
51
+ }
52
+ return tokens;
53
+ }
54
+ function assemble(tokens, order, delimiter) {
55
+ let out = '';
56
+ for (const i of order) {
57
+ out += tokens[i].text;
58
+ out += delimiter;
59
+ }
60
+ return out;
61
+ }
62
+ class Layout {
63
+ constructor(start) {
64
+ this.index = 0;
65
+ this.index = start;
66
+ }
67
+ static build(wire, delimiter, object, set) {
68
+ const tokens = tokenise(wire, delimiter);
69
+ const expected = Layout.expectedTags(object, set);
70
+ const bodyStart = Layout.locate(tokens, expected);
71
+ const builder = new Layout(bodyStart);
72
+ const root = new LayoutNode(LayoutKind.Message, set.name, set.name, -1, set);
73
+ builder.walk(object, set, root, set.name);
74
+ return {
75
+ root,
76
+ tokens,
77
+ bodyStart,
78
+ bodyEnd: builder.index
79
+ };
80
+ }
81
+ static expectedTags(object, set) {
82
+ const out = [];
83
+ const collect = (o, s) => {
84
+ for (const field of Layout.presentFields(o, s)) {
85
+ switch (field.type) {
86
+ case contained_1.ContainedFieldType.Simple: {
87
+ const sf = field;
88
+ if (sf.definition.tagType === tag_type_1.TagType.RawData && o[Layout.lengthName(s, sf)] == null) {
89
+ out.push(Layout.lengthTag(s, sf));
90
+ }
91
+ out.push(sf.definition.tag);
92
+ break;
93
+ }
94
+ case contained_1.ContainedFieldType.Component: {
95
+ const cf = field;
96
+ collect(o[cf.name], cf.definition);
97
+ break;
98
+ }
99
+ case contained_1.ContainedFieldType.Group: {
100
+ const gf = field;
101
+ const nof = gf.definition.noOfField;
102
+ if (!nof)
103
+ break;
104
+ out.push(nof.tag);
105
+ const instances = Layout.instancesOf(o, gf);
106
+ for (const instance of instances) {
107
+ collect(instance, gf.definition);
108
+ }
109
+ break;
110
+ }
111
+ default:
112
+ break;
113
+ }
114
+ }
115
+ };
116
+ collect(object, set);
117
+ return out;
118
+ }
119
+ static locate(tokens, expected) {
120
+ if (expected.length === 0)
121
+ return 0;
122
+ for (let start = 0; start + expected.length <= tokens.length; ++start) {
123
+ let ok = true;
124
+ for (let i = 0; i < expected.length; ++i) {
125
+ if (tokens[start + i].tag !== expected[i]) {
126
+ ok = false;
127
+ break;
128
+ }
129
+ }
130
+ if (ok)
131
+ return start;
132
+ }
133
+ throw new Error('layout walk does not match the encoded message - the mirror of AsciiEncoder has drifted');
134
+ }
135
+ static presentFields(o, set) {
136
+ const fields = [];
137
+ for (const key of Object.keys(o)) {
138
+ const field = set.localNameToField.get(key);
139
+ if (field)
140
+ fields.push(field);
141
+ }
142
+ fields.sort((a, b) => a.position - b.position);
143
+ return fields;
144
+ }
145
+ static instancesOf(o, gf) {
146
+ var _a;
147
+ const nof = gf.definition.noOfField;
148
+ const instances = (_a = o[gf.name]) !== null && _a !== void 0 ? _a : (nof ? o[nof.name] : null);
149
+ return Array.isArray(instances) ? instances : [];
150
+ }
151
+ static lengthField(set, sf) {
152
+ const prior = set.fields[sf.position - 1];
153
+ if (!prior || prior.type !== contained_1.ContainedFieldType.Simple)
154
+ return null;
155
+ return prior;
156
+ }
157
+ static lengthName(set, sf) {
158
+ var _a, _b;
159
+ return (_b = (_a = Layout.lengthField(set, sf)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
160
+ }
161
+ static lengthTag(set, sf) {
162
+ var _a, _b;
163
+ return (_b = (_a = Layout.lengthField(set, sf)) === null || _a === void 0 ? void 0 : _a.definition.tag) !== null && _b !== void 0 ? _b : 0;
164
+ }
165
+ walk(o, set, parent, path) {
166
+ for (const field of Layout.presentFields(o, set)) {
167
+ switch (field.type) {
168
+ case contained_1.ContainedFieldType.Simple: {
169
+ const sf = field;
170
+ let lengthIndex = -1;
171
+ if (sf.definition.tagType === tag_type_1.TagType.RawData && o[Layout.lengthName(set, sf)] == null) {
172
+ lengthIndex = this.index++;
173
+ }
174
+ const dataIndex = this.index++;
175
+ parent.children.push(new LayoutNode(LayoutKind.Field, sf.name, `${path}.${sf.name}`, lengthIndex >= 0 ? lengthIndex : dataIndex, null, lengthIndex >= 0 ? dataIndex : -1));
176
+ break;
177
+ }
178
+ case contained_1.ContainedFieldType.Component: {
179
+ const cf = field;
180
+ const node = new LayoutNode(LayoutKind.Component, cf.name, `${path}.${cf.name}`, -1, cf.definition);
181
+ parent.children.push(node);
182
+ this.walk(o[cf.name], cf.definition, node, node.path);
183
+ break;
184
+ }
185
+ case contained_1.ContainedFieldType.Group: {
186
+ const gf = field;
187
+ const nof = gf.definition.noOfField;
188
+ if (!nof)
189
+ break;
190
+ const countIndex = this.index++;
191
+ const node = new LayoutNode(LayoutKind.Group, gf.name, `${path}.${gf.name}`, countIndex, gf.definition);
192
+ parent.children.push(node);
193
+ const instances = Layout.instancesOf(o, gf);
194
+ for (let i = 0; i < instances.length; ++i) {
195
+ const instance = new LayoutNode(LayoutKind.Instance, `${gf.name}[${i}]`, `${node.path}[${i}]`, -1, gf.definition);
196
+ node.children.push(instance);
197
+ this.walk(instances[i], gf.definition, instance, instance.path);
198
+ }
199
+ break;
200
+ }
201
+ default:
202
+ break;
203
+ }
204
+ }
205
+ }
206
+ }
207
+ exports.Layout = Layout;
208
+ //# sourceMappingURL=layout.js.map