rbtc_arbitrage 1.3.0 → 1.4.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: 073f034a32dc76e95d0e5a425a0716e4c97d2208
4
- data.tar.gz: fc051d210da396065843debde1122612f09bf331
3
+ metadata.gz: 35a3e079318e368f33db37bb070cef7acd9dc3d5
4
+ data.tar.gz: 23327807ba84e9d20b99e170d25b4088c64b7587
5
5
  SHA512:
6
- metadata.gz: 09aa1b9843ff89cf3254d97801e1d1b2547cc4ae9be908d9abac68f5989250e447cc7b0f129c2540952937d58bb79ba4328acabc35767033f77cb24f53b2f1df
7
- data.tar.gz: c90035506f8efeefc460761e1e2d4e61bc2313d4e69f251cfdb1c9d51df5facb1ba1335773d657a3c6b85ef04e315b048a403ccd74bc652f44f85c76a8bc5408
6
+ metadata.gz: 8dbab32dba09e0ae422ca3ecc5bfe20dba8f5e76de1af1efaa0c8f8a537151d78fd6345472bd737288f623f088834915acffdd7e44f4872cf4dc6aaf54d09fbd
7
+ data.tar.gz: cb577476f076d7f1285cff313bd80dac03f077b8ec53a973df02aa0605ff071d406c8f8c5988d7bf0dbd817264a8d26105ebe535a2a52f4cfaf43c9b958d9839
data/.travis.yml CHANGED
@@ -19,3 +19,6 @@ env:
19
19
  - secure: IFyJX6lAmBpef0I50UPCy6L5IRxqRKoPhv74s5y0FPB4chrir7iMZ7Sd1IczxV7ly4Dt7hdALHP1qMTmkcGmTV6YOzwR46G4JAwWtX2xlf4OYk4jey7qjNsS6iijD6dvdYjqSKUuGaX3Til3kUOLcA3hhINvHxj5unv2pHB2W70=
20
20
  - secure: YiYtCBJNfgWuzQ059RMmZxM00bs4c/GuqaEaKufLPPByJHHt3z4jCNT5lurox/RIqSYTv+1Nvgor1xJZF4VPDIhtoCpVRe3g5Pvubrp4gWQry11ta0f1JhPSrm5ORlF1hpHPfzHHSh+/YVmKcO8agQAaIgfKcXDzsE6j5QqiGWQ=
21
21
  - secure: TCrSkWTG2A7ZHxU/J82R1oRn3+ISYHOZmukvBT/OkOh35yjhtig3KhroYki67guCClVxov+ZPvCRUKgmsEoVng1ljk/ZXyyNf4QNVccEJxHCwIRiqs36jlC2ebd8g+JJUPrnnWGO/U5vBm+WlrOb4lFlIsBuCYI+FBAFYTPmKEs=
22
+ - secure: cePvBAt6j7UwybsP6Cs5a7mwaXMHDteXC1ENsNMy69qV5mae7oRKqsfavZ8ar33apNXqALXDWiDnHH7wPccMl3GXIquHE7I73lAOcEu4V+f7nHqqFuJezA12IL0swOQhDNK23C5ibkFftlpG2jTxHpaRLaDNCuv404cREalwwgA=
23
+ - secure: PLTV2N3BYlqXmDDuOuZGk83YApX3oEIpskkWHUGj8f3wBpjOSPxuLBdpSGMXRqT2kIMJqle65gqlYpwh4NcTgqL93iNAT9fh7WDyNx/SUL+Mz04kphAC6N0VPyg7nvTi33bDbkmAAFNc+1yoWKAlB2gjKKXFtdxTwMp4SjvNsfs=
24
+ - secure: nyFUNdswDOM0UgW3T/jeEvIyZPSGq+ZEpyYw6KGpwb7a5F1DbAfoSy6zJGWK6S3vKf6814e43HmawhJlhcD9KYOV783O7KYu54FTmhZ/SP9QhNV+w1hiKKRQcTlJdjbPIuO5piuMDMCPacCJa+C9YO0lhhxfZ+/6F4SNR1fteN0=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbtc_arbitrage (1.3.0)
4
+ rbtc_arbitrage (1.4.0)
5
5
  activemodel (>= 3.1)
6
6
  activesupport (>= 3.1)
7
7
  bitstamp
@@ -9,6 +9,7 @@ PATH
9
9
  btce (= 0.2.4)
10
10
  coinbase (= 1.2.4)
11
11
  mtgox
12
+ pony
12
13
  thor
13
14
 
14
15
  GEM
@@ -78,6 +79,10 @@ GEM
78
79
  rb-fsevent (>= 0.9.3)
79
80
  rb-inotify (>= 0.9)
80
81
  lumberjack (1.0.4)
82
+ mail (2.2.7)
83
+ activesupport (>= 2.3.6)
84
+ mime-types
85
+ treetop (>= 1.4.5)
81
86
  method_source (0.8.2)
82
87
  mime-types (2.0)
83
88
  minitest (4.7.5)
