rbtc_arbitrage 2.0.1 → 2.0.2

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: 6ac55aba1d4c56ccf2a54c8730c4e852939fb634
4
- data.tar.gz: d7484960f957e4b317cba4c591a71bf2bc7ac573
3
+ metadata.gz: 343e03101953463b1fe628965585c402baf85ec0
4
+ data.tar.gz: bd1db8a57c03e20a6e7a3c8f8750883159e0625b
5
5
  SHA512:
6
- metadata.gz: a2403ad6d3f378a189b1abef215ba44d0ffd8c097c4d2d0f585fc544509c392a3c871ed18fb46bfda83e982fe5d7a410dcfef9f93b7b84a4ddf154212596f377
7
- data.tar.gz: 81a63d4f6b4aa587e9db4c9968bb8561a56a313f795ebf62af191106e584344cea0f34d7d5f9ab0da136e5a4974795dfdf3e84a0d7da71b87db721a4c4b15b15
6
+ metadata.gz: f94c8549b48deab8e7d56ef63f0a992358fd948e6a78218f7325c56c3c3f9716950a66c4392dcfb328acbf0a4b07c1216ca512f120a05a90813796a6524708a1
7
+ data.tar.gz: bb2e4ebc741ecf66bae436ad59e98ddea561106a9219b0f6c18f74f6fcfd12fc5b2f88b7e15311c228da60bcb6a2ba595c7837ca8d5527b367e935a27f07ae7d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbtc_arbitrage (2.0.1)
4
+ rbtc_arbitrage (2.0.2)
5
5
  activemodel (>= 3.1)
6
6
  activesupport (>= 3.1)
7
7
  btce (= 0.2.4)
@@ -70,10 +70,10 @@ module CampBX
70
70
  request.set_form_data( post_data )
71
71
  end
72
72
 
73
- # debug # need to test w/valid credentials
74
- #puts "Sending request to #{uri}"
75
- #puts "Post Data: #{post_data}"
73
+ make_request(http, request)
74
+ end
76
75
 
76
+ def make_request http, request
77
77
  # CampBX API: max 1 request per 500ms
78
78
  delta = Time.now - @@last
79
79
  #puts delta*1000
@@ -90,7 +90,6 @@ module CampBX
90
90
  else # HTTP ERROR
91
91
  warn "HTTP Error: + #{res.code}"
92
92
  end
93
-
94
93
  end
95
94
 
96
95
  end
@@ -0,0 +1,31 @@
1
+ module RbtcArbitrage
2
+ module TraderHelpers
3
+ module Logger
4
+ def logger
5
+ @options[:logger]
6
+ end
7
+
8
+ def log_info
9
+ lower_ex = @buy_client.exchange.to_s.capitalize
10
+ higher_ex = @sell_client.exchange.to_s.capitalize
11
+ logger.info "#{lower_ex}: $#{buyer[:price].round(2)}"
12
+ logger.info "#{higher_ex}: $#{seller[:price].round(2)}"
13
+ logger.info "buying #{@options[:volume]} btc from #{lower_ex} for $#{@paid.round(2)}"
14
+ logger.info "selling #{@options[:volume]} btc on #{higher_ex} for $#{@received.round(2)}"
15
+
16
+ log_profit
17
+ end
18
+
19
+ private
20
+
21
+ def log_profit
22
+ profit_msg = "profit: $#{(@received - @paid).round(2)} (#{@percent.round(2)}%)"
23
+ if cutoff = @options[:cutoff]
24
+ profit_msg << " is #{@percent < cutoff ? 'below' : 'above'} cutoff"
25
+ profit_msg << " of #{cutoff}%."
26
+ end
27
+ logger.info profit_msg
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ module RbtcArbitrage
2
+ module TraderHelpers
3
+ module Notifier
4
+ def notify
5
+ return false unless options[:notify]
6
+ return false unless @percent > options[:cutoff]
7
+ setup_pony
8
+
9
+ options[:logger].info "Sending email to #{ENV['SENDGRID_EMAIL']}"
10
+ Pony.mail({
11
+ body: notification,
12
+ to: ENV['SENDGRID_EMAIL'],
13
+ })
14
+ end
15
+
16
+ def setup_pony
17
+ Pony.options = {
18
+ from: ENV['FROM_EMAIL'] || "info@example.org",
19
+ subject: "rbtc_arbitrage notification",
20
+ via: :smtp,
21
+ via_options: {
22
+ address: 'smtp.sendgrid.net',
23
+ port: '587',
24
+ domain: 'heroku.com',
25
+ user_name: ENV['SENDGRID_USERNAME'],
26
+ password: ENV['SENDGRID_PASSWORD'],
27
+ authentication: :plain,
28
+ enable_starttls_auto: true
29
+ }
30
+ }
31
+ end
32
+
33
+ def notification
34
+ lower_ex = @buy_client.exchange.to_s.capitalize
35
+ higher_ex = @sell_client.exchange.to_s.capitalize
36
+ <<-eos
37
+ Update from your friendly rbtc_arbitrage trader:
38
+
39
+ -------------------
40
+
41
+ #{lower_ex}: $#{buyer[:price].round(2)}
42
+ #{higher_ex}: $#{seller[:price].round(2)}
43
+ buying #{@options[:volume]} btc from #{lower_ex} for $#{@paid.round(2)}
44
+ selling #{@options[:volume]} btc on #{higher_ex} for $#{@received.round(2)}
45
+ profit: $#{(@received - @paid).round(2)} (#{@percent.round(2)}%)
46
+
47
+ -------------------
48
+
49
+ options:
50
+
51
+ #{options.reject{|k,v| v.is_a?(Logger)}.collect{|k,v| "#{k}: #{v.to_s}"}.join(" | ")}
52
+
53
+ -------------------
54
+
55
+ https://github.com/hstove/rbtc_arbitrage
56
+ eos
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,5 +1,8 @@
1
1
  module RbtcArbitrage
