-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.rb
executable file
·78 lines (71 loc) · 2.47 KB
/
console.rb
1
2
3
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
### loads the ib-ruby environment
### and starts an interactive shell
###
### loads the startup-parameter of simple-monitor
### and allocates watchlists
###
### Its main purpose: Managment of watchlists
###
### The »received«-Hash is enabled and accessible through
### C.received
require "bundler/setup"
require "./simple_monitor"
include Ibo::Helpers
class Array
# enables calling members of an array, which are hashes by name
# i.e
#
# 2.5.0 :006 > C.received[:OpenOrder].local_id # instead of ...[:OpenOrder].map(&:local_id)
# => [16, 17, 21, 20, 19, 8, 7]
# 2.5.0 :007 > C.received[:OpenOrder].contract.to_human
# => ["<Bag: IECombo SMART USD legs: >", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: WFC USD>", "<Stock: WFC USD>"]
#
# its included only in the console, for inspection purposes
def method_missing(method, *key)
unless method == :to_hash || method == :to_str # || method == :to_int
map { |x| x.public_send(method, *key) }
end
end
end
puts
puts ">> S I M P L E – M O N I T O R Interactive Console <<"
puts "-" * 45
puts
puts "Namespace is IB ! "
puts
include IB
require "irb"
d_host, d_client_id = read_config { |s| [s[:host].present? ? s[:host] : "127.0.0.1", s[:client_id].present? ? s[:client_id] : 0] } # client_id 0 gets any open order
client_id = d_client_id.zero? ? 900 : d_client_id - 1
ARGV.clear
logger = Logger.new $stdout
logger.formatter = proc do |level, time, prog, msg|
"#{time.strftime("%H:%M:%S")} #{msg}\n"
end
logger.level = Logger::INFO
begin
G = Gateway.new get_account_data: true, serial_array: true,
client_id: client_id, host: d_host, logger: logger,
watchlists: read_config(:watchlist)
rescue IB::TransmissionError => e
puts "E: #{e.inspect}"
end
C = G.tws
unless C.received[:OpenOrder].blank?
puts "------------------------------- OpenOrders ----------------------------------"
puts C.received[:OpenOrder].to_human.join "\n"
end
puts "Connection established on #{d_host}, client_id #{client_id} used"
puts
puts "----> G + C point to the Gateway and the Connection -Instance"
puts "----> C.received holds all received messages"
puts "----> G.clients points to gatherd account-data"
puts ""
puts "Paramters from »config.yml« used"
puts "Simple-Monitor Helper Methods are included!"
puts ""
puts "Allocated Watchlists:"
puts watchlists.map { |w| w.to_s }.join "\n"
puts "-" * 45
IRB.start(__FILE__)