-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rule606ReportGenerator.js
1165 lines (1105 loc) · 41 KB
/
Rule606ReportGenerator.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Rule 606 Report Generator was created by staff of the U.S. Securities and Exchange Commission.
//Data and content created by government employees within the scope of their employment
//are not subject to domestic copyright protection. 17 U.S.C. 105.
const a1SectionHeaders = [ 'S&P 500 Stocks', 'Non-S&P 500 Stocks', 'Options' ];
const a1SectionTags = [ 'rSP500', 'rOtherStocks', 'rOptions' ];
const a1SummaryTableHeaders = [ 'Non-Directed Orders as % of All Orders',
'Market Orders as % of Non-Directed Orders',
'Marketable Limit Orders as % of Non-Directed Orders',
'Non-Marketable Limit Orders as % of Non-Directed Orders',
'Other Orders as % of Non-Directed Orders' ];
const a1SummaryTableTags = [ 'ndoPct', 'ndoMarketPct', 'ndoMarketableLimitPct',
'ndoNonmarketableLimitPct', 'ndoOtherPct' ];
const a1VenueTableHeaders = [
'Venue - \nNon-directed Order Flow',
'Non-Directed Orders (%)',
'Market Orders (%)',
'Marketable Limit Orders (%)',
'Non-Marketable Limit Orders (%)',
'Other Orders (%)',
'Net Payment Paid/Received for Market Orders(USD)',
'Net Payment Paid/Received for Market Orders(cents per hundred shares)',
'Net Payment Paid/Received for Marketable Limit Orders(USD)',
'Net Payment Paid/Received for Marketable Limit Orders(cents per hundred shares)',
'Net Payment Paid/Received for Non-Marketable Limit Orders(USD)',
'Net Payment Paid/Received for Non-Marketable Limit Orders(cents per hundred shares)',
'Net Payment Paid/Received for Other Orders(USD)',
'Net Payment Paid/Received for Other Orders(cents per hundred shares)' ];
const a1VenueTableTags = [ 'orderPct', 'marketPct', 'marketableLimitPct',
'nonMarketableLimitPct', 'otherPct', 'netPmtPaidRecvMarketOrdersUsd',
'netPmtPaidRecvMarketOrdersCph',
'netPmtPaidRecvMarketableLimitOrdersUsd',
'netPmtPaidRecvMarketableLimitOrdersCph',
'netPmtPaidRecvNonMarketableLimitOrdersUsd',
'netPmtPaidRecvNonMarketableLimitOrdersCph',
'netPmtPaidRecvOtherOrdersUsd', 'netPmtPaidRecvOtherOrdersCph' ];
const b1TableHeaders = [ 'Order ID', 'Type', 'Venue', 'Time of Transaction (UTC)' ];
const b1OrderTags = [ 'orderId', 'directed', 'route' ];
const b1RouteTags = [ 'venueName', 'mic', 'mpid', 'transaction' ]
const b1TransactionTags = [ 'date', 'time' ];
const b3SummaryTableHeaders = [ 'Total Shares Sent to Broker/Dealer',
'Total Number of Shares Executed as Principal',
'Total Orders Exposed (Actionable IOI)' ];
const b3SummaryTableTags = [ 'sentShr', 'executedAsPrincipalShr', 'ioiExposedOrd' ];
const b3DetailTableHeaders = [
'Venue',
'Total Shares Routed',
'Total Shares Routed Marked IOC',
'Total Shares Routed that were further Routable',
'Average Order Size Routed',
'Total Shares Executed',
'Fill Rate',
'Average Fill Size',
'Average Net Execution Fee or (Rebate)',
'Total Shares Executed at Midpoint',
'Percentage of Shares Executed at Midpoint',
'Total Shares Executed that were Priced at the Near Side',
'Percentage of Total Shares Executed that were Priced at the Near Side',
'Total Shares Executed that were Priced at the Far Side',
'Percentage of Total Shares Executed that were Priced at the Far Side',
'Total Number of Shares that Provided Liquidity',
'Percentage of Executed Shares that Provided Liquidity',
'Average Duration of Orders that Provided Liquidity (in msec)',
'Average Net Execution Rebate (or Fee Paid) for Shares that Provided Liquidity',
'Total Number of Shares that Removed Liquidity',
'Percentage of Executed Shares that Removed Liquidity',
'Average Net Execution Fee (or rebate received) for Shares that Removed Liquidity' ];
const b3DetailTableTags = [ 'routedShr', 'iocRoutedShr', 'furtherRoutableShr',
'orderSizeShr', 'executedShr', 'filledPct', 'fillSizeShr',
'netFeeOrRebateCph', 'midpointShr', 'midpointPct', 'nearsideShr',
'nearsidePct', 'farsideShr', 'farsidePct', 'providedLiqudityShr',
'providedLiquidityPct', 'orderDurationMsec', 'providedLiquidityNetCph',
'removedLiquidityShr', 'removedLiquidityPct', 'removedLiquidityNetCph' ];
const monthEnum = {
January : 1,
February : 2,
March : 3,
April : 4,
May : 5,
June : 6,
July : 7,
August : 8,
September : 9,
October : 10,
November : 11,
December : 12
};
const NS = ''; /* null string */
const WS = ' '; /* one whitespace */
const ZWSP = '\u200B'; /* zero width space */
const NL = '\n';
const SEMI = ';'; /* one semicolon */
const AUTO = 'auto';
const TEXTSTYLE = 'textStyle';
const TABLEVALUE = 'tableValue';
const COMPRESS = false; /* For debugging, set false so as to inspect pdf output. */
const FILLCOLOR = '#CCE6FF'; /* blue */
const FAILCOLOR = '#FFCCE6'; /* pink */
const GRAYCOLOR = '#CCCCCC'; /* gray */
var basename = null;
var xsdContent, xmlDoc, matrAspectsArr, detailData;
var hasTimeStamp = false;
/******* b1 *******/
function createHeldExemptNotHeldOrderRoutingCustomerReport() { /* b1 */
memoryStatInitialize();
var docStyles = {
header : { fontSize : 16, bold : true, alignment : 'center' },
header3 : { fontSize : 10, bold : true, alignment : 'center', lineHeight: 1.2 },
header4 : { fontSize : 8, bold : true, alignment : 'center', lineHeight: 1.2 },
sectionHeader : { fontSize : 12, bold : true, alignment : 'left', lineHeight: 1.2 },
subSectionHeader : { fontSize : 10, bold : true, alignment : 'left', lineHeight: 1.2 },
textStyle : { fontSize : 8 },
tableHeader : { fontSize : 9, bold : true, alignment : 'center', fillColor : FILLCOLOR },
tableValue : { fontSize : 8, alignment : 'left' },
tableNameValue : { fontSize : 9, alignment : 'left' },
failHeader: { fontSize: 9, bold: true, alignment : 'center', fillColor : FAILCOLOR }
}
var roots = [
[ 'held', 'Held NMS Stocks' ],
[ 'notHeldExempt', 'Exempt Not-Held NMS stocks', ],
[ 'options', 'Options Customer Routing Report' ]
];
var outname = ((basename == null) ? '606b1_HeldExemptNotHeldOrderRoutingCustomerReport' : removeExtension(basename.name));
var threshold = 500; // number of transactions in a single pdf report file, about 10 pages
var truncate = true;
var hasoutput = false;
// memoryStat('After XML loaded',false);
for (var i = 0; i < roots.length; i++) {
var title = roots[i][1];
var body = getprivateData(roots[i][0]);
if (body.length == 0) {
break;
}
var columnHeadings = body[0];
var chunks = [];
var chunk = [];
var failText = null;
var accumulated = 0;
for (var j = 1; j < body.length; j++) {
var order = body[j];
var orderId = order[0];
var cellSize = ((orderId.hasOwnProperty('rowSpan')) ? orderId.rowSpan : 1);
if (accumulated == 0) {
chunk = [];
chunk.push(columnHeadings);
}
if ((accumulated + cellSize) > threshold) {
if (truncate) {
failText = 'Unable to render more than '+threshold+' '+title+' transactions.'
+ NL +'Open larger 606(b)(1) XML files in a spreadsheet or other application.'
alert(failText);
}
chunks.push(chunk);
chunk = [];
accumulated = 0;
if (truncate) {
break;
}
}
accumulated += 1;
chunk.push(order);
}
if (accumulated > 0) {
chunks.push(chunk);
}
for (var j = 0; j < chunks.length; j++) {
hasoutput = true;
chunk = chunks[j];
var content = [];
content.push(
{text: getElementValue('bd') + ' - ' + title, tags: ['Div','H','/H'], style: 'header', unbreakable:true},
((hasTimeStamp) ? {
text: [ {text: 'Generated on ',
style: 'header3', unbreakable:true},
{text: formatDate(getElementValue('timestamp')), style: TEXTSTYLE},
], tags: ['H1','/H1']} : NS), {
tags: ['H1','/H1'],
text: [ {
text: ' For ',
style: 'header3', unbreakable:true
}, {
text: getElementValue('customer'),
style: TEXTSTYLE, unbreakable:true
} ]},
{
text: [{text: ' Reporting Period ', style: 'header3', unbreakable:true},
{text: getElementValue('startDate') + ' to ' + getElementValue('endDate'), style: TEXTSTYLE, unbreakable:true}],
tags: ['H1','/H1','/Div']}
);
content.push(NL, {
tags: ['Caption','/Caption'],
text: 'Orders - ' + title + (chunks.length > 1 ? ' Part ' + j : NS) + NL,
style: 'sectionHeader', unbreakable:true
},
{table: {
body : chunk,
tags: ['Table'],
headerRows : 1, dontBreakRows: true,
widths : [ AUTO, AUTO, AUTO, AUTO ]
}
});
if (failText != null) {
content.push({
table: {widths: [AUTO],
body : [[{ text: failText,
tags: ['/Table','Table','TR','TH','/TH','/TR','/Table'],
style: 'failHeader'}]]}});
}
chunks[j] = null;
var docDefinition = {
info: {title : title},
lang: 'en-US',
marked: true,
tabs: 'S',
displayDocTitle: true,
compress : COMPRESS,
content : content,
styles : docStyles
};
var name = outname + '_section_' + (i+1) + ((j == 0) ? NS : '_file_' + (j+1));
const pdf = pdfMake.createPdf(docDefinition);
const filename = name + '.pdf';
docDefinition = null;
pdf.download(filename)
// memoryStat('After generating '+filename,false);
}
}
if (!hasoutput) {
alert('No transactions in '+basename.name+', no output files.');
}
}
function getprivateData(orderType) { /* b1 */
var orderlist = xmlDoc.getElementsByTagName(orderType);
var orders = [];
var rows = [];
$.each(orderlist, function(_index, val) {
orders = val.getElementsByTagName('order');
var row = [];
$.each(b1TableHeaders, function(index, val) {
row.push({
text: val,
tags: ((index==0) ? ['Table','TR'] : [])
.concat(['TH','/TH'])
.concat((index == (b1TableHeaders.length - 1)) ? ['/TR'] : [] ),
style: 'tableHeader', unbreakable:true
});
});
rows.push(row);
$.each(orders, function(_orderIndex, order) {
var routes = [];
var type = NS;
var orderId = NS;
var orderChildNodes = order.childNodes;
$.each(orderChildNodes, function(_oChildIndex, oChild) {
if (oChild.tagName == b1OrderTags[0]) {
orderId = getNodeValue(oChild, true);
} else if (oChild.tagName == b1OrderTags[1]) {
if (getNodeValue(oChild,true) == 'Y') {
type = 'Directed';
} else {
type = 'Non-Directed';
}
} else if (oChild.tagName == b1OrderTags[2]) {
routes.push(oChild);
}
});
var orderRowSpan = 0;
$.each(routes, function(_rtIndex, route) {
var transactionCount = 0;
$.each(route.childNodes, function(_rtChildIndex, rtChild) {
if (rtChild.tagName == b1RouteTags[2]) {
transactionCount += 1;
}
});
transactionCount = Math.max(1, transactionCount);
route.routeRowSpan = transactionCount;
orderRowSpan += transactionCount;
});
if (routes.length < 1) {
row = [];
bdr = [true,true,true,true]; /* l,t,r,b */
row.push({text: ((orderId=="")?ZWSP:orderId), tags: ['TR','TD','/TD'], style: TABLEVALUE, unbreakable:true,border: bdr});
row.push({text: ((type=="")?ZWSP:type), tags: ['TD','/TD'], style: TABLEVALUE, unbreakable:true,border: bdr});
row.push({text: ZWSP, tags: ['TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
row.push({text: ZWSP, tags: ['TD','/TD','/TR'], style: TABLEVALUE, unbreakable:true,border:bdr});
rows.push(row);
} else {
$.each(routes, function(rtIndex, route) {
row = [];
var venueName = NS;
var isFirstRoute = (rtIndex == 0);
var isLastRoute = (rtIndex == (routes.length - 1))
var rtChildNodes = route.childNodes;
var transactions = [];
$.each(rtChildNodes, function(_rtChildIndex, rtChild) {
/* construct venue name and count transactions */
if (rtChild.tagName == b1RouteTags[0]) {
venueName = getNodeValue(rtChild,true);
} else if (rtChild.tagName == b1RouteTags[1] || rtChild.tagName == b1RouteTags[2]) {
if (venueName != NS) {
venueName = venueName + ' (' + getNodeValue(rtChild,true) + ')';
} else {
venueName = getNodeValue(rtChild,true);
};
} else if (rtChild.tagName == b1RouteTags[3]) { /* b1RouteTags = [ 'venueName', 'mic', 'mpid', 'transaction' ] */
transactions.push(rtChild);
}
});
if (transactions.length == 0) {
row = [];
col1 = ((isFirstRoute)?orderId:ZWSP);
col2 = ((isFirstRoute)?type:ZWSP);
col3 = (venueName);
col4 = ('-');
bdr = [true,isFirstRoute,true,isLastRoute]; /* l,t,r,b */
row.push({text: col1, tags: ['TR','TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
row.push({text: col2, tags: ['TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
bdr = [true,true,true,true]; /* l,t,r,b */
row.push({text: col3, tags: ['TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
row.push({text: col4, tags: ['TD','/TD','/TR'], style: TABLEVALUE, unbreakable:true,border:bdr});
rows.push(row);
} else {
$.each(transactions, function(txIndex, transaction) {
row = [];
isFirstTransaction = (txIndex == 0);
isLastTransaction = (txIndex == (transactions.length-1));
col1 = ((isFirstRoute && isFirstTransaction)?orderId:WS);
col2 = ((isFirstRoute && isFirstTransaction)?type:WS);
col3 = ((isFirstTransaction)?venueName:WS);
col4 = ((transactions.length==0)?'-':getTransactionDate(transaction));
bdr = [true,isFirstRoute&&isFirstTransaction,true,isLastRoute && isLastTransaction]; /* l,t,r,b */
row.push({text: col1, tags: ['TR','TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
row.push({text: col2, tags: ['TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
bdr = [true,isFirstRoute&&isFirstTransaction,true,isLastTransaction]; /* l,t,r,b */
row.push({text: col3, tags: ['TD','/TD'], style: TABLEVALUE, unbreakable:true,border:bdr});
bdr = [true,isFirstRoute&&isFirstTransaction,true,true];
row.push({text: col4, tags: ['TD','/TD','/TR'], style: TABLEVALUE, unbreakable:true,border:bdr});
rows.push(row);
});
};
});
}
});
});
return rows;
}
function getTransactionDate(transaction) { /* b1 */
var date = NS;
$.each(transaction.childNodes, function(_txChildIndex, txChild) {
if (txChild.tagName == b1TransactionTags[0]) {
date += getNodeValue(txChild, true);
} else if (txChild.tagName == b1TransactionTags[1]) {
date += WS + getNodeValue(txChild, true);
}
});
return date;
}
/****** b3 *******/
function createNotHeldOrderHandlingCustomerReportPDF(_opts) { /* b3 */
var content = [];
var outname = ((basename == null) ? '606b3_NotHeldOrderHandling' : removeExtension(basename.name));
var title = 'Not-Held NMS Stocks Order Handling Report';
content.push(
// Header
{text: getElementValue('bd') + ' - ' + title, style: 'header', unbreakable:true, tags: ['H','/H']},
((hasTimeStamp) ? {tags: ['H1','/H1'],
style: 'header4', unbreakable:true,
text: 'Generated on ' + formatDate(getElementValue('timestamp'))}
: {text: ' - ', tags: []}),
{ tags: ['H2', '/H2'],
text : [ { text : ' For ',
style : 'header3' },
{ text : getElementValue("customer"),
style : TEXTSTYLE } ] },
{ tags: ['H2', '/H2'],
text : [ { text : ' Reporting Period ',
style : 'header3' },
{ text : getElementValue("startDate") + ' to ' + getElementValue("endDate"),
style : TEXTSTYLE }
]});
var years = getAllYears();
$.each(years,
function(_yearIndex, year) {
$.each(monthEnum,
function(monthName, monthVal) {
var dateElements = xmlDoc.getElementsByTagName('mon');
var monthFound = false;
$.each(dateElements,
function(_dateIndex,dateNode)
{ var date = getNodeValue(dateNode,true);
if (date == monthVal && getYearForMonth(dateNode) == year) {
monthFound = true;
return false;
}
});
if (!monthFound) {return;}
for (var r = 0; r < 2; r++) { // r = 0:directed, 1:non directed.
var isDirected = (r == 0);
var summaryData = getSummaryData(isDirected,monthVal,year);
var hasSummaryData = (summaryData.length > 1);
if (hasSummaryData) {
content.push(// Month Header
{text: monthName + WS + year + ' - ' + ((isDirected) ? 'Directed ' : 'Non-directed ') + 'Orders', style: 'sectionHeader', unbreakable:true, tags: ['H2','/H2']},
// Horizontal Line
{canvas : [ {type : 'line',x1 : 0,y1 : 5, x2 : 762, y2 : 5, lineWidth : 1 } ] },
// Summary
{text: 'Summary', style: 'subSectionHeader', unbreakable:true, tags: ['Caption','/Caption'] },
{table: {headerRows : 1, dontBreakRows : true,
widths : [AUTO,AUTO,AUTO ],
body : summaryData}})}
var ioiExposedVenues = getDetailData(isDirected, monthVal, year); /* side-effected detailData */
var ioiExpsdVenuesArr = []; // holds tagged rows, if any.
var hasIoIExposedVenues = (ioiExposedVenues.length > 0);
if (hasIoIExposedVenues) {
var temp = [];
temp.push({text: 'Venues', style: 'tableHeader', unbreakable:true,
tags: ['Table','TR','TH','/TH','/TR']});
ioiExpsdVenuesArr.push(temp);
for (index = 0; index < ioiExposedVenues.length; index++) {
var row = [];
var isLastRow = (index == (ioiExposedVenues.length - 1));
row.push({text: ioiExposedVenues[index], style: 'tableNameValue', unbreakable:true,
tags: ['TR','TD','/TD','/TR'].concat((isLastRow?['/Table']:[]))});
ioiExpsdVenuesArr.push(row);
}
content.push(// IOI exposed Venues
{text: 'Actionable IOI Exposed Venues',
style: 'subSectionHeader',
unbreakable:true, tags: ['Caption','/Caption']}
,{table: { body : ioiExpsdVenuesArr, dontBreakRows : true,
headerRows : 1, widths : [ AUTO ]}})}
var hasDetailData = (detailData.length > 1);
if (hasDetailData) {
content.push(
{text: 'Order Routing Venues',
style: 'subSectionHeader', unbreakable:true,
tags: ['Caption','/Caption'] }
,{table: { body : detailData,
headerRows : 1, dontBreakRows : true,
widths : [ 40,
AUTO, AUTO, AUTO, AUTO, AUTO,
AUTO, AUTO, AUTO, AUTO, AUTO,
AUTO, AUTO, AUTO, AUTO, AUTO,
AUTO, AUTO, AUTO, AUTO, AUTO,
AUTO ] /* 22 columns */
} }
)
} // if
} // for
})}
);
var docDefinition = { /* b3 */
info: {title : title},
displayDocTitle: true,
lang: 'en-US',
marked: true,
tabs: 'S',
pageOrientation : 'landscape',
compress : COMPRESS,
content : content,
styles : { /* only vertical-align: top is supported */
header : {fontSize : 16, bold : true, alignment : 'center'},
header3 : {fontSize : 10, bold : true, alignment : 'center', lineHeight: 1.2
}, header4 : {fontSize : 8, bold : true, alignment : 'center', lineHeight: 1.2
}, sectionHeader : {fontSize : 12, bold : true, alignment : 'left', lineHeight: 1.2
}, majorSubSectionHeader : {fontSize : 11, bold : true, alignment : 'left', lineHeight: 1.2
}, subSectionHeader : {fontSize : 9, bold : true, alignment : 'left', lineHeight: 1.2
}, textStyle : {fontSize : 8
}, tableHeader : {fontSize : 3.5, bold : true, alignment : 'center', fillColor : FILLCOLOR
}, tableValue : {fontSize : 4, alignment : 'right'
}, tableNameValue : {fontSize : 4, alignment : 'left'
}, greyedOut : {fillColor : GRAYCOLOR}
}
};
pdfMake.createPdf(docDefinition).download(outname + '.pdf');
}
function getSummaryHeader(isLastRow) { /* b3 */
var row = [];
for (var i = 0; i < b3SummaryTableHeaders.length; i++) {
var summaryTableHeader = b3SummaryTableHeaders[i];
verified(summaryTableHeader);
isFirst = (i==0);
isLastCol = (i==(b3SummaryTableHeaders.length - 1));
row.push({
text: summaryTableHeader,
style: 'tableHeader', unbreakable:true,
tags: (isFirst?['Table','TR']:[])
.concat(['TH','/TH'])
.concat(isLastCol?['/TR']:[]) /* close row */
.concat((isLastCol && isLastRow)?['/Table']:[]) /* close table */
});
}
return row;
}
function getDetailedHeader(isLastRow) { /* b3 */
var row = [];
for (var col = 0; col < b3DetailTableHeaders.length; col++) {
var detailTableHeader = b3DetailTableHeaders[col];
verified(detailTableHeader);
var isFirstCol = (col == 0);
var isLastCol = (col == (b3DetailTableHeaders.length - 1));
row.push({
text: detailTableHeader,
style: 'tableHeader', unbreakable:true,
tags: ((isFirstCol)?['Table','TR']:[])
.concat(['TH','/TH'])
.concat((isLastCol)?['/TR']:[]) /* close row */
.concat((isLastCol && isLastRow)?['/Table']:[]) /* close table */
});
}
/* return value will not be used if there are no detail data */
return row;
}
function getSummaryData(directed, month, year) { /* b3 */
var root = xmlDoc.getElementsByTagName((directed) ? 'hDirected' : 'hNondirected');
var dataRows = [];
if (root.length==0) {return dataRows};
var monthlyAllVenues = root[0].getElementsByTagName('mon');
var allVenuesOfMonth = []; /* each month may have a different list of venues */
var allNonemptyVenuesOfMonth = [];
for (var i = 0; i < monthlyAllVenues.length; i++) {
var node = monthlyAllVenues[i];
if (getNodeValue(node) == month && getYearForMonth(node) == year) {
allVenuesOfMonth.push(i);
if (getNextSiblings(node).length > 0) {
allNonemptyVenuesOfMonth.push(i)
}
}
}
dataRows.push(getSummaryHeader(allVenuesOfMonth.length==0));
for (var i = 0; i < allVenuesOfMonth.length; i++) {
var indexOfNode = allVenuesOfMonth[i];
node = monthlyAllVenues[indexOfNode];
var j = allNonemptyVenuesOfMonth.indexOf(indexOfNode);
var isLastRow = (allNonemptyVenuesOfMonth.length == 0 || j == (allNonemptyVenuesOfMonth.length - 1));
var row = [];
var siblings = getNextSiblings(node);
for (var col = 0; col < b3SummaryTableTags.length; col++) {
var isFirstCol = (col==0);
var isLastCol = (col==(b3SummaryTableTags.length - 1));
var summaryTableTag = b3SummaryTableTags[col];
for (var m = 0; m < siblings.length; m++) {
var sibling = siblings[m];
if (sibling.tagName == summaryTableTag) {
var nodeVal = getNodeValue(sibling);
verified(nodeVal);
row.push({
text: ((nodeVal==NS)?ZWSP:nodeVal),
style: TABLEVALUE, unbreakable:true,
tags: (isFirstCol?['TR']:[])
.concat(['TD','/TD'])
.concat(isLastCol?['/TR']:[])
.concat((isLastCol && isLastRow)?['/Table']:[])
});
break;
}
}
}
dataRows.push(row);
}
return dataRows;
}
function getDetailData(isDirected, month, year) { /* b3 */
var dataRows = [];
var ioiExpsdVenues = [];
var root = xmlDoc.getElementsByTagName((isDirected) ? 'hDirected' : 'hNondirected');
dataRows.push(getDetailedHeader(root.length == 0));
if (root.length != 0) {
var hMonthlyElts = root[0].getElementsByTagName('hMonthly');
for (var i = 0; i < hMonthlyElts.length; i++) {
var hMonthly = hMonthlyElts[i];
var mon = hMonthly.getElementsByTagName('mon')[0];
var yr = hMonthly.getElementsByTagName('year')[0];
if (mon.textContent == month && yr.textContent == year) {
var ioiExposedVenueListElts = hMonthly
.getElementsByTagName('ioiExposedVenueList');
for (var j = 0; j < ioiExposedVenueListElts.length; j++) {
var ioiExposedVenueElts = ioiExposedVenueListElts[j]
.getElementsByTagName('ioiExposedVenue');
for (var k = 0; k < ioiExposedVenueElts.length; k++) {
var ioiExposedVenueElt = ioiExposedVenueElts[k];
var venueName = ioiExposedVenueElt.children[0].textContent;
venueName = venueName.replace(/\s+/g, WS).trim();
ioiExpsdVenues.push(venueName);
}
}
var routingVenueListElts = hMonthly.getElementsByTagName('routingVenueList');
for (var j = 0; j < routingVenueListElts.length; j++) {
var routingVenueListElt = routingVenueListElts[j];
var routingVenueElts = routingVenueListElt
.getElementsByTagName('iVenue');
for (var k = 0; k < routingVenueElts.length; k++) {
var isLastRow = (k == (routingVenueElts.length - 1));
var routingVenueElt = routingVenueElts[k];
var venueChildElts = routingVenueElt.children;
var netRow = [];
var nodeVal = null;
var venueNameVal = getVenueName(routingVenueElt);
netRow.push({text: venueNameVal, style: 'tableNameValue', unbreakable:true, tags: ['TR','TD','/TD']});
b3DetailTableTags.forEach(
function (tag, j) {
var isLastCol = (j == (b3DetailTableTags.length - 1));
nodeVal = NS;
$.each(venueChildElts,function(_index,elt) {
if (elt.tagName == tag) {
nodeVal = getNodeValue(elt);
verified(nodeVal, 'nodeVal');
return true;
};
});
var n = {text: ((nodeVal==NS)?ZWSP:nodeVal),
style: TABLEVALUE, unbreakable:true,
tags: ['TD','/TD']
.concat(isLastCol?['/TR']:[])
.concat((isLastCol && isLastRow)?['/Table']:[])};
netRow.push(n);
});
dataRows.push(netRow);
} // routingVenueElts
} // routingVenueListElts
} // monthlyElts
}
}
/* detailData is global */
detailData = dataRows;
return ioiExpsdVenues;
}
/****** a1 ******/
function createHeldOrderRoutingPublicReportPDF() { /* a1 */
var outname = ((basename == null) ? '606a1_HeldOrderRoutingPublicReport' : removeExtension(basename.name));
var title = 'Held NMS Stocks and Options Order Routing Public Report';
var content = [];
content.push({ text: getElementValue('bd') + ' - ' + title,
tags: ['H','/H'],
style: 'header',
unbreakable:true
}, ((hasTimeStamp) ? {
text: 'Generated on ' + formatDate(getElementValue('timestamp')),
tags: ['H1','/H1'],
style: 'header4', unbreakable:true
} : NS),
NL,
{ text: getQuarter(getElementValue('qtr')) + ', ' + getElementValue('year'),
tags: ['H2','/H2'],
style: 'header3', unbreakable:true
},
NL);
var years = getAllYears();
$.each(years, function(_yearIndex, year) {
$.each(monthEnum, function(monthName, monthVal) {
var dateElements = xmlDoc.getElementsByTagName('mon');
var monthFound = false;
$.each(dateElements, function(_dateIndex, dateNode) {
if (getNodeValue(dateNode) == monthVal
&& getYearForMonth(dateNode) == year) {
monthFound = true;
return false;
}
});
if (!monthFound) {
return;
} else {
content.push(a1body(0, monthVal, monthName, year));
content.push(
[ {
canvas : [ { /* horizontal dashed line */
type : 'line',x1 : 0,y1 : 5,x2 : 595 - 2 * 40,y2 : 5,dash : {length : 5},lineWidth : 1
} ]
} ]);
content.push(a1body(1, monthVal, monthName, year));
content.push(
[ { /* horizontal dashed line */
canvas : [ { type : 'line', x1 : 0, y1 : 5, x2 : 595 - 2 * 40, y2 : 5, dash : {length : 5}, lineWidth : 1
} ]
} ]);
content.push(a1body(2, monthVal, monthName, year));
}
});
});
var docDefinition = { /* a1 */
info: {title : title
,PageLayout: 'OneColumn'
},
displayDocTitle: true,
lang: 'en-US',
marked: true,
tabs: 'S',
compress : COMPRESS,
pageOrientation : 'landscape',
content : content,
styles : {
header : { fontSize : 16, bold : true, alignment : 'center' },
header3 : { fontSize : 10, bold : true, alignment : 'center', lineHeight: 1.2 },
header4 : { fontSize : 8, bold : true, alignment : 'center', lineHeight: 1.2 },
sectionHeader : { fontSize : 12, bold : true, alignment : 'left', lineHeight: 1.2 },
subSectionHeader : { fontSize : 8, bold : true, alignment : 'left', lineHeight: 1.2 },
textStyle : { fontSize : 6 },
tableHeader : { fontSize : 6, bold : true, alignment : 'center', fillColor : FILLCOLOR },
tableValue : { fontSize : 6, alignment : 'right' },
tableNameValue : { fontSize : 6, alignment : 'center' },
tableOrderTypVal : { fontSize : 6, alignment : 'left' }
}
};
const pdf = pdfMake.createPdf(docDefinition);
pdf.download(outname + '.pdf');
}
function getElementValueByMonth(name, parentName, month, year) { /* a1 */
var val = NS;
var x = xmlDoc.getElementsByTagName(name);
for (var i = 0; i < x.length; i++) {
var node = x[i];
var parentNodes = getParents(node);
for (var j = 0; j < parentNodes.length; j++) {
if (parentNodes[j].tagName == parentName) {
var siblings = getPreviousSiblings(parentNodes[j]);
for (var k = 0; k < siblings.length; k++) {
if (siblings[k].tagName == 'mon') {
if (getNodeValue(siblings[k]) == month
&& getYearForMonth(siblings[k]) == year) {
return getNodeValue(node);
}
}
}
}
}
}
return val;
}
function getVenuesByMonth(month, year, securityType) { /* a1 */
var netRows = [];
matrAspectsArr = [];
var name = 'mon';
var venueName;
var x = xmlDoc.getElementsByTagName(name);
for (var i = 0; i < x.length; i++) {
var node = x[i];
if (getNodeValue(node) != month || getYearForMonth(node) != year) {
continue;
}
var siblingNodes = getNextSiblings(node);
for (var j = 0; j < siblingNodes.length; j++) {
if (siblingNodes[j].tagName != securityType) continue;
var childNodes = siblingNodes[j].children;
for (var k = 0; k < childNodes.length; k++) {
if (childNodes[k].tagName != 'rVenues') continue;
var venues = childNodes[k].children;
var row = [];
a1VenueTableHeaders.forEach(function(val,index) {
var isFirstCol = (index==0);
var isLastCol = (index==(a1VenueTableHeaders.length - 1));
row.push({
text: ((val==NS)?ZWSP:val),
style: 'tableHeader', unbreakable:true,
tags: ((isFirstCol)?['Table','TR']:[])
.concat(['TH','/TH'])
.concat((isLastCol)?['/TR']:[])
.concat((isLastCol && venues.length==0)?['/Table']:[])});
});
netRows.push(row);
var isFirstMa = true;
for (var l = 0; l < venues.length; l++) {
var isLastRow = (l == (venues.length - 1));
var row = [];
var venueElt = venues[l];
if (venueElt.tagName != 'rVenue') continue;
var venueName = getVenueName(venueElt);
row.push({tags: ['TR','TD','/TD'], text: venueName, style: 'tableNameValue', unbreakable:true});
var venueChildNodes = venueElt.children;
a1VenueTableTags.concat(['materialAspects']).forEach(
function (tag,index) {
var isLastCol = (index==(a1VenueTableTags.length - 1));
var nodeVal = WS;
$.each(venueChildNodes,
function (_index,elt) {
if (elt.tagName == tag) {
nodeVal = getNodeValue(elt);
if (tag != 'materialAspects') {
row.push({
text: ((nodeVal==NS)?ZWSP:nodeVal),
tags: ['TD','/TD']
.concat((isLastCol)?['/TR']:[])
.concat((isLastCol && isLastRow)?['/Table']:[]),
style: TABLEVALUE, unbreakable:true});
} else if (nodeVal != NS) {
nodeVal = getNodeValue(elt,true);
matrAspectsArr.push({text: venueName + ':', style: TEXTSTYLE, unbreakable:true, tags: ((isFirstMa)?['L']:[]).concat(['LI','Lbl','/Lbl'])});
matrAspectsArr.push({text: nodeVal + NL + NL, style: TEXTSTYLE, unbreakable:true, tags: ['LBody','/LBody','/LI']});
isFirstMa = false;
} // if
} // if
}) // each
}); // function
netRows.push(row);
} // for l
} // for k
} // for j
} // for i
return netRows;
}
function getPublicRoutingBody(section, monthVal, year) { // a1
var empty = true;
for (var i=0;i<a1SummaryTableTags.length;i++) {
if (NS != getElementValueByMonth(a1SummaryTableTags[i],section, monthVal, year)) {
empty = false;
break;
}
}
var hdr = [
{text: a1SummaryTableHeaders[0], tags: ['Table','TR','TH','/TH'], style: 'tableHeader', unbreakable:true},
{text: a1SummaryTableHeaders[1], tags: ['TH','/TH'], style: 'tableHeader', unbreakable:true},
{text: a1SummaryTableHeaders[2], tags: ['TH','/TH'], style: 'tableHeader', unbreakable:true},
{text: a1SummaryTableHeaders[3], tags: ['TH','/TH'], style: 'tableHeader', unbreakable:true},
{text: a1SummaryTableHeaders[4], tags: ['TH','/TH','/TR'], style: 'tableHeader', unbreakable:true},
];
var row = [
{text: (empty)?'-':getElementValueByMonth(a1SummaryTableTags[0],section, monthVal, year), tags: ['TR','TD','/TD'], style: TABLEVALUE},
{text: (empty)?'-':getElementValueByMonth(a1SummaryTableTags[1],section, monthVal, year), tags: ['TD','/TD'], style: TABLEVALUE},
{text: (empty)?'-':getElementValueByMonth(a1SummaryTableTags[2],section, monthVal, year), tags: ['TD','/TD'], style: TABLEVALUE},
{text: (empty)?'-':getElementValueByMonth(a1SummaryTableTags[3],section, monthVal, year), tags: ['TD','/TD'], style: TABLEVALUE},
{text: (empty)?'-':getElementValueByMonth(a1SummaryTableTags[4],section, monthVal, year), tags: ['TD','/TD','/TR','/Table'], style: TABLEVALUE},
];
return [hdr,row];
}
function a1body(n, monthVal, monthName, year) { /* a1 */
var sectionText = a1SectionHeaders[n];
var section = a1SectionTags[n];
var body1 = getPublicRoutingBody(section, monthVal, year);
var body2 = getVenuesByMonth(monthVal, year, section);
return [
NL,
{ text: monthName + WS + year,
tags: ['H3'],
style: 'sectionHeader', unbreakable:true
},
{
canvas : [ { type : 'line', x1 : 0, y1 : 5, x2 : 595 - 2 * 40, y2 : 5, lineWidth : 1 } ]
},
NL,
{ text: sectionText,
tags: ['H4','/H4','/H3'],
fontSize : 10,
bold : true,
alignment : 'left'
},
(body1.length===0)?NS:[
NL,
{ text: 'Summary',
tags: ['Caption','/Caption'],
style: 'subSectionHeader', unbreakable:true
},
{ table: { body : body1,
headerRows : 1, dontBreakRows: true,
widths : [ 60, 60, 60, 60, 60 ]
}
}],
(body2.length===0)?NS:[
NL,
{ text: 'Venues',
tags: ['Caption','/Caption'],
style: 'subSectionHeader', unbreakable:true
},
{ table: { body : body2,
headerRows : 1,
dontBreakRows : true,
widths : [ AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO,
AUTO, AUTO, AUTO, AUTO, AUTO, AUTO ] /* 14 columns */
}
}],
(matrAspectsArr.length==0)?NS:[
NL,
{ text: 'Material Aspects:',
tags: ['Caption','/Caption'],
style: 'subSectionHeader', unbreakable:true
}, matrAspectsArr
,{ text: NL,
tags: ['/L'],
style: TEXTSTYLE, unbreakable:true }
]]
}
function getQuarter(num) { /* a1 */
var quarterVal = NS;
if (num == 1) {
quarterVal = '1st Quarter';
} else if (num == 2) {
quarterVal = '2nd Quarter';
} else if (num == 3) {
quarterVal = '3rd Quarter';
} else if (num == 4) {
quarterVal = '4th Quarter';
}
return quarterVal;
}
/***** a1 and b3 *****/
function getAllYears() { /* a1 and b3 */
var years = xmlDoc.getElementsByTagName('year');
var yearArray = [];
$.each(years, function(_yearIndex, yearNode) {
var year = getNodeValue(yearNode, true);
if (yearArray.indexOf(year) < 0) {
yearArray.push(year)
}
});
return yearArray.sort();
}
function getYearForMonth(month) { /* a1 and b3 */
var year;
var siblings = getPreviousSiblings(month);
$.each(siblings, function(_index, node) {
if (node.tagName == 'year') {
year = getNodeValue(node, true);
return false;
}
});
return year;
}
function getVenueName(venueElt) {
/* both a1 and b3 - specially concatenate up to three fields, all into one string */
var venueChildNodes = venueElt.children;
var venueNameVal = NS; //
['venueName','name','services','mic','mpid','otherNames'].forEach(
function (tag) {
var nodeVal = NS;
$.each(venueChildNodes,function(_index,elt) {
if (elt.tagName == tag) {
node = elt;
nodeVal = getNodeValue(elt, true);
verified(nodeVal, 'nodeVal');
nodeVal = nodeVal.replace(/\s+/g, WS).trim();
return true;
}
});
switch (tag) {
case 'venueName':
case 'name':
venueNameVal += nodeVal; break;
case 'services':
case 'mic':
case 'mpid':
if (nodeVal.length > 0) {
venueNameVal += ' (' + nodeVal +')';
venueNameVal = venueNameVal.trim();
}
break;
} // switch
}); // function
return ((venueNameVal==NS)?ZWSP:venueNameVal);
}
/****** a1, b1 and b3 ******/
function formatDate(timestamp) {
var date = new Date(timestamp);
return date.toString();
}
function getPreviousSiblings(node) {
var siblings = [];
while (node != null && node.nodeType === Node.ELEMENT_NODE && node !== this) {
siblings.push(node);