rbtc_arbitrage 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 276373f1908844b66b3244d21da6d7a5cdb63f13
4
- data.tar.gz: d20a6319a28c4e29706ab335b2709b6ceb61175e
3
+ metadata.gz: 073f034a32dc76e95d0e5a425a0716e4c97d2208
4
+ data.tar.gz: fc051d210da396065843debde1122612f09bf331
5
5
  SHA512:
6
- metadata.gz: 29fea525d6cf2040c0854390cb5dc72e82f6208158b7148cf90cb007a37ab5f4d10614ae6148c09cd82b63b31b48671c8382788da703a539dde39306c511c529
7
- data.tar.gz: 56095347d612509ab25450ce394238baace955cef76dc1e83b14978d1b7ca72b612e374f4169dd3241bc6ea64ba379717eb782481da4981fb9e740b463588692
6
+ metadata.gz: 09aa1b9843ff89cf3254d97801e1d1b2547cc4ae9be908d9abac68f5989250e447cc7b0f129c2540952937d58bb79ba4328acabc35767033f77cb24f53b2f1df
7
+ data.tar.gz: c90035506f8efeefc460761e1e2d4e61bc2313d4e69f251cfdb1c9d51df5facb1ba1335773d657a3c6b85ef04e315b048a403ccd74bc652f44f85c76a8bc5408
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/Gemfile CHANGED
@@ -14,4 +14,5 @@ gem 'coveralls', require: false
14
14
  gem "webmock"
15
15
  gem 'vcr'
16
16
  gem 'codeclimate-test-reporter'
