rbtc_arbitrage 1.1.0 → 1.2.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: 148434f269c04f443fcfff7fa4296afcd99c3ebd
4
- data.tar.gz: 108d60840e184dbb14e8349ca7983a6edeb599b2
3
+ metadata.gz: 5f1a7981428666494c3138632923d59f06720cf1
4
+ data.tar.gz: 847d059ba92dc899dc8f911a8f8cc03412620f3c
5
5
  SHA512:
6
- metadata.gz: 6502ed6e3c1af4bb81c35b125ee91be0883893d1d494ffcc99e92a3066acac804b6d29cc8223f649836e7f7a7a03a51a71be2e3ab6c147ff00f3bffa81737f97
7
- data.tar.gz: 6b6652d8fadd9e974282594882b605586da5284d7aa1be6a55a6523dd41a2c2f73930410d916d3c3ebfc0aa4a79bc89bf7058997372fa193ea0aee880264527c
6
+ metadata.gz: 95146a940a2d81ad26db01240834c98641ddd222ed66269329426d65a7248b8275a1484572d7f5718e960fe55e5d19a6592a1169defb4cd7d441a6095da6ecc7
7
+ data.tar.gz: ebeb1d24b38a920554ef29f2fac54fea81c9676bf94c0263f93e86038195d4297c2a44aacfee4ead4a540716d36e8f4bf25af56d3d6df4f9b3ddcf1e194ec166
@@ -9,8 +9,12 @@ module RbtcArbitrage
9
9
 
10
10
  def balance
11
11
  return @balance if @balance
12
- balances = interface.get_info["return"]["funds"]
13
- @balance = [balances["btc"], balances["usd"]]
12
+ begin
13
+ balances = interface.get_info["return"]["funds"]
14
+ @balance = [balances["btc"], balances["usd"]]
15
+ rescue NoMethodError => e
16
+ raise SecurityError, "Invalid API key for BTC-e"
17
+ end
14
18
  end
15
19
 
16
20
  def interface
@@ -4,6 +4,8 @@ module RbtcArbitrage
4
4
  attr_accessor :buyer, :seller, :options
5
5
 
6
6
  def initialize config={}
7
+ config = config.to_hash
8
+ config.each { |k,v| config[k.to_sym] = v unless k.is_a?(Symbol) }
7
9
  @buyer = {}
8
10
  @seller = {}
9
11
  @options = {}
@@ -60,8 +62,8 @@ module RbtcArbitrage
60
62
  buyer[:price] = @buy_client.price(:buy)
61
63
  seller[:price] = @sell_client.price(:sell)
62
64
  prices = [buyer[:price], seller[:price]]
63
- @paid = prices.min * 1.005 * @options[:volume]
64
- @received = prices.max * 0.994 * @options[:volume]
65
+ @paid = buyer[:price] * 1.006 * @options[:volume]
66
+ @received = seller[:price] * 0.994 * @options[:volume]
65
67
  @percent = ((received/@paid - 1) * 100).round(2)
66
68
  end
67
69
 
@@ -1,3 +1,3 @@
1
1
  module RbtcArbitrage
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -37,7 +37,7 @@ describe RbtcArbitrage::Clients::BtceClient do
37
37
  end
38
38
 
39
39
  describe "#balance" do
40
- it "fetches the balance correctly", :vcr do
40
+ it "fetches the balance correctly" do
41
41
  balances = btce.get_info["return"]["funds"]
42
42
  expected = [balances["btc"], balances["usd"]]
43
43
  client.balance.should eql(expected)
@@ -45,6 +45,11 @@ describe RbtcArbitrage::Clients::BtceClient do
45
45
  b.should be_a(Float)
46
46
  end
47
47
  end
48
+
49
+ it "should raise if bad API keys", :vcr do
50
+ btce.unstub(:get_info)
51
+ expect { client.balance }.to raise_error(SecurityError)
52
+ end
48
53
  end
49
54
 
50
55
  describe "#price" do
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://btc-e.com/tapi
6
+ body:
7
+ encoding: US-ASCII
8
+ string: method=getInfo&nonce=1387758890
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Key:
17
+ - fake
18
+ Sign:
19
+ - !ruby/object:OpenSSL::HMAC {}
20
+ Content-Type:
21
+ - application/x-www-form-urlencoded
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Server:
28
+ - cloudflare-nginx
29
+ Date:
30
+ - Mon, 23 Dec 2013 00:34:51 GMT
31
+ Content-Type:
32
+ - text/html; charset=utf-8
33
+ Transfer-Encoding:
34
+ - chunked
35
+ Connection:
36
+ - keep-alive
37
+ Set-Cookie:
38
+ - __cfduid=dd20e7e199fd945092427e1ea3835a2ee1387758891683; expires=Mon, 23-Dec-2019
39
+ 23:50:00 GMT; path=/; domain=.btc-e.com; HttpOnly
40
+ X-Frame-Options:
41
+ - DENY
42
+ Expires:
43
+ - Thu, 01 Jan 1970 00:00:01 GMT
44
+ Cache-Control:
45
+ - no-cache
46
+ Cf-Ray:
47
+ - e10f7f0a9280669
48
+ body:
49
+ encoding: UTF-8
50
+ string: '{"success":0,"error":"invalid api key"}'
51
+ http_version:
52
+ recorded_at: Mon, 23 Dec 2013 00:34:51 GMT
53
+ recorded_with: VCR 2.7.0
data/spec/trader_spec.rb CHANGED
@@ -6,9 +6,9 @@ describe RbtcArbitrage::Trader do
6
6
  before :each do
