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
Thread.new do
account_class = ->(a) do
case a
when /^U/
IB::User
when /^F/
IB::Advisor
when /^DF/
IB::DemoAdvisor
when /^DU/
IB::DemoUser
else
IB::Account
end
end
@accounts =[]
c= IB::Connection.current
man_id = c.subscribe( :ManagedAccounts ) do |msg|
@accounts = msg.accounts_list.split(',').map do |a|
account_class[a].new( account: a.upcase , last_access: Time.now ).save
end
end
rec_id = c.subscribe( :ReceiveFA ) do |msg|
msg.accounts.each{ |a| IB::Account.where( account: a.account ).first.update alias: a.alias }
end
loop{ sleep 1 ; break if !@accounts.empty? } c.unsubscribe man_id , rec_id end
end
|