2
2
  class Trader
3
+ include RbtcArbitrage::TraderHelpers::Notifier
4
+ include RbtcArbitrage::TraderHelpers::Logger
5
+
3
6
  attr_reader :buy_client, :sell_client, :received
4
7
  attr_accessor :buyer, :seller, :options
5
8
 
@@ -64,14 +67,7 @@ module RbtcArbitrage
64
67
  raise SecurityError, "--live flag is false. Not executing trade." unless options[:live]
65
68
  get_balance
66
69
  if @percent > @options[:cutoff]
67
- if @paid > buyer[:usd] || @options[:volume] > seller[:btc]
68
- raise SecurityError, "Not enough funds. Exiting."
69
- else
70
- logger.info "Trading live!" if options[:verbose]
71
- @buy_client.buy
72
- @sell_client.sell
73
- @buy_client.transfer @sell_client
74
- end
70
+ buy_and_transfer!
75
71
  else
76
72
  logger.info "Not trading live because cutoff is higher than profit." if @options[:verbose]
77
73
  end
@@ -82,25 +78,8 @@ module RbtcArbitrage
82
78
  buyer[:price] = @buy_client.price(:buy)
83
79
  seller[:price] = @sell_client.price(:sell)
84
80
  prices = [buyer[:price], seller[:price]]
85
- @paid = buyer[:price] * 1.006 * @options[:volume]
86
- @received = seller[:price] * 0.994 * @options[:volume]
87
- @percent = ((received/@paid - 1) * 100).round(2)
88
- end
89
81
 
90
- def log_info
91
- lower_ex = @buy_client.exchange.to_s.capitalize
92
- higher_ex = @sell_client.exchange.to_s.capitalize
93
- logger.info "#{lower_ex}: $#{buyer[:price].round(2)}"
94
- logger.info "#{higher_ex}: $#{seller[:price].round(2)}"
95
- logger.info "buying #{@options[:volume]} btc from #{lower_ex} for $#{@paid.round(2)}"
96
- logger.info "selling #{@options[:volume]} btc on #{higher_ex} for $#{@received.round(2)}"
97
-
98
- profit_msg = "profit: $#{(@received - @paid).round(2)} (#{@percent.round(2)}%)"
99
- if cutoff = @options[:cutoff]
100
- profit_msg << " is #{@percent < cutoff ? 'below' : 'above'} cutoff"
101
- profit_msg << " of #{cutoff}%."
102
- end
103
- logger.info profit_msg
82
+ calculate_profit
104
83
  end
105
84
 
106
85
  def get_balance
@@ -108,10 +87,6 @@ module RbtcArbitrage
108
87
  @buyer[:btc], @buyer[:usd] = @buy_client.balance
109
88
  end
110
89
 
111
- def logger
112
- @options[:logger]
113
- end
114
-
115
90
  def validate_env
