Skip to content

Commit dde1ccb

Browse files
author
Ubuntu
committed
modified console to work with config.yml
1 parent ffc3d20 commit dde1ccb

File tree

2 files changed

+62
-68
lines changed

2 files changed

+62
-68
lines changed

config.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
---
22
#host: 10.222.148.177:7496 # default is: localhost:4002
33
:gateway:
4-
:host: localhost
5-
:client_id: 900 # client_id: 0 --> display any open order
6-
:watchlists: # enter list of watchlists here (format -> :Capitalized_symbols)
7-
- :Futures # hard-coded (ib-ruby/lib/ib/sybols) and user-defined lists are supported
8-
- :Currencies # do not use :Forex, put key-currencies into :Currencies instead
9-
- :Spreads # three watchlists are listed in the contract-mask
10-
- :BuyAndHold # any further entry acts as sort criterium
4+
:host: 127.0.0.1
5+
:client_id: 900 # client_id: 0 --> display any open order
6+
:watchlist: # enter list of watchlists here (format -> :Capitalized_symbols)
7+
- :Futures # hard-coded (ib-ruby/lib/ib/sybols) and user-defined lists are supported
8+
- :Currencies # do not use :Forex, put key-currencies into :Currencies instead
9+
- :Spreads # three watchlists are listed in the contract-mask
10+
- :BuyAndHold # any further entry acts as sort criterium
1111

1212
# only needed if no account alias is specified in TWS
13-
:user:
13+
:user:
1414
DU167348: FirstUser
1515
# DU167349: SecondUser
1616
:prices: delayed # or realtime
17-

console.rb

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,78 @@
11
#!/usr/bin/env ruby
2-
### loads the ib-ruby environment
2+
### loads the ib-ruby environment
33
### and starts an interactive shell
44
###
5-
###
65
### loads the startup-parameter of simple-monitor
76
### 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
1211
### C.received
13-
require 'bundler/setup'
14-
require './simple_monitor'
15-
12+
require "bundler/setup"
13+
require "./simple_monitor"
1614

1715
include Ibo::Helpers
1816

19-
2017
class Array
2118
# enables calling members of an array, which are hashes by name
2219
# i.e
2320
#
2421
# 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>"]
2825
#
2926
# its included only in the console, for inspection purposes
3027

3128
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) }
3431
end
35-
3632
end
37-
end # Array
33+
end
3834

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
3941

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
5752

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
8277

83-
IRB.start(__FILE__)
78+
IRB.start(__FILE__)

0 commit comments

Comments
 (0)