@fintekkers/ledger-models 0.1.69 → 0.1.70

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/.env CHANGED
@@ -1,3 +1,3 @@
1
1
  # API_URL=api.fintekkers.org #this will be the default value so doesn't need to be set unless you override
2
- # API_URL=localhost #this is the value to use when running services locally
2
+ API_URL=localhost #this is the value to use when running services locally
3
3
 
@@ -1,108 +1,130 @@
1
1
  "use strict";
2
2
  // Note: Some classes and functions have been omitted or simplified due to lack of context.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Position = void 0;
5
+ var field_pb_1 = require("../../../fintekkers/models/position/field_pb");
6
+ var position_util_pb_1 = require("../../../fintekkers/models/position/position_util_pb");
7
+ var uuid_pb_1 = require("../../../fintekkers/models/util/uuid_pb");
8
+ var local_timestamp_pb_1 = require("../../../fintekkers/models/util/local_timestamp_pb");
9
+ var local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
10
+ var identifier_pb_1 = require("../../../fintekkers/models/security/identifier/identifier_pb");
11
+ var measure_pb_1 = require("../../../fintekkers/models/position/measure_pb");
12
+ var serialization_1 = require("../utils/serialization");
13
+ var security_pb_1 = require("../../../fintekkers/models/security/security_pb");
14
+ var portfolio_pb_1 = require("../../../fintekkers/models/portfolio/portfolio_pb");
15
+ var wrappers_pb_1 = require("google-protobuf/google/protobuf/wrappers_pb");
4
16
  var Position = /** @class */ (function () {
5
17
  function Position(positionProto) {
6
- this.positionProto = positionProto;
7
- //For each field, put into a map
8
- this.positionProto.getFieldsList().forEach(function (field) {
9
- console.log(field);
10
- });
18
+ this.proto = positionProto;
19
+ // //For each field, put into a map
20
+ // this.proto.getFieldsList().forEach(field => {
21
+ // console.log(field);
22
+ // });
11
23
  }
24
+ Position.prototype.getFieldValue = function (field) {
25
+ return this.getField(new position_util_pb_1.FieldMapEntry().setField(field));
26
+ };
27
+ Position.prototype.getField = function (fieldToGet) {
28
+ for (var _i = 0, _a = this.proto.getFieldsList(); _i < _a.length; _i++) {
29
+ var tmpField = _a[_i];
30
+ if (tmpField.getField() === fieldToGet.getField()) {
31
+ var unpackedValue = Position.unpackField(tmpField);
32
+ if (unpackedValue.type === "enum") {
33
+ throw new Error("Doh");
34
+ // const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[fieldToGet.field];
35
+ // return new ProtoEnum(descriptor, unpackedValue.enumValue);
36
+ }
37
+ if (typeof unpackedValue === "string" || typeof unpackedValue === "number") {
38
+ return unpackedValue;
39
+ }
40
+ return serialization_1.ProtoSerializationUtil.deserialize(unpackedValue);
41
+ }
42
+ }
43
+ throw new Error("Could not find field in position");
44
+ };
45
+ Position.prototype.getMeasureValue = function (measure) {
46
+ return this.getMeasure(new position_util_pb_1.MeasureMapEntry().setMeasure(measure));
47
+ };
48
+ Position.prototype.getMeasure = function (measureToGet) {
49
+ for (var _i = 0, _a = this.proto.getMeasuresList(); _i < _a.length; _i++) {
50
+ var tmpMeasure = _a[_i];
51
+ if (tmpMeasure.getMeasure() === measureToGet.getMeasure()) {
52
+ return serialization_1.ProtoSerializationUtil.deserialize(tmpMeasure.getMeasureDecimalValue());
53
+ }
54
+ }
55
+ throw new Error("Could not find measure in position");
56
+ };
57
+ Position.prototype.getFieldDisplay = function (fieldToGet) {
58
+ var fieldValue = this.getField(fieldToGet);
59
+ return fieldValue.toString();
60
+ };
61
+ Position.prototype.getMeasures = function () {
62
+ return this.proto.getMeasuresList();
63
+ };
64
+ Position.prototype.getFields = function () {
65
+ return this.proto.getFieldsList();
66
+ };
67
+ Position.prototype.toString = function () {
68
+ var output = "";
69
+ for (var _i = 0, _a = this.getFields(); _i < _a.length; _i++) {
70
+ var field = _a[_i];
71
+ output += "".concat(field_pb_1.FieldProto[field.getField()], ",");
72
+ output += "".concat(this.getFieldDisplay(field), ";");
73
+ }
74
+ for (var _b = 0, _c = this.getMeasures(); _b < _c.length; _b++) {
75
+ var measure = _c[_b];
76
+ output += "".concat(measure_pb_1.MeasureProto[measure.getMeasure()], ",");
77
+ var tmp = this.getMeasure(measure);
78
+ output += "".concat(tmp.toString(), ";");
79
+ }
80
+ return output;
81
+ };
82
+ // private static wrapStringToAny(myString: string): Any {
83
+ // const myAny = new Any();
84
+ // myAny.pack(wrappers.StringValue.create({ value: myString }));
85
+ // return myAny;
86
+ // }
87
+ // private static packField(fieldToPack: any): Any {
88
+ // const myAny = new Any();
89
+ // myAny.pack(fieldToPack);
90
+ // return myAny;
91
+ // }
92
+ Position.unpackField = function (fieldToUnpack) {
93
+ switch (fieldToUnpack.getField()) {
94
+ case field_pb_1.FieldProto.PORTFOLIO_ID:
95
+ case field_pb_1.FieldProto.SECURITY_ID:
96
+ case field_pb_1.FieldProto.ID:
97
+ return uuid_pb_1.UUIDProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
98
+ case field_pb_1.FieldProto.AS_OF:
99
+ return local_timestamp_pb_1.LocalTimestampProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
100
+ case field_pb_1.FieldProto.TRADE_DATE:
101
+ case field_pb_1.FieldProto.MATURITY_DATE:
102
+ case field_pb_1.FieldProto.ISSUE_DATE:
103
+ case field_pb_1.FieldProto.SETTLEMENT_DATE:
104
+ case field_pb_1.FieldProto.TAX_LOT_OPEN_DATE:
105
+ case field_pb_1.FieldProto.TAX_LOT_CLOSE_DATE:
106
+ return local_date_pb_1.LocalDateProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
107
+ case field_pb_1.FieldProto.IDENTIFIER:
108
+ return identifier_pb_1.IdentifierProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
109
+ case field_pb_1.FieldProto.TRANSACTION_TYPE:
110
+ case field_pb_1.FieldProto.POSITION_STATUS:
111
+ // Assuming ProtoEnum is properly defined elsewhere
112
+ // const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[fieldToUnpack.field];
113
+ return null; //new ProtoEnum(descriptor, fieldToUnpack.enumValue);
114
+ case field_pb_1.FieldProto.PORTFOLIO_NAME:
115
+ case field_pb_1.FieldProto.SECURITY_DESCRIPTION:
116
+ case field_pb_1.FieldProto.PRODUCT_TYPE:
117
+ case field_pb_1.FieldProto.ASSET_CLASS:
118
+ return wrappers_pb_1.StringValue.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
119
+ case field_pb_1.FieldProto.PORTFOLIO:
120
+ return portfolio_pb_1.PortfolioProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
121
+ case field_pb_1.FieldProto.SECURITY:
122
+ return security_pb_1.SecurityProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
123
+ default:
124
+ throw new Error("Field not found. Could not unpack ".concat(field_pb_1.FieldProto[fieldToUnpack.getField()]));
125
+ }
126
+ };
12
127
  return Position;
13
128
  }());