@@ -91,6 +96,9 @@ GEM
91
96
  multi_json (1.8.2)
92
97
  multi_xml (0.5.5)
93
98
  multipart-post (1.2.0)
99
+ polyglot (0.3.3)
100
+ pony (1.6.2)
101
+ mail (>= 2.0)
94
102
  pry (0.9.12.4)
95
103
  coderay (~> 1.0)
96
104
  method_source (~> 0.8)
@@ -137,6 +145,9 @@ GEM
137
145
  tilt (1.4.1)
138
146
  timers (1.1.0)
139
147
  tins (0.13.1)
148
+ treetop (1.4.15)
149
+ polyglot
150
+ polyglot (>= 0.3.1)
140
151
  tzinfo (0.3.38)
141
152
  vcr (2.8.0)
142
153
  webmock (1.16.1)
data/bin/rbtc CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
4
  require 'rbtc_arbitrage'
4
5
  RbtcArbitrage::CLI.start ARGV
@@ -9,6 +9,7 @@ module RbtcArbitrage
9
9
  option :buyer, type: :string, default: "bitstamp"
10
10
  option :seller, type: :string, default: "mtgox"
11
11
  option :repeat, type: :numeric, default: nil
12
+ option :notify, type: :boolean, default: false
12
13
  def trade
13
14
  RbtcArbitrage::Trader.new(options).trade
14
15
  end
@@ -17,6 +17,7 @@ module RbtcArbitrage
17
17
  set_key opts, :verbose, true
18
18
  set_key opts, :live, false
19
19
  set_key opts, :repeat, nil
20
+ set_key opts, :notify, false
20
21
  exchange = opts[:buyer] || :bitstamp
21
22
  @buy_client = client_for_exchange(exchange)
22
23
  exchange = opts[:seller] || :mtgox
@@ -38,9 +39,12 @@ module RbtcArbitrage
38
39
 
39
40
  execute_trade if options[:live]
40
41
 
42
+ notify
43
+
41
44
  if @options[:repeat]
42
45
  trade_again
43
46
  end
47
+
44
48
  self
45
49
  end
46
50
 
@@ -104,6 +108,15 @@ module RbtcArbitrage
104
108
  [@sell_client, @buy_client].each do |client|
105
109
  client.validate_env
106
110
  end
111
+ if options[:notify]
112
+ ["PASSWORD","USERNAME","EMAIL"].each do |key|
113
+ key = "SENDGRID_#{key}"
114
+ unless ENV[key]
115
+ raise ArgumentError, "Exiting because missing required ENV variable $#{key}."
116
+ end
117
+ end
118
+ setup_pony
119
+ end
107
120
  end
108
121
 
109
122
  def client_for_exchange market
@@ -119,5 +132,49 @@ module RbtcArbitrage
119
132
  raise ArgumentError, "Invalid exchange - '#{market}'"
120
133
  end
121
134
  end
135
+
136
+ def notify
137
+ return false unless options[:notify]
138
+ return false unless @percent > options[:cutoff]
139
+ setup_pony
140
+
141
+ options[:logger].info "Sending email to #{ENV['SENDGRID_EMAIL']}"
142
+ Pony.mail({
143
+ body: notification,
144
+ to: ENV['SENDGRID_EMAIL'],
145
+ })
146
+ end
147
+
148
+ def setup_pony
149
+ Pony.options = {
150
+ from: "info@uludum.org",
151
+ subject: "rbtc_arbitrage notification",
152
+ via: :smtp,
153
+ via_options: {
154
+ address: 'smtp.sendgrid.net',
155
+ port: '587',
156
+ domain: 'heroku.com',
157
+ user_name: ENV['SENDGRID_USERNAME'],
158
+ password: ENV['SENDGRID_PASSWORD'],
159
+ authentication: :plain,
160
+ enable_starttls_auto: true
161
+ }
162
+ }
163
+ end
164
+
165
+ def notification
166
+ lower_ex = @buy_client.exchange.to_s.capitalize
167
+ higher_ex = @sell_client.exchange.to_s.capitalize
168
+ <<-eos
169
+ Update from your friendly rbtc_arbitrage trader:
170
+ #{lower_ex}: $#{buyer[:price].round(2)}
171
+ #{higher_ex}: $#{seller[:price].round(2)}
172
+ buying #{@options[:volume]} btc from #{lower_ex} for $#{@paid.round(2)}
173
+ selling #{@options[:volume]} btc on #{higher_ex} for $#{@received.round(2)}
174
+ profit: $#{(@received - @paid).round(2)} (#{@percent.round(2)}%)
175
+
176
+ options
177
+ eos
178
+ end
122
179
  end
123
180
  end
@@ -1,3 +1,3 @@
1
1
  module RbtcArbitrage
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -4,6 +4,7 @@ require_relative 'rbtc_arbitrage/campbx.rb'
4
4
  require 'bitstamp'
5
5
  require 'btce'
6
6
  require 'coinbase'
7
+ require 'pony'
7
8
  require_relative 'rbtc_arbitrage/client.rb'
