mytradewizard 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/mytradewizard.rb +1 -0
- data/lib/mytradewizard/cli.rb +7 -5
- data/lib/mytradewizard/date_time.rb +2 -2
- data/lib/mytradewizard/email.rb +31 -0
- data/lib/mytradewizard/generators/config/mytradewizard.rb +6 -2
- data/lib/mytradewizard/generators/mytradewizard.rb +4 -2
- data/lib/mytradewizard/stock_trading_system.rb +3 -2
- data/lib/mytradewizard/trading_system.rb +18 -2
- data/lib/mytradewizard/version.rb +1 -1
- data/mytradewizard.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmY1MTVlYTg1Mjc1ZGVjMDRjM2U5Yjk4MDEzZmJlZjliMmZjNGY2ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDNkNDIwNjY3MzM4ZTQyZjIyN2Y1YWI5NGM5Yzg3ZTg5ZjU2ZWFhYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWE2MzQ1ZDJkNjEyZjhjZjBkMTdjMWNhNThiZDdhYWFhOWYzOTJmZDBjNjE5
|
10
|
+
MmI1ZWZlYzdlMmU1YjMxMjRjMjNhZjMyMWE5M2MyNzE5ZGFlOGFkNjg1Nzc0
|
11
|
+
OTAxM2I4NTUxN2I5MWFhYjlkZmI5ZTZjZjFhOGI2MzQwODE1OGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjYyMWNhM2E0MDhlNjU2NTJhN2M5OWExZmE3YWYyZDRjYTA4NmE1NWQ4NWI0
|
14
|
+
YTM5MmUxNWQ5ZTM0NzE1NDY1YTZjYzhjNmE4NGUwMzQzZTcwYzRjZTQyNDNk
|
15
|
+
MDFmOTM5NGNmODg3NzNlYThjN2FjNTczNDA2YWRhYjlkOTFkZjU=
|
data/lib/mytradewizard.rb
CHANGED
data/lib/mytradewizard/cli.rb
CHANGED
@@ -5,19 +5,21 @@ require 'mytradewizard/generators/mytradewizard'
|
|
5
5
|
module MyTradeWizard
|
6
6
|
class CLI < Thor
|
7
7
|
|
8
|
-
desc "configure [--
|
9
|
-
method_options :
|
8
|
+
desc "configure [--environment ENVIRONMENT] [--host HOST] [--port PORT] [--account ACCOUNT] [--email_to EMAIL_TO] [--gmail_username GMAIL_USERNAME] [--gmail_password GMAIL_PASSWORD]", "Generate Interactive Brokers configuration"
|
9
|
+
method_options :environment => :string, :host => :string, :port => :numeric, :account => :string, :email_to => :string, :gmail_username => :string, :gmail_password => :string
|
10
10
|
def configure
|
11
|
-
MyTradeWizard::Generators::MyTradeWizard.start([options[:
|
11
|
+
MyTradeWizard::Generators::MyTradeWizard.start([options[:environment] || "local", options[:host] || "localhost", options[:port] || 7496, options[:account] || "", options[:email_to] || "", options[:gmail_username] || "", options[:gmail_password] || ""])
|
12
12
|
end
|
13
13
|
|
14
14
|
desc "config", "Display Interactive Brokers configuration"
|
15
15
|
def config
|
16
|
-
puts "
|
17
|
-
puts "Email: " + MyTradeWizard::Configuration::EMAIL
|
16
|
+
puts "Environment: " + MyTradeWizard::Configuration::ENVIRONMENT
|
18
17
|
puts "Host: " + MyTradeWizard::Configuration::InteractiveBrokers::HOST
|
19
18
|
puts "Port: " + MyTradeWizard::Configuration::InteractiveBrokers::PORT.to_s
|
20
19
|
puts "Account: " + MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT
|
20
|
+
puts "Email To: " + MyTradeWizard::Configuration::Email::TO
|
21
|
+
puts "Gmail Username: " + MyTradeWizard::Configuration::Email::GMAIL_USERNAME
|
22
|
+
puts "Gmail Password: " + MyTradeWizard::Configuration::Email::GMAIL_PASSWORD
|
21
23
|
end
|
22
24
|
|
23
25
|
desc "connect", "Connects to Interactive Brokers"
|
@@ -4,7 +4,7 @@ module MyTradeWizard
|
|
4
4
|
HR = 360
|
5
5
|
|
6
6
|
def at(hour, minute)
|
7
|
-
unless MyTradeWizard::Configuration::
|
7
|
+
unless MyTradeWizard::Configuration::ENVIRONMENT == 'local'
|
8
8
|
print "Waiting until #{hour}:#{minute} ..."
|
9
9
|
until time_is(hour, minute)
|
10
10
|
sleep 60
|
@@ -14,7 +14,7 @@ module MyTradeWizard
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def idle(seconds)
|
17
|
-
sleep(seconds) unless MyTradeWizard::Configuration::
|
17
|
+
sleep(seconds) unless MyTradeWizard::Configuration::ENVIRONMENT == 'local'
|
18
18
|
end
|
19
19
|
|
20
20
|
def friday
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'gmail'
|
2
|
+
|
3
|
+
module MyTradeWizard
|
4
|
+
class Email
|
5
|
+
|
6
|
+
attr_accessor :subject
|
7
|
+
attr_accessor :body
|
8
|
+
|
9
|
+
def <<(msg)
|
10
|
+
@body << msg << "\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def send
|
14
|
+
to = MyTradeWizard::Configuration::Email::TO
|
15
|
+
subject = @subject
|
16
|
+
body = @body
|
17
|
+
username = MyTradeWizard::Configuration::Email::GMAIL_USERNAME
|
18
|
+
password = MyTradeWizard::Configuration::Email::GMAIL_PASSWORD
|
19
|
+
unless to.empty? || username.empty? || password.empty?
|
20
|
+
Gmail.connect!(username, password) do |gmail|
|
21
|
+
gmail.deliver! do
|
22
|
+
to(to)
|
23
|
+
subject(subject)
|
24
|
+
body(body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module MyTradeWizard
|
2
2
|
module Configuration
|
3
|
-
|
4
|
-
EMAIL = "<%= email %>"
|
3
|
+
ENVIRONMENT = "<%= environment %>"
|
5
4
|
module InteractiveBrokers
|
6
5
|
HOST = "<%= host %>"
|
7
6
|
PORT = <%= port %>
|
8
7
|
ACCOUNT = "<%= account %>"
|
9
8
|
end
|
9
|
+
module Email
|
10
|
+
TO = "<%= email_to %>"
|
11
|
+
GMAIL_USERNAME = "<%= gmail_username %>"
|
12
|
+
GMAIL_PASSWORD = "<%= gmail_password %>"
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
@@ -6,11 +6,13 @@ module MyTradeWizard
|
|
6
6
|
|
7
7
|
include Thor::Actions
|
8
8
|
|
9
|
-
argument :
|
10
|
-
argument :email, :type => :string
|
9
|
+
argument :environment, :type => :string
|
11
10
|
argument :host, :type => :string
|
12
11
|
argument :port, :type => :numeric
|
13
12
|
argument :account, :type => :string
|
13
|
+
argument :email_to, :type => :string
|
14
|
+
argument :gmail_username, :type => :string
|
15
|
+
argument :gmail_password, :type => :string
|
14
16
|
|
15
17
|
def create_config
|
16
18
|
empty_directory("config")
|
@@ -43,7 +43,7 @@ module MyTradeWizard
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def sell(position)
|
46
|
-
|
46
|
+
email << "SELL #{position.size} #{position.stock.symbol}"
|
47
47
|
place_market_order "SELL", position.size, position.stock.contract
|
48
48
|
end
|
49
49
|
|
@@ -52,9 +52,10 @@ module MyTradeWizard
|
|
52
52
|
buying_power_per_order = total_buying_power / orders.length
|
53
53
|
orders.each do |order|
|
54
54
|
order.quantity = (buying_power_per_order / order.stock.price).floor
|
55
|
-
|
55
|
+
email << "#{order.action} #{order.quantity} #{order.stock.symbol}"
|
56
56
|
place_market_order order.action.to_s, order.quantity, order.stock.contract
|
57
57
|
end
|
58
|
+
email.send
|
58
59
|
end
|
59
60
|
|
60
61
|
end
|
@@ -7,9 +7,12 @@ module MyTradeWizard
|
|
7
7
|
def initialize
|
8
8
|
@ib = MyTradeWizard::InteractiveBrokers.new
|
9
9
|
@ib_ruby = @ib.connect
|
10
|
-
@
|
10
|
+
@environment = MyTradeWizard::Configuration::ENVIRONMENT
|
11
11
|
@account = MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT.empty? ? @ib.accounts.first : MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT
|
12
12
|
@logger = Logger.new("/mtw/sys/#{self.class.to_s.downcase}/log/#{Time.now.strftime('%Y%m%d-%H%M')}") unless test?
|
13
|
+
@email = MyTradeWizard::Email.new
|
14
|
+
@email.subject = (production?) ? self.class.to_s : "#{@environment.upcase} #{self.class.to_s}"
|
15
|
+
@email.body = ""
|
13
16
|
@orders = []
|
14
17
|
end
|
15
18
|
|
@@ -29,8 +32,21 @@ module MyTradeWizard
|
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
35
|
+
def email(msg = nil)
|
36
|
+
if msg.nil?
|
37
|
+
return @email
|
38
|
+
else
|
39
|
+
@email.body = msg
|
40
|
+
@email.send
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
32
44
|
def test?
|
33
|
-
@
|
45
|
+
@environment == 'local'
|
46
|
+
end
|
47
|
+
|
48
|
+
def production?
|
49
|
+
@environment == 'production'
|
34
50
|
end
|
35
51
|
|
36
52
|
end
|
data/mytradewizard.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_dependency "tzinfo", "~> 0.3.29"
|
25
25
|
gem.add_dependency "nokogiri"
|
26
26
|
gem.add_dependency "thor"
|
27
|
+
gem.add_dependency "gmail"
|
27
28
|
|
28
29
|
gem.files = `git ls-files`.split($/)
|
29
30
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mytradewizard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ! '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: gmail
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: Helpers for CME Group, Interactive Brokers, and Yahoo Finance
|
168
182
|
email:
|
169
183
|
- zack@mytradewizard.com
|
@@ -190,6 +204,7 @@ files:
|
|
190
204
|
- lib/mytradewizard/cme.rb
|
191
205
|
- lib/mytradewizard/daily_bars.rb
|
192
206
|
- lib/mytradewizard/date_time.rb
|
207
|
+
- lib/mytradewizard/email.rb
|
193
208
|
- lib/mytradewizard/future_trading_system.rb
|
194
209
|
- lib/mytradewizard/generators/config/mytradewizard.rb
|
195
210
|
- lib/mytradewizard/generators/mytradewizard.rb
|