UNPKG

rxjs-trading-signals

Version:

The user - defined operator helps users quickly output index values. base trading-signals library

47 lines 1.78 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MACD = void 0; const big_js_1 = __importDefault(require("big.js")); const rxjs_1 = require("rxjs"); const MACD = (config) => { return (observable) => new rxjs_1.Observable((subscriber) => { let { indicator, shortInterval, longInterval } = config; const { signalInterval } = config; let macd = new big_js_1.default(0); if (shortInterval > longInterval) { [shortInterval, longInterval] = [longInterval, shortInterval]; } const source$ = observable.pipe((0, rxjs_1.share)()); const subscription = (0, rxjs_1.zip)(source$.pipe(indicator(shortInterval), (0, rxjs_1.skip)(longInterval - shortInterval)), source$.pipe(indicator(longInterval))) .pipe((0, rxjs_1.concatMap)(([short, long]) => { const x = new big_js_1.default(short).minus(long); macd = x; return (0, rxjs_1.of)(x); }), indicator(signalInterval, true), (0, rxjs_1.map)(signal => ({ histogram: macd.minus(signal), macd: macd, signal: new big_js_1.default(signal), }))) .subscribe({ next(x) { subscriber.next(x); }, error(err) { subscriber.error(err); }, complete() { subscriber.complete(); }, }); return () => { subscription.unsubscribe(); indicator = null; macd = null; }; }); }; exports.MACD = MACD; //# sourceMappingURL=MACD.js.map