|
1 | 1 | #!/usr/bin/env ruby |
2 | | -### loads the ib-ruby environment |
| 2 | +### loads the ib-ruby environment |
3 | 3 | ### and starts an interactive shell |
4 | 4 | ### |
5 | | -### |
6 | 5 | ### loads the startup-parameter of simple-monitor |
7 | 6 | ### and allocates watchlists |
8 | | -### |
9 | | -### It main proposure: Managment of watchlists |
10 | | -### |
11 | | -### The »received«-Hash is enabled and asseccible throught |
| 7 | +### |
| 8 | +### Its main purpose: Managment of watchlists |
| 9 | +### |
| 10 | +### The »received«-Hash is enabled and accessible through |
12 | 11 | ### C.received |
13 | | -require 'bundler/setup' |
14 | | -require './simple_monitor' |
15 | | - |
| 12 | +require "bundler/setup" |
| 13 | +require "./simple_monitor" |
16 | 14 |
|
17 | 15 | include Ibo::Helpers |
18 | 16 |
|
19 | | - |
20 | 17 | class Array |
21 | 18 | # enables calling members of an array, which are hashes by name |
22 | 19 | # i.e |
23 | 20 | # |
24 | 21 | # 2.5.0 :006 > C.received[:OpenOrder].local_id # instead of ...[:OpenOrder].map(&:local_id) |
25 | | - # => [16, 17, 21, 20, 19, 8, 7] |
26 | | - # 2.5.0 :007 > C.received[:OpenOrder].contract.to_human |
27 | | - # => ["<Bag: IECombo SMART USD legs: >", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: WFC USD>", "<Stock: WFC USD>"] |
| 22 | + # => [16, 17, 21, 20, 19, 8, 7] |
| 23 | + # 2.5.0 :007 > C.received[:OpenOrder].contract.to_human |
| 24 | + # => ["<Bag: IECombo SMART USD legs: >", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: GE USD>", "<Stock: WFC USD>", "<Stock: WFC USD>"] |
28 | 25 | # |
29 | 26 | # its included only in the console, for inspection purposes |
30 | 27 |
|
31 | 28 | def method_missing(method, *key) |
32 | | - unless method == :to_hash || method == :to_str #|| method == :to_int |
33 | | - return self.map{|x| x.public_send(method, *key)} |
| 29 | + unless method == :to_hash || method == :to_str # || method == :to_int |
| 30 | + map { |x| x.public_send(method, *key) } |
34 | 31 | end |
35 | | - |
36 | 32 | end |
37 | | -end # Array |
| 33 | +end |
38 | 34 |
|
| 35 | +puts |
| 36 | +puts ">> S I M P L E – M O N I T O R Interactive Console <<" |
| 37 | +puts "-" * 45 |
| 38 | +puts |
| 39 | +puts "Namespace is IB ! " |
| 40 | +puts |
39 | 41 |
|
40 | | - puts |
41 | | - puts ">> S I M P L E – M O N I T O R Interactive Console <<" |
42 | | - puts '-'* 45 |
43 | | - puts |
44 | | - puts "Namespace is IB ! " |
45 | | - puts |
46 | | - |
47 | | - include IB |
48 | | - require 'irb' |
49 | | - d_host, d_client_id = read_tws_alias{|s| [ s[:host].present? ? s[:host] :'localhost', s[:client_id].present? ? s[:client_id] :0 ] } # client_id 0 gets any open order |
50 | | - client_id = d_client_id.zero? ? 900 : d_client_id-1 |
51 | | - ARGV.clear |
52 | | - logger = Logger.new STDOUT |
53 | | - logger.formatter = proc do |level, time, prog, msg| |
54 | | - "#{time.strftime('%H:%M:%S')} #{msg}\n" |
55 | | - end |
56 | | - logger.level = Logger::INFO |
| 42 | +include IB |
| 43 | +require "irb" |
| 44 | +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 |
| 45 | +client_id = d_client_id.zero? ? 900 : d_client_id - 1 |
| 46 | +ARGV.clear |
| 47 | +logger = Logger.new $stdout |
| 48 | +logger.formatter = proc do |level, time, prog, msg| |
| 49 | + "#{time.strftime("%H:%M:%S")} #{msg}\n" |
| 50 | +end |
| 51 | +logger.level = Logger::INFO |
57 | 52 |
|
58 | | - begin |
59 | | - G = Gateway.new get_account_data: true, serial_array: true, |
60 | | - client_id: client_id, host: d_host, logger: logger, |
61 | | - watchlists: read_tws_alias(:watchlist) |
62 | | - rescue IB::TransmissionError => e |
63 | | - puts "E: #{e.inspect}" |
64 | | - end |
65 | | - C = G.tws |
66 | | - unless C.received[:OpenOrder].blank? |
67 | | - puts "------------------------------- OpenOrders ----------------------------------" |
68 | | - puts C.received[:OpenOrder].to_human.join "\n" |
69 | | - end |
70 | | - puts "Connection established on #{d_host}, client_id #{client_id} used" |
71 | | - puts |
72 | | - puts "----> G + C point to the Gateway and the Connection -Instance" |
73 | | - puts "----> C.received holds all received messages" |
74 | | - puts "----> G.active_accounts points to gatherd account-data" |
75 | | - puts "" |
76 | | - puts "Paramters from »read_tws_alias.yml« used" |
77 | | - puts "Simple-Monitor Helper Methods are included!" |
78 | | - puts "" |
79 | | - puts "Allocated Watchlists:" |
80 | | - puts watchlists.map{|w| w.to_s}.join "\n" |
81 | | - puts '-'* 45 |
| 53 | +begin |
| 54 | + G = Gateway.new get_account_data: true, serial_array: true, |
| 55 | + client_id: client_id, host: d_host, logger: logger, |
| 56 | + watchlists: read_config(:watchlist) |
| 57 | +rescue IB::TransmissionError => e |
| 58 | + puts "E: #{e.inspect}" |
| 59 | +end |
| 60 | +C = G.tws |
| 61 | +unless C.received[:OpenOrder].blank? |
| 62 | + puts "------------------------------- OpenOrders ----------------------------------" |
| 63 | + puts C.received[:OpenOrder].to_human.join "\n" |
| 64 | +end |
| 65 | +puts "Connection established on #{d_host}, client_id #{client_id} used" |
| 66 | +puts |
| 67 | +puts "----> G + C point to the Gateway and the Connection -Instance" |
| 68 | +puts "----> C.received holds all received messages" |
| 69 | +puts "----> G.clients points to gatherd account-data" |
| 70 | +puts "" |
| 71 | +puts "Paramters from »config.yml« used" |
| 72 | +puts "Simple-Monitor Helper Methods are included!" |
| 73 | +puts "" |
| 74 | +puts "Allocated Watchlists:" |
| 75 | +puts watchlists.map { |w| w.to_s }.join "\n" |
| 76 | +puts "-" * 45 |
82 | 77 |
|
83 | | - IRB.start(__FILE__) |
| 78 | +IRB.start(__FILE__) |
0 commit comments