7
7
  @old_keys = {}
8
8
  #clear env variables
9
- ["KEY", "SECRET", "ADDRESS"].each do |suffix|
10
- ["MTGOX", "BITSTAMP"].each do |prefix|
11
- key = "#{prefix}_#{suffix}"
9
+ ["KEY", "SECRET"].each do |suffix|
10
+ RbtcArbitrage.clients.each do |client_class|
11
+ key = "#{client_class.new.exchange.to_s.upcase}_#{suffix}"
12
12
  @old_keys[key] = ENV[key]
13
13
  ENV[key] = nil
14
14
  end
@@ -22,13 +22,19 @@ describe RbtcArbitrage::Trader do
22
22
  end
23
23
  end
24
24
 
25
- it "should raise errors when missing env variable" do
26
- ["KEY", "SECRET", "ADDRESS"].each do |suffix|
27
- key = "#{trader.sell_client.exchange.to_s.upcase}_#{suffix}"
28
- expect { trader.sell_client.validate_env }.to raise_error(ArgumentError, "Exiting because missing required ENV variable $#{key}.")
29
- ENV[key] = "some value"
25
+ RbtcArbitrage.clients.each do |client|
26
+ describe client do
27
+ keys = ["KEY", "SECRET"]
28
+ keys << "ADDRESS" unless client.instance_methods(false).include?(:address)
29
+ client = client.new
30
+ prefix = client.exchange.to_s.upcase
31
+ keys.each do |suffix|
32
+ key = "#{prefix}_#{suffix}"
33
+ it "should raise errors when missing env variable $#{key}" do
34
+ expect { client.validate_env }.to raise_error(ArgumentError)
35
+ end
36
+ end
30
37
  end
31
- expect { trader.sell_client.validate_env }.not_to raise_error
32
38
  end
33
39
  end
34
40
 
@@ -43,6 +49,15 @@ describe RbtcArbitrage::Trader do
43
49
  trader.buyer[:price].should be_within(0.02).of(stamp_price)
44
50
  trader.seller[:price].should be_within(0.02).of(mtgox_price)
45
51
  end
52
+
53
+ it "calculates profit and percent accurately" do
54
+ trader.buy_client.stub(:price) { 10.5 }
55
+ trader.sell_client.stub(:price) { 10 }
56
+
57
+ trader.fetch_prices
58
+ trader.instance_variable_get(:@paid).should == (10.5 * 1.006 * 0.01)
59
+ trader.instance_variable_get(:@received).should == (10 * 0.994 * 0.01)
60
+ end
46
61
  end
47
62
 
48
63
  describe "#initialize" do
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.1.0
4
+ version: 1.2.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-22 00:00:00.000000000 Z
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,6 +178,7 @@ files:
178
178
  - spec/support/cassettes/RbtcArbitrage_Clients_BitstampClient/_price/fetches_price_for_buy_correctly.yml
179
179
  - spec/support/cassettes/RbtcArbitrage_Clients_BitstampClient/_price/fetches_price_for_sell_correctly.yml
180
180
  - spec/support/cassettes/RbtcArbitrage_Clients_BitstampClient/_price/fetches_prices_correctly.yml
181
+ - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_balance/should_raise_if_bad_API_keys.yml
181
182
  - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_price/calls_btc-e.yml
182
183
  - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_price/fetches_price_for_buy_correctly.yml
183
184
  - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_price/fetches_price_for_sell_correctly.yml
@@ -233,6 +234,7 @@ test_files:
233
234
  - spec/support/cassettes/RbtcArbitrage_Clients_BitstampClient/_price/fetches_price_for_buy_correctly.yml
234
235
  - spec/support/cassettes/RbtcArbitrage_Clients_BitstampClient/_price/fetches_price_for_sell_correctly.yml
235
236
  - spec/support/cassettes/RbtcArbitrage_Clients_BitstampClient/_price/fetches_prices_correctly.yml
237
+ - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_balance/should_raise_if_bad_API_keys.yml
236
238
  - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_price/calls_btc-e.yml
237
239
  - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_price/fetches_price_for_buy_correctly.yml
238
240
  - spec/support/cassettes/RbtcArbitrage_Clients_BtceClient/_price/fetches_price_for_sell_correctly.yml