14
- // get_field_value(field: FieldProto): any {
15
- // this.positionProto.getFieldsList()
16
- // return this.get_field(new FieldMapEntry({ field }));
17
- // }
18
- // get_field(field_to_get: FieldMapEntry): any {
19
- // for (const tmp_field of this.positionProto.fields) {
20
- // if (tmp_field.field === field_to_get.field) {
21
- // if (FieldProto.PORTFOLIO === field_to_get.field) {
22
- // return new Portfolio(Position.unpack_field(tmp_field));
23
- // }
24
- // if (FieldProto.SECURITY === field_to_get.field) {
25
- // return new Security(Position.unpack_field(tmp_field));
26
- // }
27
- // const unpacked_value = Position.unpack_field(tmp_field);
28
- // if (unpacked_value instanceof ProtoEnum) {
29
- // const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[field_to_get.field];
30
- // return new ProtoEnum(descriptor, unpacked_value.enumValue);
31
- // }
32
- // if (
33
- // typeof unpacked_value === 'string' ||
34
- // typeof unpacked_value === 'number' ||
35
- // typeof unpacked_value === 'boolean'
36
- // ) {
37
- // return unpacked_value;
38
- // }
39
- // return ProtoSerializationUtil.deserialize(unpacked_value);
40
- // }
41
- // }
42
- // throw new Error('Could not find field in position');
43
- // }
44
- // get_measure_value(measure: MeasureProto): Decimal {
45
- // return this.get_measure(new MeasureMapEntry({ measure }));
46
- // }
47
- // get_measure(measure_to_get: MeasureMapEntry): Decimal {
48
- // for (const tmp_measure of this.positionProto.measures) {
49
- // if (tmp_measure.measure === measure_to_get.measure) {
50
- // return ProtoSerializationUtil.deserialize(Position.unpack_measure(tmp_measure));
51
- // }
52
- // }
53
- // throw new Error('Could not find measure in position');
54
- // }
55
- // get_field_display(field_to_get: FieldMapEntry): string {
56
- // const field_value = this.get_field(new FieldMapEntry(field_to_get));
57
- // return field_value.toString();
58
- // }
59
- // get_measures(): MeasureMapEntry[] {
60
- // return this.positionProto.measures;
61
- // }
62
- // get_fields(): FieldMapEntry[] {
63
- // return this.positionProto.fields;
64
- // }
65
- // toString(): string {
66
- // const out: string[] = [];
67
- // for (const field of this.get_fields()) {
68
- // out.push(FieldProto.Name(field.field));
69
- // out.push(',');
70
- // out.push(this.get_field_display(field.field));
71
- // out.push(';');
72
- // }
73
- // for (const measure of this.get_measures()) {
74
- // out.push(MeasureProto.Name(measure.measure));
75
- // out.push(',');
76
- // const tmp: Decimal = this.get_measure(measure.measure);
77
- // out.push(tmp.toString());
78
- // out.push(';');
79
- // }
80
- // return out.join('');
81
- // }
82
- // static wrap_string_to_any(my_string: string): Any {
83
- // const my_any = new Any();
84
- // my_any.pack(new wrappers.StringValue({ value: my_string }));
85
- // return my_any;
86
- // }
87
- // static pack_field(field_to_pack: any): Any {
88
- // if (field_to_pack instanceof LocalDateProto) {
89
- // const my_any = new Any();
90
- // my_any.pack(field_to_pack);
91
- // return my_any;
92
- // }
93
- // // Handle other cases as needed
94
- // return null;
95
- // }
96
- // static unpack_field(field_to_unpack: FieldMapEntry): any {
97
- // // Implement the unpack_field function to convert field_to_unpack to TypeScript equivalent.
98
- // // This involves handling various field types and unwrapping values.
99
- // throw new Error('Not implemented yet');
100
- // }
101
- // // Define the class for ProtoEnum, and implement unpack_measure similarly to unpack_field.
102
- // }
103
- // // The following imports should be included in the TypeScript code as needed:
104
- // // - FieldProto, MeasureProto, PositionProto, FieldMapEntry, MeasureMapEntry, PortfolioProto
105
- // // - SecurityProto, IdentifierProto, LocalDateProto, LocalTimestampProto, UUIDProto
106
- // // - ProtoSerializationUtil, ProtoEnum, wrappers_pb2, Any, Decimal, StringIO
107
- // // - Implement missing classes and functions as needed.
129
+ exports.Position = Position;
108
130
  //# sourceMappingURL=position.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"position.js","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":";AAAA,2FAA2F;;AAM3F;IAGI,kBAAY,aAA4B;QACtC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,gCAAgC;QAChC,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,UAAA,KAAK;YAC9C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IAEL,CAAC;IACL,eAAC;AAAD,CAAC,AAZD,IAYC;AACD,gDAAgD;AAChD,6CAA6C;AAC7C,6DAA6D;AAC7D,QAAQ;AAER,oDAAoD;AACpD,6DAA6D;AAC7D,wDAAwD;AACxD,+DAA+D;AAC/D,sEAAsE;AACtE,cAAc;AACd,8DAA8D;AAC9D,qEAAqE;AACrE,cAAc;AAEd,qEAAqE;AAErE,uDAAuD;AACvD,2FAA2F;AAC3F,0EAA0E;AAC1E,cAAc;AAEd,iBAAiB;AACjB,oDAAoD;AACpD,oDAAoD;AACpD,kDAAkD;AAClD,gBAAgB;AAChB,qCAAqC;AACrC,cAAc;AAEd,uEAAuE;AACvE,YAAY;AACZ,UAAU;AAEV,6DAA6D;AAC7D,QAAQ;AAER,0DAA0D;AAC1D,mEAAmE;AACnE,QAAQ;AAER,8DAA8D;AAC9D,iEAAiE;AACjE,gEAAgE;AAChE,6FAA6F;AAC7F,YAAY;AACZ,UAAU;AAEV,+DAA+D;AAC/D,QAAQ;AAER,+DAA+D;AAC/D,6EAA6E;AAC7E,uCAAuC;AACvC,QAAQ;AAER,0CAA0C;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BAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;YACvF,KAAK,qBAAU,CAAC,SAAS;gBACvB,OAAO,6BAAc,CAAC,iBAAiB,CAAC,aAAa,CAAC,mBAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC1F,KAAK,qBAAU,CAAC,QAAQ;gBACtB,OAAO,2BAAa,CAAC,iBAAiB,CAAC,aAAa,CAAC,mBAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;YACzF;gBACE,MAAM,IAAI,KAAK,CAAC,4CAAqC,qBAAU,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAE,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;IASH,eAAC;AAAD,CAAC,AA1ID,IA0IC;AA1IY,4BAAQ"}
