mytradewizard 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzZmYjUwYzM5NTUxNzZhOTQxZDFhMDJlNDE2YTRkNzk1Yzc2NjZjNA==
4
+ MmFjYjM5ZGE0Zjc3YWQ2ODIzNTkwNjNhZGYxZDg2OTdkYjllMDQ4Yg==
5
5
  data.tar.gz: !binary |-
6
- M2MzMWVjYTAzMDU3NmVhNWQzMDdjYTUzMjI0YzhhZjdlZGM2YTJlZA==
6
+ ODk3N2JiZWZlY2ZkYTU5NDM5NzJjODE3ODliMWI4YzQ2OWRiMTUyMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OGYwNDMzYTIxYzQzZDkxM2ExOTQ0MGQ2OTM1NDA3ZmE1NDU2MjkyNGVlY2U2
10
- MGUyMWNmMDM2NDBmMGZhZjVjYTBhZjExMjdkODcyNGNkZDBiNGQ4ZjU0YTNl
11
- ZGY1NDBiMThkYTY4ZDdlMWU0MjEwNWE3NGRmZGQ3ZmFjODk2ZTI=
9
+ MmU2ZTQ0OGFlMTgzMjVjNmU4ZGM1MzM0NTZmOGQzNWMwYzdhMzQ0MjVkYTI3
10
+ ZjAzZGNjMDE4NDMxYjFmZTY5YmRmYzg0ZTYzZWRmMzcyNzBhZTBhOWEyNTVh
11
+ Y2E2YWU2MTMyYzhlYTI2YWZjZWE4OWQ5N2I5NzQ2ZWVkNWM5ZDA=
12
12
  data.tar.gz: !binary |-
13
- OGY2OTRlOTk5MDYxMmNmMDQ2ODAwYWFkNDRlYmZjZTcxODY3MmZmYjRkZDVl
14
- ODlmMzBmZjM3ZDQ5OTQ0OGRkZWY5ZTE1MzJjMjE3ZmUxYWZlNDcyOWJkODlj
15
- NjFhNzE3MzU0NTcyYWEyODYwNzcyNzVjMjllNjYwZDkwMjI2NTM=
13
+ YTM1Y2I3YjQzNjMzY2JiNzhmODVmMWE5MWI0NjIwMzUyNWExMmY2OWM4YjZm
14
+ ZDUyNzg5YWUxZWZkYjVjMzlmNmQ3OGM3MTQzNGFhZjBhZTg1YTk0OTgwZTdk
15
+ YmQ1NjFjNDdjOTkzNGYyNzNiODRlOWUxMmQ1NTIwZjFmZWY1YmM=
@@ -4,11 +4,11 @@ Feature: Interactive Brokers configuration
4
4
  I want My Trade Wizard to create and use a config file
5
5
 
6
6
  Scenario: Generate Interactive Brokers configuration
7
- When I run `mtw configure localhost 7496`
7
+ When I run `mtw configure --host localhost --port 7496`
8
8
  Then the following files should exist:
9
- | ../../config/interactive_brokers.rb |
10
- Then the file "../../config/interactive_brokers.rb" should contain "localhost"
11
- Then the file "../../config/interactive_brokers.rb" should contain "7496"
9
+ | ../../config/mytradewizard.rb |
10
+ Then the file "../../config/mytradewizard.rb" should contain "localhost"
11
+ Then the file "../../config/mytradewizard.rb" should contain "7496"
12
12
 
13
13
  Scenario: Display Interactive Brokers configuration
14
14
  When I run `mtw config`
data/lib/mytradewizard.rb CHANGED
@@ -15,6 +15,11 @@ require 'mytradewizard/future_trading_system'
15
15
  require 'mytradewizard/action'
16
16
  require 'mytradewizard/position'
17
17
  require 'mytradewizard/order'
18
+ begin
19
+ require "#{Dir.pwd}/config/mytradewizard"
20
+ rescue LoadError
21
+ puts "Please configure!"
22
+ end
18
23
 
19
24
  module MyTradeWizard
20
25
  end
@@ -1,20 +1,23 @@
1
1
  require 'thor'
2
2
  require 'mytradewizard'
