rxjs-trading-signals
Version:
The user - defined operator helps users quickly output index values. base trading-signals library
32 lines • 1.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SMA = void 0;
const big_js_1 = __importDefault(require("big.js"));
const rxjs_1 = require("rxjs");
const SMA = (interval) => {
return (observable) => new rxjs_1.Observable((subscriber) => {
const subscription = observable
.pipe((0, rxjs_1.bufferCount)(interval, 1), (0, rxjs_1.filter)(items => items.length === interval), (0, rxjs_1.concatMap)(items => {
return (0, rxjs_1.from)(items).pipe((0, rxjs_1.scan)((curr, next) => curr.plus(next), new big_js_1.default(0)), (0, rxjs_1.last)(), (0, rxjs_1.map)(x => x.div(interval)));
}))
.subscribe({
next(x) {
subscriber.next(x);
},
error(err) {
subscriber.error(err);
},
complete() {
subscriber.complete();
},
});
return () => {
subscription.unsubscribe();
};
});
};
exports.SMA = SMA;
//# sourceMappingURL=SMA.js.map