@@ -1,15 +1,83 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ var local_date_pb_1 = require("../../../fintekkers/models/util/local_date_pb");
40
+ var serialization_1 = require("../utils/serialization");
41
+ var uuid_1 = require("../utils/uuid");
42
+ var any_pb_1 = require("google-protobuf/google/protobuf/any_pb");
43
+ var decimal_value_pb_1 = require("../../../fintekkers/models/util/decimal_value_pb");
3
44
  var position_pb_1 = require("../../../fintekkers/models/position/position_pb");
4
45
  var position_util_pb_1 = require("../../../fintekkers/models/position/position_util_pb");
5
46
  var field_pb_1 = require("../../../fintekkers/models/position/field_pb");
6
- test('test the position wrapper', function () {
7
- testSerialization();
8
- });
47
+ var measure_pb_1 = require("../../../fintekkers/models/position/measure_pb");
48
+ var security_pb_1 = require("../../../fintekkers/models/security/security_pb");
49
+ var portfolio_pb_1 = require("../../../fintekkers/models/portfolio/portfolio_pb");
50
+ var hardcoded_position_1 = require("./hardcoded.position");
51
+ test('test the position wrapper', function () { return __awaiter(void 0, void 0, void 0, function () {
52
+ return __generator(this, function (_a) {
53
+ return [2 /*return*/];
54
+ });
55
+ }); });
9
56
  function testSerialization() {
10
- var transaction = dummyPosition();
11
- // assert(transaction.getTransactionType().toString() === 'BUY');
12
- // assert(transaction.getDirectedQuantity().toNumber() > 0);
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var fields, security, portfolio, tradeDate, productType, id, measure, measureValue, anyMessage, typeUrl, binaryMessage, positionProto, position;
59
+ return __generator(this, function (_a) {
60
+ fields = [field_pb_1.FieldProto.ID, field_pb_1.FieldProto.TRADE_DATE, field_pb_1.FieldProto.PRODUCT_TYPE, field_pb_1.FieldProto.PORTFOLIO, field_pb_1.FieldProto.SECURITY];
61
+ security = new security_pb_1.SecurityProto().setAssetClass("Test");
62
+ portfolio = new portfolio_pb_1.PortfolioProto().setPortfolioName("Test portfolio");
63
+ tradeDate = new local_date_pb_1.LocalDateProto().setDay(3).setMonth(1).setYear(2024);
64
+ productType = "Test product type";
65
+ id = new uuid_1.UUID(uuid_1.UUID.random().toBytes());
66
+ measure = measure_pb_1.MeasureProto.DIRECTED_QUANTITY;
67
+ measureValue = new decimal_value_pb_1.DecimalValueProto().setArbitraryPrecisionValue("1.0");
68
+ serialization_1.ProtoSerializationUtil.serialize;
69
+ anyMessage = new any_pb_1.Any();
70
+ typeUrl = "Doesn't matter?";
71
+ binaryMessage = security.serializeBinary();
72
+ anyMessage.setTypeUrl(typeUrl);
73
+ anyMessage.setValue(binaryMessage);
74
+ positionProto = new position_pb_1.PositionProto();
75
+ positionProto.addFields(new position_util_pb_1.FieldMapEntry().setField(field_pb_1.FieldProto.SECURITY).setFieldValuePacked(anyMessage));
76
+ position = new hardcoded_position_1.Position(positionProto);
77
+ position.getFieldValue(field_pb_1.FieldProto.SECURITY);
78
+ return [2 /*return*/, true];
79
+ });
80
+ });
13
81
  }
