ib-ruby 0.8.1 → 0.8.3

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.
Files changed (128) hide show
  1. data/.gitignore +0 -1
  2. data/HISTORY +5 -0
  3. data/README.md +47 -53
  4. data/Rakefile +2 -1
  5. data/VERSION +1 -1
  6. data/app/assets/javascripts/ib/application.js +15 -0
  7. data/app/assets/javascripts/ib/underlyings.js +2 -0
  8. data/app/assets/stylesheets/ib/application.css +13 -0
  9. data/app/assets/stylesheets/ib/underlyings.css +4 -0
  10. data/app/assets/stylesheets/scaffold.css +56 -0
  11. data/app/controllers/ib/application_controller.rb +5 -0
  12. data/app/controllers/ib/underlyings_controller.rb +87 -0
  13. data/app/helpers/ib/application_helper.rb +4 -0
  14. data/app/helpers/ib/underlyings_helper.rb +4 -0
  15. data/app/models/ib/underlying.rb +5 -0
  16. data/app/views/ib/underlyings/_form.html.erb +33 -0
  17. data/app/views/ib/underlyings/edit.html.erb +6 -0
  18. data/app/views/ib/underlyings/index.html.erb +29 -0
  19. data/app/views/ib/underlyings/new.html.erb +5 -0
  20. data/app/views/ib/underlyings/show.html.erb +25 -0
  21. data/app/views/layouts/ib/application.html.erb +14 -0
  22. data/config/routes.rb +6 -0
  23. data/db/config.yml +19 -0
  24. data/db/migrate/{101_add_executions.rb → 101_add_ib_executions.rb} +2 -2
  25. data/db/migrate/{111_add_bars.rb → 111_add_ib_bars.rb} +2 -2
  26. data/db/migrate/{121_add_order_states.rb → 121_add_ib_order_states.rb} +2 -2
  27. data/db/migrate/{131_add_orders.rb → 131_add_ib_orders.rb} +2 -2
  28. data/db/migrate/{141_add_combo_legs.rb → 141_add_ib_combo_legs.rb} +2 -2
  29. data/db/migrate/{151_add_underlyings.rb → 151_add_ib_underlyings.rb} +2 -2
  30. data/db/migrate/{161_add_contract_details.rb → 161_add_ib_contract_details.rb} +2 -2
  31. data/db/migrate/{171_add_contracts.rb → 171_add_ib_contracts.rb} +2 -2
  32. data/db/schema.rb +245 -0
  33. data/lib/ib/base.rb +97 -0
  34. data/lib/ib/base_properties.rb +140 -0
  35. data/lib/{ib-ruby → ib}/connection.rb +2 -2
  36. data/lib/{ib-ruby → ib}/constants.rb +0 -0
  37. data/lib/{ib-ruby → ib}/db.rb +9 -5
  38. data/lib/ib/engine.rb +35 -0
  39. data/lib/{ib-ruby → ib}/errors.rb +0 -0
  40. data/lib/{ib-ruby → ib}/extensions.rb +2 -2
  41. data/lib/{ib-ruby → ib}/logger.rb +0 -0
  42. data/lib/{ib-ruby → ib}/messages/abstract_message.rb +0 -0
  43. data/lib/{ib-ruby → ib}/messages/incoming/abstract_message.rb +1 -1
  44. data/lib/{ib-ruby → ib}/messages/incoming/alert.rb +0 -0
  45. data/lib/{ib-ruby → ib}/messages/incoming/contract_data.rb +0 -0
  46. data/lib/{ib-ruby → ib}/messages/incoming/delta_neutral_validation.rb +0 -0
  47. data/lib/{ib-ruby → ib}/messages/incoming/execution_data.rb +0 -0
  48. data/lib/{ib-ruby → ib}/messages/incoming/historical_data.rb +0 -0
  49. data/lib/{ib-ruby → ib}/messages/incoming/market_depths.rb +0 -0
  50. data/lib/{ib-ruby → ib}/messages/incoming/next_valid_id.rb +0 -0
  51. data/lib/{ib-ruby → ib}/messages/incoming/open_order.rb +0 -0
  52. data/lib/{ib-ruby → ib}/messages/incoming/order_status.rb +0 -0
  53. data/lib/{ib-ruby → ib}/messages/incoming/portfolio_value.rb +0 -0
  54. data/lib/{ib-ruby → ib}/messages/incoming/real_time_bar.rb +0 -0
  55. data/lib/{ib-ruby → ib}/messages/incoming/scanner_data.rb +0 -0
  56. data/lib/{ib-ruby → ib}/messages/incoming/ticks.rb +0 -0
  57. data/lib/{ib-ruby → ib}/messages/incoming.rb +14 -14
  58. data/lib/{ib-ruby → ib}/messages/outgoing/abstract_message.rb +1 -1
  59. data/lib/{ib-ruby → ib}/messages/outgoing/bar_requests.rb +0 -0
  60. data/lib/{ib-ruby → ib}/messages/outgoing/place_order.rb +0 -0
  61. data/lib/{ib-ruby → ib}/messages/outgoing.rb +5 -5
  62. data/lib/ib/messages.rb +8 -0
  63. data/lib/ib/model.rb +8 -0
  64. data/lib/ib/models.rb +10 -0
  65. data/lib/ib/requires.rb +9 -0
  66. data/lib/{ib-ruby → ib}/socket.rb +0 -0
  67. data/lib/{ib-ruby → ib}/symbols/forex.rb +1 -1
  68. data/lib/{ib-ruby → ib}/symbols/futures.rb +2 -2
  69. data/lib/{ib-ruby → ib}/symbols/options.rb +1 -1
  70. data/lib/{ib-ruby → ib}/symbols/stocks.rb +1 -1
  71. data/lib/ib/symbols.rb +9 -0
  72. data/lib/{ib-ruby → ib}/version.rb +0 -0
  73. data/lib/ib-ruby.rb +2 -24
  74. data/lib/ib.rb +23 -0
  75. data/lib/models/ib/bag.rb +51 -0
  76. data/lib/models/ib/bar.rb +41 -0
  77. data/lib/models/ib/combo_leg.rb +102 -0
  78. data/lib/models/ib/contract.rb +287 -0
  79. data/lib/models/ib/contract_detail.rb +68 -0
  80. data/lib/models/ib/execution.rb +62 -0
  81. data/lib/models/ib/option.rb +60 -0
  82. data/lib/models/ib/order.rb +389 -0
  83. data/lib/models/ib/order_state.rb +126 -0
  84. data/lib/models/ib/underlying.rb +35 -0
  85. data/spec/README.md +34 -2
  86. data/spec/TODO +5 -1
  87. data/spec/comb.rb +13 -0
  88. data/spec/db.rb +1 -1
  89. data/spec/db_helper.rb +3 -3
  90. data/spec/dummy.rb +13 -0
  91. data/spec/gw.rb +4 -0
  92. data/spec/{ib-ruby → ib}/connection_spec.rb +0 -0
  93. data/spec/{ib-ruby → ib}/messages/incoming/alert_spec.rb +0 -0
  94. data/spec/{ib-ruby → ib}/messages/incoming/open_order_spec.rb +0 -0
  95. data/spec/{ib-ruby → ib}/messages/incoming/order_status_spec.rb +16 -17
  96. data/spec/{ib-ruby → ib}/messages/outgoing/account_data_spec.rb +0 -0
  97. data/spec/{ib-ruby → ib}/messages/outgoing/market_data_type_spec.rb +0 -0
  98. data/spec/integration/historic_data_spec.rb +3 -3
  99. data/spec/integration/orders/trades_spec.rb +1 -1
  100. data/spec/{ib-ruby/models → models/ib}/bag_spec.rb +2 -7
  101. data/spec/{ib-ruby/models → models/ib}/bar_spec.rb +1 -6
  102. data/spec/{ib-ruby/models → models/ib}/combo_leg_spec.rb +2 -12
  103. data/spec/{ib-ruby/models → models/ib}/contract_detail_spec.rb +3 -8
  104. data/spec/{ib-ruby/models → models/ib}/contract_spec.rb +4 -12
  105. data/spec/{ib-ruby/models → models/ib}/execution_spec.rb +2 -7
  106. data/spec/{ib-ruby/models → models/ib}/option_spec.rb +1 -6
  107. data/spec/{ib-ruby/models → models/ib}/order_spec.rb +5 -10
  108. data/spec/{ib-ruby/models → models/ib}/order_state_spec.rb +2 -7
  109. data/spec/{ib-ruby/models → models/ib}/underlying_spec.rb +3 -7
  110. data/spec/my.rb +5 -0
  111. data/spec/spec_helper.rb +62 -36
  112. metadata +417 -544
  113. data/lib/ib-ruby/messages.rb +0 -8
  114. data/lib/ib-ruby/models/bag.rb +0 -54
  115. data/lib/ib-ruby/models/bar.rb +0 -43
  116. data/lib/ib-ruby/models/combo_leg.rb +0 -104
  117. data/lib/ib-ruby/models/contract.rb +0 -287
  118. data/lib/ib-ruby/models/contract_detail.rb +0 -70
  119. data/lib/ib-ruby/models/execution.rb +0 -64
  120. data/lib/ib-ruby/models/model.rb +0 -105
  121. data/lib/ib-ruby/models/model_properties.rb +0 -146
  122. data/lib/ib-ruby/models/option.rb +0 -62
  123. data/lib/ib-ruby/models/order.rb +0 -389
  124. data/lib/ib-ruby/models/order_state.rb +0 -128
  125. data/lib/ib-ruby/models/underlying.rb +0 -36
  126. data/lib/ib-ruby/models.rb +0 -15
  127. data/lib/ib-ruby/symbols.rb +0 -9
  128. data/spec/test.rb +0 -61
