@barchart/portfolio-api-common 1.0.5 → 1.0.10

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.
@@ -62,9 +62,9 @@ module.exports = (() => {
62
62
  transaction.formatted = formatted;
63
63
 
64
64
  return transaction;
65
+ } else {
66
+ return formatted;
65
67
  }
66
-
67
- return formatted;
68
68
  });
69
69
  }
70
70
 
@@ -74,12 +74,18 @@ module.exports = (() => {
74
74
  }
75
75
 
76
76
  const getBasicTransaction = (t) => {
77
- return {
77
+ const basic = {
78
78
  date: t.date,
79
79
  type: t.type,
80
80
  sequence: t.sequence,
81
81
  instrument: t.instrument
82
82
  };
83
+
84
+ if (basic.instrument) {
85
+ delete basic.instrument.id;
86
+ }
87
+
88
+ return basic;
83
89
  };
84
90
 
85
91
  const formatters = new Map();
@@ -131,14 +137,14 @@ module.exports = (() => {
131
137
  fee: t.fee,
132
138
  total: t.quantity,
133
139
  rate: t.dividend.rate
134
- }
140
+ };
135
141
  });
136
142
 
137
143
  formatters.set(TransactionType.DISTRIBUTION_FUND, (t) => {
138
144
  return {
139
145
  shares: t.snapshot.open.subtract(t.quantity),
140
146
  fee: t.fee
141
- }
147
+ };
142
148
  });
143
149
 
144
150
  formatters.set(TransactionType.INCOME, (t) => {
@@ -28,12 +28,16 @@ module.exports = (() => {
28
28
  return this._schema;
29
29
  }
30
30
 
31
+ static get CREATE() {
32
+ return create;
33
+ }
34
+
31
35
  static get COMPLETE() {
32
36
  return complete;
33
37
  }
34
38
 
35
- static get SIMPLE() {
36
- return simple;
39
+ static get UPDATE() {
40
+ return update;
37
41
  }
38
42
 
39
43
  toString() {
@@ -60,14 +64,29 @@ module.exports = (() => {
60
64
  .schema
61
65
  );
62
66
 
63
- const simple = new PortfolioSchema(SchemaBuilder.withName('Simple')
67
+ const create = new PortfolioSchema(SchemaBuilder.withName('Create')
64
68
  .withField('user', DataType.STRING)
65
69
  .withField('portfolio', DataType.STRING)
66
70
  .withField('name', DataType.STRING)
67
71
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
72
+ .withField('dates.create', DataType.DAY)
73
+ .withField('dates.cash', DataType.DAY, true)
68
74
  .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
69
- .withField('legacy.warnings', DataType.NUMBER, true)
70
- .withField('legacy.drops', DataType.NUMBER, true)
75
+ .withField('defaults.reinvest', DataType.BOOLEAN, true)
76
+ .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
77
+ .withField('legacy.system', DataType.STRING, true)
78
+ .withField('legacy.user', DataType.STRING, true)
79
+ .withField('system.version', DataType.NUMBER, true)
80
+ .schema
81
+ );
82
+
83
+ const update = new PortfolioSchema(SchemaBuilder.withName('Update')
84
+ .withField('name', DataType.STRING)
85
+ .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
86
+ .withField('dates.cash', DataType.DAY, true)
87
+ .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
88
+ .withField('defaults.reinvest', DataType.BOOLEAN, true)
89
+ .withField('defaults.valuation', DataType.forEnum(ValuationType, 'ValuationType'))
71
90
  .schema
72
91
  );
73
92
 
@@ -31,10 +31,6 @@ module.exports = (() => {
31
31
  return complete;
32
32
  }
33
33
 
34
- static get SIMPLE() {
35
- return simple;
36
- }
37
-
38
34
  toString() {
39
35
  return '[PositionSchema]';
40
36
  }
@@ -72,25 +68,5 @@ module.exports = (() => {
72
68
  .schema
73
69
  );
74
70
 
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
71
  return PositionSchema;
96
72
  })();
@@ -30,22 +30,6 @@ module.exports = (() => {
30
30
  return complete;
31
31
  }
32
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
33
  toString() {
50
34
  return '[TransactionSchema]';
51
35
  }
@@ -91,58 +75,5 @@ module.exports = (() => {
91
75
  .schema
92
76
  );
93
77
 
94
- const simple = new TransactionSchema(SchemaBuilder.withName('Simple')
95
- .withField('sequence', DataType.NUMBER)
96
- .withField('date', DataType.DAY)
97
- .withField('description', DataType.STRING)
98
- .withField('amount', DataType.DECIMAL)
99
- .schema
100
- );
101
-
102
- const display = new TransactionSchema(SchemaBuilder.withName('Display')
103
- .withField('sequence', DataType.NUMBER)
104
- .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
105
- .withField('date', DataType.DAY)
106
- .withField('amount', DataType.DECIMAL)
107
- .withField('quantity', DataType.DECIMAL)
108
- .withField('fee', DataType.DECIMAL)
109
- .withField('snapshot.open', DataType.DECIMAL)
110
- .withField('trade.price', DataType.DECIMAL, true)
111
- .withField('dividend.rate', DataType.DECIMAL, true)
112
- .withField('dividend.amount', DataType.DECIMAL, true)
113
- .withField('charge.amount', DataType.DECIMAL, true)
114
- .withField('income.amount', DataType.DECIMAL, true)
115
- .withField('valuation.value', DataType.DECIMAL, true)
116
- .schema
117
- );
118
-
119
- const download = new TransactionSchema(SchemaBuilder.withName('Download')
120
- .withField('sequence', DataType.NUMBER)
121
- .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
122
- .withField('date', DataType.DAY)
123
- .withField('amount', DataType.DECIMAL)
124
- .withField('quantity', DataType.DECIMAL)
125
- .withField('fee', DataType.DECIMAL)
126
- .withField('snapshot.open', DataType.DECIMAL)
127
- .withField('trade.price', DataType.DECIMAL, true)
128
- .withField('dividend.rate', DataType.DECIMAL, true)
129
- .withField('dividend.amount', DataType.DECIMAL, true)
130
- .withField('charge.amount', DataType.DECIMAL, true)
131
- .withField('income.amount', DataType.DECIMAL, true)
132
- .withField('valuation.value', DataType.DECIMAL, true)
133
- .schema);
134
-
135
- const snapshot = new TransactionSchema(SchemaBuilder.withName('Snapshot')
136
- .withField('position', DataType.STRING)
137
- .withField('sequence', DataType.NUMBER)
138
- .withField('date', DataType.DAY)
139
- .withField('snapshot.open', DataType.DECIMAL)
140
- .withField('snapshot.gain', DataType.DECIMAL)
141
- .withField('snapshot.basis', DataType.DECIMAL)
142
- .withField('snapshot.income', DataType.DECIMAL)
143
- .withField('snapshot.value', DataType.DECIMAL)
144
- .schema
145
- );
146
-
147
78
  return TransactionSchema;
148
79
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.5",
3
+ "version": "1.0.10",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",