Module: IB::AccountInfos

Included in:
OrientGateway
Defined in:
lib/ib/account-init.rb

Instance Method Summary collapse

Instance Method Details

#load_managed_accountsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ib/account-init.rb', line 4

def load_managed_accounts

  # defines the callback of the  ManagedAccount message
  #
  # The @accounts-array is initialized with active accounts
Thread.new do 
   =  ->(a) do
                            case a
                            when /^U/
                              IB::User
                            when /^F/
                              IB::Advisor
                            when  /^DF/
                              IB::DemoAdvisor
                            when /^DU/
                              IB::DemoUser
                            else
                              IB::
                            end
  end
  @accounts =[]
  c= IB::Connection.current
  man_id = c.subscribe( :ManagedAccounts ) do |msg| 
    @accounts =  msg.accounts_list.split(',').map do |a| 
      [a].new( account: a.upcase ,  last_access: Time.now ).save
    end
  end
  rec_id = c.subscribe( :ReceiveFA )  do |msg|
    msg.accounts.each{ |a| IB::.where( account: a. ).first.update alias: a.alias }
  end

  loop{ sleep 1 ; break if !@accounts.empty? }  # keep it active for 1 second
  c.unsubscribe man_id , rec_id # release callbacks
end

end