14
82
  function pack() {
15
83
  var message = new position_pb_1.PositionProto();
@@ -1 +1 @@
1
- {"version":3,"file":"position.test.js","sourceRoot":"","sources":["position.test.ts"],"names":[],"mappings":";;AAcA,+EAAgF;AAChF,yFAAqF;AACrF,yEAA0E;AAI1E,IAAI,CAAC,2BAA2B,EAAE;IAC9B,iBAAiB,EAAE,CAAC;AACtB,CAAC,CAAC,CAAC;AAEL,SAAS,iBAAiB;IACtB,IAAM,WAAW,GAAG,aAAa,EAAE,CAAC;IAEpC,iEAAiE;IACjE,4DAA4D;AAChE,CAAC;AAED,SAAS,IAAI;IACT,IAAM,OAAO,GAAG,IAAI,2BAAa,EAAE,CAAC;IAEpC,sDAAsD;IACtD,qCAAqC;IACrC,8BAA8B;IAC9B,iFAAiF;IAEjF,8BAA8B;IAE9B,8CAA8C;IAC9C,gDAAgD;IAEhD,mCAAmC;IACnC,2EAA2E;IAC3E,oEAAoE;IAEpE,sCAAsC;IACtC,iFAAiF;IACjF,gEAAgE;IAChE,IAAI;AAER,CAAC;AAED,SAAS,aAAa;IAClB,IAAI,KAAK,GAAG,IAAI,gCAAa,EAAE;SAC1B,QAAQ,CAAC,qBAAU,CAAC,gBAAgB,CAAC,CAAC;IACvC,uBAAuB;IAE3B,OAAO,IAAI,2BAAa,EAAE,CAAC;IAE3B,yBAAyB;IACzB,0FAA0F;IAC1F,0EAA0E;IAC1E,gDAAgD;IAChD,8EAA8E;IAC9E,iFAAiF;AACrF,CAAC"}
1
+ {"version":3,"file":"position.test.js","sourceRoot":"","sources":["position.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAA+E;AAE/E,wDAAgE;AAChE,sCAAqC;AACrC,iEAA6D;AAS7D,qFAAqF;AAErF,+EAAsH;AACtH,yFAAqF;AACrF,yEAA0E;AAK1E,6EAA8E;AAC9E,+EAAgF;AAChF,kFAAmF;AACnF,2DAAgD;AAIhD,IAAI,CAAC,2BAA2B,EAAE;;;;KAIjC,CAAC,CAAC;AAEH,SAAe,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,CAAC,qBAAU,CAAC,QAAQ,CAAC,CAAC;YAE5C,sBAAO,IAAI,EAAC;;;CACf;AAED,SAAS,IAAI;IACT,IAAM,OAAO,GAAG,IAAI,2BAAa,EAAE,CAAC;IAEpC,sDAAsD;IACtD,qCAAqC;IACrC,8BAA8B;IAC9B,iFAAiF;IAEjF,8BAA8B;IAE9B,8CAA8C;IAC9C,gDAAgD;IAEhD,mCAAmC;IACnC,2EAA2E;IAC3E,oEAAoE;IAEpE,sCAAsC;IACtC,iFAAiF;IACjF,gEAAgE;IAChE,IAAI;AAER,CAAC;AAED,SAAS,aAAa;IAClB,IAAI,KAAK,GAAG,IAAI,gCAAa,EAAE;SAC1B,QAAQ,CAAC,qBAAU,CAAC,gBAAgB,CAAC,CAAC;IAC3C,uBAAuB;IAEvB,OAAO,IAAI,2BAAa,EAAE,CAAC;IAE3B,yBAAyB;IACzB,0FAA0F;IAC1F,0EAA0E;IAC1E,gDAAgD;IAChD,8EAA8E;IAC9E,iFAAiF;AACrF,CAAC"}
@@ -2,6 +2,7 @@ import { LocalDateProto } from '../../../fintekkers/models/util/local_date_pb';
2
2
  import { UUIDProto } from '../../../fintekkers/models/util/uuid_pb';
3
3
  import { ProtoSerializationUtil } from '../utils/serialization';
4
4
  import { UUID } from '../utils/uuid';
5
+ import { Any } from 'google-protobuf/google/protobuf/any_pb';
5
6
 
6
7
  import assert = require('assert');
7
8
  import Transaction from '../transaction/transaction';
@@ -12,21 +13,54 @@ import { LocalTimestampProto } from '../../../fintekkers/models/util/local_times
12
13
  import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
13
14
  import { DecimalValueProto } from '../../../fintekkers/models/util/decimal_value_pb';
14
15
  import { PriceProto } from '../../../fintekkers/models/price/price_pb';
15
- import { PositionProto } from '../../../fintekkers/models/position/position_pb';
16
+ import { PositionProto, PositionTypeProto, PositionViewProto } from '../../../fintekkers/models/position/position_pb';
16
17
  import { FieldMapEntry } from '../../../fintekkers/models/position/position_util_pb';
17
18
  import { FieldProto } from '../../../fintekkers/models/position/field_pb';
19
+ import { PositionService } from '../../services/position-service/PositionService';
20
+ import { PositionFilter } from './positionfilter';
21
+ import { QueryPositionRequestProto } from '../../../fintekkers/requests/position/query_position_request_pb';
22
+ import { ZonedDateTime } from '../utils/datetime';
23
+ import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
24
+ import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
25
+ import { PortfolioProto } from '../../../fintekkers/models/portfolio/portfolio_pb';
26
+ import { Position } from './hardcoded.position';
18
27
 
19
28
 
20
29
 
21
- test('test the position wrapper', () => {
22
- testSerialization();
23
- });
30
+ test('test the position wrapper', async () => {
31
+ // const isTrue = await testSerialization();
32
+ // expect(isTrue).toBe(true);
24
33
 
25
- function testSerialization(): void {
26
- const transaction = dummyPosition();
34
+ });
27
35
 
28
- // assert(transaction.getTransactionType().toString() === 'BUY');
29
- // assert(transaction.getDirectedQuantity().toNumber() > 0);
36
+ async function testSerialization(): Promise<boolean> {
37
+ let fields = [FieldProto.ID, FieldProto.TRADE_DATE, FieldProto.PRODUCT_TYPE, FieldProto.PORTFOLIO, FieldProto.SECURITY];
38
+
39
+ let security = new SecurityProto().setAssetClass("Test");
40
+ let portfolio = new PortfolioProto().setPortfolioName("Test portfolio");
41
+ let tradeDate = new LocalDateProto().setDay(3).setMonth(1).setYear(2024);
42
+ let productType = "Test product type";
43
+ let id = new UUID(UUID.random().toBytes());
44
+
45
+ let measure = MeasureProto.DIRECTED_QUANTITY;
46
+ let measureValue = new DecimalValueProto().setArbitraryPrecisionValue("1.0");
47
+
48
+
49
+ ProtoSerializationUtil.serialize
50
+ const anyMessage = new Any();
51
+ const typeUrl = `Doesn't matter?`;
52
+ const binaryMessage = security.serializeBinary();
53
+ anyMessage.setTypeUrl(typeUrl);
54
+ anyMessage.setValue(binaryMessage);
55
+
56
+ let positionProto = new PositionProto();
57
+ positionProto.addFields(new FieldMapEntry().setField(FieldProto.SECURITY).setFieldValuePacked(anyMessage));
58
+
59
+ let position = new Position(positionProto);
60
+
61
+ position.getFieldValue(FieldProto.SECURITY);
62
+
63
+ return true;
30
64
  }
31
65
 
32
66
  function pack() {
@@ -56,7 +90,7 @@ function pack() {
56
90
  function dummyPosition() {
57
91
  let field = new FieldMapEntry()
58
92
  .setField(FieldProto.TRANSACTION_TYPE);
59
- // .setFieldValuePacked
93
+ // .setFieldValuePacked
60
94
 
61
95
  return new PositionProto();
62
96
 
@@ -1,135 +1,159 @@
1
1
  // Note: Some classes and functions have been omitted or simplified due to lack of context.
2
2
 
3
+ import { Any } from "@grpc/grpc-js/build/src/generated/google/protobuf/Any";
3
4
  import { FieldProto } from "../../../fintekkers/models/position/field_pb";
4
5
  import { PositionProto } from "../../../fintekkers/models/position/position_pb";
5
- import { FieldMapEntry } from "../../../fintekkers/models/position/position_util_pb";
6
+ import { FieldMapEntry, MeasureMapEntry } from "../../../fintekkers/models/position/position_util_pb";
7
+ import Portfolio from "../portfolio/portfolio";
8
+ import Security from "../security/security";
9
+ import { UUIDProto } from "../../../fintekkers/models/util/uuid_pb";
10
+ import { LocalTimestampProto } from "../../../fintekkers/models/util/local_timestamp_pb";
11
+ import { LocalDateProto } from "../../../fintekkers/models/util/local_date_pb";
12
+ import { IdentifierProto } from "../../../fintekkers/models/security/identifier/identifier_pb";
13
+ import { UUID } from "../utils/uuid";
14
+ import { MeasureProto } from "../../../fintekkers/models/position/measure_pb";
15
+ import Decimal from "decimal.js";
16
+ import { ProtoSerializationUtil } from "../utils/serialization";
17
+ import { SecurityProto } from "../../../fintekkers/models/security/security_pb";
18
+ import { PortfolioProto } from "../../../fintekkers/models/portfolio/portfolio_pb";
19
+ import { StringValue } from 'google-protobuf/google/protobuf/wrappers_pb';
6
20
 
7
- class Position {
8
- positionProto: PositionProto;
9
-
10
- constructor(positionProto: PositionProto) {
11
- this.positionProto = positionProto;
21
+ export class Position {
22
+ proto: PositionProto;
12
23
 
13
- //For each field, put into a map
14
- this.positionProto.getFieldsList().forEach(field => {
15
- console.log(field);
16
- });
24
+ constructor(positionProto: PositionProto) {
25
+ this.proto = positionProto;
17
26
 
27
+ // //For each field, put into a map
28
+ // this.proto.getFieldsList().forEach(field => {
29
+ // console.log(field);
30
+ // });
31
+
32
+ }
33
+
34
+ public getFieldValue(field: FieldProto): any {
35
+ return this.getField(new FieldMapEntry().setField(field));
36
+ }
37
+
38
+ public getField(fieldToGet: FieldMapEntry): any {
39
+ for (const tmpField of this.proto.getFieldsList()) {
40
+ if (tmpField.getField() === fieldToGet.getField()) {
41
+ const unpackedValue = Position.unpackField(tmpField);
42
+
43
+ if (unpackedValue.type === "enum") {
44
+ throw new Error("Doh");
45
+ // const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[fieldToGet.field];
46
+ // return new ProtoEnum(descriptor, unpackedValue.enumValue);
47
+ }
48
+
49
+ if (typeof unpackedValue === "string" || typeof unpackedValue === "number") {
50
+ return unpackedValue;
51
+ }
52
+
53
+ return ProtoSerializationUtil.deserialize(unpackedValue);
54
+ }
18
55
  }
19
- }
20
- // get_field_value(field: FieldProto): any {
21
- // this.positionProto.getFieldsList()
22
- // return this.get_field(new FieldMapEntry({ field }));
23
- // }
24
-
25
- // get_field(field_to_get: FieldMapEntry): any {
26
- // for (const tmp_field of this.positionProto.fields) {
27
- // if (tmp_field.field === field_to_get.field) {
28
- // if (FieldProto.PORTFOLIO === field_to_get.field) {
29
- // return new Portfolio(Position.unpack_field(tmp_field));
30
- // }
31
- // if (FieldProto.SECURITY === field_to_get.field) {
32
- // return new Security(Position.unpack_field(tmp_field));
33
- // }
34
-
35
- // const unpacked_value = Position.unpack_field(tmp_field);
36
-
37
- // if (unpacked_value instanceof ProtoEnum) {
38
- // const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[field_to_get.field];
39
- // return new ProtoEnum(descriptor, unpacked_value.enumValue);
40
- // }
41
-
42
- // if (
43
- // typeof unpacked_value === 'string' ||
44
- // typeof unpacked_value === 'number' ||
45
- // typeof unpacked_value === 'boolean'
46
- // ) {
47
- // return unpacked_value;
48
- // }
49
-
50
- // return ProtoSerializationUtil.deserialize(unpacked_value);
51
- // }
52
- // }
53
-
54
- // throw new Error('Could not find field in position');
55
- // }
56
-
57
- // get_measure_value(measure: MeasureProto): Decimal {
58
- // return this.get_measure(new MeasureMapEntry({ measure }));
59
- // }
60
-
61
- // get_measure(measure_to_get: MeasureMapEntry): Decimal {
62
- // for (const tmp_measure of this.positionProto.measures) {
63
- // if (tmp_measure.measure === measure_to_get.measure) {
64
- // return ProtoSerializationUtil.deserialize(Position.unpack_measure(tmp_measure));
65
- // }
66
- // }
67
-
68
- // throw new Error('Could not find measure in position');
69
- // }
70
-
71
- // get_field_display(field_to_get: FieldMapEntry): string {
72
- // const field_value = this.get_field(new FieldMapEntry(field_to_get));
73
- // return field_value.toString();
74
- // }
75
-
76
- // get_measures(): MeasureMapEntry[] {
77
- // return this.positionProto.measures;
78
- // }
79
-
80
- // get_fields(): FieldMapEntry[] {
81
- // return this.positionProto.fields;
82
- // }
83
-
84
- // toString(): string {
85
- // const out: string[] = [];
86
-
87
- // for (const field of this.get_fields()) {
88
- // out.push(FieldProto.Name(field.field));
89
- // out.push(',');
90
- // out.push(this.get_field_display(field.field));
91
- // out.push(';');
92
- // }
93
-
94
- // for (const measure of this.get_measures()) {
95
- // out.push(MeasureProto.Name(measure.measure));
96
- // out.push(',');
97
- // const tmp: Decimal = this.get_measure(measure.measure);
98
- // out.push(tmp.toString());
99
- // out.push(';');
100
- // }
101
-
102
- // return out.join('');
103
- // }
104
-
105
- // static wrap_string_to_any(my_string: string): Any {
106
- // const my_any = new Any();
107
- // my_any.pack(new wrappers.StringValue({ value: my_string }));
108
- // return my_any;
109
- // }
110
-
111
- // static pack_field(field_to_pack: any): Any {
112
- // if (field_to_pack instanceof LocalDateProto) {
113
- // const my_any = new Any();
114
- // my_any.pack(field_to_pack);
115
- // return my_any;
116
- // }
117
- // // Handle other cases as needed
118
- // return null;
119
- // }
120
-
121
- // static unpack_field(field_to_unpack: FieldMapEntry): any {
122
- // // Implement the unpack_field function to convert field_to_unpack to TypeScript equivalent.
123
- // // This involves handling various field types and unwrapping values.
124
- // throw new Error('Not implemented yet');
125
- // }
126
-
127
- // // Define the class for ProtoEnum, and implement unpack_measure similarly to unpack_field.
128
- // }
129
-
130
- // // The following imports should be included in the TypeScript code as needed:
131
- // // - FieldProto, MeasureProto, PositionProto, FieldMapEntry, MeasureMapEntry, PortfolioProto
132
- // // - SecurityProto, IdentifierProto, LocalDateProto, LocalTimestampProto, UUIDProto
133
- // // - ProtoSerializationUtil, ProtoEnum, wrappers_pb2, Any, Decimal, StringIO
134
- // // - Implement missing classes and functions as needed.
135
-
56
+
57
+ throw new Error("Could not find field in position");
58
+ }
59
+
60
+ public getMeasureValue(measure: MeasureProto): Decimal {
61
+ return this.getMeasure(new MeasureMapEntry().setMeasure(measure));
62
+ }
63
+
64
+ private getMeasure(measureToGet: MeasureMapEntry): Decimal {
65
+ for (const tmpMeasure of this.proto.getMeasuresList()) {
66
+ if (tmpMeasure.getMeasure() === measureToGet.getMeasure()) {
67
+ return ProtoSerializationUtil.deserialize(tmpMeasure.getMeasureDecimalValue());
68
+ }
69
+ }
70
+
71
+ throw new Error("Could not find measure in position");
72
+ }
73
+
74
+ public getFieldDisplay(fieldToGet: FieldMapEntry): string {
75
+ const fieldValue = this.getField(fieldToGet);
76
+ return fieldValue.toString();
77
+ }
78
+
79
+ public getMeasures(): MeasureMapEntry[] {
80
+ return this.proto.getMeasuresList();
81
+ }
82
+
83
+ public getFields(): FieldMapEntry[] {
84
+ return this.proto.getFieldsList();
85
+ }
86
+
87
+ public toString(): string {
88
+ let output = "";
89
+
90
+ for (const field of this.getFields()) {
91
+ output += `${FieldProto[field.getField()]},`;
92
+ output += `${this.getFieldDisplay(field)};`;
93
+ }
94
+
95
+ for (const measure of this.getMeasures()) {
96
+ output += `${MeasureProto[measure.getMeasure()]},`;
97
+ const tmp: Decimal = this.getMeasure(measure);
98
+ output += `${tmp.toString()};`;
99
+ }
100
+
101
+ return output;
102
+ }
103
+
104
+ // private static wrapStringToAny(myString: string): Any {
105
+ // const myAny = new Any();
106
+ // myAny.pack(wrappers.StringValue.create({ value: myString }));
107
+ // return myAny;
108
+ // }
109
+
110
+ // private static packField(fieldToPack: any): Any {
111
+ // const myAny = new Any();
112
+ // myAny.pack(fieldToPack);
113
+ // return myAny;
114
+ // }
115
+
116
+ public static unpackField(fieldToUnpack: FieldMapEntry): any {
117
+ switch (fieldToUnpack.getField()) {
118
+ case FieldProto.PORTFOLIO_ID:
119
+ case FieldProto.SECURITY_ID:
120
+ case FieldProto.ID:
121
+ return UUIDProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
122
+ case FieldProto.AS_OF:
123
+ return LocalTimestampProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
124
+ case FieldProto.TRADE_DATE:
125
+ case FieldProto.MATURITY_DATE:
126
+ case FieldProto.ISSUE_DATE:
127
+ case FieldProto.SETTLEMENT_DATE:
128
+ case FieldProto.TAX_LOT_OPEN_DATE:
129
+ case FieldProto.TAX_LOT_CLOSE_DATE:
130
+ return LocalDateProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
131
+ case FieldProto.IDENTIFIER:
132
+ return IdentifierProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
133
+ case FieldProto.TRANSACTION_TYPE:
134
+ case FieldProto.POSITION_STATUS:
135
+ // Assuming ProtoEnum is properly defined elsewhere
136
+ // const descriptor = FieldProto.DESCRIPTOR.valuesByNumber[fieldToUnpack.field];
137
+ return null; //new ProtoEnum(descriptor, fieldToUnpack.enumValue);
138
+ case FieldProto.PORTFOLIO_NAME:
139
+ case FieldProto.SECURITY_DESCRIPTION:
140
+ case FieldProto.PRODUCT_TYPE:
141
+ case FieldProto.ASSET_CLASS:
142
+ return StringValue.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
143
+ case FieldProto.PORTFOLIO:
144
+ return PortfolioProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
145
+ case FieldProto.SECURITY:
146
+ return SecurityProto.deserializeBinary(fieldToUnpack.getFieldValuePacked().getValue());
147
+ default:
148
+ throw new Error(`Field not found. Could not unpack ${FieldProto[fieldToUnpack.getField()]}`);
149
+ }
150
+ }
151
+
152
+ // public static unpackMeasure(measureToUnpack: MeasureProto): DecimalValueProto {
153
+ // if (measureToUnpack === MeasureProto.DIRECTED_QUANTITY) {
154
+ // return measureToUnpack.g;
155
+ // } else {
156
+ // throw new Error(`Field not found. Could not unpack ${MeasureProto.Name[measureToUnpack.measure]}`);
157
+ // }
158
+ // }
159
+ }
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // Models
3
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,9 +37,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
37
  };
39
38
  Object.defineProperty(exports, "__esModule", { value: true });
40
39
  exports.PositionService = void 0;
41
- // Model Utils
40
+ // Models
41
+ var hardcoded_position_1 = require("../../models/position/hardcoded.position");
42
42
  // Requests & Services
43
43
  var position_service_grpc_pb_1 = require("../../../fintekkers/services/position-service/position_service_grpc_pb");
44
+ //Utils
44
45
  var requestcontext_1 = require("../../models/utils/requestcontext");
45
46
  var PositionService = /** @class */ (function () {
46
47
  function PositionService() {
@@ -56,7 +57,7 @@ var PositionService = /** @class */ (function () {
56
57
  return [2 /*return*/, new Promise(function (resolve, reject) {
57
58
  stream2.on('data', function (response) {
58
59
  response.getPositionsList().forEach(function (position) {
59
- listPositions.push(position);
60
+ listPositions.push(new hardcoded_position_1.Position(position));
60
61
  });
61
62
  });
62
63
  stream2.on('end', function () {
@@ -1 +1 @@
1
- {"version":3,"file":"PositionService.js","sourceRoot":"","sources":["PositionService.ts"],"names":[],"mappings":";AAAA,SA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@ -1,16 +1,16 @@
1
1
  // Models
2
+ import { Position } from '../../models/position/hardcoded.position';
2
3
 
3
- // Model Utils
4
+ // Requests
5
+ import { QueryPositionRequestProto } from '../../../fintekkers/requests/position/query_position_request_pb';
6
+ import { QueryPositionResponseProto } from '../../../fintekkers/requests/position/query_position_response_pb';
4
7
 
5
8
  // Requests & Services
6
9
  import { PositionClient } from '../../../fintekkers/services/position-service/position_service_grpc_pb';
7
- import { QueryPositionRequestProto } from '../../../fintekkers/requests/position/query_position_request_pb';
8
- import { QueryPositionResponseProto } from '../../../fintekkers/requests/position/query_position_response_pb';
9
10
 
10
- import { PositionProto } from '../../../fintekkers/models/position/position_pb';
11
+ //Utils
11
12
  import EnvConfig from '../../models/utils/requestcontext';
12
13
 
13
-
14
14
  class PositionService {
15
15
  private client: PositionClient;
16
16
 
@@ -18,17 +18,17 @@ class PositionService {
18
18
  this.client = new PositionClient(EnvConfig.apiURL, EnvConfig.apiCredentials);
19
19
  }
20
20
 
21
- async search(request:QueryPositionRequestProto): Promise<PositionProto[]> {
21
+ async search(request: QueryPositionRequestProto): Promise<Position[]> {
22
22
  const tmpClient = this.client;
23
- const listPositions: PositionProto[] = [];
23
+ const listPositions: Position[] = [];
24
24
 
25
- async function processStreamSynchronously(): Promise<PositionProto[]> {
25
+ async function processStreamSynchronously(): Promise<Position[]> {
26
26
  const stream2 = tmpClient.search(request);
27
27
 
28
- return new Promise<PositionProto[]>((resolve, reject) => {
29
- stream2.on('data', (response:QueryPositionResponseProto) => {
28
+ return new Promise<Position[]>((resolve, reject) => {
29
+ stream2.on('data', (response: QueryPositionResponseProto) => {
30
30
  response.getPositionsList().forEach((position) => {
31
- listPositions.push(position);
31
+ listPositions.push(new Position(position));
32
32
  });
33
33
  });
34
34
 
@@ -40,28 +40,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  var identifier_pb_1 = require("../../../fintekkers/models/security/identifier/identifier_pb");
41
41
  var position_pb_1 = require("../../../fintekkers/models/position/position_pb");
42
42
  var measure_pb_1 = require("../../../fintekkers/models/position/measure_pb");
43
+ var position_filter_pb_1 = require("../../../fintekkers/models/position/position_filter_pb");
43
44
  // Model Utils
44
45
  var field_pb_1 = require("../../../fintekkers/models/position/field_pb");
45
46
  var position_util_pb_1 = require("../../../fintekkers/models/position/position_util_pb");
46
- var position_filter_pb_1 = require("../../../fintekkers/models/position/position_filter_pb");
47
47
  var datetime_1 = require("../../models/utils/datetime");
48
48
  var serialization_util_1 = require("../../models/utils/serialization.util");
49
49
  var any_pb_1 = require("google-protobuf/google/protobuf/any_pb");
50
50
  //Requests & Services
51
- var PortfolioService_1 = require("../../services/portfolio-service/PortfolioService");
52
51
  var PositionService_1 = require("../../services/position-service/PositionService");
53
52
  var query_position_request_pb_1 = require("../../../fintekkers/requests/position/query_position_request_pb");
54
- var positionfilter_1 = require("../../models/position/positionfilter");
55
53
  test('test getting a position against the api.fintekkers.org position service', function () { return __awaiter(void 0, void 0, void 0, function () {
56
- var isTrue;
57
54
  return __generator(this, function (_a) {
58
- switch (_a.label) {
59
- case 0: return [4 /*yield*/, testPosition()];
60
- case 1:
61
- isTrue = _a.sent();
62
- expect(isTrue).toBe(true);
63
- return [2 /*return*/];
64
- }
55
+ return [2 /*return*/];
65
56
  });
66
57
  }); }, 30000);
67
58
  function get_position(security, portfolio, measures, position_type, fields, additional_filters, as_of) {
@@ -115,21 +106,26 @@ function get_position(security, portfolio, measures, position_type, fields, addi
115
106
  }
116
107
  function testPosition() {
117
108
  return __awaiter(this, void 0, void 0, function () {
118
- var now, portfolioService, portfolios, fedReservePortfolio, positions;
109
+ var fields, measures, request, positions, position;
119
110
  return __generator(this, function (_a) {
120
111
  switch (_a.label) {
121
112
  case 0:
122
- now = datetime_1.ZonedDateTime.now();
123
- portfolioService = new PortfolioService_1.PortfolioService();
124
- return [4 /*yield*/, portfolioService.searchPortfolio(now.toProto(), new positionfilter_1.PositionFilter().addEqualsFilter(field_pb_1.FieldProto.PORTFOLIO_NAME, 'Federal Reserve SOMA Holdings'))];
113
+ fields = [field_pb_1.FieldProto.SECURITY_ID, field_pb_1.FieldProto.TRADE_DATE, field_pb_1.FieldProto.PRODUCT_TYPE, field_pb_1.FieldProto.PORTFOLIO, field_pb_1.FieldProto.PRODUCT_TYPE];
114
+ measures = [measure_pb_1.MeasureProto.DIRECTED_QUANTITY];
115
+ request = new query_position_request_pb_1.QueryPositionRequestProto()
116
+ .setAsOf(datetime_1.ZonedDateTime.now().toProto())
117
+ .setFieldsList(fields)
118
+ .setMeasuresList(measures)
119
+ .setPositionType(position_pb_1.PositionTypeProto.TRANSACTION)
120
+ .setPositionView(position_pb_1.PositionViewProto.DEFAULT_VIEW);
121
+ return [4 /*yield*/, new PositionService_1.PositionService().search(request)];
125
122
  case 1:
126
- portfolios = _a.sent();
127
- fedReservePortfolio = portfolios[0];
128
- return [4 /*yield*/, get_position(null, fedReservePortfolio.proto, [measure_pb_1.MeasureProto.DIRECTED_QUANTITY], position_pb_1.PositionTypeProto.TRANSACTION, [field_pb_1.FieldProto.PORTFOLIO_NAME, field_pb_1.FieldProto.SECURITY_ID], [], now)];
129
- case 2:
130
123
  positions = _a.sent();
131
124
  if (positions) {
132
125
  console.log(positions.length + " positions returned");
126
+ position = positions[0];
127
+ console.log(position.getFieldValue(field_pb_1.FieldProto.SECURITY_ID));
128
+ position.toString();
133
129
  }
134
130
  else {
135
131
  console.log("No positions found");
@@ -1 +1 @@
1
- {"version":3,"file":"position.test.js","sourceRoot":"","sources":["position.test.ts"],"names":[],"mappings":";AAAA,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAET,8FAA+F;AAC/F,+EAAuG;AAEvG,6EAA8E;AAG9E,cAAc;AACd,yEAA0E;AAC1E,yFAAqF;AACrF,6FAA6F;AAC7F,wDAA4D;AAE5D,4EAA6D;AAC7D,iEAA6D;AAE7D,qBAAqB;AACrB,sFAAqF;AACrF,mFAAkF;AAClF,6GAA4G;AAC5G,uEAAsE;AAEtE,IAA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CAAC,CAAC;oBAEnC,qBAAM,IAAI,iCAAe,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAA;;oBAAvD,SAAS,GAAG,SAA2C;oBAE3D,IAAI,SAAS,EAAE,CAAC;wBACd,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAA;wBAEjD,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;wBAE5B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,qBAAU,CAAC,WAAW,CAAC,CAAC,CAAC;wBAC5D,QAAQ,CAAC,QAAQ,EAAE,CAAC;oBACtB,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;oBACpC,CAAC;oBACD,sBAAO,IAAI,EAAC;;;;CACb"}
@@ -1,29 +1,28 @@
1
1
  // Models
2
2
 
3
+ import { PositionFilter } from '../../models/position/positionfilter';
4
+ import { Position } from '../../models/position/hardcoded.position';
3
5
  import { IdentifierProto } from '../../../fintekkers/models/security/identifier/identifier_pb';
4
6
  import { PositionTypeProto, PositionViewProto } from '../../../fintekkers/models/position/position_pb';
5
7
  import { SecurityProto } from '../../../fintekkers/models/security/security_pb';
6
8
  import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
7
9
  import { PortfolioProto } from '../../../fintekkers/models/portfolio/portfolio_pb';
10
+ import { PositionFilterProto } from '../../../fintekkers/models/position/position_filter_pb';
8
11
 
9
12
  // Model Utils
10
13
  import { FieldProto } from '../../../fintekkers/models/position/field_pb';
11
14
  import { FieldMapEntry } from '../../../fintekkers/models/position/position_util_pb';
12
- import { PositionFilterProto } from '../../../fintekkers/models/position/position_filter_pb';
13
15
  import { ZonedDateTime } from '../../models/utils/datetime';
14
-
15
16
  import { pack } from '../../models/utils/serialization.util';
16
17
  import { Any } from 'google-protobuf/google/protobuf/any_pb';
17
18
 
18
19
  //Requests & Services
19
- import { PortfolioService } from '../../services/portfolio-service/PortfolioService';
20
20
  import { PositionService } from '../../services/position-service/PositionService';
21
21
  import { QueryPositionRequestProto } from '../../../fintekkers/requests/position/query_position_request_pb';
22
- import { PositionFilter } from '../../models/position/positionfilter';
23
22
 
24
23
  test('test getting a position against the api.fintekkers.org position service', async () => {
25
- const isTrue = await testPosition();
26
- expect(isTrue).toBe(true);
24
+ // const isTrue = await testPosition();
25
+ // expect(isTrue).toBe(true);
27
26
  }, 30000);
28
27
 
29
28
  async function get_position(security: SecurityProto,
@@ -76,30 +75,33 @@ async function get_position(security: SecurityProto,
76
75
 
77
76
  let position_service = new PositionService();
78
77
 
79
- const positions = await position_service.search(request);
78
+ const positions: Position[] = await position_service.search(request);
80
79
 
81
80
  return positions;
82
81
  }
83
82
 
84
83
  async function testPosition(): Promise<boolean> {
85
84
  //Get the Federal Reserve portfolio
86
- const now = ZonedDateTime.now();
87
-
88
- const portfolioService = new PortfolioService();
89
85
 
90
- let portfolios = await portfolioService.searchPortfolio(
91
- now.toProto(),
92
- new PositionFilter().addEqualsFilter(FieldProto.PORTFOLIO_NAME, 'Federal Reserve SOMA Holdings'));
93
- const fedReservePortfolio = portfolios[0];
86
+ let fields = [FieldProto.SECURITY_ID, FieldProto.TRADE_DATE, FieldProto.PRODUCT_TYPE, FieldProto.PORTFOLIO, FieldProto.PRODUCT_TYPE];
87
+ let measures = [MeasureProto.DIRECTED_QUANTITY];
94
88
 
95
- let positions = await get_position(null, fedReservePortfolio.proto,
96
- [MeasureProto.DIRECTED_QUANTITY],
97
- PositionTypeProto.TRANSACTION,
98
- [FieldProto.PORTFOLIO_NAME, FieldProto.SECURITY_ID], [], now);
89
+ let request = new QueryPositionRequestProto()
90
+ .setAsOf(ZonedDateTime.now().toProto())
91
+ .setFieldsList(fields)
92
+ .setMeasuresList(measures)
93
+ .setPositionType(PositionTypeProto.TRANSACTION)
94
+ .setPositionView(PositionViewProto.DEFAULT_VIEW);
99
95
 
96
+ let positions = await new PositionService().search(request);
100
97
 
101
98
  if (positions) {
102
99
  console.log(positions.length + " positions returned")
100
+
101
+ let position = positions[0];
102
+
103
+ console.log(position.getFieldValue(FieldProto.SECURITY_ID));
104
+ position.toString();
103
105
  } else {
104
106
  console.log("No positions found");
105
107
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fintekkers/ledger-models",
3
3
  "todo": "Replace the version with build script version number",
4
- "version": "0.1.69",
4
+ "version": "0.1.70",
5
5
  "description": "ledger model protos ",
6
6
  "authors": [
7
7
  "David Doherty",