crypto_arbitrer 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/crypto_arbitrer/spec_helper.rb +20 -0
- data/lib/crypto_arbitrer/version.rb +1 -1
- data/lib/crypto_arbitrer.rb +2 -1
- data/spec/base_spec.rb +15 -26
- metadata +3 -2
@@ -0,0 +1,20 @@
|
|
1
|
+
module CryptoArbitrer
|
2
|
+
module SpecHelper
|
3
|
+
def stub_crypto_arbitrer_get(url, mock_name)
|
4
|
+
stub_request(:get, url)
|
5
|
+
.to_return(body: open(File.expand_path("../../../spec/mocks/#{mock_name}", __FILE__)).read)
|
6
|
+
end
|
7
|
+
def mock_crypto_arbitrer_requests!
|
8
|
+
stub_crypto_arbitrer_get("http://www.eldolarblue.net/getDolarBlue.php?as=json", 'dolarblue.json')
|
9
|
+
stub_crypto_arbitrer_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
10
|
+
stub_crypto_arbitrer_get('http://www.dolarparalelo.org/', 'dolarparalelo.html')
|
11
|
+
%w(ltc nmc nvc trc ppc ftc cnc).each do |crypto|
|
12
|
+
stub_crypto_arbitrer_get("https://btc-e.com/exchange/#{crypto}_btc", "btce_#{crypto}_btc.html")
|
13
|
+
end
|
14
|
+
%w(uyu brl clp sgd eur).each do |currency|
|
15
|
+
stub_crypto_arbitrer_get("http://rate-exchange.appspot.com/currency?from=usd&to=#{currency}",
|
16
|
+
"rate_exchange_usd_#{currency}.json")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/crypto_arbitrer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "crypto_arbitrer/version"
|
2
|
+
require "crypto_arbitrer/spec_helper"
|
2
3
|
require "json"
|
3
4
|
require "open-uri"
|
4
5
|
|
@@ -159,7 +160,7 @@ module CryptoArbitrer
|
|
159
160
|
# @param force [Boolean] Ignore the cache (does not read from it, and does not write to it). Defaults to false.
|
160
161
|
# @return [{'buy' => Float, 'sell' => Float}] The buy and sell prices
|
161
162
|
def self.fetch(from,to, force = false)
|
162
|
-
new.fetch(from, to, force)
|
163
|
+
new.fetch(from.downcase, to.downcase, force)
|
163
164
|
end
|
164
165
|
|
165
166
|
protected
|
data/spec/base_spec.rb
CHANGED
@@ -1,25 +1,14 @@
|
|
1
1
|
require_relative '../lib/crypto_arbitrer.rb'
|
2
2
|
require 'webmock/rspec'
|
3
3
|
require 'csv'
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.include CryptoArbitrer::SpecHelper
|
6
|
+
end
|
4
7
|
|
5
8
|
describe CryptoArbitrer::Base do
|
6
|
-
def stub_get(url, mock_name)
|
7
|
-
stub_request(:get, url)
|
8
|
-
.to_return(body: open(File.expand_path("../mocks/#{mock_name}", __FILE__)).read)
|
9
|
-
end
|
10
|
-
|
11
9
|
describe 'when matching corpus of conversion rates' do
|
12
10
|
before :each do
|
13
|
-
|
14
|
-
stub_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
15
|
-
stub_get('http://www.dolarparalelo.org/', 'dolarparalelo.html')
|
16
|
-
%w(ltc nmc nvc trc ppc ftc cnc).each do |crypto|
|
17
|
-
stub_get("https://btc-e.com/exchange/#{crypto}_btc", "btce_#{crypto}_btc.html")
|
18
|
-
end
|
19
|
-
%w(uyu brl clp sgd eur).each do |currency|
|
20
|
-
stub_get("http://rate-exchange.appspot.com/currency?from=usd&to=#{currency}",
|
21
|
-
"rate_exchange_usd_#{currency}.json")
|
22
|
-
end
|
11
|
+
mock_crypto_arbitrer_requests!
|
23
12
|
end
|
24
13
|
|
25
14
|
CSV.read(File.expand_path('../conversions.csv', __FILE__), 'r').each do |from, to, buy, sell|
|
@@ -52,26 +41,26 @@ describe CryptoArbitrer::Base do
|
|
52
41
|
end
|
53
42
|
|
54
43
|
it 'hits dolarblue for usd to ars rate' do
|
55
|
-
stub =
|
44
|
+
stub = stub_crypto_arbitrer_get("http://www.eldolarblue.net/getDolarBlue.php?as=json", 'dolarblue.json')
|
56
45
|
subject.fetch_usd_ars
|
57
46
|
stub.should have_been_requested
|
58
47
|
end
|
59
48
|
|
60
49
|
it 'hits mt.gox for the btc to usd rate' do
|
61
|
-
stub =
|
50
|
+
stub = stub_crypto_arbitrer_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
62
51
|
subject.fetch_btc_usd
|
63
52
|
stub.should have_been_requested
|
64
53
|
end
|
65
54
|
|
66
55
|
it 'hits dolarparalelo for venezuelan bolivar' do
|
67
|
-
stub =
|
56
|
+
stub = stub_crypto_arbitrer_get('http://www.dolarparalelo.org/', 'dolarparalelo.html')
|
68
57
|
subject.fetch_usd_vef
|
69
58
|
stub.should have_been_requested
|
70
59
|
end
|
71
60
|
|
72
61
|
it 'hits mt.gox and dolarblue for the btc to ars rate' do
|
73
|
-
stub_ars =
|
74
|
-
stub_btc =
|
62
|
+
stub_ars = stub_crypto_arbitrer_get("http://www.eldolarblue.net/getDolarBlue.php?as=json", 'dolarblue.json')
|
63
|
+
stub_btc = stub_crypto_arbitrer_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
75
64
|
subject.fetch_btc_ars
|
76
65
|
stub_ars.should have_been_requested
|
77
66
|
stub_btc.should have_been_requested
|
@@ -79,7 +68,7 @@ describe CryptoArbitrer::Base do
|
|
79
68
|
|
80
69
|
%w(ltc nmc nvc trc ppc ftc cnc).each do |currency|
|
81
70
|
it "hits btc-e for the #{currency} to btc rate" do
|
82
|
-
stub =
|
71
|
+
stub = stub_crypto_arbitrer_get("https://btc-e.com/exchange/#{currency}_btc", "btce_#{currency}_btc.html")
|
83
72
|
subject.fetch(currency, 'btc')
|
84
73
|
subject.fetch('btc', currency)
|
85
74
|
stub.should have_been_requested.twice
|
@@ -88,7 +77,7 @@ describe CryptoArbitrer::Base do
|
|
88
77
|
|
89
78
|
%w(uyu brl clp sgd eur).each do |currency|
|
90
79
|
it "hits rate-exchange for the #{currency} to usd rate" do
|
91
|
-
stub =
|
80
|
+
stub = stub_crypto_arbitrer_get("http://rate-exchange.appspot.com/currency?from=usd&to=#{currency}",
|
92
81
|
"rate_exchange_usd_#{currency}.json")
|
93
82
|
subject.fetch('usd', currency)
|
94
83
|
subject.fetch(currency, 'usd')
|
@@ -98,7 +87,7 @@ describe CryptoArbitrer::Base do
|
|
98
87
|
|
99
88
|
describe 'when caching remote calls' do
|
100
89
|
it 'does not cache anything by default' do
|
101
|
-
stub =
|
90
|
+
stub = stub_crypto_arbitrer_get("http://www.eldolarblue.net/getDolarBlue.php?as=json", 'dolarblue.json')
|
102
91
|
2.times{ subject.fetch('usd', 'ars') }
|
103
92
|
stub.should have_been_requested.twice
|
104
93
|
end
|
@@ -106,7 +95,7 @@ describe CryptoArbitrer::Base do
|
|
106
95
|
it 'caches when a cache_backend has been set, stops caching afterwards' do
|
107
96
|
cache = {}
|
108
97
|
subject.class.cache_backend = lambda {|from, to, block| cache[[from,to]] ||= block.call }
|
109
|
-
stub =
|
98
|
+
stub = stub_crypto_arbitrer_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
110
99
|
subject.fetch('btc', 'usd')
|
111
100
|
cache[['btc','usd']].should be_a(Hash)
|
112
101
|
subject.fetch('btc', 'usd')
|
@@ -119,7 +108,7 @@ describe CryptoArbitrer::Base do
|
|
119
108
|
it 'does not cache for low level calls' do
|
120
109
|
cache = {}
|
121
110
|
subject.class.cache_backend = lambda {|from, to, block| cache[key] ||= block.call }
|
122
|
-
stub =
|
111
|
+
stub = stub_crypto_arbitrer_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
123
112
|
subject.fetch_btc_usd
|
124
113
|
subject.fetch_btc_usd
|
125
114
|
stub.should have_been_requested.twice
|
@@ -128,7 +117,7 @@ describe CryptoArbitrer::Base do
|
|
128
117
|
it 'does not cache when using a force argument' do
|
129
118
|
cache = {}
|
130
119
|
subject.class.cache_backend = lambda {|from, to, block| cache[key] ||= block.call }
|
131
|
-
stub =
|
120
|
+
stub = stub_crypto_arbitrer_get('http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast', 'mtgox.json')
|
132
121
|
subject.fetch('btc', 'usd', true)
|
133
122
|
subject.fetch('btc', 'usd', true)
|
134
123
|
stub.should have_been_requested.twice
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypto_arbitrer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- crypto_arbitrer.gemspec
|
111
111
|
- lib/crypto_arbitrer.rb
|
112
|
+
- lib/crypto_arbitrer/spec_helper.rb
|
112
113
|
- lib/crypto_arbitrer/version.rb
|
113
114
|
- spec/base_spec.rb
|
114
115
|
- spec/conversions.csv
|