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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2dcd51324e1616bebf87c3b14b17ebc1e0ff08b6
4
- data.tar.gz: 94ba368a322db05aa2e79658eddf871d58177e48
5
- SHA512:
6
- metadata.gz: cbc285b0c09c21ed076bd7fa417f324266d1e847a936fdd4fe4bc633691b28e716c0db277d61f329d29a8668f559209b912cbbd744b46e7de8b990efffe27c92
7
- data.tar.gz: f51c9f338452e48304227e6e50379c0dbc61ac9b8a7ad63f08d0193de035e4d15a3d0ec686079b8b1a7dbaca9deaa5ad8beb32bfb1cf9b3a8e8e47c2f423687b
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-2.0.0-p247"
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013 mytradewizard
3
+ Copyright (c) 2013 My Trade Wizard LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # MyTradeWizard
1
+ # mytradewizard gem
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -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,19 @@
1
+ module MyTradeWizard
2
+ class OHLC
3
+ def initialize(hash)
4
+ @hash = hash
5
+ end
6
+ def open
7
+ @hash['Open']
8
+ end
9
+ def high
10
+ @hash['High']
11
+ end
12
+ def low
13
+ @hash['Low']
14
+ end
15
+ def close
16
+ @hash['Close']
17
+ end
18
+ end
19
+ 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,17 @@
1
+ module MyTradeWizard
2
+ module TechnicalIndicator
3
+ class << self
4
+
5
+ def SMA(bars)
6
+ x = 0
7
+ n = 0
8
+ bars.each do |bar|
9
+ x += bar.close
10
+ n += 1
11
+ end
12
+ return x / n
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module MyTradeWizard
2
+ class TradingSystem
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module MyTradeWizard
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  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
@@ -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 Interactive Brokers"
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.2
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-07-31 00:00:00.000000000 Z
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 Interactive Brokers
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