ib-ruby 0.8.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore CHANGED
@@ -21,7 +21,6 @@ tmtags
21
21
 
22
22
  ## PROJECT::GENERAL
23
23
  coverage
24
- config
25
24
  data
26
25
  rdoc
27
26
  doc
data/HISTORY CHANGED
@@ -193,3 +193,8 @@
193
193
  == 0.8.1 / 2012-06-13
194
194
 
195
195
  * Combo routing parameters and algo parameters supported
196
+
197
+ == 0.8.3 / 2012-07-15
198
+
199
+ * Rails Engine integration
200
+
data/README.md CHANGED
@@ -69,8 +69,8 @@ other API implementations. The choice is yours.
69
69
  |:------------|------------:|:------------:|
70
70
  | 0.5.21 | 918-920 | 965 |
71
71
  | 0.6.1 | 921-923 | 966 |
72
- | 0.7.1+ | 924-925 | 966 |
73
- | 0.8.0+ | 926+ | 967 |
72
+ | 0.7.1 | 924-925 | 966 |
73
+ | 0.8.1+ | 926-927 | 967 |
74
74
 
75
75
  4. Start Interactive Broker's Trader Work Station or Gateway before your code
76
76
  attempts to connect to it. Note that TWS and Gateway listen to different ports,
@@ -82,8 +82,8 @@ other API implementations. The choice is yours.
82
82
  This is an example of your script that requests and prints out account data, then
83
83
  places limit order to buy 100 lots of WFC and waits for execution. All in about ten
84
84
  lines of code - and without sacrificing code readability or flexibility.
85
-
86
- require 'ib-ruby'
85
+ ``` ruby
86
+ require 'ib'
87
87
 
88
88
  ib = IB::Connection.new :port => 7496
89
89
  ib.subscribe(:Alert, :AccountValue) { |msg| puts msg.to_human }
@@ -98,7 +98,7 @@ lines of code - and without sacrificing code readability or flexibility.
98
98
  :action => :buy, :order_type => :limit
99
99
  ib.place_order buy_order, contract
100
100
  ib.wait_for :ExecutionData
101
-
101
+ ```
102
102
  Your code interacts with TWS via exchange of messages. Messages that you send to
103
103
  TWS are called 'Outgoing', messages your code receives from TWS - 'Incoming'.
104
104
 
@@ -115,7 +115,7 @@ given to `#subscribe`.
115
115
  In order to give TWS time to respond, you either run a message processing loop or
116
116
  just wait until Connection receives the messages type you requested.
117
117
 
118
- See `lib/ib-ruby/messages` for a full list of supported incoming/outgoing messages
118
+ See `lib/ib/messages` for a full list of supported incoming/outgoing messages
119
119
  and their attributes. The original TWS docs and code samples can also be found
120
120
  in `misc` directory.
121
121
 
@@ -123,65 +123,59 @@ The sample scripts in `bin` directory provide examples of how common tasks
123
123
  can be achieved using ib-ruby. You may also want to look into `spec/integration`
124
124
  directory for more scenarios and examples of handling IB messages.
125
125
 
126
- ## DB BACKEND:
127
-
128
- Latest versions of the gem added (optional and experimental) support for data
129
- persistance (ActiveRecord ORM). In order to use this support, you have to set up
130
- the database (SQLite recommended for simplicity) and run migrations located at
131
- 'db/migrate' folder.
132
-
133
- You further need to:
134
-
135
- require 'ib-ruby/db'
136
-
137
- IB::DB.connect :adapter => 'sqlite3',
138
- :database => 'db/test.sqlite3'
126
+ ## RAILS INTEGRATION:
139
127
 
140
- require 'ib-ruby'
128
+ This gem has two operating modes: standalone and Rails-engine. If you require it in a
129
+ Rails environment, it loads Rails engine automatically. Otherwise, it does not load any
130
+ Rails integration.
141
131
 
142
- Only require 'ib-ruby' AFTER you connected to DB, otherwise your Models will not
143
- inherit from ActiveRecord::Base and won't be persistent. If you are using Rails,
144
- you don't need IB::DB.connect part, Rails will take care of it for you. So, just use:
145
-
146
- require 'ib-ruby/db'
147
- require 'ib-ruby'
132
+ To add ib-ruby to your Rails 3 project, follow these steps:
148
133
 
149
- Now, all your IB Models are just ActiveRecords and you can do whatever you want with them:
150
- persist to DB, use in Rails applications, develop controllers and views.
134
+ Add to your Gemfile:
135
+ ``` ruby
136
+ gem 'ib-ruby', '~>0.8'
137
+ ```
138
+ Add the require to your config/application.rb:
139
+ ``` ruby
140
+ require File.expand_path('../boot', __FILE__)
141
+ require 'rails/all'
142
+ require 'ib'
143
+ if defined?(Bundler)
144
+ ```
145
+ Now run:
151
146
 
