@quantform/core 0.3.217 → 0.3.222
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/dist/indicator/atr.d.ts +1 -2
- package/dist/indicator/atr.js +4 -1
- package/dist/indicator/atr.js.map +1 -1
- package/dist/indicator/donchian.d.ts +7 -6
- package/dist/indicator/donchian.js +6 -15
- package/dist/indicator/donchian.js.map +1 -1
- package/dist/indicator/ema.d.ts +1 -10
- package/dist/indicator/ema.js +13 -32
- package/dist/indicator/ema.js.map +1 -1
- package/dist/indicator/ema.spec.js +4 -23
- package/dist/indicator/ema.spec.js.map +1 -1
- package/dist/indicator/envelope.js +4 -8
- package/dist/indicator/envelope.js.map +1 -1
- package/dist/indicator/index.d.ts +1 -1
- package/dist/indicator/index.js +1 -1
- package/dist/indicator/index.js.map +1 -1
- package/dist/indicator/macd.js +3 -12
- package/dist/indicator/macd.js.map +1 -1
- package/dist/indicator/min-max.d.ts +4 -11
- package/dist/indicator/min-max.js +12 -29
- package/dist/indicator/min-max.js.map +1 -1
- package/dist/indicator/rma.d.ts +1 -10
- package/dist/indicator/rma.js +13 -32
- package/dist/indicator/rma.js.map +1 -1
- package/dist/indicator/sma.d.ts +1 -10
- package/dist/indicator/sma.js +11 -22
- package/dist/indicator/sma.js.map +1 -1
- package/dist/indicator/sma.spec.js +1 -1
- package/dist/indicator/sma.spec.js.map +1 -1
- package/dist/indicator/swma.d.ts +1 -9
- package/dist/indicator/swma.js +11 -26
- package/dist/indicator/swma.js.map +1 -1
- package/dist/indicator/tma.d.ts +1 -2
- package/dist/indicator/tma.js +4 -1
- package/dist/indicator/tma.js.map +1 -1
- package/dist/indicator/tma.spec.js +1 -1
- package/dist/indicator/tma.spec.js.map +1 -1
- package/dist/indicator/truerange.d.ts +1 -1
- package/dist/indicator/truerange.js +3 -1
- package/dist/indicator/truerange.js.map +1 -1
- package/dist/indicator/truerange.spec.js +2 -2
- package/dist/indicator/truerange.spec.js.map +1 -1
- package/dist/indicator/window.d.ts +3 -0
- package/dist/indicator/window.js +22 -0
- package/dist/indicator/window.js.map +1 -0
- package/dist/indicator/wma.d.ts +1 -11
- package/dist/indicator/wma.js +13 -33
- package/dist/indicator/wma.js.map +1 -1
- package/dist/indicator/wma.spec.js +1 -1
- package/dist/indicator/wma.spec.js.map +1 -1
- package/dist/session/session-descriptor.d.ts +0 -1
- package/dist/session/session-optimizer.js.map +1 -1
- package/dist/session/session.d.ts +10 -6
- package/dist/session/session.js +26 -15
- package/dist/session/session.js.map +1 -1
- package/dist/storage/measurement.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/indicator/atr.ts +9 -4
- package/src/indicator/donchian.ts +26 -26
- package/src/indicator/ema.spec.ts +4 -23
- package/src/indicator/ema.ts +15 -42
- package/src/indicator/envelope.ts +8 -14
- package/src/indicator/index.ts +1 -1
- package/src/indicator/macd.ts +8 -19
- package/src/indicator/min-max.ts +15 -37
- package/src/indicator/rma.ts +15 -43
- package/src/indicator/sma.spec.ts +1 -1
- package/src/indicator/sma.ts +13 -29
- package/src/indicator/swma.ts +14 -35
- package/src/indicator/tma.spec.ts +1 -1
- package/src/indicator/tma.ts +9 -4
- package/src/indicator/truerange.spec.ts +2 -2
- package/src/indicator/truerange.ts +15 -10
- package/src/indicator/window.ts +27 -0
- package/src/indicator/wma.spec.ts +1 -1
- package/src/indicator/wma.ts +16 -44
- package/src/session/session-descriptor.ts +0 -2
- package/src/session/session-optimizer.ts +1 -1
- package/src/session/session.ts +47 -17
- package/src/storage/measurement.ts +1 -2
- package/dist/indicator/window-indicator.d.ts +0 -10
- package/dist/indicator/window-indicator.js +0 -28
- package/dist/indicator/window-indicator.js.map +0 -1
- package/src/indicator/window-indicator.ts +0 -35
package/src/session/session.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
filter,
|
|
4
4
|
map,
|
|
5
5
|
mergeMap,
|
|
6
|
+
share,
|
|
6
7
|
shareReplay,
|
|
7
8
|
startWith,
|
|
8
9
|
switchMap,
|
|
@@ -20,13 +21,12 @@ import {
|
|
|
20
21
|
OrderState
|
|
21
22
|
} from '../domain';
|
|
22
23
|
import { Store } from '../store';
|
|
23
|
-
import { from, Observable, Subscription } from 'rxjs';
|
|
24
|
+
import { concat, from, Observable, Subject, Subscription } from 'rxjs';
|
|
24
25
|
import { Behaviour, CombinedBehaviour, FunctionBehaviour } from '../behaviour';
|
|
25
26
|
import { AdapterAggregate } from '../adapter/adapter-aggregate';
|
|
26
27
|
import { Worker } from '../common';
|
|
27
28
|
import { Trade } from '../domain/trade';
|
|
28
29
|
import { SessionDescriptor } from './session-descriptor';
|
|
29
|
-
import { Measure } from '../storage/measurement';
|
|
30
30
|
import {
|
|
31
31
|
AdapterHistoryQuery,
|
|
32
32
|
AdapterOrderCancelCommand,
|
|
@@ -34,12 +34,18 @@ import {
|
|
|
34
34
|
AdapterSubscribeCommand
|
|
35
35
|
} from '../adapter';
|
|
36
36
|
|
|
37
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
38
|
+
|
|
37
39
|
export class Session {
|
|
38
40
|
private initialized = false;
|
|
39
41
|
private subscription: Subscription;
|
|
40
42
|
private behaviour: Behaviour;
|
|
41
43
|
private worker = new Worker();
|
|
42
44
|
|
|
45
|
+
get timestamp(): number {
|
|
46
|
+
return this.store.snapshot.timestamp;
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
constructor(
|
|
44
50
|
readonly store: Store,
|
|
45
51
|
readonly aggregate: AdapterAggregate,
|
|
@@ -83,33 +89,57 @@ export class Session {
|
|
|
83
89
|
await this.worker.wait();
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
if (!this.
|
|
92
|
+
statement(output: Record<string, any>) {
|
|
93
|
+
if (!this.behaviour?.statement) {
|
|
88
94
|
return;
|
|
89
95
|
}
|
|
90
96
|
|
|
91
|
-
this.
|
|
92
|
-
this.descriptor.measurement.save(this.descriptor.id, measure)
|
|
93
|
-
);
|
|
97
|
+
this.behaviour.statement(output);
|
|
94
98
|
}
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
useMeasure<T extends { timestamp: number }>(
|
|
101
|
+
params: { key: string; timestamp?: number },
|
|
102
|
+
defaultValue: T = undefined
|
|
103
|
+
): [Observable<T>, (value: Optional<T, 'timestamp'>) => void] {
|
|
104
|
+
const stored$ = from(
|
|
98
105
|
this.descriptor.measurement.query(this.descriptor.id, {
|
|
99
|
-
type: params.
|
|
100
|
-
timestamp: params.timestamp ?? this.
|
|
106
|
+
type: params.key,
|
|
107
|
+
timestamp: params.timestamp ?? this.timestamp,
|
|
101
108
|
limit: 1,
|
|
102
109
|
direction: 'BACKWARD'
|
|
103
110
|
})
|
|
104
|
-
).pipe(
|
|
111
|
+
).pipe(
|
|
112
|
+
map(it =>
|
|
113
|
+
it.length ? { timestamp: it[0].timestamp, ...it[0].payload } : defaultValue
|
|
114
|
+
),
|
|
115
|
+
share()
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const subject$ = new Subject<T>();
|
|
119
|
+
|
|
120
|
+
const setter = (value: T) => {
|
|
121
|
+
const timestamp = value.timestamp ?? this.timestamp;
|
|
122
|
+
const measure = { timestamp, type: params.key, payload: value };
|
|
123
|
+
|
|
124
|
+
this.worker.enqueue(() =>
|
|
125
|
+
this.descriptor.measurement.save(this.descriptor.id, [measure])
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
subject$.next({ ...value, timestamp });
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return [concat(stored$, subject$.asObservable()), setter];
|
|
105
132
|
}
|
|
106
133
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
134
|
+
useOptimizer(path: string): any {
|
|
135
|
+
const session = this;
|
|
136
|
+
const [order$, setOrderMeasure] = session.useMeasure(
|
|
137
|
+
{ key: 'ordered' },
|
|
138
|
+
{ limt: 10, timestamp: 0 }
|
|
139
|
+
);
|
|
111
140
|
|
|
112
|
-
|
|
141
|
+
setOrderMeasure({ limt: 0, timestamp: 0 });
|
|
142
|
+
return undefined;
|
|
113
143
|
}
|
|
114
144
|
|
|
115
145
|
async subscribe(instrument: Array<InstrumentSelector>): Promise<void> {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RingBuffer } from './ring-buffer';
|
|
2
|
-
export declare abstract class WindowIndicator<T> {
|
|
3
|
-
private _buffer;
|
|
4
|
-
get capacity(): number;
|
|
5
|
-
get size(): number;
|
|
6
|
-
get isCompleted(): boolean;
|
|
7
|
-
constructor(capacity: number);
|
|
8
|
-
abstract calculate(added: T, removed: T, buffer: RingBuffer<T>): any;
|
|
9
|
-
append(value: T): void;
|
|
10
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WindowIndicator = void 0;
|
|
4
|
-
const ring_buffer_1 = require("./ring-buffer");
|
|
5
|
-
class WindowIndicator {
|
|
6
|
-
constructor(capacity) {
|
|
7
|
-
this._buffer = new ring_buffer_1.RingBuffer(capacity);
|
|
8
|
-
}
|
|
9
|
-
get capacity() {
|
|
10
|
-
return this._buffer.capacity;
|
|
11
|
-
}
|
|
12
|
-
get size() {
|
|
13
|
-
return this._buffer.size;
|
|
14
|
-
}
|
|
15
|
-
get isCompleted() {
|
|
16
|
-
return this._buffer.isFull;
|
|
17
|
-
}
|
|
18
|
-
append(value) {
|
|
19
|
-
let removed = null;
|
|
20
|
-
if (this.isCompleted) {
|
|
21
|
-
removed = this._buffer.peek();
|
|
22
|
-
}
|
|
23
|
-
this._buffer.enqueue(value);
|
|
24
|
-
this.calculate(value, removed, this._buffer);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.WindowIndicator = WindowIndicator;
|
|
28
|
-
//# sourceMappingURL=window-indicator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"window-indicator.js","sourceRoot":"","sources":["../../src/indicator/window-indicator.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAE3C,MAAsB,eAAe;IAenC,YAAY,QAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,wBAAU,CAAI,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAdD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7B,CAAC;IAQM,MAAM,CAAC,KAAQ;QACpB,IAAI,OAAO,GAAG,IAAI,CAAC;QAEnB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;SAC/B;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAE5B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;CACF;AAhCD,0CAgCC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { RingBuffer } from './ring-buffer';
|
|
2
|
-
|
|
3
|
-
export abstract class WindowIndicator<T> {
|
|
4
|
-
private _buffer: RingBuffer<T>;
|
|
5
|
-
|
|
6
|
-
get capacity(): number {
|
|
7
|
-
return this._buffer.capacity;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get size(): number {
|
|
11
|
-
return this._buffer.size;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get isCompleted(): boolean {
|
|
15
|
-
return this._buffer.isFull;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor(capacity: number) {
|
|
19
|
-
this._buffer = new RingBuffer<T>(capacity);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
abstract calculate(added: T, removed: T, buffer: RingBuffer<T>);
|
|
23
|
-
|
|
24
|
-
public append(value: T) {
|
|
25
|
-
let removed = null;
|
|
26
|
-
|
|
27
|
-
if (this.isCompleted) {
|
|
28
|
-
removed = this._buffer.peek();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this._buffer.enqueue(value);
|
|
32
|
-
|
|
33
|
-
this.calculate(value, removed, this._buffer);
|
|
34
|
-
}
|
|
35
|
-
}
|