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.
- data/.gitignore +0 -1
- data/HISTORY +5 -0
- data/README.md +47 -53
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/app/assets/javascripts/ib/application.js +15 -0
- data/app/assets/javascripts/ib/underlyings.js +2 -0
- data/app/assets/stylesheets/ib/application.css +13 -0
- data/app/assets/stylesheets/ib/underlyings.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/ib/application_controller.rb +5 -0
- data/app/controllers/ib/underlyings_controller.rb +87 -0
- data/app/helpers/ib/application_helper.rb +4 -0
- data/app/helpers/ib/underlyings_helper.rb +4 -0
- data/app/models/ib/underlying.rb +5 -0
- data/app/views/ib/underlyings/_form.html.erb +33 -0
- data/app/views/ib/underlyings/edit.html.erb +6 -0
- data/app/views/ib/underlyings/index.html.erb +29 -0
- data/app/views/ib/underlyings/new.html.erb +5 -0
- data/app/views/ib/underlyings/show.html.erb +25 -0
- data/app/views/layouts/ib/application.html.erb +14 -0
- data/config/routes.rb +6 -0
- data/db/config.yml +19 -0
- data/db/migrate/{101_add_executions.rb → 101_add_ib_executions.rb} +2 -2
- data/db/migrate/{111_add_bars.rb → 111_add_ib_bars.rb} +2 -2
- data/db/migrate/{121_add_order_states.rb → 121_add_ib_order_states.rb} +2 -2
- data/db/migrate/{131_add_orders.rb → 131_add_ib_orders.rb} +2 -2
- data/db/migrate/{141_add_combo_legs.rb → 141_add_ib_combo_legs.rb} +2 -2
- data/db/migrate/{151_add_underlyings.rb → 151_add_ib_underlyings.rb} +2 -2
- data/db/migrate/{161_add_contract_details.rb → 161_add_ib_contract_details.rb} +2 -2
- data/db/migrate/{171_add_contracts.rb → 171_add_ib_contracts.rb} +2 -2
- data/db/schema.rb +245 -0
- data/lib/ib/base.rb +97 -0
- data/lib/ib/base_properties.rb +140 -0
- data/lib/{ib-ruby → ib}/connection.rb +2 -2
- data/lib/{ib-ruby → ib}/constants.rb +0 -0
- data/lib/{ib-ruby → ib}/db.rb +9 -5
- data/lib/ib/engine.rb +35 -0
- data/lib/{ib-ruby → ib}/errors.rb +0 -0
- data/lib/{ib-ruby → ib}/extensions.rb +2 -2
- data/lib/{ib-ruby → ib}/logger.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/abstract_message.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/abstract_message.rb +1 -1
- data/lib/{ib-ruby → ib}/messages/incoming/alert.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/contract_data.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/delta_neutral_validation.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/execution_data.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/historical_data.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/market_depths.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/next_valid_id.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/open_order.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/order_status.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/portfolio_value.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/real_time_bar.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/scanner_data.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming/ticks.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/incoming.rb +14 -14
- data/lib/{ib-ruby → ib}/messages/outgoing/abstract_message.rb +1 -1
- data/lib/{ib-ruby → ib}/messages/outgoing/bar_requests.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/outgoing/place_order.rb +0 -0
- data/lib/{ib-ruby → ib}/messages/outgoing.rb +5 -5
- data/lib/ib/messages.rb +8 -0
- data/lib/ib/model.rb +8 -0
- data/lib/ib/models.rb +10 -0
- data/lib/ib/requires.rb +9 -0
- data/lib/{ib-ruby → ib}/socket.rb +0 -0
- data/lib/{ib-ruby → ib}/symbols/forex.rb +1 -1
- data/lib/{ib-ruby → ib}/symbols/futures.rb +2 -2
- data/lib/{ib-ruby → ib}/symbols/options.rb +1 -1
- data/lib/{ib-ruby → ib}/symbols/stocks.rb +1 -1
- data/lib/ib/symbols.rb +9 -0
- data/lib/{ib-ruby → ib}/version.rb +0 -0
- data/lib/ib-ruby.rb +2 -24
- data/lib/ib.rb +23 -0
- data/lib/models/ib/bag.rb +51 -0
- data/lib/models/ib/bar.rb +41 -0
- data/lib/models/ib/combo_leg.rb +102 -0
- data/lib/models/ib/contract.rb +287 -0
- data/lib/models/ib/contract_detail.rb +68 -0
- data/lib/models/ib/execution.rb +62 -0
- data/lib/models/ib/option.rb +60 -0
- data/lib/models/ib/order.rb +389 -0
- data/lib/models/ib/order_state.rb +126 -0
- data/lib/models/ib/underlying.rb +35 -0
- data/spec/README.md +34 -2
- data/spec/TODO +5 -1
- data/spec/comb.rb +13 -0
- data/spec/db.rb +1 -1
- data/spec/db_helper.rb +3 -3
- data/spec/dummy.rb +13 -0
- data/spec/gw.rb +4 -0
- data/spec/{ib-ruby → ib}/connection_spec.rb +0 -0
- data/spec/{ib-ruby → ib}/messages/incoming/alert_spec.rb +0 -0
- data/spec/{ib-ruby → ib}/messages/incoming/open_order_spec.rb +0 -0
- data/spec/{ib-ruby → ib}/messages/incoming/order_status_spec.rb +16 -17
- data/spec/{ib-ruby → ib}/messages/outgoing/account_data_spec.rb +0 -0
- data/spec/{ib-ruby → ib}/messages/outgoing/market_data_type_spec.rb +0 -0
- data/spec/integration/historic_data_spec.rb +3 -3
- data/spec/integration/orders/trades_spec.rb +1 -1
- data/spec/{ib-ruby/models → models/ib}/bag_spec.rb +2 -7
- data/spec/{ib-ruby/models → models/ib}/bar_spec.rb +1 -6
- data/spec/{ib-ruby/models → models/ib}/combo_leg_spec.rb +2 -12
- data/spec/{ib-ruby/models → models/ib}/contract_detail_spec.rb +3 -8
- data/spec/{ib-ruby/models → models/ib}/contract_spec.rb +4 -12
- data/spec/{ib-ruby/models → models/ib}/execution_spec.rb +2 -7
- data/spec/{ib-ruby/models → models/ib}/option_spec.rb +1 -6
- data/spec/{ib-ruby/models → models/ib}/order_spec.rb +5 -10
- data/spec/{ib-ruby/models → models/ib}/order_state_spec.rb +2 -7
- data/spec/{ib-ruby/models → models/ib}/underlying_spec.rb +3 -7
- data/spec/my.rb +5 -0
- data/spec/spec_helper.rb +62 -36
- metadata +417 -544
- data/lib/ib-ruby/messages.rb +0 -8
- data/lib/ib-ruby/models/bag.rb +0 -54
- data/lib/ib-ruby/models/bar.rb +0 -43
- data/lib/ib-ruby/models/combo_leg.rb +0 -104
- data/lib/ib-ruby/models/contract.rb +0 -287
- data/lib/ib-ruby/models/contract_detail.rb +0 -70
- data/lib/ib-ruby/models/execution.rb +0 -64
- data/lib/ib-ruby/models/model.rb +0 -105
- data/lib/ib-ruby/models/model_properties.rb +0 -146
- data/lib/ib-ruby/models/option.rb +0 -62
- data/lib/ib-ruby/models/order.rb +0 -389
- data/lib/ib-ruby/models/order_state.rb +0 -128
- data/lib/ib-ruby/models/underlying.rb +0 -36
- data/lib/ib-ruby/models.rb +0 -15
- data/lib/ib-ruby/symbols.rb +0 -9
- data/spec/test.rb +0 -61
data/.gitignore
CHANGED
data/HISTORY
CHANGED
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
|
|
73
|
-
| 0.8.
|
|
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
|
|
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
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
150
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
170
|
-
|
|
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
|
-
|
|
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
|
-
|
|
175
|
-
|
|
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
|
-
|
|
174
|
+
## RUNNING TESTS:
|
|
181
175
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
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
|
+
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,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,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,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,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,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,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 %>
|
data/config/routes.rb
ADDED
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
|
|
1
|
+
class AddIbExecutions < ActiveRecord::Migration
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
|
-
create_table(:
|
|
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
|
|
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(:
|
|
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
|
|
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(:
|
|
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
|
|
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(:
|
|
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
|
|
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(:
|
|
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
|
|
1
|
+
class AddIbUnderlyings < ActiveRecord::Migration
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
4
|
# Calculated characteristics of underlying Contract (volatile)
|
|
5
|
-
create_table(:
|
|
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
|
|
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(:
|
|
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
|
|
1
|
+
class AddIbContracts < ActiveRecord::Migration
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
|
-
create_table(:
|
|
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
|