ib-extensions 1.2 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -4
- data/Gemfile.lock +52 -42
- data/README.md +56 -10
- data/bin/console +10 -3
- data/bin/gateway +14 -9
- data/changelog.md +54 -0
- data/ib-extensions.gemspec +7 -5
- data/lib/ib/alerts/base-alert.rb +10 -13
- data/lib/ib/eod.rb +243 -127
- data/lib/ib/extensions/version.rb +14 -1
- data/lib/ib/extensions.rb +5 -0
- data/lib/ib/gateway/account-infos.rb +74 -47
- data/lib/ib/gateway/order-handling.rb +57 -25
- data/lib/ib/gateway.rb +45 -31
- data/lib/ib/market-price.rb +34 -34
- data/lib/ib/models/account.rb +177 -144
- data/lib/ib/models/bag.rb +19 -0
- data/lib/ib/models/contract.rb +16 -0
- data/lib/ib/models/future.rb +20 -0
- data/lib/ib/models/option.rb +20 -13
- data/lib/ib/option-chain.rb +4 -6
- data/lib/ib/option-greeks.rb +27 -21
- data/lib/ib/order_prototypes/all-in-one.rb +46 -0
- data/lib/ib/plot-poec.rb +60 -0
- data/lib/ib/probability_of_expiring.rb +109 -0
- data/lib/ib/spread-prototypes.rb +1 -0
- data/lib/ib/spread_prototypes/butterfly.rb +2 -4
- data/lib/ib/spread_prototypes/calendar.rb +25 -23
- data/lib/ib/spread_prototypes/straddle.rb +3 -3
- data/lib/ib/spread_prototypes/strangle.rb +8 -9
- data/lib/ib/spread_prototypes/vertical.rb +6 -7
- data/lib/ib/verify.rb +34 -39
- data/lib/ib-gateway.rb +12 -0
- metadata +53 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e2c6ed9342fd33767b9abd239b57aded0c91338801602366ff245575a7c812f
|
4
|
+
data.tar.gz: 17a2acdf9865cfb34dabaeb6826052614c6ecd099b0ff534f2784c79826200bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e3e6c88f52142cfff920ab547a269cf32ed21174713f8b5386fe5e9bb5be0dff922442d94b6990b9d084f85d5d429ecbe4a6fd9fb245ab3a1d0c8de7e4d7f6
|
7
|
+
data.tar.gz: 7f45042d846d30ffdbbf6d59775bdca595399366c66ba91cfea7a25e93ae0d91ab7307b20969a1589b53541bb9e05f66adf6c7545104bb9d35a94d4f16518da0
|
data/Gemfile
CHANGED
@@ -2,9 +2,8 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in ib-extensions.gemspec
|
4
4
|
gemspec
|
5
|
-
gem "ib-api",
|
5
|
+
#gem "ib-api", path: "../ib-api/"
|
6
6
|
## move this to gemspec and include as development dependency after the gem is released
|
7
|
-
gem "ib-symbols"
|
8
|
-
|
7
|
+
gem "ib-symbols" # , path: "../ib-symbols/"
|
8
|
+
gem "ib-api" #, :git=> 'https://github.com/ib-ruby/ib-api.git'
|
9
9
|
gem "rake", "~> 12.0"
|
10
|
-
gem 'dry-core'
|
data/Gemfile.lock
CHANGED
@@ -1,42 +1,47 @@
|
|
1
|
-
|
2
|
-
remote:
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/ib-ruby/ib-api.git
|
3
|
+
revision: 90b3a97952565c198560009c0388a6cf23e80c65
|
3
4
|
specs:
|
4
|
-
ib-api (972.
|
5
|
+
ib-api (972.5.2)
|
5
6
|
activemodel
|
6
7
|
activesupport (>= 6.0)
|
8
|
+
ox
|
9
|
+
terminal-table
|
7
10
|
|
8
11
|
PATH
|
9
12
|
remote: .
|
10
13
|
specs:
|
11
|
-
ib-extensions (
|
12
|
-
|
14
|
+
ib-extensions (2.0)
|
15
|
+
distribution
|
16
|
+
ib-api (~> 972.5.2)
|
13
17
|
ox
|
18
|
+
polars-df (~> 0.3.1)
|
19
|
+
prime
|
14
20
|
|
15
21
|
GEM
|
16
22
|
remote: https://rubygems.org/
|
17
23
|
specs:
|
18
|
-
activemodel (
|
19
|
-
activesupport (=
|
20
|
-
activesupport (
|
24
|
+
activemodel (7.0.4.2)
|
25
|
+
activesupport (= 7.0.4.2)
|
26
|
+
activesupport (7.0.4.2)
|
21
27
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
28
|
i18n (>= 1.6, < 2)
|
23
29
|
minitest (>= 5.1)
|
24
30
|
tzinfo (~> 2.0)
|
25
|
-
zeitwerk (~> 2.3)
|
26
31
|
coderay (1.1.3)
|
27
|
-
concurrent-ruby (1.
|
28
|
-
diff-lcs (1.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
guard (2.
|
32
|
+
concurrent-ruby (1.2.2)
|
33
|
+
diff-lcs (1.5.0)
|
34
|
+
distribution (0.8.0)
|
35
|
+
ffi (1.15.5)
|
36
|
+
formatador (1.1.0)
|
37
|
+
forwardable (1.3.3)
|
38
|
+
guard (2.18.0)
|
34
39
|
formatador (>= 0.2.4)
|
35
40
|
listen (>= 2.7, < 4.0)
|
36
41
|
lumberjack (>= 1.0.12, < 2.0)
|
37
42
|
nenv (~> 0.1)
|
38
43
|
notiffany (~> 0.0)
|
39
|
-
pry (>= 0.
|
44
|
+
pry (>= 0.13.0)
|
40
45
|
shellany (~> 0.0)
|
41
46
|
thor (>= 0.18.1)
|
42
47
|
guard-compat (1.2.1)
|
@@ -44,59 +49,64 @@ GEM
|
|
44
49
|
guard (~> 2.1)
|
45
50
|
guard-compat (~> 1.1)
|
46
51
|
rspec (>= 2.99.0, < 4.0)
|
47
|
-
i18n (1.
|
52
|
+
i18n (1.12.0)
|
48
53
|
concurrent-ruby (~> 1.0)
|
49
|
-
ib-symbols (1.
|
54
|
+
ib-symbols (1.5)
|
50
55
|
ib-api
|
51
|
-
|
52
|
-
listen (3.5.1)
|
56
|
+
listen (3.8.0)
|
53
57
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
54
58
|
rb-inotify (~> 0.9, >= 0.9.10)
|
55
59
|
lumberjack (1.2.8)
|
56
60
|
method_source (1.0.0)
|
57
|
-
minitest (5.
|
61
|
+
minitest (5.18.0)
|
58
62
|
nenv (0.3.0)
|
59
63
|
notiffany (0.1.3)
|
60
64
|
nenv (~> 0.1)
|
61
65
|
shellany (~> 0.0)
|
62
|
-
ox (2.14.
|
63
|
-
|
66
|
+
ox (2.14.14)
|
67
|
+
polars-df (0.3.1-x86_64-linux)
|
68
|
+
prime (0.1.2)
|
69
|
+
forwardable
|
70
|
+
singleton
|
71
|
+
pry (0.14.2)
|
64
72
|
coderay (~> 1.1)
|
65
73
|
method_source (~> 1.0)
|
66
74
|
rake (12.3.3)
|
67
|
-
rb-fsevent (0.
|
75
|
+
rb-fsevent (0.11.2)
|
68
76
|
rb-inotify (0.10.1)
|
69
77
|
ffi (~> 1.0)
|
70
|
-
rspec (3.
|
71
|
-
rspec-core (~> 3.
|
72
|
-
rspec-expectations (~> 3.
|
73
|
-
rspec-mocks (~> 3.
|
78
|
+
rspec (3.12.0)
|
79
|
+
rspec-core (~> 3.12.0)
|
80
|
+
rspec-expectations (~> 3.12.0)
|
81
|
+
rspec-mocks (~> 3.12.0)
|
74
82
|
rspec-collection_matchers (1.2.0)
|
75
83
|
rspec-expectations (>= 2.99.0.beta1)
|
76
|
-
rspec-core (3.
|
77
|
-
rspec-support (~> 3.
|
78
|
-
rspec-expectations (3.
|
84
|
+
rspec-core (3.12.1)
|
85
|
+
rspec-support (~> 3.12.0)
|
86
|
+
rspec-expectations (3.12.2)
|
79
87
|
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
-
rspec-support (~> 3.
|
88
|
+
rspec-support (~> 3.12.0)
|
81
89
|
rspec-its (1.3.0)
|
82
90
|
rspec-core (>= 3.0.0)
|
83
91
|
rspec-expectations (>= 3.0.0)
|
84
|
-
rspec-mocks (3.
|
92
|
+
rspec-mocks (3.12.3)
|
85
93
|
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
-
rspec-support (~> 3.
|
87
|
-
rspec-support (3.
|
94
|
+
rspec-support (~> 3.12.0)
|
95
|
+
rspec-support (3.12.0)
|
88
96
|
shellany (0.0.1)
|
89
|
-
|
90
|
-
|
97
|
+
singleton (0.1.1)
|
98
|
+
terminal-table (3.0.2)
|
99
|
+
unicode-display_width (>= 1.1.1, < 3)
|
100
|
+
thor (1.2.1)
|
101
|
+
tzinfo (2.0.6)
|
91
102
|
concurrent-ruby (~> 1.0)
|
92
|
-
|
103
|
+
unicode-display_width (2.4.2)
|
93
104
|
|
94
105
|
PLATFORMS
|
95
|
-
|
106
|
+
x86_64-linux
|
96
107
|
|
97
108
|
DEPENDENCIES
|
98
109
|
bundler (~> 2.0)
|
99
|
-
dry-core
|
100
110
|
guard
|
101
111
|
guard-rspec
|
102
112
|
ib-api!
|
@@ -108,4 +118,4 @@ DEPENDENCIES
|
|
108
118
|
rspec-its
|
109
119
|
|
110
120
|
BUNDLED WITH
|
111
|
-
2.
|
121
|
+
2.4.6
|
data/README.md
CHANGED
@@ -6,7 +6,6 @@ __Documentation: [https://ib-ruby.github.io/ib-doc/](https://ib-ruby.github.io/i
|
|
6
6
|
|
7
7
|
__Questions, Contributions, Remarks: [Discussions are opened in ib-api](https://github.com/ib-ruby/ib-api/discussions)__
|
8
8
|
|
9
|
-
---
|
10
9
|
|
11
10
|
__Helpers and Macros that ease the usage of the TWS-API of Interactive Brokers__
|
12
11
|
|
@@ -46,6 +45,8 @@ puts IB::Symbols.Index.estx.eod( duration: '10 d' )
|
|
46
45
|
```
|
47
46
|
Fetch historical data with just one line of code ([documentation](https://ib-ruby.github.io/ib-doc/Historical_data.html) )
|
48
47
|
|
48
|
+
**NEW :: Contract.eod returns a PolarsDataframe **
|
49
|
+
|
49
50
|
## Order Prototypes
|
50
51
|
```
|
51
52
|
require 'ib-api'
|
@@ -62,38 +63,83 @@ More details in the [documentation](https://ib-ruby.github.io/ib-doc/order_proto
|
|
62
63
|
|
63
64
|
## Spread Prototypes
|
64
65
|
|
65
|
-
```
|
66
|
+
``` ruby
|
66
67
|
require 'ib-api'
|
67
68
|
require 'ib/spread-prototypes'
|
68
69
|
```
|
69
70
|
|
70
71
|
Compose most common spreads through
|
71
72
|
|
72
|
-
```
|
73
|
+
``` ruby
|
73
74
|
s = IB::Straddle.build from: IB::Symbols::Index.stoxx,
|
74
|
-
strike:
|
75
|
-
expiry:
|
75
|
+
strike: 4200,
|
76
|
+
expiry: 202112
|
76
77
|
|
77
|
-
|
78
|
+
t = IB::Strangle.build from: IB::Symbols::Index.stoxx,
|
78
79
|
c: 2400, p: 2200,
|
79
80
|
expiry: 202103
|
80
81
|
|
81
|
-
|
82
|
-
|
82
|
+
puts s.as_table
|
83
|
+
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
84
|
+
│ Straddle ESTX50(4200.0)[Dec 2021] │
|
85
|
+
├────────┬────────┬────────────┬──────────┬──────────┬────────────┬───────────────┬───────┬────────┬──────────┤
|
86
|
+
│ │ symbol │ con_id │ exchange │ expiry │ multiplier │ trading-class │ right │ strike │ currency │
|
87
|
+
╞════════╪════════╪════════════╪══════════╪══════════╪════════════╪═══════════════╪═══════╪════════╪══════════╡
|
88
|
+
│ Spread │ ESTX50 │ -532066861 │ DTB │ │ 10 │ │ │ │ EUR │
|
89
|
+
│ Option │ ESTX50 │ 266033438 │ DTB │ 20211217 │ 10 │ OESX │ put │ 4200.0 │ EUR │
|
90
|
+
│ Option │ ESTX50 │ 266033423 │ DTB │ 20211217 │ 10 │ OESX │ call │ 4200.0 │ EUR │
|
91
|
+
└────────┴────────┴────────────┴──────────┴──────────┴────────────┴───────────────┴───────┴────────┴──────────┘
|
92
|
+
```
|
93
|
+
and use the speads like any other contract. ([documentation](https://ib-ruby.github.io/ib-doc/spreads.html))
|
83
94
|
|
84
95
|
## Gateway
|
85
96
|
```
|
86
97
|
require 'ib-gateway'
|
87
98
|
```
|
88
|
-
IB::Gateway is an
|
99
|
+
IB::Gateway is an enhancement of IB::Connection. Upon initialization, it detects active accounts and stores them in thread safe arrays.
|
100
|
+
|
101
|
+
``` ruby
|
102
|
+
g = IB::Gateway.current
|
103
|
+
clients = G.clients
|
104
|
+
puts client.first.portfolio_values.as_table
|
105
|
+
┌───────────┬─────────────────────────────────────────────┬─────┬──────────┬──────────┬───────────┬────────────┬──────────┐
|
106
|
+
│ │ │ pos │ entry │ market │ value │ unrealized │ realized │
|
107
|
+
╞═══════════╪═════════════════════════════════════════════╪═════╪══════════╪══════════╪═══════════╪════════════╪══════════╡
|
108
|
+
│ Uxxxxxxx │ Stock: BEPC USD NYSE │ 200 │ 43.038 │ 41.042 │ 8208.4 │ -399.17 │ │
|
109
|
+
│ Uxxxxxxx │ Option: CNHI 20210819 put 13.0 IDEM EUR │ -2 │ 0.386 │ 0.01 │ -9.63 │ 376.37 │ │
|
110
|
+
│ Uxxxxxxx │ Stock: EQT SEK SFB │ 200 │ 443.8 │ 420.469 │ 84093.85 │ -4666.19 │ -1369.02 │
|
111
|
+
│ Uxxxxxxx │ Future: ESTX50 20210917 EUR │ -1 │ 4145.3 │ 4098.15 │ -40981.5 │ 471.5 │ │
|
112
|
+
│ Uxxxxxxx │ Option: ESTX50 20211217 call 4200.0 DTB EUR │ -4 │ 97.85 │ 99.398 │ -3975.9 │ -61.9 │ │
|
113
|
+
│ Uxxxxxxx │ Option: IWM 20210903 call 230.0 AMEX USD │ -4 │ 1.943 │ 0.124 │ -49.72 │ 727.49 │ │
|
114
|
+
|
115
|
+
```
|
89
116
|
Details in the [documentation](https://ib-ruby.github.io/ib-doc/gateway.html)
|
90
117
|
|
118
|
+
Generally `puts IB::Model.as_table` provides a modern and convient output for the console and notebooks.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
g.update_orders
|
122
|
+
puts g.clients.first.orders.as_table
|
123
|
+
┌──────────┬───────────┬─────────────────────────────────────────┬──────┬─────┬────────┬────────┬───────┬────────┐
|
124
|
+
│ account │ status │ │ Type │ tif │ action │ amount │ price │ id/fee │
|
125
|
+
╞══════════╪═══════════╪═════════════════════════════════════════╪══════╪═════╪════════╪════════╪═══════╪════════╡
|
126
|
+
│ U123456 │ Submitted │ Option: SLV 20210716 put 24.0 SMART USD │ LMT │ GTC │ sell │ 5.0 │ 0.98 │ 0 │
|
127
|
+
└──────────┴───────────┴─────────────────────────────────────────┴──────┴─────┴────────┴────────┴───────┴────────┘
|
128
|
+
puts g.clients.first.orders.contract.as_table
|
129
|
+
┌────────┬────────┬───────────┬──────────┬──────────┬────────────┬───────────────┬───────┬────────┬──────────┐
|
130
|
+
│ │ symbol │ con_id │ exchange │ expiry │ multiplier │ trading-class │ right │ strike │ currency │
|
131
|
+
╞════════╪════════╪═══════════╪══════════╪══════════╪════════════╪═══════════════╪═══════╪════════╪══════════╡
|
132
|
+
│ Option │ SLV │ 456347029 │ SMART │ 20210716 │ 100 │ SLV │ put │ 24.0 │ USD │
|
133
|
+
└────────┴────────┴───────────┴──────────┴──────────┴────────────┴───────────────┴───────┴────────┴──────────┘
|
134
|
+
```
|
91
135
|
Its used in [Simple Monitor](https://github.com/ib-ruby/simple-monitor)
|
92
136
|
|
93
137
|
|
138
|
+
## Notebooks
|
139
|
+
**`IB-Ruby`** code can be executed in [iruby jupyter notebooks](https://github.com/SciRuby/iruby). A few scripts are included in [IB-Examples](https://github.com/ib-ruby/ib-examples). (*.ipynb- files)
|
94
140
|
|
95
141
|
|
96
|
-
|
142
|
+
```
|
97
143
|
## Contributing
|
98
144
|
|
99
145
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ib-ruby/ib-extensions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[ib-ruby/ib-extensions/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
CHANGED
@@ -65,7 +65,8 @@ read_yml = -> (key) do
|
|
65
65
|
|
66
66
|
## The Block takes instructions which are executed after initializing all instance-variables
|
67
67
|
## and prior to the connection-process
|
68
|
-
## Here we just subscribe to some events
|
68
|
+
## Here we just subscribe to some events
|
69
|
+
begin
|
69
70
|
C = Connection.new client_id: client_id, port: port do |c| # future use__ , optional_capacities: "+PACEAPI" do |c|
|
70
71
|
|
71
72
|
c.subscribe( :ContractData, :BondContractData) { |msg| c.logger.info { msg.contract.to_human } }
|
@@ -77,8 +78,8 @@ read_yml = -> (key) do
|
|
77
78
|
# puts
|
78
79
|
# end
|
79
80
|
|
80
|
-
c.subscribe( :OpenOrder){ |msg| "Open Order detected and stored: C.received[:OpenOrders] " }
|
81
|
-
c.logger.level = Logger::INFO
|
81
|
+
c.subscribe( :OpenOrder){ |msg| c.logger.info "Open Order detected and stored: C.received[:OpenOrders] " }
|
82
|
+
c.logger.level = Logger::WARN # set to INFO for more verbose output
|
82
83
|
end
|
83
84
|
unless C.received[:OpenOrder].blank?
|
84
85
|
puts "------------------------------- OpenOrders ----------------------------------"
|
@@ -91,4 +92,10 @@ read_yml = -> (key) do
|
|
91
92
|
puts "some basic Messages are subscribed and accordingly displayed"
|
92
93
|
puts '-'* 45
|
93
94
|
|
95
|
+
rescue IB::TransmissionError => e
|
96
|
+
Connection.logger.fatal e.message
|
97
|
+
Connection.logger.fatal "Aborting"
|
98
|
+
Kernel.exit
|
99
|
+
end
|
100
|
+
|
94
101
|
IRB.start(__FILE__)
|
data/bin/gateway
CHANGED
@@ -64,21 +64,26 @@ read_yml = -> (key) do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
ARGV.clear
|
67
|
-
logger = Logger.new STDOUT
|
68
|
-
logger.formatter = proc do |level, time, prog, msg|
|
69
|
-
"#{time.strftime('%H:%M:%S')} #{msg}\n"
|
70
|
-
end
|
71
|
-
logger.level = Logger::INFO
|
72
67
|
|
73
68
|
## The Block takes instructions which are executed after initializing all instance-variables
|
74
69
|
## and prior to the connection-process
|
75
70
|
## Here we just subscribe to some events
|
76
71
|
begin
|
77
72
|
G = Gateway.new get_account_data: true, serial_array: true,
|
78
|
-
client_id: client_id, port: port ,
|
79
|
-
watchlists: [:Spreads, :Stillhalter, :BuyAndHold]
|
80
|
-
|
81
|
-
|
73
|
+
client_id: client_id, port: port ,
|
74
|
+
watchlists: [:Spreads, :Stillhalter, :BuyAndHold] do |c|
|
75
|
+
c.tws.subscribe( :Alert, :ContractDataEnd, :ManagedAccounts, :OrderStatus ) {| m| c.logger.info { m.to_human } }
|
76
|
+
end
|
77
|
+
rescue IB::TransmissionError => e
|
78
|
+
if e.message =~ /client-id/
|
79
|
+
IB::Connection.logger.fatal "Increasing client_id"
|
80
|
+
client_id +=1
|
81
|
+
retry
|
82
|
+
else
|
83
|
+
puts "E: #{e.inspect}"
|
84
|
+
puts "Please restart"
|
85
|
+
Kernel.exit
|
86
|
+
end
|
82
87
|
end
|
83
88
|
|
84
89
|
C = G.tws
|
data/changelog.md
CHANGED
@@ -35,3 +35,57 @@
|
|
35
35
|
|
36
36
|
* Gateway#connect: Occasionally the request for AccountPositions/AllOrders fails. Then a reconnect is
|
37
37
|
appropriate. This is now implemented.
|
38
|
+
|
39
|
+
* Order.auto_adjust
|
40
|
+
|
41
|
+
Auto Adjust implements a simple algorithm to ensure that an order is accepted
|
42
|
+
|
43
|
+
It reads `contract_detail.min_tick`.
|
44
|
+
|
45
|
+
If min_tick < 0.01, the real tick-increments differ from the min_tick_value
|
46
|
+
|
47
|
+
For J36 (jardines) min tick is 0.001, but the minimal increment is 0.005
|
48
|
+
For Tui1 its the same, min_tick is 0.00001 , minimal increment ist 0.00005
|
49
|
+
|
50
|
+
Thus, for min-tick smaller then 0.01, the value is rounded to the next higher digit.
|
51
|
+
|
52
|
+
| min-tick | round |
|
53
|
+
|--------------|------------|
|
54
|
+
| 10 | 110 |
|
55
|
+
| 1 | 111 |
|
56
|
+
| 0.1 | 111.1 |
|
57
|
+
| 0.001 | 111.11 |
|
58
|
+
| 0.0001 | 111.11 |
|
59
|
+
| 0.00001 | 111.111 |
|
60
|
+
|--------------|------------|
|
61
|
+
|
62
|
+
* Client.place: defaults are
|
63
|
+
* auto_adjust is "true"
|
64
|
+
* convert_size: true
|
65
|
+
|
66
|
+
If a negative value for 'total amount' is used, then Order.action is set to :sell.
|
67
|
+
If a positive value is used, Order.action is kept
|
68
|
+
|
69
|
+
* Client.place raises an `IB::Symbol Error` if the order is not submitted
|
70
|
+
|
71
|
+
* Included Contract#included_in?( an IB::Account ) and Contract#portfolio_value( an IB::Account )
|
72
|
+
|
73
|
+
Suppose, you want to check, if a complex Contract is included in the Portfolio
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
s = Straddle.build symbol: Symbols::Index.stoxx, strike=4200, expiry: 20211217
|
77
|
+
puts s.included__in?(IB::Gateway.current.clients.first).to_human
|
78
|
+
=> "<Straddle ESTX50(4200.0)[Dec 2021]>"
|
79
|
+
puts s.portfolio_value( IB::Gateway.current.clients.first ).to_human
|
80
|
+
=> <PortfolioValue: Uxxxxxx Pos=-4 @ 225.158;Value=-9006.31;PNL=-1812.31 unrealized;<Option: ESTX50 20211217 put 4200.0 DTB EUR>
|
81
|
+
=> <PortfolioValue: Uxxxxxxx Pos=-4 @ 99.398;Value=-3975.9;PNL=-61.9 unrealized;<Option: ESTX50 20211217 call 4200.0 DTB EUR>
|
82
|
+
|
83
|
+
```
|
84
|
+
Both methods are available for IB::Contracts.
|
85
|
+
|
86
|
+
* IB::Gateway.current.get_account_data accepts only one parameter and is not persistent anymore
|
87
|
+
The former second argument (watchlists: ) is defaulted by those initialized through e IB::Gateway.new (IB::Gateway.current.active_watchlists)
|
88
|
+
The method now fetches the account- and portfoliodate, initialises Account#contracts, Account#portfolio_values, Account#account_values , Account#focusses and desubscribes from the TWS. (Before, the subscription to AccountData was permanently active).
|
89
|
+
|
90
|
+
* IB::Gateway.current.add_watchlist( a symbol ) -- Watchlists can added after initialisation
|
91
|
+
|
data/ib-extensions.gemspec
CHANGED
@@ -25,13 +25,15 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
spec.add_dependency "
|
31
|
-
|
28
|
+
spec.add_dependency "ox"
|
29
|
+
spec.add_dependency "prime"
|
30
|
+
spec.add_dependency "distribution"
|
31
|
+
spec.add_dependency "polars-df" , "~> 0.3.1"
|
32
|
+
spec.add_dependency "ib-api", "~> 972.5.2"
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
35
|
spec.add_development_dependency 'rspec-collection_matchers'
|
34
|
-
spec.add_development_dependency 'rspec-its'
|
36
|
+
spec.add_development_dependency 'rspec-its'
|
35
37
|
|
36
38
|
spec.add_development_dependency "guard"
|
37
39
|
spec.add_development_dependency "guard-rspec"
|
data/lib/ib/alerts/base-alert.rb
CHANGED
@@ -43,15 +43,15 @@ Important: The class is accessed asynchronically. Be careful while raising inter
|
|
43
43
|
|
44
44
|
def self.method_missing( method_id, msg , *args, &block )
|
45
45
|
if msg.is_a? IB::Messages::Incoming::Alert
|
46
|
-
logger.debug { msg.to_human }
|
46
|
+
# IB::Connection.logger.debug { msg.to_human }
|
47
47
|
else
|
48
|
-
logger.error { "Argument to IB::Alert is not a IB::Messages::Incoming::Alert" }
|
49
|
-
logger.error { "The object: #{msg.inspect} " }
|
48
|
+
IB::Connection.logger.error { "Argument to IB::Alert is not a IB::Messages::Incoming::Alert" }
|
49
|
+
IB::Connection.logger.error { "The object: #{msg.inspect} " }
|
50
50
|
end
|
51
51
|
rescue NoMethodError
|
52
|
-
unless logger.nil?
|
53
|
-
logger.error { "The Argument is not a valid IB::Messages:Incoming::Alert object"}
|
54
|
-
logger.error { "The object: #{msg.inspect} " }
|
52
|
+
unless IB::Connection.logger.nil?
|
53
|
+
IB::Connection.logger.error { "The Argument is not a valid IB::Messages:Incoming::Alert object"}
|
54
|
+
IB::Connection.logger.error { "The object: #{msg.inspect} " }
|
55
55
|
else
|
56
56
|
puts "No Logging-Device specified"
|
57
57
|
puts "The object: #{msg.inspect} "
|
@@ -61,9 +61,6 @@ Important: The class is accessed asynchronically. Be careful while raising inter
|
|
61
61
|
|
62
62
|
|
63
63
|
class << self
|
64
|
-
def logger
|
65
|
-
IB::Connection.logger || IB::Gateway.logger
|
66
|
-
end
|
67
64
|
|
68
65
|
def ignore_alert *codes
|
69
66
|
codes.each do |n|
|
@@ -78,7 +75,7 @@ Important: The class is accessed asynchronically. Be careful while raising inter
|
|
78
75
|
codes.each do |n|
|
79
76
|
class_eval <<-EOD
|
80
77
|
def self.alert_#{n} msg
|
81
|
-
logger.info { msg.to_human }
|
78
|
+
# IB::Connection.logger.info { msg.to_human }
|
82
79
|
end
|
83
80
|
EOD
|
84
81
|
end
|
@@ -87,7 +84,7 @@ Important: The class is accessed asynchronically. Be careful while raising inter
|
|
87
84
|
codes.each do |n|
|
88
85
|
class_eval <<-EOD
|
89
86
|
def self.alert_#{n} msg
|
90
|
-
logger.warn { msg.to_human }
|
87
|
+
# IB::Connection.logger.warn { msg.to_human }
|
91
88
|
end
|
92
89
|
EOD
|
93
90
|
end
|
@@ -98,9 +95,9 @@ Important: The class is accessed asynchronically. Be careful while raising inter
|
|
98
95
|
class_eval <<-EOD
|
99
96
|
def self.alert_#{n} msg
|
100
97
|
if msg.error_id.present? && msg.error_id > 0
|
101
|
-
logger.error { msg.message + ' id: ' + msg.error_id.to_s }
|
98
|
+
# IB::Connection.logger.error { msg.message + ' id: ' + msg.error_id.to_s }
|
102
99
|
else
|
103
|
-
logger.error { msg.message }
|
100
|
+
# IB::Connection.logger.error { msg.message }
|
104
101
|
end
|
105
102
|
end
|
106
103
|
EOD
|