3
- require 'mytradewizard/generators/interactive_brokers'
3
+ require 'mytradewizard/generators/mytradewizard'
4
4
 
5
5
  module MyTradeWizard
6
6
  class CLI < Thor
7
7
 
8
- desc "configure [-- host HOST] [-- port PORT]", "Generate Interactive Brokers configuration"
9
- method_options :host => :string, :port => :numeric
8
+ desc "configure [-- env ENV] [-- email EMAIL] [-- host HOST] [-- port PORT] [-- account ACCOUNT]", "Generate Interactive Brokers configuration"
9
+ method_options :env => :string, :email => :string, :host => :string, :port => :numeric, :account => :string
10
10
  def configure
11
- MyTradeWizard::Generators::InteractiveBrokers.start([options[:host] || "localhost", options[:port] || 7496])
11
+ MyTradeWizard::Generators::MyTradeWizard.start([options[:env] || "local", options[:email] || "", options[:host] || "localhost", options[:port] || 7496, options[:account] || ""])
12
12
  end
13
13
 
14
14
  desc "config", "Display Interactive Brokers configuration"
15
15
  def config
16
- puts "Host: " + MyTradeWizard::InteractiveBrokers.host
17
- puts "Port: " + MyTradeWizard::InteractiveBrokers.port.to_s
16
+ puts "Env: " + MyTradeWizard::Configuration::ENV
17
+ puts "Email: " + MyTradeWizard::Configuration::EMAIL
18
+ puts "Host: " + MyTradeWizard::Configuration::InteractiveBrokers::HOST
19
+ puts "Port: " + MyTradeWizard::Configuration::InteractiveBrokers::PORT.to_s
20
+ puts "Account: " + MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT
18
21
  end
19
22
 
20
23
  desc "connect", "Connects to Interactive Brokers"
@@ -3,14 +3,20 @@ module MyTradeWizard
3
3
 
4
4
  HR = 360
5
5
 
6
- def wait_until(hour, minute)
7
- print "Waiting until #{hour}:#{minute} ..."
8
- until time_is(hour, minute)
9
- sleep 60
10
- print '.'
6
+ def at(hour, minute)
7
+ unless MyTradeWizard::Configuration::ENV == 'local'
8
+ print "Waiting until #{hour}:#{minute} ..."
9
+ until time_is(hour, minute)
10
+ sleep 60
11
+ print '.'
12
+ end
11
13
  end
12
14
  end
13
15
 
16
+ def idle(seconds)
17
+ sleep(seconds) unless MyTradeWizard::Configuration::ENV == 'local'
18
+ end
19
+
14
20
  def friday
15
21
  Time.now.utc.wday == 5
16
22
  end
@@ -0,0 +1,11 @@
1
+ module MyTradeWizard
2
+ module Configuration
3
+ ENV = "<%= env %>"
4
+ EMAIL = "<%= email %>"
5
+ module InteractiveBrokers
6
+ HOST = "<%= host %>"
7
+ PORT = <%= port %>
8
+ ACCOUNT = "<%= account %>"
9
+ end
10
+ end
11
+ end
@@ -2,19 +2,22 @@ require 'thor/group'
2
2
 
3
3
  module MyTradeWizard
4
4
  module Generators
5
- class InteractiveBrokers < Thor::Group
5
+ class MyTradeWizard < Thor::Group
6
6
 
7
7
  include Thor::Actions
8
-
8
+
9
+ argument :env, :type => :string
10
+ argument :email, :type => :string
9
11
  argument :host, :type => :string
10
12
  argument :port, :type => :numeric
13
+ argument :account, :type => :string
11
14
 
12
15
  def create_config
13
16
  empty_directory("config")
14
17
  end
15
18
 
16
19
  def copy_config
17
- template("interactive_brokers.rb", "config/interactive_brokers.rb", {force: true})
20
+ template("mytradewizard.rb", "config/mytradewizard.rb", {force: true})
18
21
  end
19
22
 
20
23
  def self.source_root
@@ -1,9 +1,4 @@
1
1
  require 'ib'
2
- begin
3
- require "#{Dir.pwd}/config/interactive_brokers"
4
- rescue LoadError
5
- puts "Please configure Interactive Brokers!"
6
- end
7
2
 