116
91
  [@sell_client, @buy_client].each do |client|
117
92
  client.validate_env
@@ -141,59 +116,24 @@ module RbtcArbitrage
141
116
  end
142
117
  end
143
118
 
144
- def notify
145
- return false unless options[:notify]
146
- return false unless @percent > options[:cutoff]
147
- setup_pony
119
+ private
148
120
 
149
- options[:logger].info "Sending email to #{ENV['SENDGRID_EMAIL']}"
150
- Pony.mail({
151
- body: notification,
152
- to: ENV['SENDGRID_EMAIL'],
153
- })
121
+ def calculate_profit
122
+ @paid = buyer[:price] * 1.006 * @options[:volume]
123
+ @received = seller[:price] * 0.994 * @options[:volume]
124
+ @percent = ((received/@paid - 1) * 100).round(2)
154
125
  end
155
126
 
156
- def setup_pony
157
- Pony.options = {
158
- from: ENV['FROM_EMAIL'] || "info@example.org",
159
- subject: "rbtc_arbitrage notification",
160
- via: :smtp,
161
- via_options: {
162
- address: 'smtp.sendgrid.net',
163
- port: '587',
164
- domain: 'heroku.com',
165
- user_name: ENV['SENDGRID_USERNAME'],
166
- password: ENV['SENDGRID_PASSWORD'],
167
- authentication: :plain,
168
- enable_starttls_auto: true
169
- }
170
- }
127
+ def buy_and_transfer!
128
+ if @paid > buyer[:usd] || @options[:volume] > seller[:btc]
129
+ raise SecurityError, "Not enough funds. Exiting."
130
+ else
131
+ logger.info "Trading live!" if options[:verbose]
132
+ @buy_client.buy
133
+ @sell_client.sell
134
+ @buy_client.transfer @sell_client
135
+ end
171
136
  end
172
137
 
173
- def notification
174
- lower_ex = @buy_client.exchange.to_s.capitalize
175
- higher_ex = @sell_client.exchange.to_s.capitalize
176
- <<-eos
177
- Update from your friendly rbtc_arbitrage trader:
178
-
179
- -------------------
180
-
181
- #{lower_ex}: $#{buyer[:price].round(2)}
182
- #{higher_ex}: $#{seller[:price].round(2)}
183
- buying #{@options[:volume]} btc from #{lower_ex} for $#{@paid.round(2)}
184
- selling #{@options[:volume]} btc on #{higher_ex} for $#{@received.round(2)}
185
- profit: $#{(@received - @paid).round(2)} (#{@percent.round(2)}%)
186
-
187
- -------------------
188
-
189
- options:
190
-
191
- #{options.reject{|k,v| v.is_a?(Logger)}.collect{|k,v| "#{k}: #{v.to_s}"}.join(" | ")}
192
-
193
- -------------------
194
-
195
- https://github.com/hstove/rbtc_arbitrage
196
- eos
197
- end
198
138
  end
199
139
  end
@@ -1,3 +1,3 @@
1
1
  module RbtcArbitrage
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -6,6 +6,7 @@ require 'btce'
6
6
  require 'coinbase'
7
7
  require 'pony'
8
8
  require_relative 'rbtc_arbitrage/client.rb'
9
+ Dir["#{File.dirname(__FILE__)}/rbtc_arbitrage/trader/*.rb"].each { |f| require(f) }
9
10
  Dir["#{File.dirname(__FILE__)}/rbtc_arbitrage/**/*.rb"].each { |f| require(f) }
10
11
 
11
12
  module RbtcArbitrage
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,7 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
10
  SimpleCov.start do
11
11
  add_filter "/spec/"
12
12
  add_filter "/lib/rbtc_arbitrage/campbx.rb"
13
+ add_filter "/bitstamp/"
13
14
  end
14
15
 
15
16
  require 'bundler'
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: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hank Stoever
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,6 +167,8 @@ files:
167
167
  - lib/rbtc_arbitrage/clients/client.rb.example
168
168
  - lib/rbtc_arbitrage/clients/coinbase_client.rb
169
169
  - lib/rbtc_arbitrage/trader.rb
170
+ - lib/rbtc_arbitrage/trader/logger.rb
171
+ - lib/rbtc_arbitrage/trader/notifier.rb
170
172
  - lib/rbtc_arbitrage/version.rb
171
173
  - rbtc_arbitrage.gemspec
172
174
  - spec/cli_spec.rb