ib-api 972.5 → 972.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +36 -41
- data/README.md +21 -13
- data/VERSION +1 -1
- data/api.gemspec +2 -0
- data/bin/console +15 -17
- data/bin/console.yml +1 -1
- data/lib/extensions/class-extensions.rb +9 -0
- data/lib/ib/base_properties.rb +22 -1
- data/lib/ib/connection.rb +122 -100
- data/lib/ib/constants.rb +5 -2
- data/lib/ib/errors.rb +3 -1
- data/lib/ib/messages/incoming/alert.rb +4 -4
- data/lib/ib/messages/incoming/ticks.rb +1 -1
- data/lib/ib/messages/outgoing/bar_requests.rb +2 -2
- data/lib/ib/messages/outgoing/place_order.rb +3 -3
- data/lib/ib/messages/outgoing/request_marketdata.rb +1 -1
- data/lib/ib/raw_message.rb +85 -0
- data/lib/ib/socket.rb +2 -2
- data/lib/logging.rb +9 -8
- data/lib/models/ib/contract.rb +64 -5
- data/lib/models/ib/index.rb +1 -1
- data/lib/models/ib/option_detail.rb +13 -0
- data/lib/models/ib/order.rb +23 -0
- data/lib/models/ib/portfolio_value.rb +34 -12
- data/lib/models/ib/spread.rb +33 -18
- data/lib/requires.rb +2 -1
- metadata +32 -4
- data/lib/ib/logger.rb +0 -26
data/lib/models/ib/order.rb
CHANGED
@@ -514,11 +514,34 @@ Format of serialisation
|
|
514
514
|
(account ? "/#{account}" : '') +
|
515
515
|
(commission ? " fee #{commission}" : '') + ">"
|
516
516
|
end
|
517
|
+
|
518
|
+
|
519
|
+
def table_header
|
520
|
+
[ 'account','status' ,'', 'Type', 'tif', 'action', 'amount','price' , 'id/fee' ]
|
521
|
+
end
|
522
|
+
|
523
|
+
def table_row
|
524
|
+
[ account, order_ref.present? ? order_ref.to_s : status,
|
525
|
+
contract.to_human[1..-2],
|
526
|
+
self[:order_type] ,
|
527
|
+
self[:tif],
|
528
|
+
action,
|
529
|
+
total_quantity,
|
530
|
+
(limit_price ? "#{limit_price} " : '') + ((aux_price && aux_price != 0) ? "/#{aux_price}" : '') ,
|
531
|
+
commission ? " fee #{commission}" : local_id ]
|
532
|
+
end
|
533
|
+
|
517
534
|
def serialize_rabbit
|
518
535
|
{ 'Contract' => contract.present? ? contract.serialize( :option, :trading_class ): '' ,
|
519
536
|
'Order' => self,
|
520
537
|
'OrderState' => order_state}
|
521
538
|
end
|
522
539
|
|
540
|
+
# expell uncommon attributes
|
541
|
+
def invariant_attributes
|
542
|
+
attributes.reject{ |x| [ :designated_location, :display_size, :etrade_only, :exempt_code, :ext_operator, :random_size, :random_price, :firm_quote_only, :scale_auto_reset, :scale_random_percent, :scale_table, :short_sale_slot, :solicided, :created_at, :modified_at ].include? x }
|
543
|
+
|
544
|
+
end
|
545
|
+
|
523
546
|
end # class Order
|
524
547
|
end # module IB
|
@@ -47,18 +47,40 @@ class PortfolioValue < IB::Model
|
|
47
47
|
end
|
48
48
|
alias to_s to_human
|
49
49
|
|
50
|
+
def table_header
|
51
|
+
if block_given?
|
52
|
+
[ '' , yield , 'pos', 'entry', 'market', 'value', 'unrealized', 'realized' ]
|
53
|
+
else
|
54
|
+
[ '' , '', 'pos', 'entry', 'market', 'value', 'unrealized', 'realized' ]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def table_row
|
59
|
+
outprice= ->( item ) { { value: item.nil? ? "--" : item , alignment: :right } }
|
60
|
+
|
61
|
+
the_account = if account.present?
|
62
|
+
if account.is_a?(String)
|
63
|
+
account + " "
|
64
|
+
else
|
65
|
+
account.account+" "
|
66
|
+
end
|
67
|
+
else
|
68
|
+
""
|
69
|
+
end
|
70
|
+
|
71
|
+
entry = average_cost.to_f / (contract.multiplier.to_i.zero? ? 1 : contract.multiplier.to_i)
|
72
|
+
|
73
|
+
[ the_account,
|
74
|
+
contract.to_human[1..-2],
|
75
|
+
outprice[position.to_i],
|
76
|
+
outprice[entry.to_f.round(3)],
|
77
|
+
outprice[market_price.to_f.round(3)],
|
78
|
+
outprice[market_value.to_f.round(2)],
|
79
|
+
unrealized_pnl.to_i.zero? ? "": outprice[unrealized_pnl],
|
80
|
+
realized_pnl.to_i.zero? ? "" : outprice[realized_pnl]
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
50
84
|
|
51
|
-
# def to_invest
|
52
|
-
# a=attributes
|
53
|
-
# a.delete "created_at"
|
54
|
-
# a.delete "updated_at"
|
55
|
-
# a.delete "id"
|
56
|
-
# a.delete "account_id"
|
57
|
-
# a.delete "currency_id"
|
58
|
-
# a[:currency] = currency.symbol.presence || currency.name.presence || nil unless currency.nil?
|
59
|
-
# a #return_value
|
60
|
-
#
|
61
|
-
#
|
62
|
-
# end
|
63
85
|
end # class
|
64
86
|
end # module
|
data/lib/models/ib/spread.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# require 'ib/verify'
|
2
1
|
module IB
|
3
2
|
if defined?(Spread)
|
4
3
|
puts "Bag already a #{defined?(Spread)}"
|
@@ -21,7 +20,7 @@ Adds (or substracts) relative (back) measures to the front month, just passes ab
|
|
21
20
|
front: 20180908 back: 1w (-1w) --> 20180918 (20180902)
|
22
21
|
=end
|
23
22
|
|
24
|
-
|
23
|
+
def self.transform_distance front, back
|
25
24
|
# Check Format of back: 201809 --> > 200.000
|
26
25
|
# 20180989 ---> 20.000.000
|
27
26
|
start_date = front.to_i < 20000000 ? Date.strptime(front.to_s,"%Y%m") : Date.strptime(front.to_s,"%Y%m%d")
|
@@ -80,17 +79,14 @@ Adds (or substracts) relative (back) measures to the front month, just passes ab
|
|
80
79
|
# Default: action: :buy, weight: 1
|
81
80
|
|
82
81
|
def add_leg contract, **leg_params
|
83
|
-
|
84
|
-
|
82
|
+
error "need a IB::Contract as first argument" unless contract.is_a? IB::Contract
|
83
|
+
self.legs << contract
|
84
|
+
error "cannot add leg if no con_id is provided" if contract.con_id.blank?
|
85
85
|
# weigth = 1 --> sets Combo.side to buy and overwrites the action statement
|
86
86
|
# leg_params[:weight] = 1 unless leg_params.key?(:weight) || leg_params.key?(:ratio)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
self.combo_legs << the_leg
|
91
|
-
self.description = "#{description.nil? ? "": description} added #{nc.to_human}" rescue "Spread: #{nc.to_human}"
|
92
|
-
self.legs << nc
|
93
|
-
end
|
87
|
+
self.combo_legs << ComboLeg.new( contract.attributes.slice( :con_id, :exchange ).merge( leg_params ))
|
88
|
+
self.description = "#{description.nil? ? "": description} added #{contract.to_human}" rescue "Spread: #{contract.to_human}"
|
89
|
+
|
94
90
|
self # return value to enable chaining
|
95
91
|
|
96
92
|
|
@@ -98,13 +94,20 @@ Adds (or substracts) relative (back) measures to the front month, just passes ab
|
|
98
94
|
|
99
95
|
# removes the contract from the spread definition
|
100
96
|
#
|
101
|
-
def remove_leg
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
97
|
+
def remove_leg contract_or_position = nil
|
98
|
+
contract = if contract_or_position.is_a? (IB::Contract)
|
99
|
+
contract_or_position
|
100
|
+
elsif contract_or_position.is_a? Numeric
|
101
|
+
legs.at contract_or_position
|
102
|
+
else
|
103
|
+
error "Specify a contract to be removed or the position in the legs-array as parameter to remove a leg"
|
104
|
+
end
|
105
|
+
the_con_id = contract.verify.first &.con_id
|
106
|
+
error "Invalid Contract specified" unless the_con_id.is_a? Numeric
|
107
|
+
legs.delete_if { |x| x.con_id == the_con_id }
|
108
|
+
combo_legs.delete_if { |x| x.con_id == the_con_id }
|
109
|
+
self.description = description + " removed #{contract.to_human}"
|
110
|
+
self # make method chainable
|
108
111
|
end
|
109
112
|
|
110
113
|
# essentail
|
@@ -146,6 +149,18 @@ Adds (or substracts) relative (back) measures to the front month, just passes ab
|
|
146
149
|
# end
|
147
150
|
|
148
151
|
|
152
|
+
def as_table
|
153
|
+
t= Terminal::Table.new title: description[1..-2] ,
|
154
|
+
headings: table_header,
|
155
|
+
|
156
|
+
style: { border: :unicode }
|
157
|
+
|
158
|
+
t.add_row table_row
|
159
|
+
legs.each{ |y| t.add_row y.table_row }
|
160
|
+
t.render
|
161
|
+
|
162
|
+
end
|
163
|
+
|
149
164
|
def self.build_from_json container
|
150
165
|
read_leg = ->(a) do
|
151
166
|
IB::ComboLeg.new :con_id => a.read_int,
|
data/lib/requires.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ib-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 972.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hartmut Bischoff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ox
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Ruby Implementation of the Interactive Brokers TWS API
|
84
112
|
email:
|
85
113
|
- topofocus@gmail.com
|
@@ -110,7 +138,6 @@ files:
|
|
110
138
|
- lib/ib/connection.rb
|
111
139
|
- lib/ib/constants.rb
|
112
140
|
- lib/ib/errors.rb
|
113
|
-
- lib/ib/logger.rb
|
114
141
|
- lib/ib/messages.rb
|
115
142
|
- lib/ib/messages/abstract_message.rb
|
116
143
|
- lib/ib/messages/incoming.rb
|
@@ -138,6 +165,7 @@ files:
|
|
138
165
|
- lib/ib/messages/outgoing/request_tick_data.rb
|
139
166
|
- lib/ib/model.rb
|
140
167
|
- lib/ib/models.rb
|
168
|
+
- lib/ib/raw_message.rb
|
141
169
|
- lib/ib/server_versions.rb
|
142
170
|
- lib/ib/socket.rb
|
143
171
|
- lib/ib/support.rb
|
@@ -185,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
213
|
- !ruby/object:Gem::Version
|
186
214
|
version: '0'
|
187
215
|
requirements: []
|
188
|
-
rubygems_version: 3.
|
216
|
+
rubygems_version: 3.3.7
|
189
217
|
signing_key:
|
190
218
|
specification_version: 4
|
191
219
|
summary: Ruby Implementation of the Interactive Brokers TWS API
|
data/lib/ib/logger.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "logger"
|
2
|
-
module LogDev
|
3
|
-
# define default_logger
|
4
|
-
def default_logger
|
5
|
-
@default_logger ||= Logger.new(STDOUT).tap do |l|
|
6
|
-
l.formatter = proc do |severity, datetime, progname, msg|
|
7
|
-
# "#{datetime.strftime("%d.%m.(%X)")}#{"%5s" % severity}->#{progname}##{msg}\n"
|
8
|
-
## the default logger displays the message only
|
9
|
-
msg.to_s + "\n"
|
10
|
-
end
|
11
|
-
l.level = Logger::INFO
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
def default_logger= logger
|
17
|
-
@default_logger = logger
|
18
|
-
end
|
19
|
-
|
20
|
-
# Add universally accessible log method/accessor into Object
|
21
|
-
def logger *args
|
22
|
-
default_logger.tap do |logger|
|
23
|
-
logger.fatal *args unless args.empty?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end # module
|