trade_watcher 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trade_watcher.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jason Rylance
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # TradeWatcher
2
+
3
+ TradeWatcher is a gem that notifies you when / if a stock's value has met or exceeded your target value.
4
+
5
+ In this version (1.0.0):
6
+
7
+ * TradeWatcher will only watch a stock for up to 1 hour from the time you initiate the command.
8
+
9
+ * TradeWatcher will only be able to watch for a stock to surpass a value, not drop below a value (you can monitor long states, not short).
10
+
11
+ * TradeWatcher will print updates to your console for the duration of an existing notification task.
12
+
13
+ TradeWatcher depends on the Market_Beat gem written by Michaeldv https://github.com/michaeldv/market_beat
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'trade_watcher'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install trade_watcher
28
+
29
+ ## Usage
30
+
31
+ The following command will set up an alert that:
32
+
33
+ * Checks the market value of AAPL (Apple Inc. on Nasdaq)
34
+ * every 10 seconds
35
+ * to see if the value has surpassed $800.00.
36
+
37
+ $ TradeKing.check_stock_every_x_seconds_for_value(:AAPL, 10, 800.54)
38
+
39
+ While the stock's value is below your target value, a string will print to your console every time the stock's value is checked:
40
+
41
+ $2013-04-15 10:55:32 -0500 AAPL has not met your target of 800.54.
42
+
43
+ When the stock's value meets or exceeds your target value, a string will print to your console stating it has done so:
44
+
45
+ $2013-04-15 12:06:32 -0500 The monitoring of AAPL with a target of 800.54 has expired due to the time limit of 1 hour being rached
46
+
47
+
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ module TradeWatcher
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,45 @@
1
+ require "trade_watcher/version"
2
+ require "market_beat"
3
+
4
+ module TradeWatcher
5
+
6
+
7
+ def self.check_stock_every_x_seconds_for_value(symbol, seconds, value)
8
+ t1 = Thread.new{(self.checker(symbol, seconds, value))}
9
+ end
10
+
11
+ private
12
+ def self.checker(symbol, seconds, value)
13
+ stop_time = get_stop_time
14
+ pp stop_time
15
+ until is_stock_at_or_above_value(symbol, value) || Time.now >= stop_time
16
+ pp "#{Time.now} #{symbol} has not yet met your target of #{value}."
17
+ sleep(seconds)
18
+ end
19
+ if Time.now >= stop_time
20
+ out_of_time(symbol, value)
21
+ else
22
+ reached_target(symbol, value)
23
+ end
24
+ end
25
+
26
+ def self.get_stop_time
27
+ Time.now + 3600 # an hour from Time.now
28
+ end
29
+
30
+ def self.reached_target(symbol, value)
31
+ pp "#{Time.now} #{symbol} has met or exceeded your target of #{value}."
32
+ end
33
+
34
+ def self.out_of_time(symbol, value)
35
+ pp "#{Time.now} The monitoring of #{symbol} with a target of #{value} has expired due to the time limit of 1 hour being rached."
36
+ end
37
+
38
+ def self.last_trade(symbol)
39
+ MarketBeat.last_trade_real_time symbol
40
+ end
41
+
42
+ def self.is_stock_at_or_above_value(symbol, value)
43
+ last_trade(symbol).to_f >= value
44
+ end
45
+ end
data/mino.rb ADDED
@@ -0,0 +1,24 @@
1
+ def func1
2
+ i=0
3
+ while i<=2
4
+ puts "func1 at: #{Time.now}"
5
+ sleep(2)
6
+ i=i+1
7
+ end
8
+ end
9
+
10
+ def func2
11
+ j=0
12
+ while j<=2
13
+ puts "func2 at: #{Time.now}"
14
+ sleep(1)
15
+ j=j+1
16
+ end
17
+ end
18
+
19
+ puts "Started At #{Time.now}"
20
+ t1=Thread.new{func1()}
21
+ t2=Thread.new{func2()}
22
+ t1.join
23
+ t2.join
24
+ puts "End at #{Time.now}"
@@ -0,0 +1 @@
1
+ require 'trade_watcher'
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe "TradeWatcher" do
4
+ context "when comparing quotes to targets values" do
5
+ it "can report true if a quote is above a target value" do
6
+ TradeWatcher.stub!(:last_trade).and_return(901)
7
+ TradeWatcher.is_stock_at_or_above_value(:AAPL, 900).should == true
8
+ end
9
+
10
+ it "can report false if a quote is below a target value" do
11
+ TradeWatcher.stub!(:last_trade).and_return(901)
12
+ TradeWatcher.is_stock_at_or_above_value(:AAPL, 1000).should == false
13
+ end
14
+ end
15
+
16
+ it "checks stock value multiple times while stock is not at or above the target value" do
17
+ TradeWatcher.stub!(:last_trade).and_return(200)
18
+ TradeWatcher.should_receive(:is_stock_at_or_above_value).at_least(2).times
19
+ TradeWatcher.check_stock_every_x_seconds_for_value(:AAPL, 1, 400.01)
20
+ sleep(2)
21
+ end
22
+
23
+ it "triggers target_value_reahed when the stock has met or surpassed the target value" do
24
+ TradeWatcher.stub!(:last_trade).and_return(200)
25
+ TradeWatcher.should_receive(:reached_target).exactly(1).times
26
+ TradeWatcher.check_stock_every_x_seconds_for_value(:AAPL, 1, 100.01)
27
+ sleep(2)
28
+ end
29
+
30
+ it "returns a 'time limit reached' message once a stock has been monitored for the maximum of 1 hour" do
31
+ TradeWatcher.stub!(:last_trade).and_return(200)
32
+ TradeWatcher.stub!(:get_stop_time).and_return(Time.now - 3700)
33
+ TradeWatcher.check_stock_every_x_seconds_for_value(:AAPL, 1, 100.01)
34
+ TradeWatcher.should_receive(:out_of_time).exactly(1).times
35
+ sleep(2)
36
+ end
37
+
38
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trade_watcher/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "trade_watcher"
8
+ gem.version = TradeWatcher::VERSION
9
+ gem.authors = ["Jason Rylance"]
10
+ gem.email = ["ecnalyr@gmail.com"]
11
+ gem.description = %q{TradeWatcher is a gem that notifies you when / if a stock's value has met or exceeded your target value.}
12
+ gem.summary = %q{TradeKing.check_stock_every_x_seconds_for_value(:AAPL, 10, 800.54) Checks AAPL every 10 seconds to see if it reaches 800.54}
13
+ gem.homepage = "http://github.com/ecnalyr/trade_watcher"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "market_beat"
21
+
22
+ gem.add_development_dependency "rspec"
23
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trade_watcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Rylance
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: market_beat
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: TradeWatcher is a gem that notifies you when / if a stock's value has
47
+ met or exceeded your target value.
48
+ email:
49
+ - ecnalyr@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/trade_watcher.rb
60
+ - lib/trade_watcher/version.rb
61
+ - mino.rb
62
+ - spec/spec_helper.rb
63
+ - spec/trade_watcher_spec.rb
64
+ - trade_watcher.gemspec
65
+ homepage: http://github.com/ecnalyr/trade_watcher
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: TradeKing.check_stock_every_x_seconds_for_value(:AAPL, 10, 800.54) Checks
89
+ AAPL every 10 seconds to see if it reaches 800.54
90
+ test_files:
91
+ - spec/spec_helper.rb
92
+ - spec/trade_watcher_spec.rb