ib-ruby 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -145,3 +145,7 @@
145
145
  == 0.7.2 / 2012-03-23
146
146
 
147
147
  * Better spec documentation
148
+
149
+ == 0.7.3 / 2012-03-23
150
+
151
+ * Connection API extended
data/README.md CHANGED
@@ -24,10 +24,11 @@ the same machine as TWS.
24
24
  As a rule of thumb, most recent version of ib-ruby gem only supports latest versions
25
25
  of TWS/Gateway API. Older versions of API are supported by previous gem versions:
26
26
 
27
- ib-ruby gem TWS version API version
28
- 0.5.21 918-920 965
29
- 0.6.1 921-923 966
30
- 0.7.1 924+ 967
27
+ ib-ruby gem TWS version API version
28
+
29
+ 0.5.21 918-920 965
30
+ 0.6.1 921-923 966
31
+ 0.7.1+ 924+ 967
31
32
 
32
33
  ## INSTALLATION:
33
34
 
data/TODO CHANGED
@@ -23,12 +23,13 @@ Done:
23
23
 
24
24
  2. IB#subscribe should accept regexes.
25
25
 
26
- 3. Compatibility with for API v.966, 967
26
+ 3. Compatibility with API v.966, 967
27
27
 
28
28
  4. Collect all received messages in Connection#received[:type] by default
29
29
 
30
30
  5. Flow handlers: Connection#wait_for / Connection#received?
31
31
 
32
+
32
33
  Ideas for future:
33
34
 
34
35
  1. Decouple Broker-specific Adapter from universal high-level messaging layer
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
@@ -155,16 +155,6 @@ module IB
155
155
 
156
156
  ### Working with received messages Hash
157
157
 
158
- # Hash of received messages, keyed by message type
159
- def received
160
- @received ||= Hash.new { |hash, message_type| hash[message_type] = Array.new }
161
- end
162
-
163
- # Check if messages of given type were received at_least n times
164
- def received? message_type, times=1
165
- received[message_type].size >= times
166
- end
167
-
168
158
  # Clear received messages Hash
169
159
  def clear_received *message_types
170
160
  if message_types.empty?
@@ -174,15 +164,19 @@ module IB
174
164
  end
175
165
  end
176
166
 
177
- # Wait for specific condition(s) - given as callable/block, or
178
- # message type(s) - given as Symbol or [Symbol, times] pair.
179
- # Timeout after given time or 1 second.
180
- def wait_for *args, &block
181
- timeout = args.find { |arg| arg.is_a? Numeric } # extract timeout from args
182
- end_time = Time.now + (timeout || 1) # default timeout 1 sec
183
- conditions = args.delete_if { |arg| arg.is_a? Numeric }.push(block).compact
167
+ # Hash of received messages, keyed by message type
168
+ def received
169
+ @received ||= Hash.new { |hash, message_type| hash[message_type] = Array.new }
170
+ end
171
+
172
+ # Check if messages of given type were received at_least n times
173
+ def received? message_type, times=1
174
+ received[message_type].size >= times
175
+ end
184
176
 
185
- sleep 0.1 until end_time < Time.now || !conditions.empty? &&
177
+ # Check if all given conditions are satisfied
178
+ def satisfied? *conditions
179
+ !conditions.empty? &&
186
180
  conditions.inject(true) do |result, condition|
187
181
  result && if condition.is_a?(Symbol)
188
182
  received?(condition)
@@ -196,6 +190,23 @@ module IB
196
190
  end
197
191
  end
198
192
 
193
+ # Wait for specific condition(s) - given as callable/block, or
194
+ # message type(s) - given as Symbol or [Symbol, times] pair.
195
+ # Timeout after given time or 1 second.
196
+ def wait_for *args, &block
197
+ timeout = args.find { |arg| arg.is_a? Numeric } # extract timeout from args
198
+ end_time = Time.now + (timeout || 1) # default timeout 1 sec
199
+ conditions = args.delete_if { |arg| arg.is_a? Numeric }.push(block).compact
200
+
201
+ until end_time < Time.now || satisfied?(*conditions)
202
+ if server[:reader]
203
+ sleep 0.05
204
+ else
205
+ process_messages 50
206
+ end
207
+ end
208
+ end
209
+
199
210
  ### Working with Incoming messages from IB
200
211
 
201
212
  # Start reader thread that continuously reads messages from server in background.
@@ -358,6 +358,7 @@ module IB
358
358
  :scale_auto_reset => false,
359
359
  :scale_random_percent => false,
360
360
  :opt_out_smart_routing => false,
361
+ :status => 'New' # Starting new Orders with this statu
361
362
  }
362
363
 
363
364
  def initialize opts = {}
data/spec/README.md CHANGED
@@ -21,7 +21,7 @@ Pattern for writing integration specs is like this:
21
21
  wait_for in a context before(:all) block.
22
22
 
23
23
  6. It is now time to examine what responses you've got from IB and see if they meet
24
- your expectations. All messages received frem IB are caught and placed into
24
+ your expectations. All messages received from IB are caught and placed into
25
25
  @ib.received Hash, keyed by message type. The Hash has following structure:
26
26
  {:MessageType1 => [msg1, msg2, msg3...], :MessageType2 => [msg1, msg2, msg3...] }.
27
27
 
@@ -41,7 +41,7 @@ describe "Combo Order", :connected => true, :integration => true, :slow => true
41
41
  @contract = butterfly 'GOOG', '201301', 'CALL', 500, 510, 520
42
42
 
43
43
  place_order @contract, :limit_price => 0.01 #, :what_if => true
44
- @ib.wait_for :OpenOrder, :OrderStatus, 5
44
+ @ib.wait_for :OpenOrder, :OrderStatus, 8
45
45
  end
46
46
 
47
47
  after(:all) { close_connection }
@@ -78,7 +78,7 @@ describe "Combo Order", :connected => true, :integration => true, :slow => true
78
78
 
79
79
  @order_id_attached = @ib.place_order @attached_order, @contract
80
80
  @order_id_after = @ib.next_order_id
81
- @ib.wait_for :OpenOrder, :OrderStatus, 5
81
+ @ib.wait_for [:OpenOrder, 2], [:OrderStatus, 2], 8
82
82
  end
83
83
 
84
84
  it_behaves_like 'Placed Order'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ib-ruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.2
5
+ version: 0.7.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paul Legato