17
- gem 'hashie'
17
+ gem 'hashie'
18
+ gem 'sinatra'
data/Gemfile.lock ADDED
@@ -0,0 +1,165 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rbtc_arbitrage (1.3.0)
5
+ activemodel (>= 3.1)
6
+ activesupport (>= 3.1)
7
+ bitstamp
8
+ bitstamp
9
+ btce (= 0.2.4)
10
+ coinbase (= 1.2.4)
11
+ mtgox
12
+ thor
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ activemodel (4.0.2)
18
+ activesupport (= 4.0.2)
19
+ builder (~> 3.1.0)
20
+ activesupport (4.0.2)
21
+ i18n (~> 0.6, >= 0.6.4)
22
+ minitest (~> 4.2)
23
+ multi_json (~> 1.3)
24
+ thread_safe (~> 0.1)
25
+ tzinfo (~> 0.3.37)
26
+ addressable (2.3.5)
27
+ atomic (1.1.14)
28
+ bitstamp (0.3.0)
29
+ activemodel (>= 3.1)
30
+ activesupport (>= 3.1)
31
+ curb (> 0.8.1)
32
+ ruby-hmac (= 0.4.0)
33
+ btce (0.2.4)
34
+ monkey-patch
35
+ builder (3.1.4)
36
+ celluloid (0.15.2)
37
+ timers (~> 1.1.0)
38
+ codeclimate-test-reporter (0.2.0)
39
+ simplecov (>= 0.7.1, < 1.0.0)
40
+ coderay (1.1.0)
41
+ coinbase (1.2.4)
42
+ hashie (>= 1.2.0)
43
+ httparty (>= 0.8.3)
44
+ money (>= 4.0.1)
45
+ multi_json (>= 1.3.4)
46
+ coveralls (0.7.0)
47
+ multi_json (~> 1.3)
48
+ rest-client
49
+ simplecov (>= 0.7)
50
+ term-ansicolor
51
+ thor
52
+ crack (0.4.1)
53
+ safe_yaml (~> 0.9.0)
54
+ curb (0.8.5)
55
+ diff-lcs (1.2.5)
56
+ docile (1.1.1)
57
+ faraday (0.8.8)
58
+ multipart-post (~> 1.2.0)
59
+ ffi (1.9.3)
60
+ formatador (0.2.4)
61
+ guard (2.2.5)
62
+ formatador (>= 0.2.4)
63
+ listen (~> 2.1)
64
+ lumberjack (~> 1.0)
65
+ pry (>= 0.9.12)
66
+ thor (>= 0.18.1)
67
+ guard-rspec (4.2.1)
68
+ guard (>= 2.1.1)
69
+ rspec (~> 3.0.0.beta, >= 2.14, < 4.0)
70
+ hashie (2.0.5)
71
+ httparty (0.12.0)
72
+ json (~> 1.8)
73
+ multi_xml (>= 0.5.2)
74
+ i18n (0.6.9)
75
+ json (1.8.1)
76
+ listen (2.4.0)
77
+ celluloid (>= 0.15.2)
78
+ rb-fsevent (>= 0.9.3)
79
+ rb-inotify (>= 0.9)
80
+ lumberjack (1.0.4)
81
+ method_source (0.8.2)
82
+ mime-types (2.0)
83
+ minitest (4.7.5)
84
+ money (6.0.0)
85
+ i18n (~> 0.6.4)
86
+ monkey-patch (0.0.14)
87
+ activesupport
88
+ mtgox (1.1.0)
89
+ faraday (~> 0.8, < 0.10)
90
+ json (~> 1.7, >= 1.7.7)
91
+ multi_json (1.8.2)
92
+ multi_xml (0.5.5)
93
+ multipart-post (1.2.0)
94
+ pry (0.9.12.4)
95
+ coderay (~> 1.0)
96
+ method_source (~> 0.8)
97
+ slop (~> 3.4)
98
+ rack (1.5.2)
99
+ rack-protection (1.5.1)
100
+ rack
101
+ rake (10.1.1)
102
+ rb-fsevent (0.9.3)
103
+ rb-inotify (0.9.3)
104
+ ffi (>= 0.5.0)
105
+ rest-client (1.6.7)
106
+ mime-types (>= 1.16)
107
+ rspec (3.0.0.beta1)
108
+ rspec-core (= 3.0.0.beta1)
109
+ rspec-expectations (= 3.0.0.beta1)
110
+ rspec-mocks (= 3.0.0.beta1)
111
+ rspec-core (3.0.0.beta1)
112
+ rspec-support (= 3.0.0.beta1)
113
+ rspec-expectations (3.0.0.beta1)
114
+ diff-lcs (>= 1.1.3, < 2.0)
115
+ rspec-support (= 3.0.0.beta1)
116
+ rspec-mocks (3.0.0.beta1)
117
+ rspec-support (= 3.0.0.beta1)
118
+ rspec-support (3.0.0.beta1)
119
+ ruby-hmac (0.4.0)
120
+ ruby_gntp (0.3.4)
121
+ safe_yaml (0.9.7)
122
+ simplecov (0.8.2)
123
+ docile (~> 1.1.0)
124
+ multi_json
125
+ simplecov-html (~> 0.8.0)
126
+ simplecov-html (0.8.0)
127
+ sinatra (1.4.4)
128
+ rack (~> 1.4)
129
+ rack-protection (~> 1.4)
130
+ tilt (~> 1.3, >= 1.3.4)
131
+ slop (3.4.7)
132
+ term-ansicolor (1.2.2)
133
+ tins (~> 0.8)
134
+ thor (0.18.1)
135
+ thread_safe (0.1.3)
136
+ atomic
137
+ tilt (1.4.1)
138
+ timers (1.1.0)
139
+ tins (0.13.1)
140
+ tzinfo (0.3.38)
141
+ vcr (2.8.0)
142
+ webmock (1.16.1)
143
+ addressable (>= 2.2.7)
144
+ crack (>= 0.3.2)
145
+
146
+ PLATFORMS
147
+ ruby
148
+
149
+ DEPENDENCIES
150
+ activemodel (>= 3.1)
151
+ activesupport (>= 3.1)
152
+ bundler (~> 1.3)
153
+ codeclimate-test-reporter
154
+ coveralls
155
+ guard
156
+ guard-rspec
157
+ hashie
158
+ rake
159
+ rbtc_arbitrage!
160
+ rspec
161
+ ruby_gntp
162
+ simplecov
163
+ sinatra
164
+ vcr
165
+ webmock
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec ruby dummy_web_server.rb -p $PORT
@@ -0,0 +1,9 @@
1
+ # This is a dummy web server that will
2
+ # make it easy for us to run ruby
3
+ # scripts on Heroku.
4
+
5
+ require 'sinatra'
6
+
7
+ get '/' do
8
+ "Hello, world"
9
+ end
@@ -8,6 +8,7 @@ module RbtcArbitrage
8
8
  option :verbose, type: :boolean, default: true, desc: "Whether you wish to log information."
9
9
  option :buyer, type: :string, default: "bitstamp"
10
10
  option :seller, type: :string, default: "mtgox"
11
+ option :repeat, type: :numeric, default: nil
11
12
  def trade