8
9
  Dir["#{File.dirname(__FILE__)}/rbtc_arbitrage/**/*.rb"].each { |f| require(f) }
9
10
 
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "btce", '0.2.4'
30
30
  spec.add_dependency "bitstamp"
31
31
  spec.add_dependency "coinbase", '1.2.4'
32
+ spec.add_dependency "pony"
32
33
  end
data/spec/trader_spec.rb CHANGED
@@ -37,6 +37,20 @@ describe RbtcArbitrage::Trader do
37
37
  end
38
38
  end
39
39
  end
40
+
41
+ ["PASSWORD","USERNAME","EMAIL"].each do |key|
42
+ key = "SENDGRID_#{key}"
43
+ it "should raise if --notify and not ENV[#{key}]" do
44
+ trader.sell_client.stub(:validate_env)
45
+ trader.buy_client.stub(:validate_env)
46
+ old_val = ENV[key]
47
+ ENV[key] = nil
48
+ trader.options[:notify] = true
49
+ expect { trader.validate_env }.to raise_error(ArgumentError)
50
+ trader.options[:notify] = false
51
+ expect { trader.validate_env }.not_to raise_error
52
+ end
53
+ end
40
54
  end
41
55
 
42
56
  describe "#fetch_prices" do
@@ -71,6 +85,7 @@ describe RbtcArbitrage::Trader do
71
85
  live: true,
72
86
  seller: :bitstamp,
73
87
  buyer: :mtgox,
88
+ notify: true,
74
89
  }
75
90
  }
76
91
 
@@ -142,6 +157,7 @@ describe RbtcArbitrage::Trader do
142
157
  describe "#trade" do
143
158
  it "calls the right methods" do
144
159
  trader.should_receive(:fetch_prices)
160
+ trader.should_receive(:notify)
145
161
  trader.should_not_receive(:log_info)
146
162
  trader.should_not_receive(:execute_trade)
147
163
 
@@ -225,4 +241,79 @@ describe RbtcArbitrage::Trader do
225
241
  end
226
242
  end
227
243
 
244
+ describe "#notify" do
245
+ it "returns false when notify == false" do
246
+ trader.notify.should == false
247
+ end
248
+
249
+ it "returns false unless cutoff < percent" do
250
+ trader.options[:notify] = true
251
+ trader.instance_variable_set :@percent, 1
252
+ trader.notify.should == false
253
+ end
254
+
255
+ it "calls Sendgrid when notify == true" do
256
+ trader.options[:notify] = true
257
+ trader.instance_variable_set :@percent, 3
258
+ trader.instance_variable_set :@paid, 5
259
+ trader.instance_variable_set :@received, 6
260
+ trader.buyer[:price] = 1
261
+ trader.seller[:price] = 1
262
+
263
+ trader.options[:logger].should_receive(:info)
264
+ Pony.should_receive(:mail).with({
265
+ to: ENV['SENDGRID_EMAIL'],
266
+ body: trader.notification,
267
+ })
268
+
269
+ trader.notify
270
+ end
271
+ end
272
+
273
+ describe "#setup_pony" do
274
+ it "gets called on validation when --notify" do
275
+ ["PASSWORD","USERNAME","EMAIL"].each do |key|
276
+ key = "SENDGRID_#{key}"
277
+ ENV[key] ||= "something"
278
+ end
279
+ trader.options[:notify] = true
280
+ trader.should_receive(:setup_pony).once
281
+ trader.validate_env
282
+ end
283
+ it "sets up pony correctly" do
284
+ opts = {
285
+ from: "info@uludum.org",
286
+ subject: "rbtc_arbitrage notification",
287
+ :via => :smtp,
288
+ :via_options => {
289
+ :address => 'smtp.sendgrid.net',
290
+ :port => '587',
291
+ :domain => 'heroku.com',
292
+ :user_name => ENV['SENDGRID_USERNAME'],
293
+ :password => ENV['SENDGRID_PASSWORD'],
294
+ :authentication => :plain,
295
+ :enable_starttls_auto => true
296
+ }
297
+ }
298
+ Pony.should_receive(:options=).with(opts)
299
+ trader.setup_pony
300
+ end
301
+ end
302
+
303
+ describe "#notification" do
304
+ it "includes the right values" do
305
+ trader.instance_variable_set :@percent, 3
306
+ trader.instance_variable_set :@paid, 5
307
+ trader.instance_variable_set :@received, 8
308
+ trader.buyer[:price] = 1.00453
309
+ trader.seller[:price] = 3.50453
310
+
311
+ value = trader.notification
312
+ value.should include("$1.0")
313
+ value.should include("$3.5")
314
+ value.should include("$3.0")
315
+ value.should include("3.0%")
316
+ end
317
+ end
318
+
228
319
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtc_arbitrage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hank Stoever
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-23 00:00:00.000000000 Z
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.2.4
153
+ - !ruby/object:Gem::Dependency
154
+ name: pony
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: A gem for conducting arbitrage with Bitcoin.
154
168
  email:
155
169
  - hstove@gmail.com