-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to override Profile.format with custom delegate
- Loading branch information
1 parent
e814b2f
commit d1b4b3c
Showing
7 changed files
with
244 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**New Features** | ||
|
||
* Added the `AssetClass` enumeration to describe instrument types (e.g. stocks, futures, options, etc). | ||
* Added the `Profile.asset` property which references an `AssetClass` item, assuming the asset class can be inferred from the instrument's symbol. | ||
* Added the `Profile.setPriceFormatterCustom` function which allows the consumer to specify their own price format function, completely overriding the default price formatting logic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
const Enum = require('@barchart/common-js/lang/Enum'); | ||
|
||
module.exports = (() => { | ||
'use strict'; | ||
|
||
/** | ||
* An enumeration for instrument types (e.g. stock, future, etc). | ||
* | ||
* @public | ||
* @exported | ||
* @extends {Enum} | ||
* @param {String} code | ||
* @param {String} description | ||
* @param {Number} id | ||
*/ | ||
class AssetClass extends Enum { | ||
constructor(code, description, id) { | ||
super(code, description); | ||
|
||
this._id = id; | ||
} | ||
|
||
/** | ||
* A unique numeric identifier assigned by Barchart. | ||
* | ||
* @public | ||
* @returns {Number} | ||
*/ | ||
get id() { | ||
return this._id; | ||
} | ||
|
||
toJSON() { | ||
return this._id; | ||
} | ||
|
||
/** | ||
* Converts the string-based identifier into an enumeration item. | ||
* | ||
* @public | ||
* @static | ||
* @param {String} code | ||
* @returns {AssetClass|null} | ||
*/ | ||
static parse(code) { | ||
return Enum.fromCode(UnitCode, code); | ||
} | ||
|
||
/** | ||
* Converts the numeric identifier into an enumeration item. | ||
* | ||
* @public | ||
* @static | ||
* @param {Number} id | ||
* @returns {AssetClass|null} | ||
*/ | ||
static fromId(id) { | ||
return Enum.getItems(AssetClass).find(x => x.id === id) || null; | ||
} | ||
|
||
/** | ||
* A stock. | ||
* | ||
* @public | ||
* @static | ||
* @returns {AssetClass} | ||
*/ | ||
static get STOCK() { | ||
return STOCK; | ||
} | ||
|
||
/** | ||
* A stock option. | ||
* | ||
* @public | ||
* @static | ||
* @returns {AssetClass} | ||
*/ | ||
static get STOCK_OPTION() { | ||
return STOCK_OPTION; | ||
} | ||
|
||
/** | ||
* A future. | ||
* | ||
* @public | ||
* @static | ||
* @returns {AssetClass} | ||
*/ | ||
static get FUTURE() { | ||
return FUTURE; | ||
} | ||
|
||
/** | ||
* A future option. | ||
* | ||
* @public | ||
* @static | ||
* @returns {AssetClass} | ||
*/ | ||
static get FUTURE_OPTION() { | ||
return FUTURE_OPTION; | ||
} | ||
|
||
/** | ||
* A foreign exchange instrument. | ||
* | ||
* @public | ||
* @static | ||
* @returns {AssetClass} | ||
*/ | ||
static get FOREX() { | ||
return FOREX; | ||
} | ||
|
||
toString() { | ||
return `[AssetClass (id=${this.id}, code=${this.code})]`; | ||
} | ||
} | ||
|
||
const STOCK = new AssetClass('STK', 'U.S. Equity', 1); | ||
const STOCK_OPTION = new AssetClass('STKOPT', 'Equity Option', 34); | ||
|
||
const FUTURE = new AssetClass('FUT', 'Future', 2); | ||
const FUTURE_OPTION = new AssetClass('FUTOPT', 'Future Option', 12); | ||
|
||
const FOREX = new AssetClass('FOREX', 'FOREX', 10); | ||
|
||
return AssetClass; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.