mytradewizard 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/.rvmrc +1 -1
- data/LICENSE +1 -1
- data/README.md +34 -3
- data/lib/mytradewizard.rb +6 -0
- data/lib/mytradewizard/ohlc.rb +19 -0
- data/lib/mytradewizard/stock.rb +15 -0
- data/lib/mytradewizard/technical_indicator.rb +17 -0
- data/lib/mytradewizard/trading_system.rb +4 -0
- data/lib/mytradewizard/version.rb +1 -1
- data/lib/mytradewizard/watch_list.rb +23 -0
- data/lib/mytradewizard/yahoo.rb +55 -0
- data/mytradewizard.gemspec +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmM3MTIxNGNiYTVmNDVlMzYyMDUxMmFlNjViOWIxOWI0ODk5NjFkOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWM3NGFmNmQ0ZGU2YjcwYzhlMWM4ZGY0NTMxMDYzMTU5MzQ4OTMyMQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDFhODNiNjNmMzAwNmNhMTM1ZjJhZWQzMDljNjAzMzNiOTc2ZjRhMWIxZWU3
|
10
|
+
YjQwOGU3ODIzMjYyYWRkZmNjYTViNGQ2ZWIxY2UxMTQ3OTE3YWM5NGM3OGQx
|
11
|
+
ZDY5N2I1ZTg3YzU1ODQ4ZDIxMmY1NTQxZjM3MjRmZTFhNWQyMmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDJmOGQ2MDM0MjE3MTIxNjU3NjQzMTYzYWI5ZDc1ZTBmNDcyMjg1MzQzZGM2
|
14
|
+
MGNhZWQwY2NjNGZjYTU5ZjA3N2ExYmJlNjZjODkxNTgwMDFiNTEwNWYzNGFj
|
15
|
+
MGFiMWE1NzMyMTI4ZWE4MzRmYTdlNjU5Y2FmM2JlNDZmNDViMGI=
|
data/.rvmrc
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
7
|
# Only full ruby name is supported here, for short names use:
|
8
8
|
# echo "rvm use 1.9.2" > .rvmrc
|
9
|
-
environment_id="ruby-
|
9
|
+
environment_id="ruby-1.9.3-p448"
|
10
10
|
|
11
11
|
# Uncomment the following lines if you want to verify rvm version per project
|
12
12
|
# rvmrc_rvm_version="1.21.14 (stable)" # 1.10.1 seems like a safe start
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# mytradewizard gem
|
2
2
|
|
3
|
-
|
3
|
+
This gem provides a Ruby and Command Line Interface for the Interactive Brokers API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,38 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
By default, mytradewizard assumes that the Interactive Brokers Trader Workstation is running on localhost port 7496. To configure hostname and/or port:
|
22
|
+
|
23
|
+
$ mtw configure [-- host HOST] [-- port PORT]
|
24
|
+
|
25
|
+
You can always display current configuration:
|
26
|
+
|
27
|
+
$ mtw config
|
28
|
+
|
29
|
+
To begin, it is recommended that you test the connection:
|
30
|
+
|
31
|
+
$ mtw connect
|
32
|
+
|
33
|
+
Then you can display a list of accounts:
|
34
|
+
|
35
|
+
$ mtw accounts
|
36
|
+
|
37
|
+
Determine front month Crude:
|
38
|
+
|
39
|
+
$ mtw CL
|
40
|
+
|
41
|
+
Or Mini-Crude:
|
42
|
+
|
43
|
+
$ mtw QM
|
44
|
+
|
45
|
+
To do the same from a ruby program:
|
46
|
+
|
47
|
+
require 'mytradewizard'
|
48
|
+
ib = MyTradeWizard::InteractiveBrokers.new
|
49
|
+
ib.connect(60) # optional 60 second timeout
|
50
|
+
ib.accounts
|
51
|
+
ib.front_month(:CL)
|
52
|
+
ib.front_month(:QM)
|
22
53
|
|
23
54
|
## Contributing
|
24
55
|
|
data/lib/mytradewizard.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'mytradewizard/version'
|
2
2
|
require 'mytradewizard/interactive_brokers'
|
3
3
|
require 'mytradewizard/cme'
|
4
|
+
require 'mytradewizard/yahoo'
|
5
|
+
require 'mytradewizard/ohlc'
|
6
|
+
require 'mytradewizard/stock'
|
7
|
+
require 'mytradewizard/watch_list'
|
8
|
+
require 'mytradewizard/technical_indicator'
|
9
|
+
require 'mytradewizard/trading_system'
|
4
10
|
|
5
11
|
module MyTradeWizard
|
6
12
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ib'
|
2
|
+
|
3
|
+
module MyTradeWizard
|
4
|
+
class Stock
|
5
|
+
|
6
|
+
attr_reader :symbol
|
7
|
+
attr_reader :contract
|
8
|
+
|
9
|
+
def initialize(symbol)
|
10
|
+
@symbol = symbol
|
11
|
+
@contract = IB::Contract.new(:sec_type => :stock, :symbol => symbol, :currency => "USD")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MyTradeWizard
|
2
|
+
class WatchList
|
3
|
+
|
4
|
+
attr_accessor :stocks
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@stocks = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(x)
|
11
|
+
if x.is_a?(MyTradeWizard::Stock)
|
12
|
+
@stocks << x
|
13
|
+
elsif x.is_a?(Array) && x.first.is_a?(MyTradeWizard::Stock)
|
14
|
+
x.each { |stock| @stocks << stock }
|
15
|
+
elsif x.is_a?(String)
|
16
|
+
@stocks << MyTradeWizard::Stock.new(x)
|
17
|
+
elsif x.is_a?(Array) && x.first.is_a?(String)
|
18
|
+
x.each { |symbol| @stocks << MyTradeWizard::Stock.new(symbol) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'csv'
|
3
|
+
require 'active_support/time'
|
4
|
+
|
5
|
+
module MyTradeWizard
|
6
|
+
class Yahoo
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def OHLC(symbol, days, end_date = Date.today)
|
10
|
+
sd = start_date(end_date, days)
|
11
|
+
u = url(symbol, sd.month - 1, sd.day, sd.year, end_date.month, end_date.day, end_date.year, 'd')
|
12
|
+
csv = CSV.parse(open(u))
|
13
|
+
header = csv.first
|
14
|
+
if (Date.parse(csv[1][0]) == end_date)
|
15
|
+
day = 0
|
16
|
+
else
|
17
|
+
day = -1
|
18
|
+
end
|
19
|
+
row = 1
|
20
|
+
bars = Hash.new
|
21
|
+
while (bars.length < days)
|
22
|
+
bar = Hash.new
|
23
|
+
csv[row].each_with_index do |col, i|
|
24
|
+
name = header[i]
|
25
|
+
value = csv[row][i]
|
26
|
+
if name == "Date"
|
27
|
+
value = Date.parse(value)
|
28
|
+
elsif ["Open", "High", "Low", "Close", "Adj Close"].include?(name)
|
29
|
+
value = value.to_f
|
30
|
+
elsif name == "Volume"
|
31
|
+
value = value.to_i
|
32
|
+
end
|
33
|
+
bar[name] = value
|
34
|
+
end
|
35
|
+
bars[day] = MyTradeWizard::OHLC.new(bar)
|
36
|
+
row += 1
|
37
|
+
day -= 1
|
38
|
+
end
|
39
|
+
bars
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def start_date(end_date, n)
|
45
|
+
end_date - (2*n+1).days
|
46
|
+
end
|
47
|
+
|
48
|
+
def url(symbol, start_month, start_day, start_year, end_month, end_day, end_year, frequency)
|
49
|
+
query_string = "?s=#{symbol}&a=#{start_month}&b#{start_day}&c=#{start_year}&d=#{end_month}&e=#{end_day}&f=#{end_year}&g=#{frequency}"
|
50
|
+
url = 'http://ichart.finance.yahoo.com/table.csv' + query_string
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/mytradewizard.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = MyTradeWizard::VERSION
|
9
9
|
gem.authors = ["mytradewizard"]
|
10
10
|
gem.email = ["zack@mytradewizard.com"]
|
11
|
-
gem.description = "Helpers for CME Group and
|
11
|
+
gem.description = "Helpers for CME Group, Interactive Brokers, and Yahoo Finance"
|
12
12
|
gem.summary = "My Trade Wizard"
|
13
13
|
gem.homepage = ""
|
14
14
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mytradewizard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mytradewizard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -164,7 +164,7 @@ dependencies:
|
|
164
164
|
- - ! '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
-
description: Helpers for CME Group and
|
167
|
+
description: Helpers for CME Group, Interactive Brokers, and Yahoo Finance
|
168
168
|
email:
|
169
169
|
- zack@mytradewizard.com
|
170
170
|
executables:
|
@@ -191,7 +191,13 @@ files:
|
|
191
191
|
- lib/mytradewizard/generators/config/interactive_brokers.rb
|
192
192
|
- lib/mytradewizard/generators/interactive_brokers.rb
|
193
193
|
- lib/mytradewizard/interactive_brokers.rb
|
194
|
+
- lib/mytradewizard/ohlc.rb
|
195
|
+
- lib/mytradewizard/stock.rb
|
196
|
+
- lib/mytradewizard/technical_indicator.rb
|
197
|
+
- lib/mytradewizard/trading_system.rb
|
194
198
|
- lib/mytradewizard/version.rb
|
199
|
+
- lib/mytradewizard/watch_list.rb
|
200
|
+
- lib/mytradewizard/yahoo.rb
|
195
201
|
- mytradewizard.gemspec
|
196
202
|
- spec/cme_spec.rb
|
197
203
|
- spec/interactive_brokers_spec.rb
|