From 6c1e86329608cdfa745dbd255f91135a9d592f5e Mon Sep 17 00:00:00 2001 From: Ruben Meza Date: Thu, 6 Sep 2018 12:29:22 -0500 Subject: [PATCH] combineLast Observer of openSocket and userData was added --- lib/getAccountPositions.js | 11 +++++++---- lib/rx.js | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/getAccountPositions.js b/lib/getAccountPositions.js index da772ff..e2c4737 100644 --- a/lib/getAccountPositions.js +++ b/lib/getAccountPositions.js @@ -2,13 +2,16 @@ const rx = require('./rx.js') const rpc = require('./rpc.js') const { filter, take } = require('rxjs/operators') -function getAccountPositions (instrument, callback = () => {}) { - rx.socketOpen - .pipe(filter(open => open),take(1)) +function getAccountPositions (callback = () => {}) { + rx.socketOpenUserData + .pipe(filter(data => { + const [socket, user] = data + return socket && user.UserId != 0 + }),take(1)) .subscribe(open => { rpc.call('GetAccountPositions', { OMSId: rx.userData.value.OMSId || 1, - AccountId: cubobit.user.AccountId + AccountId: rx.userData.value.AccountId }, callback) }) } diff --git a/lib/rx.js b/lib/rx.js index 56f5396..120b650 100644 --- a/lib/rx.js +++ b/lib/rx.js @@ -1,9 +1,11 @@ -const { BehaviorSubject } = require('rxjs') +const { BehaviorSubject, combineLatest } = require('rxjs') const socketOpen = new BehaviorSubject(false) -const userData = new BehaviorSubject({}) +const userData = new BehaviorSubject({ UserId: 0 }) +const socketOpenUserData = combineLatest(socketOpen, userData) module.exports = { socketOpen, - userData + userData, + socketOpenUserData }