@@ -1,6 +1,6 @@
1
1
  require 'model_helper'
2
2
 
3
- describe IB::Models::OrderState,
3
+ describe IB::OrderState,
4
4
  :props =>
5
5
  {:local_id => 23,
6
6
  :perm_id => 173276893,
@@ -42,11 +42,6 @@ describe IB::Models::OrderState,
42
42
  it_behaves_like 'Self-equal Model'
43
43
  it_behaves_like 'Model with invalid defaults'
44
44
 
45
- it 'has class name shortcut' do
46
- IB::OrderState.should == IB::Models::OrderState
47
- IB::OrderState.new.should == IB::Models::OrderState.new
48
- end
49
-
50
45
  context '#update_missing' do
51
46
  let(:nil_state) { IB::OrderState.new(:filled => nil, :remaining => nil,
52
47
  :price => nil, :average_price => nil) }
@@ -108,4 +103,4 @@ describe IB::Models::OrderState,
108
103
  subject.should_not be_submitted
109
104
  end
110
105
 
111
- end # describe IB::Order
106
+ end # describe IB::OrderState
@@ -1,6 +1,6 @@
1
1
  require 'model_helper'
2
2
 
3
- describe IB::Models::Underlying,
3
+ describe IB::Underlying,
4
4
  :props =>
5
5
  {:con_id => 234567,
6
6
  :delta => 0.55,
@@ -17,13 +17,9 @@ describe IB::Models::Underlying,
17
17
  :assigns =>
18
18
  {[:con_id, :delta, :price] => numeric_assigns,
19
19
 
20
- } do # AKA IB::Underlying
20
+ } do
21
21
 
22
22
  it_behaves_like 'Self-equal Model'
23
23
  it_behaves_like 'Model with invalid defaults'
24
24
 
25
- it 'has class name shortcut' do
26
- IB::Underlying.should == IB::Models::Underlying
27
- IB::Underlying.new.should == IB::Models::Underlying.new
28
- end
29
- end # describe IB::Contract
25
+ end # describe IB::ib/
data/spec/my.rb ADDED
@@ -0,0 +1,5 @@
1
+ # My very specific IB connection configuration to run the specs
2
+
3
+ ACCOUNT = 'DU118180'
4
+ HOST = '10.211.55.2'
5
+ PORT = 4001
data/spec/spec_helper.rb CHANGED
@@ -1,61 +1,87 @@
1
1
  require 'rspec'
2
- require 'ib-ruby'
2
+ require 'ib'
3
3
 
4
- PORT ||= 4001 # 4001 for Gateway, 7496 for TWS GUI
4
+ # Configure top level option indicating how the test suite should be run
5
5
 
6
- # Top (test suite) level metadata
7
6
  OPTS ||= {
8
- :verbose => false, #true, # Verbosity of test outputs
9
- :brokertron => false, # Use mock (Brokertron) instead of paper account
7
+ :verbose => false, #true, # Run test suite in a verbose mode ?
8
+ :brokertron => false, # Use mock (Brokertron) instead of paper account ?
9
+ :db => IB.db_backed?,
10
+ :rails => IB.rails?
10
11
  }
11
12
 
12
13
  if OPTS[:brokertron]
14
+ puts "Using Brokerton free.brokertron.com mock service."
13
15
  # Connection to mock (Brokertron) account
14
- OPTS[:connection] =
15
- {:client_id => 1111, # Just an arbitrary id
16
- :host => 'free.brokertron.com',
17
- :port=> 10501
18
- }
16
+ OPTS[:connection] = {
17
+ :client_id => 1111, # Client id that identifies the test suit
18
+ :host => 'free.brokertron.com',
19
+ :port => 10501
20
+ }
19
21
  else
20
22
  # Connection to IB PAPER ACCOUNT
21
- OPTS[:connection] =
22
- {:account_name => 'DU118180', # Your IB PAPER ACCOUNT, tests will only run against it
23
- :client_id => 1111, # Just an arbitrary id
24
- :host => '10.211.55.2', # Where your TWS/gateway is located, likely '127.0.0.1'
25
- :port => PORT,
26
- :reuters => true # Subscription to Reuters data enabled ?
27
- }
23
+ ACCOUNT ||= 'DU60320'
24
+ HOST ||= '127.0.0.1'
25
+ PORT ||= 7496
26
+
27
+ OPTS[:connection] = {
28
+ :account => ACCOUNT, # Your IB PAPER ACCOUNT, tests will only run against it
29
+ :host => HOST, # Where your TWS/gateway is located, likely '127.0.0.1'
30
+ :port => PORT, # 4001 for Gateway, 7496 for TWS GUI
31
+ :client_id => 1111, # Client id that identifies the test suit
32
+ :reuters => true # Subscription to Reuters data enabled ?
33
+ }
28
34
  end
29
35
 
30
36
  RSpec.configure do |config|
31
- config.exclusion_filter = {
32
- :if => proc do |condition|
33
- t = Time.now.utc
34
- case condition # NB: excludes if condition is false!
35
- when :us_trading_hours
36
- # 09:30 - 16:00 (ET) Mon-Fri 14:30 - 21:00 (UTC)
37
- !(t.wday >= 1 && t.wday <= 5 && t.hour >= 15 && t.hour <= 21)
38
- when :forex_trading_hours
39
- # 17:15 - 17:00 (ET) Sunday-Friday Forex 22:15 - 22:00 (UTC)
40
- !(t.wday > 0 && t.wday < 5 || t.wday == 5 && t.hour < 22)
41
- end
42
- end,
43
-
44
- :db => proc { |condition| !IB::DB == condition }, # true/false
45
-
46
- :reuters => proc { |condition| !OPTS[:connection][:reuters] == condition } # true/false
47
- }
37
+
38
+ puts "Running specs '#{config.pattern}' with OPTS:"
39
+ pp OPTS
40
+
48
41
  # config.filter = { :focus => true }
49
42
  # config.include(UserExampleHelpers)
50
43
  # config.mock_with :mocha
51
44
  # config.mock_with :flexmock
52
45
  # config.mock_with :rr
53
46
 
54
- if IB::DB
47
+ config.exclusion_filter = {
48
+ :if => proc do |condition|
49
+ t = Time.now.utc
50
+ case condition # NB: excludes if condition is false!
51
+ when :us_trading_hours
52
+ # 09:30 - 16:00 (ET) Mon-Fri 14:30 - 21:00 (UTC)
53
+ !(t.wday >= 1 && t.wday <= 5 && t.hour >= 15 && t.hour <= 21)
54
+ when :forex_trading_hours
55
+ # 17:15 - 17:00 (ET) Sunday-Friday Forex 22:15 - 22:00 (UTC)
56
+ !(t.wday > 0 && t.wday < 5 || t.wday == 5 && t.hour < 22)
57
+ end
58
+ end,
59
+
60
+ :db => proc { |condition| IB.db_backed? != condition }, # true/false
61
+
62
+ :rails => proc { |condition| IB.rails? != condition }, # true/false
63
+
64
+ :reuters => proc { |condition| !OPTS[:connection][:reuters] == condition }, # true/false
65
+ }
66
+
67
+ if OPTS[:db]
68
+ require 'database_cleaner'
69
+
55
70
  config.before(:suite) do
56
71
  DatabaseCleaner.strategy = :truncation
57
72
  DatabaseCleaner.clean
58
73
  end
74
+
75
+ config.after(:suite) do
76
+ DatabaseCleaner.clean
77
+ end
59
78
  end
60
- end
61
79
 
80
+ if OPTS[:rails]
81
+ config.include IB::Engine.routes.url_helpers,
82
+ :example_group => {:file_path => /\brails_spec\//}
83
+
84
+ config.include Capybara::DSL,
85
+ :example_group => { :file_path => /\brails_spec\//}
86
+ end
87
+ end