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 +8 -8
- data/features/generator.feature +4 -4
- data/lib/mytradewizard.rb +5 -0
- data/lib/mytradewizard/cli.rb +9 -6
- data/lib/mytradewizard/date_time.rb +11 -5
- data/lib/mytradewizard/generators/config/mytradewizard.rb +11 -0
- data/lib/mytradewizard/generators/{interactive_brokers.rb → mytradewizard.rb} +6 -3
- data/lib/mytradewizard/interactive_brokers.rb +1 -6
- data/lib/mytradewizard/trading_system.rb +4 -23
- data/lib/mytradewizard/version.rb +1 -1
- metadata +4 -5
- data/config/interactive_brokers.rb +0 -12
- data/lib/mytradewizard/generators/config/interactive_brokers.rb +0 -12
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmFjYjM5ZGE0Zjc3YWQ2ODIzNTkwNjNhZGYxZDg2OTdkYjllMDQ4Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODk3N2JiZWZlY2ZkYTU5NDM5NzJjODE3ODliMWI4YzQ2OWRiMTUyMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmU2ZTQ0OGFlMTgzMjVjNmU4ZGM1MzM0NTZmOGQzNWMwYzdhMzQ0MjVkYTI3
|
10
|
+
ZjAzZGNjMDE4NDMxYjFmZTY5YmRmYzg0ZTYzZWRmMzcyNzBhZTBhOWEyNTVh
|
11
|
+
Y2E2YWU2MTMyYzhlYTI2YWZjZWE4OWQ5N2I5NzQ2ZWVkNWM5ZDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTM1Y2I3YjQzNjMzY2JiNzhmODVmMWE5MWI0NjIwMzUyNWExMmY2OWM4YjZm
|
14
|
+
ZDUyNzg5YWUxZWZkYjVjMzlmNmQ3OGM3MTQzNGFhZjBhZTg1YTk0OTgwZTdk
|
15
|
+
YmQ1NjFjNDdjOTkzNGYyNzNiODRlOWUxMmQ1NTIwZjFmZWY1YmM=
|
data/features/generator.feature
CHANGED
@@ -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/
|
10
|
-
Then the file "../../config/
|
11
|
-
Then the file "../../config/
|
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
|
data/lib/mytradewizard/cli.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'mytradewizard'
|
3
|
-
require 'mytradewizard/generators/
|
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::
|
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 "
|
17
|
-
puts "
|
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
@@ -2,19 +2,22 @@ require 'thor/group'
|
|
2
2
|
|
3
3
|
module MyTradeWizard
|
4
4
|
module Generators
|
5
|
-
class
|
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("
|
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 =>
|
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
|
-
@
|
11
|
-
@account = @ib.accounts.first
|
12
|
-
|
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
|
-
|
33
|
+
@env == 'local'
|
53
34
|
end
|
54
35
|
|
55
36
|
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.
|
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-
|
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/
|
196
|
-
- lib/mytradewizard/generators/
|
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
|