@barchart/portfolio-api-common 1.0.1
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.
- package/LICENSE +674 -0
- package/README.md +2 -0
- package/gulpfile.js +129 -0
- package/jsdoc.json +8 -0
- package/lib/data/CorporateActionType.js +36 -0
- package/lib/data/InstrumentType.js +83 -0
- package/lib/data/PositionSummaryFrame.js +72 -0
- package/lib/data/TransactionType.js +325 -0
- package/lib/data/ValuationType.js +60 -0
- package/lib/formatters/TransactionFormatter.js +37 -0
- package/lib/serialization/PortfolioSchema.js +75 -0
- package/lib/serialization/PositionSchema.js +96 -0
- package/lib/serialization/TransactionSchema.js +116 -0
- package/package.json +32 -0
- package/test/SpecRunner.js +1 -0
- package/test/SpecRunnner.html +19 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert');
|
|
2
|
+
|
|
3
|
+
const ValuationType = require('./../data/ValuationType');
|
|
4
|
+
|
|
5
|
+
module.exports = (() => {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Static utilities for formatting {@link Transaction} objects for
|
|
10
|
+
* display to humans.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
* @extends {Enum}
|
|
14
|
+
*/
|
|
15
|
+
class TransactionFormatter {
|
|
16
|
+
constructor(schema) {
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Formats transactions for display to humans.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @static
|
|
25
|
+
* @param {Array.<Transaction>} transactions
|
|
26
|
+
*/
|
|
27
|
+
static format(transactions) {
|
|
28
|
+
return [ ];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toString() {
|
|
32
|
+
return '[TransactionFormatter]';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return TransactionFormatter;
|
|
37
|
+
})();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
|
+
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
|
+
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
+
is = require('@barchart/common-js/lang/is'),
|
|
6
|
+
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder'),
|
|
7
|
+
Timezones = require('@barchart/common-js/lang/Timezones');
|
|
8
|
+
|
|
9
|
+
const ValuationType = require('./../data/ValuationType');
|
|
10
|
+
|
|
11
|
+
module.exports = (() => {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The schemas which can be used to represent a portfolio objects.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
* @extends {Enum}
|
|
19
|
+
*/
|
|
20
|
+
class PortfolioSchema extends Enum {
|
|
21
|
+
constructor(schema) {
|
|
22
|
+
super(schema.name, schema.name);
|
|
23
|
+
|
|
24
|
+
this._schema = schema;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get schema() {
|
|
28
|
+
return this._schema;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static get COMPLETE() {
|
|
32
|
+
return complete;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static get SIMPLE() {
|
|
36
|
+
return simple;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
toString() {
|
|
40
|
+
return '[PortfolioSchema]';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const complete = new PortfolioSchema(SchemaBuilder.withName('Complete')
|
|
45
|
+
.withField('user', DataType.STRING)
|
|
46
|
+
.withField('portfolio', DataType.STRING)
|
|
47
|
+
.withField('name', DataType.STRING)
|
|
48
|
+
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
|
|
49
|
+
.withField('dates.create', DataType.DAY)
|
|
50
|
+
.withField('dates.cash', DataType.DAY, true)
|
|
51
|
+
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
|
|
52
|
+
.withField('defaults.reinvest', DataType.BOOLEAN, true)
|
|
53
|
+
.withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
|
|
54
|
+
.withField('legacy.system', DataType.STRING, true)
|
|
55
|
+
.withField('legacy.user', DataType.STRING, true)
|
|
56
|
+
.withField('legacy.portfolio', DataType.STRING, true)
|
|
57
|
+
.withField('legacy.warnings', DataType.NUMBER, true)
|
|
58
|
+
.withField('legacy.drops', DataType.NUMBER, true)
|
|
59
|
+
.withField('system.version', DataType.NUMBER, true)
|
|
60
|
+
.schema
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const simple = new PortfolioSchema(SchemaBuilder.withName('Simple')
|
|
64
|
+
.withField('user', DataType.STRING)
|
|
65
|
+
.withField('portfolio', DataType.STRING)
|
|
66
|
+
.withField('name', DataType.STRING)
|
|
67
|
+
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
|
|
68
|
+
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
|
|
69
|
+
.withField('legacy.warnings', DataType.NUMBER, true)
|
|
70
|
+
.withField('legacy.drops', DataType.NUMBER, true)
|
|
71
|
+
.schema
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return PortfolioSchema;
|
|
75
|
+
})();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
|
+
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
|
+
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
+
is = require('@barchart/common-js/lang/is'),
|
|
6
|
+
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
|
|
7
|
+
|
|
8
|
+
const ValuationType = require('./../data/ValuationType');
|
|
9
|
+
|
|
10
|
+
module.exports = (() => {
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The schemas which can be used to represent a position objects.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
* @extends {Enum}
|
|
18
|
+
*/
|
|
19
|
+
class PositionSchema extends Enum {
|
|
20
|
+
constructor(schema) {
|
|
21
|
+
super(schema.name, schema.name);
|
|
22
|
+
|
|
23
|
+
this._schema = schema;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get schema() {
|
|
27
|
+
return this._schema;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static get COMPLETE() {
|
|
31
|
+
return complete;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static get SIMPLE() {
|
|
35
|
+
return simple;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toString() {
|
|
39
|
+
return '[PositionSchema]';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const complete = new PositionSchema(SchemaBuilder.withName('Complete')
|
|
44
|
+
.withField('user', DataType.STRING)
|
|
45
|
+
.withField('portfolio', DataType.STRING)
|
|
46
|
+
.withField('sequence', DataType.NUMBER)
|
|
47
|
+
.withField('instrument.id', DataType.STRING)
|
|
48
|
+
.withField('instrument.name', DataType.STRING)
|
|
49
|
+
.withField('instrument.type', DataType.STRING)
|
|
50
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
51
|
+
.withField('instrument.delist', DataType.DAY, true)
|
|
52
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
53
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
54
|
+
.withField('position', DataType.STRING)
|
|
55
|
+
.withField('open', DataType.BOOLEAN, true)
|
|
56
|
+
.withField('transaction', DataType.NUMBER)
|
|
57
|
+
.withField('valuation', DataType.forEnum(ValuationType, 'ValuationType'))
|
|
58
|
+
.withField('reinvest', DataType.BOOLEAN)
|
|
59
|
+
.withField('snapshot.date', DataType.DAY)
|
|
60
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
61
|
+
.withField('snapshot.buys', DataType.DECIMAL)
|
|
62
|
+
.withField('snapshot.sells', DataType.DECIMAL)
|
|
63
|
+
.withField('snapshot.gain', DataType.DECIMAL)
|
|
64
|
+
.withField('snapshot.basis', DataType.DECIMAL)
|
|
65
|
+
.withField('snapshot.income', DataType.DECIMAL)
|
|
66
|
+
.withField('snapshot.value', DataType.DECIMAL)
|
|
67
|
+
.withField('legacy.system', DataType.STRING, true)
|
|
68
|
+
.withField('legacy.user', DataType.STRING, true)
|
|
69
|
+
.withField('legacy.portfolio', DataType.STRING, true)
|
|
70
|
+
.withField('legacy.position', DataType.STRING, true)
|
|
71
|
+
.withField('system.version', DataType.NUMBER, true)
|
|
72
|
+
.schema
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const simple = new PositionSchema(SchemaBuilder.withName('Simple')
|
|
76
|
+
.withField('position', DataType.STRING)
|
|
77
|
+
.withField('instrument.id', DataType.STRING)
|
|
78
|
+
.withField('instrument.name', DataType.STRING)
|
|
79
|
+
.withField('instrument.type', DataType.STRING)
|
|
80
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
81
|
+
.withField('instrument.delist', DataType.DAY, true)
|
|
82
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
83
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
84
|
+
.withField('snapshot.date', DataType.DAY)
|
|
85
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
86
|
+
.withField('snapshot.buys', DataType.DECIMAL)
|
|
87
|
+
.withField('snapshot.sells', DataType.DECIMAL)
|
|
88
|
+
.withField('snapshot.gain', DataType.DECIMAL)
|
|
89
|
+
.withField('snapshot.basis', DataType.DECIMAL)
|
|
90
|
+
.withField('snapshot.income', DataType.DECIMAL)
|
|
91
|
+
.withField('snapshot.value', DataType.DECIMAL)
|
|
92
|
+
.schema
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return PositionSchema;
|
|
96
|
+
})();
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
|
+
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
|
+
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
+
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
|
|
6
|
+
|
|
7
|
+
const TransactionType = require('./../data/TransactionType');
|
|
8
|
+
|
|
9
|
+
module.exports = (() => {
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The schemas which can be used to represent a transaction objects.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
* @extends {Enum}
|
|
17
|
+
*/
|
|
18
|
+
class TransactionSchema extends Enum {
|
|
19
|
+
constructor(schema) {
|
|
20
|
+
super(schema.name, schema.name);
|
|
21
|
+
|
|
22
|
+
this._schema = schema;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get schema() {
|
|
26
|
+
return this._schema;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static get COMPLETE() {
|
|
30
|
+
return complete;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static get SIMPLE() {
|
|
34
|
+
return simple;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static get DISPLAY() {
|
|
38
|
+
return display;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static get DOWNLOAD() {
|
|
42
|
+
return download;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static get SNAPSHOT() {
|
|
46
|
+
return snapshot;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toString() {
|
|
50
|
+
return '[TransactionSchema]';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const complete = new TransactionSchema(SchemaBuilder.withName('Complete')
|
|
55
|
+
.withField('sequence', DataType.NUMBER)
|
|
56
|
+
.withField('date', DataType.DAY)
|
|
57
|
+
.withField('description', DataType.STRING)
|
|
58
|
+
.withField('amount', DataType.DECIMAL)
|
|
59
|
+
.schema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const simple = new TransactionSchema(SchemaBuilder.withName('Simple')
|
|
63
|
+
.withField('sequence', DataType.NUMBER)
|
|
64
|
+
.withField('date', DataType.DAY)
|
|
65
|
+
.withField('description', DataType.STRING)
|
|
66
|
+
.withField('amount', DataType.DECIMAL)
|
|
67
|
+
.schema
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const display = new TransactionSchema(SchemaBuilder.withName('Display')
|
|
71
|
+
.withField('sequence', DataType.NUMBER)
|
|
72
|
+
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
73
|
+
.withField('date', DataType.DAY)
|
|
74
|
+
.withField('amount', DataType.DECIMAL)
|
|
75
|
+
.withField('quantity', DataType.DECIMAL)
|
|
76
|
+
.withField('fee', DataType.DECIMAL)
|
|
77
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
78
|
+
.withField('trade.price', DataType.DECIMAL, true)
|
|
79
|
+
.withField('dividend.rate', DataType.DECIMAL, true)
|
|
80
|
+
.withField('dividend.amount', DataType.DECIMAL, true)
|
|
81
|
+
.withField('charge.amount', DataType.DECIMAL, true)
|
|
82
|
+
.withField('income.amount', DataType.DECIMAL, true)
|
|
83
|
+
.withField('valuation.value', DataType.DECIMAL, true)
|
|
84
|
+
.schema
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const download = new TransactionSchema(SchemaBuilder.withName('Download')
|
|
88
|
+
.withField('sequence', DataType.NUMBER)
|
|
89
|
+
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
90
|
+
.withField('date', DataType.DAY)
|
|
91
|
+
.withField('amount', DataType.DECIMAL)
|
|
92
|
+
.withField('quantity', DataType.DECIMAL)
|
|
93
|
+
.withField('fee', DataType.DECIMAL)
|
|
94
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
95
|
+
.withField('trade.price', DataType.DECIMAL, true)
|
|
96
|
+
.withField('dividend.rate', DataType.DECIMAL, true)
|
|
97
|
+
.withField('dividend.amount', DataType.DECIMAL, true)
|
|
98
|
+
.withField('charge.amount', DataType.DECIMAL, true)
|
|
99
|
+
.withField('income.amount', DataType.DECIMAL, true)
|
|
100
|
+
.withField('valuation.value', DataType.DECIMAL, true)
|
|
101
|
+
.schema);
|
|
102
|
+
|
|
103
|
+
const snapshot = new TransactionSchema(SchemaBuilder.withName('Snapshot')
|
|
104
|
+
.withField('position', DataType.STRING)
|
|
105
|
+
.withField('sequence', DataType.NUMBER)
|
|
106
|
+
.withField('date', DataType.DAY)
|
|
107
|
+
.withField('snapshot.open', DataType.DECIMAL)
|
|
108
|
+
.withField('snapshot.gain', DataType.DECIMAL)
|
|
109
|
+
.withField('snapshot.basis', DataType.DECIMAL)
|
|
110
|
+
.withField('snapshot.income', DataType.DECIMAL)
|
|
111
|
+
.withField('snapshot.value', DataType.DECIMAL)
|
|
112
|
+
.schema
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return TransactionSchema;
|
|
116
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@barchart/portfolio-api-common",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Common classes used by the Portfolio system",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Bryan Ingle",
|
|
7
|
+
"email": "bryan.ingle@barchart.com",
|
|
8
|
+
"url": "http://www.barchart.com"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@barchart/common-js": "3.2.35"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"babel-core": "^6.26.0",
|
|
16
|
+
"babel-preset-es2015": "^6.24.1",
|
|
17
|
+
"browserify": "^14.5.0",
|
|
18
|
+
"git-get-status": "^1.0.5",
|
|
19
|
+
"glob": "^6.0.1",
|
|
20
|
+
"gulp": "~3.9.0",
|
|
21
|
+
"gulp-bump": "~1.0.0",
|
|
22
|
+
"gulp-git": "~1.6.0",
|
|
23
|
+
"gulp-jasmine": "^2.2.1",
|
|
24
|
+
"gulp-jshint": "~1.11.2",
|
|
25
|
+
"gulp-util": "^3.0.7",
|
|
26
|
+
"jsdoc": "^3.5.5",
|
|
27
|
+
"run-sequence": "~1.1.4",
|
|
28
|
+
"vinyl-buffer": "^1.0.0",
|
|
29
|
+
"vinyl-source-stream": "^1.1.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "GPL-3.0"
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({},{},[]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Jasmine Spec Runner</title>
|
|
6
|
+
|
|
7
|
+
<link rel="shortcut icon" type="image/png" href="../node_modules/jasmine-core/images/jasmine_favicon.png">
|
|
8
|
+
<link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
|
|
9
|
+
|
|
10
|
+
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
|
|
11
|
+
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
|
|
12
|
+
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
|
13
|
+
|
|
14
|
+
<script src="./SpecRunner.js"></script>
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|