ib-api 10.33.1 → 10.33.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/VERSION +1 -1
- data/api.gemspec +1 -1
- data/lib/ib/connection.rb +46 -20
- data/lib/ib/support.rb +9 -3
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d9a4c216502efb44ea4f2623804809e053f1ba64b86f46aa36bde860a9ade25
|
|
4
|
+
data.tar.gz: 1afd8025c476db5dd8db0aaf266888bd3ee56594a7cf530d8adc739d3095305a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 76cd2898733774d607d2e57ecb6dbf68b9e4edbc3c79f3daaa9648188c93f77157048a03709cd49c633c32cd545d318ce97c482da6cabc942a6425e833d91c2a
|
|
7
|
+
data.tar.gz: 23046dad3ed7332c14d8a3135d5047dd2cbe5fb8b0d157fadfd3dda87131e4188366b5d361508776815ea95e8be6e8d6706e4b38121ef21d3bf2a3af5e8c2da5
|
data/README.md
CHANGED
|
@@ -4,15 +4,18 @@ Ruby interface to Interactive Brokers' TWS API
|
|
|
4
4
|
Reimplementation of ib-ruby
|
|
5
5
|
|
|
6
6
|
---
|
|
7
|
-
|
|
7
|
+
__VERSION 10__
|
|
8
8
|
|
|
9
|
+
You have to switch from "require 'ib-extentions', 'ib-symbols'," etc. to "activate_plugin :name"
|
|
9
10
|
---
|
|
10
11
|
|
|
12
|
+
**Whats new**
|
|
13
|
+
|
|
11
14
|
* Zeitwerk integration.
|
|
12
15
|
* Plugin's to ease automations
|
|
13
16
|
---
|
|
14
17
|
|
|
15
|
-
__Documentation: [https://ib-ruby.github.io/ib-doc/](https://ib-ruby.github.io/ib-doc/)__
|
|
18
|
+
__Documentation: [https://ib-ruby.github.io/ib-doc/](https://ib-ruby.github.io/ib-doc/)__
|
|
16
19
|
|
|
17
20
|
----
|
|
18
21
|
`ib-api` offers a modular access to the TWS-API-Interface of Interactive Brokers.
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
10.33.
|
|
1
|
+
10.33.4
|
data/api.gemspec
CHANGED
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
|
40
40
|
spec.add_development_dependency "bundler", "~> 2.0"
|
|
41
41
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
42
42
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
43
|
-
spec.add_dependency 'activesupport', '~>
|
|
43
|
+
spec.add_dependency 'activesupport', '~> 7.0'
|
|
44
44
|
spec.add_dependency 'activemodel', '~> 7.0'
|
|
45
45
|
spec.add_dependency 'ox', '~> 2.14'
|
|
46
46
|
spec.add_dependency 'terminal-table', '~> 3.0'
|
data/lib/ib/connection.rb
CHANGED
|
@@ -161,7 +161,19 @@ module IB
|
|
|
161
161
|
logger.info { "Got next valid order id: #{@next_local_id}." }
|
|
162
162
|
end
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
retries = 5
|
|
165
|
+
begin
|
|
166
|
+
self.socket = IB::Socket.open(@host, @port)
|
|
167
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
|
|
168
|
+
if (retries -= 1) > 0
|
|
169
|
+
logger.warn "Connection refused, retrying in 10 seconds (#{retries} retries left)..."
|
|
170
|
+
sleep 10
|
|
171
|
+
retry
|
|
172
|
+
else
|
|
173
|
+
logger.error "Connection failed after multiple retries: #{e.message}"
|
|
174
|
+
raise
|
|
175
|
+
end
|
|
176
|
+
end
|
|
165
177
|
socket.initialising_handshake
|
|
166
178
|
@parser = RawMessageParser.new socket
|
|
167
179
|
@parser.each do | the_message |
|
|
@@ -359,7 +371,7 @@ module IB
|
|
|
359
371
|
if reader_running?
|
|
360
372
|
sleep 0.05
|
|
361
373
|
else
|
|
362
|
-
process_messages
|
|
374
|
+
process_messages
|
|
363
375
|
end
|
|
364
376
|
end
|
|
365
377
|
end
|
|
@@ -372,7 +384,7 @@ module IB
|
|
|
372
384
|
@reader_running && @reader_thread && @reader_thread.alive?
|
|
373
385
|
end
|
|
374
386
|
|
|
375
|
-
# Process incoming messages during *poll_time* (
|
|
387
|
+
# Process incoming messages during *poll_time* (50) msecs, nonblocking
|
|
376
388
|
def process_messages poll_time = 50 # in msec
|
|
377
389
|
time_out = Time.now + poll_time/1000.0
|
|
378
390
|
begin
|
|
@@ -385,16 +397,17 @@ module IB
|
|
|
385
397
|
# the following checks for shutdown of TWS side; ensures we don't run in a spin loop.
|
|
386
398
|
# unfortunately, it raises Errors in windows environment
|
|
387
399
|
if select [socket], nil, nil, time_left
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
400
|
+
# Peek at the message from the socket; if it's blank or recvmsg returns nil
|
|
401
|
+
# (Ruby 3.4+ behavior), the server side of connection (TWS) has likely shut down.
|
|
402
|
+
peek_result = socket.recvmsg(100, ::Socket::MSG_PEEK)
|
|
403
|
+
socket_likely_shutdown = peek_result.nil? || peek_result[0] == ""
|
|
404
|
+
# We go ahead process messages regardless (a no-op if socket_likely_shutdown).
|
|
405
|
+
process_message
|
|
406
|
+
# After processing, if socket has shut down we sleep for 100ms
|
|
407
|
+
# to avoid spinning in a tight loop. If the server side somehow
|
|
408
|
+
# comes back up (gets reconnedted), normal processing
|
|
409
|
+
# (without the 1s wait) should happen.
|
|
410
|
+
sleep(1) if socket_likely_shutdown
|
|
398
411
|
end # if
|
|
399
412
|
end # if
|
|
400
413
|
end # while
|
|
@@ -483,16 +496,29 @@ module IB
|
|
|
483
496
|
if @reader_running
|
|
484
497
|
@reader_thread
|
|
485
498
|
else # connected? # if called from try_connection, the connected state is not set
|
|
486
|
-
begin
|
|
487
499
|
Thread.abort_on_exception = true
|
|
488
500
|
@reader_running = true
|
|
489
|
-
@reader_thread = Thread.new
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
501
|
+
@reader_thread = Thread.new do
|
|
502
|
+
begin
|
|
503
|
+
process_messages while @reader_running
|
|
504
|
+
rescue NoMethodError => e
|
|
505
|
+
# this error is raised if the socket is closed (recvfrom returns nil)
|
|
506
|
+
# a daily reset of the TWS is a typical reason for this
|
|
507
|
+
if e.message.include?("undefined method '[]' for nil")
|
|
508
|
+
logger.info "Socket read error. Connection likely closed by TWS. Reconnecting."
|
|
509
|
+
@reader_running = false
|
|
510
|
+
Thread.new{ reconnect }
|
|
511
|
+
else
|
|
512
|
+
# re-raise other NoMethodErrors
|
|
513
|
+
raise e
|
|
514
|
+
end
|
|
515
|
+
rescue Errno::ECONNRESET => e
|
|
516
|
+
logger.fatal "Connection reset. Reconnecting."
|
|
517
|
+
logger.fatal e.message
|
|
518
|
+
@reader_running = false
|
|
519
|
+
Thread.new{ reconnect }
|
|
520
|
+
end
|
|
493
521
|
end
|
|
494
|
-
# else
|
|
495
|
-
# error "Could not start reader, not connected!", :reader, true
|
|
496
522
|
end
|
|
497
523
|
end
|
|
498
524
|
|
data/lib/ib/support.rb
CHANGED
|
@@ -28,9 +28,15 @@ module IB
|
|
|
28
28
|
|
|
29
29
|
end
|
|
30
30
|
def read_decimal
|
|
31
|
-
i= self.shift
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
i = self.shift rescue nil
|
|
32
|
+
return nil if i.blank?
|
|
33
|
+
d = i.to_d
|
|
34
|
+
return nil unless d.is_a?(Numeric) && d < IB::TWS_MAX
|
|
35
|
+
if d == d.to_i
|
|
36
|
+
d.to_i
|
|
37
|
+
else
|
|
38
|
+
d.to_f
|
|
39
|
+
end
|
|
34
40
|
end
|
|
35
41
|
|
|
36
42
|
alias read_decimal_max read_decimal
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ib-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 10.33.
|
|
4
|
+
version: 10.33.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hartmut Bischoff
|
|
@@ -57,14 +57,14 @@ dependencies:
|
|
|
57
57
|
requirements:
|
|
58
58
|
- - "~>"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '
|
|
60
|
+
version: '7.0'
|
|
61
61
|
type: :runtime
|
|
62
62
|
prerelease: false
|
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '
|
|
67
|
+
version: '7.0'
|
|
68
68
|
- !ruby/object:Gem::Dependency
|
|
69
69
|
name: activemodel
|
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|