rxjs-trading-signals
Version:
The user - defined operator helps users quickly output index values. base trading-signals library
40 lines • 1.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetchProfit = exports.fetchSum = void 0;
const big_js_1 = __importDefault(require("big.js"));
const rxjs_1 = require("rxjs");
const fetchSum = () => {
return (0, rxjs_1.pipe)((0, rxjs_1.scan)((curr, next) => curr.plus(next), new big_js_1.default(0)), (0, rxjs_1.map)(x => x.round(8).toNumber()), (0, rxjs_1.toArray)());
};
exports.fetchSum = fetchSum;
const FetchProfit = (direction) => {
return (observable) => new rxjs_1.Observable((subscriber) => {
let prev = new big_js_1.default(0);
const subscription = observable.subscribe({
next(x) {
if (x.offset === 'open') {
prev = new big_js_1.default(x.price);
}
else if (x.offset === 'close' && !prev.eq(0)) {
const profit = direction === 'buy' ? new big_js_1.default(x.price).minus(prev) : prev.minus(x.price);
subscriber.next(profit);
}
},
error(err) {
subscriber.error(err);
},
complete() {
subscriber.complete();
},
});
return () => {
subscription.unsubscribe();
prev = null;
};
});
};
exports.FetchProfit = FetchProfit;
//# sourceMappingURL=FetchSum.js.map