@quantform/core 0.7.22 → 0.7.25

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.
Files changed (195) hide show
  1. package/lib/app.d.ts +12 -0
  2. package/lib/app.d.ts.map +1 -0
  3. package/lib/app.js +35 -0
  4. package/lib/cli/build.d.ts.map +1 -1
  5. package/lib/cli/build.js +8 -18
  6. package/lib/cli/index.js +3 -12
  7. package/lib/cli/internal/script.d.ts +1 -1
  8. package/lib/cli/internal/script.d.ts.map +1 -1
  9. package/lib/cli/internal/script.js +8 -28
  10. package/lib/cli/live.js +10 -22
  11. package/lib/cli/paper.js +10 -22
  12. package/lib/cli/replay.d.ts.map +1 -1
  13. package/lib/cli/replay.js +15 -26
  14. package/lib/index.d.ts +1 -6
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +1 -6
  17. package/lib/make-test-module.d.ts +1 -6
  18. package/lib/make-test-module.d.ts.map +1 -1
  19. package/lib/make-test-module.js +19 -30
  20. package/lib/module.d.ts.map +1 -1
  21. package/lib/module.js +9 -24
  22. package/lib/module.spec.js +8 -17
  23. package/lib/replay/use-replay-options.d.ts +5 -4
  24. package/lib/replay/use-replay-options.d.ts.map +1 -1
  25. package/lib/replay/use-replay-options.js +5 -1
  26. package/lib/replay/use-replay-scheduler.d.ts +7 -6
  27. package/lib/replay/use-replay-scheduler.d.ts.map +1 -1
  28. package/lib/replay/use-replay-scheduler.js +64 -70
  29. package/lib/replay/use-replay-storage-buffer.d.ts +3 -2
  30. package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -1
  31. package/lib/replay/use-replay-storage-buffer.js +12 -23
  32. package/lib/replay/use-replay-storage-cursor.d.ts +9 -8
  33. package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -1
  34. package/lib/replay/use-replay-storage-cursor.js +17 -25
  35. package/lib/replay/use-replay-storage.d.ts +5 -4
  36. package/lib/replay/use-replay-storage.d.ts.map +1 -1
  37. package/lib/replay/use-replay-storage.js +32 -39
  38. package/lib/session/use-session-storage.d.ts +1 -1
  39. package/lib/session/use-session-storage.d.ts.map +1 -1
  40. package/lib/session/use-session-storage.js +8 -5
  41. package/lib/shared/environment.js +1 -1
  42. package/lib/shared/index.d.ts +0 -1
  43. package/lib/shared/index.d.ts.map +1 -1
  44. package/lib/shared/index.js +0 -1
  45. package/lib/simulator/use-simulator.spec.js +17 -30
  46. package/lib/storage/in-memory/in-memory-storage.d.ts.map +1 -1
  47. package/lib/storage/in-memory/in-memory-storage.factory.js +2 -2
  48. package/lib/storage/in-memory/in-memory-storage.js +56 -55
  49. package/lib/storage/in-memory/in-memory-storage.spec.js +90 -100
  50. package/lib/storage/storage.d.ts +9 -8
  51. package/lib/storage/storage.d.ts.map +1 -1
  52. package/lib/storage/storage.js +8 -2
  53. package/lib/storage/use-cache.d.ts +1 -1
  54. package/lib/storage/use-cache.d.ts.map +1 -1
  55. package/lib/storage/use-cache.js +5 -5
  56. package/lib/storage/use-cache.spec.js +14 -25
  57. package/lib/storage/use-storage.d.ts +1 -1
  58. package/lib/storage/use-storage.d.ts.map +1 -1
  59. package/lib/storage/use-storage.js +9 -6
  60. package/lib/use-execution-mode.js +2 -2
  61. package/lib/use-hash.spec.js +3 -6
  62. package/lib/use-logger.d.ts +1 -1
  63. package/lib/use-logger.d.ts.map +1 -1
  64. package/lib/use-logger.js +10 -7
  65. package/lib/use-memo.spec.js +14 -25
  66. package/lib/use-socket.d.ts +3 -2
  67. package/lib/use-socket.d.ts.map +1 -1
  68. package/lib/use-socket.js +2 -2
  69. package/lib/use-timestamp.d.ts +14 -1
  70. package/lib/use-timestamp.d.ts.map +1 -1
  71. package/lib/use-timestamp.js +30 -3
  72. package/lib/with-request.d.ts +2 -1
  73. package/lib/with-request.d.ts.map +1 -1
  74. package/lib/with-request.js +4 -13
  75. package/package.json +6 -10
  76. package/src/app.ts +52 -0
  77. package/src/cli/build.ts +11 -6
  78. package/src/cli/internal/script.ts +25 -54
  79. package/src/cli/replay.ts +13 -2
  80. package/src/index.ts +1 -6
  81. package/src/make-test-module.ts +13 -21
  82. package/src/module.ts +0 -3
  83. package/src/replay/use-replay-options.ts +7 -3
  84. package/src/replay/use-replay-scheduler.ts +75 -67
  85. package/src/replay/use-replay-storage-buffer.ts +2 -1
  86. package/src/replay/use-replay-storage-cursor.ts +33 -28
  87. package/src/replay/use-replay-storage.ts +36 -27
  88. package/src/session/use-session-storage.ts +7 -5
  89. package/src/shared/index.ts +0 -1
  90. package/src/storage/in-memory/in-memory-storage.spec.ts +55 -54
  91. package/src/storage/in-memory/in-memory-storage.ts +24 -7
  92. package/src/storage/storage.ts +16 -7
  93. package/src/storage/use-cache.ts +4 -4
  94. package/src/storage/use-storage.ts +8 -6
  95. package/src/use-hash.spec.ts +3 -6
  96. package/src/use-logger.ts +9 -6
  97. package/src/use-socket.ts +5 -5
  98. package/src/use-timestamp.ts +41 -3
  99. package/src/with-request.ts +3 -3
  100. package/lib/asset/asset.d.ts +0 -41
  101. package/lib/asset/asset.d.ts.map +0 -1
  102. package/lib/asset/asset.js +0 -76
  103. package/lib/asset/asset.spec.d.ts +0 -2
  104. package/lib/asset/asset.spec.d.ts.map +0 -1
  105. package/lib/asset/asset.spec.js +0 -54
  106. package/lib/asset/index.d.ts +0 -2
  107. package/lib/asset/index.d.ts.map +0 -1
  108. package/lib/asset/index.js +0 -17
  109. package/lib/component/distinct-until-timesamp-changed.d.ts +0 -5
  110. package/lib/component/distinct-until-timesamp-changed.d.ts.map +0 -1
  111. package/lib/component/distinct-until-timesamp-changed.js +0 -9
  112. package/lib/component/error.d.ts +0 -17
  113. package/lib/component/error.d.ts.map +0 -1
  114. package/lib/component/error.js +0 -33
  115. package/lib/component/index.d.ts +0 -8
  116. package/lib/component/index.d.ts.map +0 -1
  117. package/lib/component/index.js +0 -23
  118. package/lib/component/ohlc-operator.d.ts +0 -11
  119. package/lib/component/ohlc-operator.d.ts.map +0 -1
  120. package/lib/component/ohlc-operator.js +0 -69
  121. package/lib/component/ohlc-operator.spec.d.ts +0 -2
  122. package/lib/component/ohlc-operator.spec.d.ts.map +0 -1
  123. package/lib/component/ohlc-operator.spec.js +0 -110
  124. package/lib/component/ohlc.d.ts +0 -12
  125. package/lib/component/ohlc.d.ts.map +0 -1
  126. package/lib/component/ohlc.js +0 -20
  127. package/lib/component/ohlc.spec.d.ts +0 -2
  128. package/lib/component/ohlc.spec.d.ts.map +0 -1
  129. package/lib/component/ohlc.spec.js +0 -25
  130. package/lib/component/timeframe.d.ts +0 -15
  131. package/lib/component/timeframe.d.ts.map +0 -1
  132. package/lib/component/timeframe.js +0 -21
  133. package/lib/core.d.ts +0 -3
  134. package/lib/core.d.ts.map +0 -1
  135. package/lib/core.js +0 -17
  136. package/lib/instrument/commission/commission.d.ts +0 -16
  137. package/lib/instrument/commission/commission.d.ts.map +0 -1
  138. package/lib/instrument/commission/commission.js +0 -28
  139. package/lib/instrument/commission/commission.spec.d.ts +0 -2
  140. package/lib/instrument/commission/commission.spec.d.ts.map +0 -1
  141. package/lib/instrument/commission/commission.spec.js +0 -30
  142. package/lib/instrument/index.d.ts +0 -3
  143. package/lib/instrument/index.d.ts.map +0 -1
  144. package/lib/instrument/index.js +0 -18
  145. package/lib/instrument/instrument.d.ts +0 -28
  146. package/lib/instrument/instrument.d.ts.map +0 -1
  147. package/lib/instrument/instrument.js +0 -53
  148. package/lib/instrument/instrument.spec.d.ts +0 -2
  149. package/lib/instrument/instrument.spec.d.ts.map +0 -1
  150. package/lib/instrument/instrument.spec.js +0 -51
  151. package/lib/operators.d.ts +0 -5
  152. package/lib/operators.d.ts.map +0 -1
  153. package/lib/operators.js +0 -16
  154. package/lib/shared/datetime.d.ts +0 -3
  155. package/lib/shared/datetime.d.ts.map +0 -1
  156. package/lib/shared/datetime.js +0 -7
  157. package/lib/strategy.d.ts +0 -15
  158. package/lib/strategy.d.ts.map +0 -1
  159. package/lib/strategy.js +0 -26
  160. package/lib/strategy.spec.d.ts +0 -2
  161. package/lib/strategy.spec.d.ts.map +0 -1
  162. package/lib/strategy.spec.js +0 -34
  163. package/lib/when-socket.d.ts +0 -8
  164. package/lib/when-socket.d.ts.map +0 -1
  165. package/lib/when-socket.js +0 -53
  166. package/lib/with-memo.d.ts +0 -5
  167. package/lib/with-memo.d.ts.map +0 -1
  168. package/lib/with-memo.js +0 -20
  169. package/lib/with-memo.spec.d.ts +0 -2
  170. package/lib/with-memo.spec.d.ts.map +0 -1
  171. package/lib/with-memo.spec.js +0 -47
  172. package/src/asset/asset.spec.ts +0 -70
  173. package/src/asset/asset.ts +0 -89
  174. package/src/asset/index.ts +0 -1
  175. package/src/component/distinct-until-timesamp-changed.ts +0 -11
  176. package/src/component/error.ts +0 -32
  177. package/src/component/index.ts +0 -7
  178. package/src/component/ohlc-operator.spec.ts +0 -125
  179. package/src/component/ohlc-operator.ts +0 -122
  180. package/src/component/ohlc.spec.ts +0 -30
  181. package/src/component/ohlc.ts +0 -18
  182. package/src/component/timeframe.ts +0 -17
  183. package/src/core.ts +0 -16
  184. package/src/instrument/commission/commission.spec.ts +0 -35
  185. package/src/instrument/commission/commission.ts +0 -27
  186. package/src/instrument/index.ts +0 -2
  187. package/src/instrument/instrument.spec.ts +0 -76
  188. package/src/instrument/instrument.ts +0 -65
  189. package/src/operators.ts +0 -18
  190. package/src/shared/datetime.ts +0 -5
  191. package/src/strategy.spec.ts +0 -42
  192. package/src/strategy.ts +0 -36
  193. package/src/when-socket.ts +0 -61
  194. package/src/with-memo.spec.ts +0 -46
  195. package/src/with-memo.ts +0 -33
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("../instrument/instrument"), exports);
18
- __exportStar(require("../instrument/commission/commission"), exports);
@@ -1,28 +0,0 @@
1
- import { Asset, AssetSelector } from '../asset';
2
- import { Commission } from './commission/commission';
3
- export declare const InstrumentSelectorSeparator = "-";
4
- export declare class MissingInstrumentError extends Error {
5
- constructor(instrument: InstrumentSelector);
6
- }
7
- export declare class InstrumentSelector {
8
- readonly id: string;
9
- readonly base: AssetSelector;
10
- readonly quote: AssetSelector;
11
- constructor(base: string, quote: string, adapter: string);
12
- toString(): string;
13
- }
14
- /**
15
- * Represents trading market which is made up by two trading assets (base and quoted).
16
- */
17
- export declare class Instrument extends InstrumentSelector {
18
- timestamp: number;
19
- readonly base: Asset;
20
- readonly quote: Asset;
21
- readonly raw: string;
22
- commission: Commission;
23
- readonly cross: Instrument | undefined;
24
- leverage: number | undefined;
25
- constructor(timestamp: number, base: Asset, quote: Asset, raw: string, commission: Commission);
26
- }
27
- export declare function instrumentOf(selector: string): InstrumentSelector;
28
- //# sourceMappingURL=instrument.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instrument.d.ts","sourceRoot":"","sources":["../../src/instrument/instrument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAA0B,MAAM,YAAY,CAAC;AAG1E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,UAAU,EAAE,kBAAkB;CAG3C;AAED,qBAAa,kBAAkB;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAElB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAOxD,QAAQ;CAGT;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,kBAAkB;IAKvC,SAAS,EAAE,MAAM;aACN,IAAI,EAAE,KAAK;aACX,KAAK,EAAE,KAAK;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM;IACb,UAAU,EAAE,UAAU;IAR/B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAa;gBAGhC,SAAS,EAAE,MAAM,EACN,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,KAAK,EACrB,GAAG,EAAE,MAAM,EACb,UAAU,EAAE,UAAU;CAQhC;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,kBAAkB,CAYjE"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instrumentOf = exports.Instrument = exports.InstrumentSelector = exports.MissingInstrumentError = exports.InstrumentSelectorSeparator = void 0;
4
- const asset_1 = require("../asset");
5
- const component_1 = require("../component");
6
- exports.InstrumentSelectorSeparator = '-';
7
- class MissingInstrumentError extends Error {
8
- constructor(instrument) {
9
- super(`Missing instrument: ${instrument}`);
10
- }
11
- }
12
- exports.MissingInstrumentError = MissingInstrumentError;
13
- class InstrumentSelector {
14
- constructor(base, quote, adapter) {
15
- this.base = new asset_1.AssetSelector(base.toLowerCase(), adapter.toLowerCase());
16
- this.quote = new asset_1.AssetSelector(quote.toLowerCase(), adapter.toLowerCase());
17
- this.id = `${this.base.id}${exports.InstrumentSelectorSeparator}${this.quote.name}`;
18
- }
19
- toString() {
20
- return this.id;
21
- }
22
- }
23
- exports.InstrumentSelector = InstrumentSelector;
24
- /**
25
- * Represents trading market which is made up by two trading assets (base and quoted).
26
- */
27
- class Instrument extends InstrumentSelector {
28
- constructor(timestamp, base, quote, raw, commission) {
29
- super(base.name, quote.name, base.adapterName);
30
- this.timestamp = timestamp;
31
- this.base = base;
32
- this.quote = quote;
33
- this.raw = raw;
34
- this.commission = commission;
35
- this.leverage = undefined;
36
- if (base.adapterName != quote.adapterName) {
37
- throw new component_1.AdapterMismatchError();
38
- }
39
- }
40
- }
41
- exports.Instrument = Instrument;
42
- function instrumentOf(selector) {
43
- const [adapterName, asset, ...rest] = selector.split(asset_1.AssetSelectorSeparator);
44
- if (!adapterName || !asset || rest.length) {
45
- throw new component_1.InvalidInstrumentSelectorError(selector);
46
- }
47
- const [baseAssetName, quoteAssetName] = asset.split(exports.InstrumentSelectorSeparator);
48
- if (!baseAssetName || !quoteAssetName) {
49
- throw new component_1.InvalidInstrumentSelectorError(selector);
50
- }
51
- return new InstrumentSelector(baseAssetName, quoteAssetName, adapterName);
52
- }
53
- exports.instrumentOf = instrumentOf;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=instrument.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instrument.spec.d.ts","sourceRoot":"","sources":["../../src/instrument/instrument.spec.ts"],"names":[],"mappings":""}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const component_1 = require("../component");
4
- const shared_1 = require("../shared");
5
- describe(component_1.Instrument.name, () => {
6
- test('should construct a instrument', () => {
7
- const sut = new component_1.Instrument(0, new component_1.Asset('abc', 'xyz', 4), new component_1.Asset('def', 'xyz', 4), 'abc-def', (0, component_1.commissionPercentOf)({
8
- maker: shared_1.d.Zero,
9
- taker: shared_1.d.Zero
10
- }));
11
- expect(sut.base.name).toEqual('abc');
12
- expect(sut.base.adapterName).toEqual('xyz');
13
- expect(sut.quote.name).toEqual('def');
14
- expect(sut.quote.adapterName).toEqual('xyz');
15
- expect(sut.id).toEqual('xyz:abc-def');
16
- });
17
- });
18
- describe(component_1.InstrumentSelector.name, () => {
19
- test('should construct a instrument selector', () => {
20
- const sut = (0, component_1.instrumentOf)('xyz:abc-def');
21
- expect(sut.base.name).toEqual('abc');
22
- expect(sut.base.adapterName).toEqual('xyz');
23
- expect(sut.quote.name).toEqual('def');
24
- expect(sut.quote.adapterName).toEqual('xyz');
25
- expect(sut.id).toEqual('xyz:abc-def');
26
- });
27
- test('should construct a instrument selector capital case', () => {
28
- const sut = (0, component_1.instrumentOf)('XYZ:ABC-DEF');
29
- expect(sut.base.name).toEqual('abc');
30
- expect(sut.base.adapterName).toEqual('xyz');
31
- expect(sut.quote.name).toEqual('def');
32
- expect(sut.quote.adapterName).toEqual('xyz');
33
- expect(sut.id).toEqual('xyz:abc-def');
34
- });
35
- test('should throw invalid format message for missing separator', () => {
36
- const fn = () => (0, component_1.instrumentOf)('xyzabc-def');
37
- expect(fn).toThrowError();
38
- });
39
- test('should throw invalid format message for multiple separators', () => {
40
- const fn = () => (0, component_1.instrumentOf)('xyz:abc:-def');
41
- expect(fn).toThrowError();
42
- });
43
- test('should throw invalid format message for missing pair name', () => {
44
- const fn = () => (0, component_1.instrumentOf)('xyz:');
45
- expect(fn).toThrowError();
46
- });
47
- test('should throw invalid format message for missing adapter name', () => {
48
- const fn = () => (0, component_1.assetOf)(':abc-def');
49
- expect(fn).toThrowError();
50
- });
51
- });
@@ -1,5 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- export declare function asReadonly<T>(): (input: Observable<T>) => Observable<Readonly<T>>;
3
- export declare function defined<T>(): (observable: Observable<T | undefined | null>) => Observable<T | null | undefined>;
4
- export declare function exclude<T, S extends symbol>(s: S): (observable: Observable<T | S>) => Observable<Exclude<T, S>>;
5
- //# sourceMappingURL=operators.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAE,MAAM,MAAM,CAAC;AAE/C,wBAAgB,UAAU,CAAC,CAAC,aACX,WAAW,CAAC,CAAC,6BAC7B;AAED,wBAAgB,OAAO,CAAC,CAAC,kBACH,WAAW,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,sCAErD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAC3B,WAAW,CAAC,GAAG,CAAC,CAAC,+BAKtC"}
package/lib/operators.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exclude = exports.defined = exports.asReadonly = void 0;
4
- const rxjs_1 = require("rxjs");
5
- function asReadonly() {
6
- return (input) => input.pipe((0, rxjs_1.map)(it => it));
7
- }
8
- exports.asReadonly = asReadonly;
9
- function defined() {
10
- return (observable) => observable.pipe((0, rxjs_1.filter)(it => it !== undefined && it !== null));
11
- }
12
- exports.defined = defined;
13
- function exclude(s) {
14
- return (observable) => observable.pipe((0, rxjs_1.filter)(it => it !== s), (0, rxjs_1.map)(it => it));
15
- }
16
- exports.exclude = exclude;
@@ -1,3 +0,0 @@
1
- export type timestamp = number;
2
- export declare function now(): timestamp;
3
- //# sourceMappingURL=datetime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../../src/shared/datetime.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,wBAAgB,GAAG,IAAI,SAAS,CAE/B"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.now = void 0;
4
- function now() {
5
- return new Date().getTime();
6
- }
7
- exports.now = now;
package/lib/strategy.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { Dependency } from './module';
3
- export type Descriptor = () => Observable<unknown>;
4
- export declare let before: (descriptor: Descriptor) => void;
5
- export declare let behavior: (descriptor: Descriptor) => void;
6
- export declare let after: (descriptor: Descriptor) => void;
7
- export declare function strategy(descriptor: () => Dependency[]): {
8
- dependencies: Dependency[];
9
- description: {
10
- before: Descriptor[];
11
- behavior: Descriptor[];
12
- after: Descriptor[];
13
- };
14
- };
15
- //# sourceMappingURL=strategy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAM,MAAM,MAAM,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;AAEnD,eAAO,IAAI,MAAM,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AACpD,eAAO,IAAI,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AACtD,eAAO,IAAI,KAAK,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;AAEnD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,UAAU,EAAE;;;;;;;EAyBtD"}
package/lib/strategy.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strategy = exports.after = exports.behavior = exports.before = void 0;
4
- const rxjs_1 = require("rxjs");
5
- function strategy(descriptor) {
6
- const description = {
7
- before: Array.of(),
8
- behavior: Array.of(),
9
- after: Array.of()
10
- };
11
- exports.before = descriptor => description.before.push(descriptor);
12
- exports.behavior = descriptor => description.behavior.push(descriptor);
13
- exports.after = descriptor => description.after.push(descriptor);
14
- const dependencies = descriptor();
15
- if (!description.before.length) {
16
- description.before.push(() => (0, rxjs_1.of)(true));
17
- }
18
- if (!description.after.length) {
19
- description.after.push(() => (0, rxjs_1.of)(true));
20
- }
21
- return {
22
- dependencies,
23
- description
24
- };
25
- }
26
- exports.strategy = strategy;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=strategy.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"strategy.spec.d.ts","sourceRoot":"","sources":["../src/strategy.spec.ts"],"names":[],"mappings":""}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const rxjs_1 = require("rxjs");
4
- const strategy_1 = require("./strategy");
5
- describe(strategy_1.strategy.name, () => {
6
- let fixtures;
7
- beforeEach(() => {
8
- fixtures = getFixtures();
9
- });
10
- test('happy path', () => {
11
- const sut = (0, strategy_1.strategy)(() => {
12
- (0, strategy_1.before)(() => (0, rxjs_1.of)('before'));
13
- (0, strategy_1.behavior)(() => (0, rxjs_1.of)('behavior 1'));
14
- (0, strategy_1.behavior)(() => (0, rxjs_1.of)('behavior 2'));
15
- (0, strategy_1.after)(() => (0, rxjs_1.of)('after'));
16
- return fixtures.given.dependencies();
17
- });
18
- expect(sut.dependencies).toEqual(expect.arrayContaining(fixtures.given.dependencies()));
19
- expect(sut.description).toEqual({
20
- before: [expect.any(Function)],
21
- behavior: [expect.any(Function), expect.any(Function)],
22
- after: [expect.any(Function)]
23
- });
24
- });
25
- });
26
- function getFixtures() {
27
- return {
28
- given: {
29
- dependencies() {
30
- return [];
31
- }
32
- }
33
- };
34
- }
@@ -1,8 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- export declare function whenSocket(url: string, options?: {
3
- pingInterval?: number;
4
- }): [Observable<{
5
- timestamp: number;
6
- payload: unknown;
7
- }>, (message: unknown) => void];
8
- //# sourceMappingURL=when-socket.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"when-socket.d.ts","sourceRoot":"","sources":["../src/when-socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMlC,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAA2B,GAC1D,CAAC,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC,CAmDnF"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.whenSocket = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const ws_1 = require("ws");
6
- const use_logger_1 = require("./use-logger");
7
- const use_timestamp_1 = require("./use-timestamp");
8
- function whenSocket(url, options = { pingInterval: 5000 }) {
9
- const { debug } = (0, use_logger_1.useLogger)('whenSocket');
10
- const message = new rxjs_1.Observable(stream => {
11
- const socket = new ws_1.WebSocket(url);
12
- let isAlive = false;
13
- let interval;
14
- socket.onmessage = it => stream.next({ timestamp: (0, use_timestamp_1.useTimestamp)(), payload: JSON.parse(it.data) });
15
- socket.onerror = it => {
16
- clearInterval(interval);
17
- debug('errored', url);
18
- stream.error(it);
19
- };
20
- socket.onclose = () => {
21
- debug('closed', url);
22
- clearInterval(interval);
23
- stream.error();
24
- };
25
- socket.onopen = () => {
26
- debug('opened', url);
27
- isAlive = true;
28
- interval = setInterval(() => {
29
- if (isAlive) {
30
- isAlive = false;
31
- socket.ping();
32
- }
33
- else {
34
- socket.terminate();
35
- clearInterval(interval);
36
- }
37
- }, options.pingInterval);
38
- socket.on('pong', () => {
39
- isAlive = true;
40
- });
41
- socket.on('ping', () => {
42
- isAlive = true;
43
- socket.pong();
44
- });
45
- };
46
- return () => {
47
- socket.terminate();
48
- clearInterval(interval);
49
- };
50
- });
51
- return [message, (message) => JSON.stringify(message)];
52
- }
53
- exports.whenSocket = whenSocket;
@@ -1,5 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from './use-hash';
3
- export declare function withMemo<T extends Array<dependency>, U>(fn: (...args: T) => U): (...args: T) => U;
4
- export declare function withMemo<T extends Array<dependency>, U>(fn: (...args: T) => Observable<U>): (...args: T) => Observable<U>;
5
- //# sourceMappingURL=with-memo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"with-memo.d.ts","sourceRoot":"","sources":["../src/with-memo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAe,MAAM,MAAM,CAAC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACrD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AACrB,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACrD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAChC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC"}
package/lib/with-memo.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withMemo = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const uuid_1 = require("uuid");
6
- const module_1 = require("./module");
7
- const operators_1 = require("./operators");
8
- const use_memo_1 = require("./use-memo");
9
- function withMemo(fn) {
10
- (0, module_1.throwWithContext)();
11
- const uniqueId = (0, uuid_1.v4)();
12
- return (...args) => (0, use_memo_1.useMemo)(() => {
13
- const value = fn(...args);
14
- if ((0, rxjs_1.isObservable)(value)) {
15
- return value.pipe((0, operators_1.asReadonly)(), (0, rxjs_1.shareReplay)(1));
16
- }
17
- return value;
18
- }, [uniqueId, ...args]);
19
- }
20
- exports.withMemo = withMemo;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=with-memo.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"with-memo.spec.d.ts","sourceRoot":"","sources":["../src/with-memo.spec.ts"],"names":[],"mappings":""}
@@ -1,47 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const make_test_module_1 = require("./make-test-module");
13
- const instrument_1 = require("./instrument");
14
- const with_memo_1 = require("./with-memo");
15
- describe(with_memo_1.withMemo.name, () => {
16
- let fixtures;
17
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
18
- fixtures = yield getFixtures();
19
- }));
20
- test('memorize same values for same arguments', () => {
21
- const { act, getValue } = fixtures;
22
- act(() => {
23
- const value1 = getValue((0, instrument_1.instrumentOf)('binance:btc-usdt'));
24
- const value2 = getValue((0, instrument_1.instrumentOf)('binance:btc-usdt'));
25
- expect(Object.is(value1, value2)).toBeTruthy();
26
- });
27
- });
28
- test('memorize different values for different arguments', () => {
29
- const { act, getValue } = fixtures;
30
- act(() => {
31
- const value1 = getValue((0, instrument_1.instrumentOf)('binance:btc-usdt'));
32
- const value2 = getValue((0, instrument_1.instrumentOf)('binance:btc-busd'));
33
- expect(value1).toEqual('binance:btc-usdt');
34
- expect(value2).toEqual('binance:btc-busd');
35
- });
36
- });
37
- });
38
- function getFixtures() {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const { act } = yield (0, make_test_module_1.makeTestModule)([]);
41
- const getValue = (0, with_memo_1.withMemo)((instrument) => instrument.id);
42
- return {
43
- act,
44
- getValue: act(() => (instrument) => getValue(instrument))
45
- };
46
- });
47
- }
@@ -1,70 +0,0 @@
1
- import { Asset, assetOf, AssetSelector } from '@lib/component';
2
- import { d } from '@lib/shared';
3
-
4
- describe(Asset.name, () => {
5
- test('should construct a new asset', () => {
6
- const sut = new Asset('abc', 'xyz', 4);
7
-
8
- expect(sut.name).toEqual('abc');
9
- expect(sut.adapterName).toEqual('xyz');
10
- expect(sut.scale).toEqual(4);
11
- expect(sut.tickSize).toEqual(d(0.0001));
12
- expect(sut.floor(d(1.1234567))).toEqual(d(1.1234));
13
- expect(sut.ceil(d(1.1234567))).toEqual(d(1.1235));
14
- expect(sut.id).toEqual('xyz:abc');
15
- });
16
-
17
- test('should throw for missing asset name', () => {
18
- const fn = () => new Asset('xyz', '', 5);
19
-
20
- expect(fn).toThrowError();
21
- });
22
-
23
- test('should throw for missing adapter name', () => {
24
- const fn = () => new Asset('', 'xyz', 5);
25
-
26
- expect(fn).toThrowError();
27
- });
28
- });
29
-
30
- describe(AssetSelector.name, () => {
31
- test('should construct a new asset selector from unified string', () => {
32
- const sut = assetOf('xyz:abc');
33
-
34
- expect(sut.name).toEqual('abc');
35
- expect(sut.adapterName).toEqual('xyz');
36
- expect(sut.id).toEqual('xyz:abc');
37
- });
38
-
39
- test('should instantiate proper asset selector capital case', () => {
40
- const sut = assetOf('XYZ:ABC');
41
-
42
- expect(sut.name).toEqual('abc');
43
- expect(sut.adapterName).toEqual('xyz');
44
- expect(sut.id).toEqual('xyz:abc');
45
- });
46
-
47
- test('should throw invalid format message for missing separator', () => {
48
- const fn = () => assetOf('xyzabc');
49
-
50
- expect(fn).toThrowError();
51
- });
52
-
53
- test('should throw for multiple separators', () => {
54
- const fn = () => assetOf('xyz:abc:');
55
-
56
- expect(fn).toThrowError();
57
- });
58
-
59
- test('should throw for missing asset name', () => {
60
- const fn = () => assetOf('xyz:');
61
-
62
- expect(fn).toThrowError();
63
- });
64
-
65
- test('should throw for missing adapter name', () => {
66
- const fn = () => assetOf(':abc');
67
-
68
- expect(fn).toThrowError();
69
- });
70
- });
@@ -1,89 +0,0 @@
1
- import { InvalidArgumentsError, InvalidAssetSelectorError } from '@lib/component';
2
- import { d, decimal } from '@lib/shared';
3
-
4
- export const AssetSelectorSeparator = ':';
5
-
6
- export class MissingAssetError extends Error {
7
- constructor(asset: AssetSelector) {
8
- super(`Missing asset: ${asset}`);
9
- }
10
- }
11
-
12
- /**
13
- * Supposed to query specific @see Asset based on string notation.
14
- */
15
- export class AssetSelector {
16
- readonly id: string;
17
- readonly name: string;
18
- readonly adapterName: string;
19
-
20
- constructor(name: string, adapterName: string) {
21
- if (!name?.length) {
22
- throw new InvalidArgumentsError({ name });
23
- }
24
-
25
- if (!adapterName?.length) {
26
- throw new InvalidArgumentsError({ adapterName });
27
- }
28
-
29
- this.name = name.toLowerCase();
30
- this.adapterName = adapterName.toLowerCase();
31
- this.id = `${this.adapterName}${AssetSelectorSeparator}${this.name}`;
32
- }
33
-
34
- toString() {
35
- return this.id;
36
- }
37
- }
38
-
39
- /**
40
- * Creates @see AssetSelector based on unified string notation.
41
- */
42
- export function assetOf(selector: string): AssetSelector {
43
- const [adapterName, name, ...rest] = selector.split(AssetSelectorSeparator);
44
-
45
- if (!adapterName || !name || rest.length) {
46
- throw new InvalidAssetSelectorError(selector);
47
- }
48
-
49
- return new AssetSelector(name, adapterName);
50
- }
51
-
52
- /**
53
- * Represents a security that you can trade or hold in your wallet.
54
- * For example, you can combine two trading assets to create a trading instrument.
55
- */
56
- export class Asset extends AssetSelector {
57
- readonly tickSize: decimal;
58
-
59
- constructor(name: string, adapterName: string, public readonly scale: number) {
60
- super(name, adapterName);
61
-
62
- if (scale && (scale < 0 || Number.isNaN(scale))) {
63
- throw new InvalidArgumentsError({ scale });
64
- }
65
-
66
- this.tickSize = d(1.0).div(Math.pow(10, this.scale));
67
- }
68
-
69
- /**
70
- * Formats a number to string with fixed number of decimal places.
71
- */
72
- fixed(number: decimal): string {
73
- return number.toFixed(this.scale);
74
- }
75
-
76
- /**
77
- * Rounds down a number to the asset precision.
78
- */
79
- floor(number: decimal): decimal {
80
- return number.toFloor(this.scale);
81
- }
82
-
83
- /**
84
- * Rounds up a number to the asset precision.
85
- */
86
- ceil(number: decimal): decimal {
87
- return number.toCeil(this.scale);
88
- }
89
- }
@@ -1 +0,0 @@
1
- export * from '@lib/asset/asset';
@@ -1,11 +0,0 @@
1
- import { filter, Observable, tap } from 'rxjs';
2
-
3
- export function distinctUntilTimestampChanged<T extends { timestamp: number }>() {
4
- let prevTimestamp: number | undefined;
5
-
6
- return (stream: Observable<T>) =>
7
- stream.pipe(
8
- filter(it => prevTimestamp === undefined || it.timestamp > prevTimestamp),
9
- tap(it => (prevTimestamp = it.timestamp))
10
- );
11
- }