147
+ $ bundle install
148
+ $ rake ib_engine:install:migrations
152
149
 
153
- ## RUNNING TESTS:
154
-
155
- The gem comes with a spec suit that may be used to test ib-ruby compatibility
156
- with your specific TWS/Gateway installation. The test suit should be run ONLY
157
- against your IB paper trading account. Running it against live account may result
158
- in financial losses.
150
+ This will install ib-ruby gem and copy its migrations into your Rails apps migrations.
159
151
 
160
- In order to run tests, you should set up your IB paper trading connection parameters
161
- in 'spec/spec_helper' file. Modify account_name, host and port under section
162
- 'Your IB PAPER ACCOUNT'. Do not change the client_id.
152
+ You can now use or modify IB models, develop controllers and views for them in your Rails app.
163
153
 
164
- Before running tests, you need to start your TWS/Gateway and allow API connection.
165
- You should not have any open/pending orders on your IB paper trading account prior
166
- to running tests, otherwise some tests will fail. Use 'bin/cancel_orders' script for
167
- bulk cancelling of open orders before running tests as needed.
154
+ ## DB BACKEND:
168
155
 
169
- By default, specs are run without database support (tableless). In order to run them
170
- with database backend, use:
156
+ Even if you don't use Rails, you can still take advantage of its data persistance layer
157
+ (ActiveRecord ORM). In order to use data persistance, you have to set up the database
158
+ (SQLite recommended for simplicity) and run migrations located at gems 'db/migrate' folder.
159
+ It is recommended that you use a gem like [standalone_migrations](https://github.com/thuss/standalone-migrations) for this.
171
160
 
172
- $ rspec -rdb [spec/specific_spec.rb]
161
+ You further need to:
162
+ ``` ruby
163
+ require 'ib/db'
164
+ IB::DB.connect :adapter => 'sqlite3', :database => 'db/test.sqlite3'
165
+ require 'ib'
166
+ ```
167
+ Only require 'ib' AFTER you've connected to DB, otherwise your Models will not
168
+ inherit from ActiveRecord::Base and won't be persistent. If you are using Rails,
169
+ you don't need IB::DB.connect part, Rails will take care of it for you.
173
170
 
174
- Also, by default, specs suppress logging output that is normally produced by IB::Connection.
175
- This may make it difficult to debug a failing spec. Following option will switch on verbose
176
- output (both logger output and content of all received IB messages is dumped). Do not use
177
- this mode to run a whole spec - you will be swamped! Use it to debug specific failing specs
178
- only:
171
+ Now, all your IB Models are just ActiveRecords and you can save them to DB just
172
+ like you would with Rails models.
179
173
 
180
- $ rspec -rv [spec/specific_spec.rb]
174
+ ## RUNNING TESTS:
181
175
 
182
- You can easily create your own tests following the guide in 'spec/README'.
183
- Help the development! See 'spec/TODO' for the list of use cases/scenarios
184
- that still need to be tested.
176
+ The gem comes with a spec suit that may be used to test ib-ruby compatibility with your
177
+ specific TWS/Gateway installation. Please read 'spec/Readme.md' for more details about
178
+ running specs.
185
179
 
186
180
  ## CONTRIBUTING:
187
181
 
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ PKG_PATH = BASE_PATH + 'pkg'
14
14
  DOC_PATH = BASE_PATH + 'rdoc'
15
15
 
16
16
  $LOAD_PATH.unshift LIB_PATH.to_s
17
- require 'ib-ruby/version'
17
+ require 'ib/version'
18
18
 
19
19
  NAME = 'ib-ruby'
20
20
  CLASS_NAME = IB
@@ -39,6 +39,7 @@ rescue LoadError => e
39
39
  puts "gem install standalone_migrations to get db:migrate:* tasks! (Error: #{e})"
40
40
  end
41
41
 
42
+
42
43
  # rake db:redo DB=test"
43
44
  namespace :db do
44
45
  desc "Remake db from scratch: $ rake db:redo DB=test"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.3
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,5 @@
1
+ module Ib
2
+ class ApplicationController <
3
+ defined?(::ApplicationController) ? ::ApplicationController : ActionController::Base
4
+ end
5
+ end
@@ -0,0 +1,87 @@
1
+ require_dependency "ib/application_controller"
2
+
3
+ module Ib
4
+ class UnderlyingsController < ApplicationController
5
+ # GET /underlyings
6
+ # GET /underlyings.json
7
+ def index
8
+ @underlyings = Underlying.all
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.json { render :json => @underlyings }
13
+ end
14
+ end
15
+
16
+ # GET /underlyings/1
17
+ # GET /underlyings/1.json
18
+ def show
19
+ @underlying = Underlying.find(params[:id])
20
+
21
+ respond_to do |format|
22
+ format.html # show.html.erb
23
+ format.json { render :json => @underlying }
24
+ end
25
+ end
26
+
27
+ # GET /underlyings/new
28
+ # GET /underlyings/new.json
29
+ def new
30
+ @underlying = Underlying.new
31
+
32
+ respond_to do |format|
33
+ format.html # new.html.erb
34
+ format.json { render :json => @underlying }
35
+ end
36
+ end
37
+
38
+ # GET /underlyings/1/edit
39
+ def edit
40
+ @underlying = Underlying.find(params[:id])
41
+ end
42
+
43
+ # POST /underlyings
44
+ # POST /underlyings.json
45
+ def create
46
+ @underlying = Underlying.new(params[:underlying])
47
+
48
+ respond_to do |format|
49
+ if @underlying.save
50
+ format.html { redirect_to @underlying, :notice => 'Underlying was successfully created.' }
51
+ format.json { render :json => @underlying, :status => :created, :location => @underlying }
52
+ else
53
+ format.html { render :action => "new" }
54
+ format.json { render :json => @underlying.errors, :status => :unprocessable_entity }
55
+ end
56
+ end
57
+ end
58
+
59
+ # PUT /underlyings/1
60
+ # PUT /underlyings/1.json
61
+ def update
62
+ @underlying = Underlying.find(params[:id])
63
+
64
+ respond_to do |format|
65
+ if @underlying.update_attributes(params[:underlying])
66
+ format.html { redirect_to @underlying, :notice => 'Underlying was successfully updated.' }
67
+ format.json { head :no_content }
68
+ else
69
+ format.html { render :action => "edit" }
70
+ format.json { render :json => @underlying.errors, :status => :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+
75
+ # DELETE /underlyings/1
76
+ # DELETE /underlyings/1.json
77
+ def destroy
78
+ @underlying = Underlying.find(params[:id])
79
+ @underlying.destroy
80
+
81
+ respond_to do |format|
82
+ format.html { redirect_to underlyings_url }
83
+ format.json { head :no_content }
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,4 @@
1
+ module Ib
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Ib
2
+ module UnderlyingsHelper
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module Ib
2
+ class Underlying < ActiveRecord::Base
3
+ attr_accessible :con_id, :contract_id, :delta, :price
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ <%= form_for(@underlying) do |f| %>
2
+ <% if @underlying.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@underlying.errors.count, "error") %> prohibited this underlying from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @underlying.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :contract_id %><br />
16
+ <%= f.number_field :contract_id %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :con_id %><br />
20
+ <%= f.number_field :con_id %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :delta %><br />
24
+ <%= f.text_field :delta %>
25
+ </div>
26
+ <div class="field">
27
+ <%= f.label :price %><br />
28
+ <%= f.text_field :price %>
29
+ </div>
30
+ <div class="actions">
31
+ <%= f.submit %>
32
+ </div>
33
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing underlying</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @underlying %> |
6
+ <%= link_to 'Back', underlyings_path %>
@@ -0,0 +1,29 @@
1
+ <h1>Listing underlyings</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Contract</th>
6
+ <th>Con_id</th>
7
+ <th>Delta</th>
8
+ <th>Price</th>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+
14
+ <% @underlyings.each do |underlying| %>
15
+ <tr>
16
+ <td><%= underlying.contract_id %></td>
17
+ <td><%= underlying.con_id %></td>
18
+ <td><%= underlying.delta %></td>
19
+ <td><%= underlying.price %></td>
20
+ <td><%= link_to 'Show', underlying %></td>
21
+ <td><%= link_to 'Edit', edit_underlying_path(underlying) %></td>
22
+ <td><%= link_to 'Destroy', underlying, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td>
23
+ </tr>
24
+ <% end %>
25
+ </table>
26
+
27
+ <br />
28
+
29
+ <%= link_to 'New Underlying', new_underlying_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New underlying</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', underlyings_path %>
@@ -0,0 +1,25 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Contract:</b>
5
+ <%= @underlying.contract_id %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Con:</b>
10
+ <%= @underlying.con_id %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Delta:</b>
15
+ <%= @underlying.delta %>
16
+ </p>
17
+
18
+ <p>
19
+ <b>Price:</b>
20
+ <%= @underlying.price %>
21
+ </p>
22
+
23
+
24
+ <%= link_to 'Edit', edit_underlying_path(@underlying) %> |
25
+ <%= link_to 'Back', underlyings_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ib</title>
5
+ <%= stylesheet_link_tag "ib/application", :media => "all" %>
6
+ <%= javascript_include_tag "ib/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ IB::Engine.routes.draw do
2
+ resources :underlyings
3
+ # resources :underlyings, :module => "ib"
4
+
5
+ root :to => "underlyings#index"
6
+ end
data/db/config.yml ADDED
@@ -0,0 +1,19 @@
1
+ # DB configuration file
2
+
3
+ # Test stand configurations (JRuby)
4
+ test: &test
5
+ :adapter: jdbcsqlite3
6
+ :database: db/test.sqlite3
7
+ :pool: 5
8
+ :timeout: 5000
9
+
10
+ # Test stand configurations (MRI)
11
+ test-mri:
12
+ <<: *test
13
+ :adapter: sqlite3
14
+
15
+ # Battle configurations (JRuby)
16
+ prod:
17
+ <<: *test
18
+ :database: db/prod.sqlite3
19
+
@@ -1,7 +1,7 @@
1
- class AddExecutions < ActiveRecord::Migration
1
+ class AddIbExecutions < ActiveRecord::Migration
2
2
 
3
3
  def change
4
- create_table(:executions) do |t|
4
+ create_table(:ib_executions) do |t|
5
5
  # TWS orders have fixed local_id of 0 AND client id of 0
6
6
  t.references :order
7
7
  t.integer :local_id # TWS orders have a fixed order id of 0
@@ -1,8 +1,8 @@
1
- class AddBars < ActiveRecord::Migration
1
+ class AddIbBars < ActiveRecord::Migration
2
2
 
3
3
  def change
4
4
  # This is a single data point delivered by HistoricData or RealTimeBar messages.
5
- create_table(:bars) do |t|
5
+ create_table(:ib_bars) do |t|
6
6
  t.float :open # double:
7
7
  t.float :high # double:
8
8
  t.float :low # double:
@@ -1,8 +1,8 @@
1
- class AddOrderStates < ActiveRecord::Migration
1
+ class AddIbOrderStates < ActiveRecord::Migration
2
2
 
3
3
  def change
4
4
  # OrderState represents dynamic (changeable) info about a single Order
5
- create_table(:order_states) do |t|
5
+ create_table(:ib_order_states) do |t|
6
6
  t.references :order
7
7
  t.integer :local_id # int: Order id associated with client (volatile).
8
8
  t.integer :client_id # int: The id of the client that placed this order.
@@ -1,8 +1,8 @@
1
- class AddOrders < ActiveRecord::Migration
1
+ class AddIbOrders < ActiveRecord::Migration
2
2
 
3
3
  def change
4
4
  # OrderState represents dynamic (changeable) info about a single Order
5
- create_table(:orders) do |t|
5
+ create_table(:ib_orders) do |t|
6
6
  t.references :contract # Optional link of Order to its contract
7
7
 
8
8
  t.integer :local_id # int: Order id associated with client (volatile).
@@ -1,8 +1,8 @@
1
- class AddComboLegs < ActiveRecord::Migration
1
+ class AddIbComboLegs < ActiveRecord::Migration
2
2
 
3
3
  def change
4
4
  # ComboLeg objects represent individual security legs in a "BAG"
5
- create_table(:combo_legs) do |t|
5
+ create_table(:ib_combo_legs) do |t|
6
6
  t.references :combo
7
7
  t.references :leg_contract
8
8
  t.integer :con_id # # int: The unique contract identifier specifying the security.
@@ -1,8 +1,8 @@
1
- class AddUnderlyings < ActiveRecord::Migration
1
+ class AddIbUnderlyings < ActiveRecord::Migration
2
2
 
3
3
  def change
4
4
  # Calculated characteristics of underlying Contract (volatile)
5
- create_table(:underlyings) do |t|
5
+ create_table(:ib_underlyings) do |t|
6
6
  t.references :contract
7
7
  t.integer :con_id # # int: The unique contract identifier specifying the security
8
8
  t.float :delta # double: The underlying stock or future delta
@@ -1,8 +1,8 @@
1
- class AddContractDetails < ActiveRecord::Migration
1
+ class AddIbContractDetails < ActiveRecord::Migration
2
2
 
3
3
  def change
4
4
  # ComboLeg objects represent individual security legs in a "BAG"
5
- create_table(:contract_details) do |t|
5
+ create_table(:ib_contract_details) do |t|
6
6
  t.references :contract
7
7
  t.string :market_name # The market name for this contract.
8
8
  t.string :trading_class # The trading class name for this contract.
@@ -1,7 +1,7 @@
1
- class AddContracts < ActiveRecord::Migration
1
+ class AddIbContracts < ActiveRecord::Migration
2
2
 
3
3
  def change
4
- create_table(:contracts) do |t|
4
+ create_table(:ib_contracts) do |t|
5
5
 
6
6
  t.integer :con_id # int: The unique contract identifier.
7
7
  t.string :sec_type, :limit => 5 # Security type. Valid values are: SECURITY_TYPES