12
13
  RbtcArbitrage::Trader.new(options).trade
13
14
  end
@@ -16,6 +16,7 @@ module RbtcArbitrage
16
16
  set_key opts, :logger, Logger.new(STDOUT)
17
17
  set_key opts, :verbose, true
18
18
  set_key opts, :live, false
19
+ set_key opts, :repeat, nil
19
20
  exchange = opts[:buyer] || :bitstamp
20
21
  @buy_client = client_for_exchange(exchange)
21
22
  exchange = opts[:seller] || :mtgox
@@ -31,15 +32,26 @@ module RbtcArbitrage
31
32
  fetch_prices
32
33
  log_info if options[:verbose]
33
34
 
34
- if options[:cutoff] > @percent && options[:live]
35
+ if options[:live] && options[:cutoff] > @percent
35
36
  raise SecurityError, "Exiting because real profit (#{@percent.round(2)}%) is less than cutoff (#{options[:cutoff].round(2)}%)"
36
37
  end
37
38
 
38
39
  execute_trade if options[:live]
39
40
 
41
+ if @options[:repeat]
42
+ trade_again
43
+ end
40
44
  self
41
45
  end
42
46
 
47
+ def trade_again
48
+ sleep @options[:repeat]
49
+ @logger.info " - " if @options[:verbose]
50
+ @buy_client = @buy_client.class.new(@options)
51
+ @sell_client = @sell_client.class.new(@options)
52
+ trade
53
+ end
54
+
43
55
  def execute_trade
44
56
  fetch_prices unless @paid
45
57
  validate_env
@@ -1,3 +1,3 @@
1
1
  module RbtcArbitrage
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  end
data/spec/trader_spec.rb CHANGED
@@ -161,6 +161,14 @@ describe RbtcArbitrage::Trader do
161
161
  expect { trader.trade }.to raise_error(SecurityError)
162
162
  end
163
163
 
164
+ it "should repeat if specified" do
165
+ trader.options[:repeat] = 10
166
+ trader.should_receive(:fetch_prices)
167
+ trader.should_receive(:trade).and_call_original
168
+ trader.should_receive(:trade_again)
169
+ trader.trade
170
+ end
171
+
164
172
  it "calls #execute_trade if percent > cutoff" do
165
173
  trader.options[:live] = true
166
174
  trader.options[:cutoff] = 1
@@ -190,4 +198,31 @@ describe RbtcArbitrage::Trader do
190
198
  it { trader.logger.should == trader.options[:logger] }
191
199
  end
192
200
 
201
+ describe "#trade_again" do
202
+ before(:each) { trader.options[:repeat] = 10 }
203
+
204
+ it "should call #trade" do
205
+ trader.should_receive(:sleep).with(10)
206
+ trader.should_receive(:trade)
207
+ trader.trade_again
208
+ end
209
+
210
+ it "should create new clients" do
211
+ buy_client = trader.buy_client
212
+ sell_client = trader.sell_client
213
+ trader.should_receive(:sleep)
214
+ trader.should_receive(:trade)
215
+ trader.trade_again
216
+ buy_client.should_not == trader.buy_client
217
+ sell_client.should_not == trader.sell_client
218
+ end
219
+ end
220
+
221
+ describe "#client_for_exchange" do
222
+ it "should raise if wrong market" do
223
+ error = "Invalid exchange - 'test'"
224
+ expect { trader.client_for_exchange(:test) }.to raise_error(ArgumentError, error)
225
+ end
226
+ end
227
+
193
228
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtc_arbitrage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hank Stoever
@@ -162,12 +162,14 @@ files:
162
162
  - .rspec
163
163
  - .travis.yml
164
164
  - Gemfile
165
+ - Gemfile.lock
165
166
  - Guardfile
166
167
  - LICENSE.txt
168
+ - Procfile
167
169
  - README.md
168
170
  - Rakefile
169
171
  - bin/rbtc
170
- - btce-api-key.yml
172
+ - dummy_web_server.rb
171
173
  - lib/rbtc_arbitrage.rb
172
174
  - lib/rbtc_arbitrage/campbx.rb
173
175
  - lib/rbtc_arbitrage/cli.rb
data/btce-api-key.yml DELETED
@@ -1,2 +0,0 @@
1
- key: #{ENV['BTCE_KEY']}
2
- secret: #{ENV['BTCE_SECRET']}