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