8
3
  module MyTradeWizard
9
4
  class InteractiveBrokers
@@ -16,7 +11,7 @@ module MyTradeWizard
16
11
  exception = nil
17
12
  while (timeout.nil? || Time.now - start_time <= timeout)
18
13
  begin
19
- @ib_ruby = IB::Connection.new :host => self.class.host, :port => self.class.port
14
+ @ib_ruby = IB::Connection.new :host => MyTradeWizard::Configuration::InteractiveBrokers::HOST, :port => MyTradeWizard::Configuration::InteractiveBrokers::PORT
20
15
  subscribe_to_alerts
21
16
  sleep 0.1
22
17
  fetch_accounts
@@ -7,17 +7,12 @@ module MyTradeWizard
7
7
  def initialize
8
8
  @ib = MyTradeWizard::InteractiveBrokers.new
9
9
  @ib_ruby = @ib.connect
10
- @live = false
11
- @account = @ib.accounts.first
12
- #fetch_positions
10
+ @env = MyTradeWizard::Configuration::ENV
11
+ @account = MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT.empty? ? @ib.accounts.first : MyTradeWizard::Configuration::InteractiveBrokers::ACCOUNT
12
+ @logger = Logger.new("/mtw/sys/#{self.class.to_s.downcase}/log/#{Time.now.strftime('%Y%m%d-%H%M')}") unless test?
13
13
  @orders = []
14
14
  end
15
15
 
16
- def account=(a)
17
- @account = a
18
- make_live
19
- end
20
-
21
16
  def positions
22
17
  @positions = @ib.positions(@account)
23
18
  end
@@ -26,20 +21,6 @@ module MyTradeWizard
26
21
  @ib.place_market_order(@account, action, quantity, contract)
27
22
  end
28
23
 
29
- def make_live
30
- @live = true
31
- @logger = Logger.new("/mtw/log/#{self.class}/#{Time.now.strftime('%Y%m%d-%H%M')}.log")
32
- #fetch_positions
33
- end
34
-
35
- def at(hour, minute)
36
- wait_until(hour, minute) if @live
37
- end
38
-
39
- def idle(seconds)
40
- sleep(seconds) if @live
41
- end
42
-
43
24
  def output(msg)
44
25
  if @logger.present?
45
26
  @logger.info msg
@@ -49,7 +30,7 @@ module MyTradeWizard
49
30
  end
50
31
 
51
32
  def test?
52
- !@live
33
+ @env == 'local'
53
34
  end
54
35
 
55
36
  end
@@ -1,3 +1,3 @@
1
1
  module MyTradeWizard
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
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.6
4
+ version: 0.0.7
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-09 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -180,7 +180,6 @@ files:
180
180
  - README.md
181
181
  - Rakefile
182
182
  - bin/mtw
183
- - config/interactive_brokers.rb
184
183
  - features/cme.feature
185
184
  - features/generator.feature
186
185
  - features/interactive_brokers.feature
@@ -192,8 +191,8 @@ files:
192
191
  - lib/mytradewizard/daily_bars.rb
193
192
  - lib/mytradewizard/date_time.rb
194
193
  - lib/mytradewizard/future_trading_system.rb
195
- - lib/mytradewizard/generators/config/interactive_brokers.rb
196
- - lib/mytradewizard/generators/interactive_brokers.rb
194
+ - lib/mytradewizard/generators/config/mytradewizard.rb
195
+ - lib/mytradewizard/generators/mytradewizard.rb
197
196
  - lib/mytradewizard/interactive_brokers.rb
198
197
  - lib/mytradewizard/ohlc.rb
199
198
  - lib/mytradewizard/order.rb
@@ -1,12 +0,0 @@
1
- module MyTradeWizard
2
- class InteractiveBrokers
3
- class << self
4
- def host
5
- "localhost"
6
- end
7
- def port
8
- 7496
9
- end
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module MyTradeWizard
2
- class InteractiveBrokers
3
- class << self
4
- def host
5
- "<%= host %>"
6
- end
7
- def port
8
- <%= port %>
9
- end
10
- end
11
- end
12
- end