@@ -1239,15 +1239,15 @@ module.exports = (() => {
12391239 /**
12401240 * Rounds a value to the nearest valid tick.
12411241 *
1242- * @param {Number|Decimal} value
1243- * @param {Number} tickIncrement
1244- * @param {Boolean=} roundToZero
1242+ * @param {Number|Decimal} value - The price to round.
1243+ * @param {Number|Decimal} minimumTick - The minimum tick size (see {@link UnitCode#getMinimumTick})
1244+ * @param {Boolean=} roundToZero - When true, the rounding will always go towards zero.
12451245 * @returns {Number}
12461246 */
1247- roundToNearestTick(value, tickIncrement , roundToZero) {
1247+ roundToNearestTick(value, minimumTick , roundToZero) {
12481248 assert.argumentIsValid(value, 'value', x => is.number(x) || x instanceof Decimal, 'must be a number primitive or a Decimal instance');
1249+ assert.argumentIsValid(minimumTick, 'minimumTick', x => is.number(x) || x instanceof Decimal, 'must be a number primitive or a Decimal instance');
12491250 assert.argumentIsOptional(roundToZero, 'roundToZero', Boolean);
1250- const minimumTick = this.getMinimumTick(tickIncrement);
12511251 let valueToUse;
12521252 if (value instanceof Decimal) {
12531253 valueToUse = value;
@@ -11450,116 +11450,126 @@ describe('When calculating minimum ticks and minimum tick values', () => {
1145011450describe('When rounding a value to the nearest tick value', () => {
1145111451 describe('For unit code "2" and with a tickIncrement of 2 (e.g. corn)', () => {
1145211452 let uc;
11453+ let mt;
1145311454 beforeEach(() => {
1145411455 uc = UnitCode.parse('2');
11456+ mt = uc.getMinimumTick(2);
1145511457 });
1145611458 it('A value of 0 should be rounded to 0', () => {
11457- expect(uc.roundToNearestTick(0, 2 )).toEqual(0);
11459+ expect(uc.roundToNearestTick(0, mt )).toEqual(0);
1145811460 });
1145911461 it('A value of 488.5 should be rounded to 488.5', () => {
11460- expect(uc.roundToNearestTick(488.5, 2 )).toEqual(488.5);
11462+ expect(uc.roundToNearestTick(488.5, mt )).toEqual(488.5);
1146111463 });
1146211464 it('A value of 488.51 should be rounded to 488.5', () => {
11463- expect(uc.roundToNearestTick(488.51, 2 )).toEqual(488.5);
11465+ expect(uc.roundToNearestTick(488.51, mt )).toEqual(488.5);
1146411466 });
1146511467 it('A value of 488.74 should be rounded to 488.75', () => {
11466- expect(uc.roundToNearestTick(488.74, 2 )).toEqual(488.75);
11468+ expect(uc.roundToNearestTick(488.74, mt )).toEqual(488.75);
1146711469 });
1146811470 it('A value of 488.625 should be rounded to 488.75', () => {
11469- expect(uc.roundToNearestTick(488.625, 2 )).toEqual(488.75);
11471+ expect(uc.roundToNearestTick(488.625, mt )).toEqual(488.75);
1147011472 });
1147111473 it('A value of 488.625 should be rounded to 488.5 (when using "roundDown" option)', () => {
11472- expect(uc.roundToNearestTick(488.625, 2 , true)).toEqual(488.5);
11474+ expect(uc.roundToNearestTick(488.625, mt , true)).toEqual(488.5);
1147311475 });
1147411476 });
1147511477 describe('For unit code "A" and with a tickIncrement of 25 (e.g. e-mini)', () => {
1147611478 let uc;
11479+ let mt;
1147711480 beforeEach(() => {
1147811481 uc = UnitCode.parse('A');
11482+ mt = uc.getMinimumTick(25);
1147911483 });
1148011484 it('A value of 4455.5 should be rounded to 4455.5', () => {
11481- expect(uc.roundToNearestTick(4455.5, 25 )).toEqual(4455.5);
11485+ expect(uc.roundToNearestTick(4455.5, mt )).toEqual(4455.5);
1148211486 });
1148311487 it('A value of 4455.51 should be rounded to 4455.5', () => {
11484- expect(uc.roundToNearestTick(4455.51, 25 )).toEqual(4455.5);
11488+ expect(uc.roundToNearestTick(4455.51, mt )).toEqual(4455.5);
1148511489 });
1148611490 it('A value of 4455.74 should be rounded to 4455.75', () => {
11487- expect(uc.roundToNearestTick(4455.74, 25 )).toEqual(4455.75);
11491+ expect(uc.roundToNearestTick(4455.74, mt )).toEqual(4455.75);
1148811492 });
1148911493 it('A value of 4455.625 should be rounded to 4455.75', () => {
11490- expect(uc.roundToNearestTick(4455.625, 25 )).toEqual(4455.75);
11494+ expect(uc.roundToNearestTick(4455.625, mt )).toEqual(4455.75);
1149111495 });
1149211496 it('A value of 4455.625 should be rounded to 4455.5 (when using "roundDown" option)', () => {
11493- expect(uc.roundToNearestTick(4455.625, 25 , true)).toEqual(4455.5);
11497+ expect(uc.roundToNearestTick(4455.625, mt , true)).toEqual(4455.5);
1149411498 });
1149511499 });
1149611500 describe('For unit code "A" and with a tickIncrement of 1 (e.g. crude)', () => {
1149711501 let uc;
11502+ let mt;
1149811503 beforeEach(() => {
1149911504 uc = UnitCode.parse('A');
11505+ mt = uc.getMinimumTick(1);
1150011506 });
1150111507 it('A value of 87.30 should be rounded to 87.30', () => {
11502- expect(uc.roundToNearestTick(87.30, 1 )).toEqual(87.30);
11508+ expect(uc.roundToNearestTick(87.30, mt )).toEqual(87.30);
1150311509 });
1150411510 it('A value of 87.31 should be rounded to 87.31', () => {
11505- expect(uc.roundToNearestTick(87.31, 1 )).toEqual(87.31);
11511+ expect(uc.roundToNearestTick(87.31, mt )).toEqual(87.31);
1150611512 });
1150711513 it('A value of 87.312 should be rounded to 87.31', () => {
11508- expect(uc.roundToNearestTick(87.312, 1 )).toEqual(87.31);
11514+ expect(uc.roundToNearestTick(87.312, mt )).toEqual(87.31);
1150911515 });
1151011516 it('A value of 87.318 should be rounded to 87.32', () => {
11511- expect(uc.roundToNearestTick(87.318, 1 )).toEqual(87.32);
11517+ expect(uc.roundToNearestTick(87.318, mt )).toEqual(87.32);
1151211518 });
1151311519 it('A value of 87.325 should be rounded to 87.33', () => {
11514- expect(uc.roundToNearestTick(87.325, 1 )).toEqual(87.33);
11520+ expect(uc.roundToNearestTick(87.325, mt )).toEqual(87.33);
1151511521 });
1151611522 it('A value of 87.325 should be rounded to 87.32 (when using "roundDown" option)', () => {
11517- expect(uc.roundToNearestTick(87.325, 1 , true)).toEqual(87.32);
11523+ expect(uc.roundToNearestTick(87.325, mt , true)).toEqual(87.32);
1151811524 });
1151911525 });
1152011526 describe('For unit code "9" and with a tickIncrement of 1 (e.g. gold)', () => {
1152111527 let uc;
11528+ let mt;
1152211529 beforeEach(() => {
1152311530 uc = UnitCode.parse('9');
11531+ mt = uc.getMinimumTick(1);
1152411532 });
1152511533 it('A value of 1922.5 should be rounded to 1922.5', () => {
11526- expect(uc.roundToNearestTick(1922.5, 1 )).toEqual(1922.5);
11534+ expect(uc.roundToNearestTick(1922.5, mt )).toEqual(1922.5);
1152711535 });
1152811536 it('A value of 1922.6 should be rounded to 1922.6', () => {
11529- expect(uc.roundToNearestTick(1922.6, 1 )).toEqual(1922.6);
11537+ expect(uc.roundToNearestTick(1922.6, mt )).toEqual(1922.6);
1153011538 });
1153111539 it('A value of 1922.51 should be rounded to 1922.5', () => {
11532- expect(uc.roundToNearestTick(1922.51, 1 )).toEqual(1922.5);
11540+ expect(uc.roundToNearestTick(1922.51, mt )).toEqual(1922.5);
1153311541 });
1153411542 it('A value of 1922.59 should be rounded to 1922.6', () => {
11535- expect(uc.roundToNearestTick(1922.59, 1 )).toEqual(1922.6);
11543+ expect(uc.roundToNearestTick(1922.59, mt )).toEqual(1922.6);
1153611544 });
1153711545 it('A value of 1922.55 should be rounded to 1922.6', () => {
11538- expect(uc.roundToNearestTick(1922.55, 1 )).toEqual(1922.6);
11546+ expect(uc.roundToNearestTick(1922.55, mt )).toEqual(1922.6);
1153911547 });
1154011548 it('A value of 1922.55 should be rounded to 1922.5 (when using "roundDown" option)', () => {
11541- expect(uc.roundToNearestTick(1922.55, 1 , true)).toEqual(1922.5);
11549+ expect(uc.roundToNearestTick(1922.55, mt , true)).toEqual(1922.5);
1154211550 });
1154311551 });
1154411552 describe('For unit code "5" and with a tickIncrement of 1 (e.g. t-notes)', () => {
1154511553 let uc;
11554+ let mt;
1154611555 beforeEach(() => {
1154711556 uc = UnitCode.parse('5');
11557+ mt = uc.getMinimumTick(1);
1154811558 });
1154911559 it('A value of 110.328125 should be rounded to 110.328125', () => {
11550- expect(uc.roundToNearestTick(110.328125, 1 )).toEqual(110.328125);
11560+ expect(uc.roundToNearestTick(110.328125, mt )).toEqual(110.328125);
1155111561 });
1155211562 it('A value of 110.34375 should be rounded to 110.34375', () => {
11553- expect(uc.roundToNearestTick(110.34375, 1 )).toEqual(110.34375);
11563+ expect(uc.roundToNearestTick(110.34375, mt )).toEqual(110.34375);
1155411564 });
1155511565 it('A value of 110.328126 should be rounded to 110.328125', () => {
11556- expect(uc.roundToNearestTick(110.328126, 1 )).toEqual(110.328125);
11566+ expect(uc.roundToNearestTick(110.328126, mt )).toEqual(110.328125);
1155711567 });
1155811568 it('A value of 110.34374 should be rounded to 110.34375', () => {
11559- expect(uc.roundToNearestTick(110.34374, 1 )).toEqual(110.34375);
11569+ expect(uc.roundToNearestTick(110.34374, mt )).toEqual(110.34375);
1156011570 });
1156111571 it('A value of 110.34374 should be rounded to 110.328125 (when using "roundDown" option)', () => {
11562- expect(uc.roundToNearestTick(110.34374, 1 , true)).toEqual(110.328125);
11572+ expect(uc.roundToNearestTick(110.34374, mt , true)).toEqual(110.328125);
1156311573 });
1156411574 });
1156511575});
0 commit comments