diff --git a/docs/_coverpage.md b/docs/_coverpage.md index 76a0417..c2de608 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -1,4 +1,4 @@ -# Barchart Market Data SDK JavaScript 6.0.2 +# Barchart Market Data SDK JavaScript 6.0.3 > Inject real-time market data into your JavaScript applications diff --git a/example/browser/example.js b/example/browser/example.js index b313a38..eb07cf2 100644 --- a/example/browser/example.js +++ b/example/browser/example.js @@ -4903,7 +4903,7 @@ module.exports = (() => { this.pointValue = pointValue; /** - * @property {number} tickIncrement - The minimum price movement. + * @property {number} tickIncrement - The minimum price movement, expressed as an integer multiple of the number of the possible divisions within one unit. For example, the number of discrete divisions of a dollar is 100. If the tick increment is ten, that means quotes and trades can occur at $0.10, $0.20, $0.30, etc. * @public * @readonly */ @@ -5312,7 +5312,7 @@ module.exports = (() => { 'use strict'; return { - version: '6.0.2' + version: '6.0.3' }; })(); @@ -5567,6 +5567,8 @@ module.exports = (() => { })(); },{"@barchart/common-js/lang/Enum":48}],28:[function(require,module,exports){ +const assert = require('@barchart/common-js/lang/assert'), + is = require('@barchart/common-js/lang/is'); const Enum = require('@barchart/common-js/lang/Enum'); module.exports = (() => { 'use strict'; @@ -5723,6 +5725,40 @@ module.exports = (() => { getFractionDigits(special) { return special === true ? this._fractionDigitsSpecial : this._fractionDigits; } + + /** + * Determines the minimum price fluctuation. In other words, multiples + * of this value determine the set of valid quote and trade prices + * for an instrument. + * + * @public + * @param {Number} tickIncrement - Taken from a {@link Profile} instance. + * @returns {Number} + */ + getMinimumTick(tickIncrement) { + assert.argumentIsValid(tickIncrement, 'tickIncrement', is.integer, 'must be an integer'); + let discretePrice; + if (this.supportsFractions) { + discretePrice = 1 / this._fractionFactor; + } else { + discretePrice = 1 / Math.pow(10, this._decimalDigits); + } + return discretePrice * tickIncrement; + } + + /** + * Returns the change in value of a position when the instrument's price moves + * up by the minimum tick. + * + * @public + * @param {Number} tickIncrement - Taken from a {@link Profile} instance. + * @param {Number} pointValue - Taken from a {@link Profile} instance. + */ + getMinimumTickValue(tickIncrement, pointValue) { + assert.argumentIsValid(tickIncrement, 'tickIncrement', is.integer, 'must be an integer'); + assert.argumentIsValid(pointValue, 'pointValue', is.number, 'must be a number'); + return this.getMinimumTick(tickIncrement) * pointValue; + } toString() { return `[UnitCode (code=${this.code})]`; } @@ -5768,7 +5804,7 @@ module.exports = (() => { return UnitCode; })(); -},{"@barchart/common-js/lang/Enum":48}],29:[function(require,module,exports){ +},{"@barchart/common-js/lang/Enum":48,"@barchart/common-js/lang/assert":51,"@barchart/common-js/lang/is":52}],29:[function(require,module,exports){ const timezone = require('@barchart/common-js/lang/timezone'); module.exports = (() => { 'use strict'; diff --git a/lib/meta.js b/lib/meta.js index 9058a10..5eb1185 100644 --- a/lib/meta.js +++ b/lib/meta.js @@ -2,6 +2,6 @@ module.exports = (() => { 'use strict'; return { - version: '6.0.2' + version: '6.0.3' }; })(); \ No newline at end of file diff --git a/package.json b/package.json index 67d0d0d..ae4fda8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@barchart/marketdata-api-js", - "version": "6.0.2", + "version": "6.0.3", "description": "SDK for streaming market data from Barchart.com", "author": { "name": "Eero Pikat", diff --git a/test/dist/barchart-marketdata-api-tests-6.js b/test/dist/barchart-marketdata-api-tests-6.js index dfb1fe3..d206c77 100644 --- a/test/dist/barchart-marketdata-api-tests-6.js +++ b/test/dist/barchart-marketdata-api-tests-6.js @@ -578,7 +578,7 @@ module.exports = (() => { this.pointValue = pointValue; /** - * @property {number} tickIncrement - The minimum price movement. + * @property {number} tickIncrement - The minimum price movement, expressed as an integer multiple of the number of the possible divisions within one unit. For example, the number of discrete divisions of a dollar is 100. If the tick increment is ten, that means quotes and trades can occur at $0.10, $0.20, $0.30, etc. * @public * @readonly */ @@ -1036,6 +1036,8 @@ module.exports = (() => { })(); },{"@barchart/common-js/lang/Enum":34}],14:[function(require,module,exports){ +const assert = require('@barchart/common-js/lang/assert'), + is = require('@barchart/common-js/lang/is'); const Enum = require('@barchart/common-js/lang/Enum'); module.exports = (() => { 'use strict'; @@ -1192,6 +1194,40 @@ module.exports = (() => { getFractionDigits(special) { return special === true ? this._fractionDigitsSpecial : this._fractionDigits; } + + /** + * Determines the minimum price fluctuation. In other words, multiples + * of this value determine the set of valid quote and trade prices + * for an instrument. + * + * @public + * @param {Number} tickIncrement - Taken from a {@link Profile} instance. + * @returns {Number} + */ + getMinimumTick(tickIncrement) { + assert.argumentIsValid(tickIncrement, 'tickIncrement', is.integer, 'must be an integer'); + let discretePrice; + if (this.supportsFractions) { + discretePrice = 1 / this._fractionFactor; + } else { + discretePrice = 1 / Math.pow(10, this._decimalDigits); + } + return discretePrice * tickIncrement; + } + + /** + * Returns the change in value of a position when the instrument's price moves + * up by the minimum tick. + * + * @public + * @param {Number} tickIncrement - Taken from a {@link Profile} instance. + * @param {Number} pointValue - Taken from a {@link Profile} instance. + */ + getMinimumTickValue(tickIncrement, pointValue) { + assert.argumentIsValid(tickIncrement, 'tickIncrement', is.integer, 'must be an integer'); + assert.argumentIsValid(pointValue, 'pointValue', is.number, 'must be a number'); + return this.getMinimumTick(tickIncrement) * pointValue; + } toString() { return `[UnitCode (code=${this.code})]`; } @@ -1237,7 +1273,7 @@ module.exports = (() => { return UnitCode; })(); -},{"@barchart/common-js/lang/Enum":34}],15:[function(require,module,exports){ +},{"@barchart/common-js/lang/Enum":34,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":38}],15:[function(require,module,exports){ module.exports = (() => { 'use strict'; @@ -9797,6 +9833,68 @@ describe('When parsing a valid character as a unit code', () => { }); }); }); +describe('When calculating minimum ticks and minimum tick values', () => { + describe('For unit code "2" and with a tickIncrement of 2 and a pointValue of 50 (e.g. corn)', () => { + let uc; + beforeEach(() => { + uc = UnitCode.parse('2'); + }); + it('The minimum tick should be 0.25', () => { + expect(uc.getMinimumTick(2)).toEqual(0.25); + }); + it('The minimum tick value should be 12.50', () => { + expect(uc.getMinimumTickValue(2, 50)).toEqual(12.5); + }); + }); + describe('For unit code "A" and with a tickIncrement of 25 and a pointValue of 50 (e.g. e-mini)', () => { + let uc; + beforeEach(() => { + uc = UnitCode.parse('A'); + }); + it('The minimum tick should be 0.25', () => { + expect(uc.getMinimumTick(25)).toEqual(0.25); + }); + it('The minimum tick value should be 12.50', () => { + expect(uc.getMinimumTickValue(25, 50)).toEqual(12.5); + }); + }); + describe('For unit code "A" and with a tickIncrement of 1 and a pointValue of 1000 (e.g. crude)', () => { + let uc; + beforeEach(() => { + uc = UnitCode.parse('A'); + }); + it('The minimum tick should be 0.01', () => { + expect(uc.getMinimumTick(1)).toEqual(0.01); + }); + it('The minimum tick value should be 10', () => { + expect(uc.getMinimumTickValue(1, 1000)).toEqual(10); + }); + }); + describe('For unit code "9" and with a tickIncrement of 1 and a pointValue of 100 (e.g. gold)', () => { + let uc; + beforeEach(() => { + uc = UnitCode.parse('9'); + }); + it('The minimum tick should be 0.1', () => { + expect(uc.getMinimumTick(1)).toEqual(0.1); + }); + it('The minimum tick value should be 10', () => { + expect(uc.getMinimumTickValue(1, 100)).toEqual(10); + }); + }); + describe('For unit code "5" and with a tickIncrement of 1 and a pointValue of 1000 (e.g. t-notes)', () => { + let uc; + beforeEach(() => { + uc = UnitCode.parse('5'); + }); + it('The minimum tick should be 0.015625', () => { + expect(uc.getMinimumTick(1)).toEqual(0.015625); + }); + it('The minimum tick value should be 15.625', () => { + expect(uc.getMinimumTickValue(1, 1000)).toEqual(15.625); + }); + }); +}); },{"../../../../lib/utilities/data/UnitCode":14}],63:[function(require,module,exports){ const monthCodes = require('../../../../lib/utilities/data/monthCodes');