Skip to content

Commit

Permalink
combineLast Observer of openSocket and userData was added
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenmeza committed Sep 6, 2018
1 parent ae3a7d3 commit 6c1e863
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/getAccountPositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
8 changes: 5 additions & 3 deletions lib/rx.js
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6c1e863

Please sign in to comment.