money-bank-cryptocompare 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +9 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/money/bank/cryptocompare.rb +30 -0
- data/money-bank-cryptocompare.gemspec +28 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c6ed758c024e1785d40d226934c3b57eb4fccf6
|
4
|
+
data.tar.gz: 901752f7c5ee656f9688d8a7151609a9afa5d45d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a2496fd58e40f77cb9fdfad86236f38400ea18506c99aed2b78e205fb78429c441b7b691c5ebe768971b52b1f09543ae572100c2a69128f3d9ed2f0658e62d2
|
7
|
+
data.tar.gz: 4e7775b74d09be6e94245a954a7f2b6005bd4c61f00bc1fb213a43001d1d3ee14a15ef8c68b46f99fc754d8d03cce295f98562957b6ec0bc15b9a7f5ff43c3ea
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 LULALALA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Money::Bank::Cryptocompare
|
2
|
+
|
3
|
+
Money gem's Bank implementation to Cryptocompare API to do cryptocurrency exchange, like converting Bitcoin to Ethereum.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'money-bank-cryptocompare'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install money-bank-cryptocompare
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
First you need to define the cryptocurrency you need:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'money'
|
27
|
+
|
28
|
+
curr = {
|
29
|
+
:priority => 1,
|
30
|
+
:iso_code => "IOT",
|
31
|
+
:name => "IOT",
|
32
|
+
:subunit => "IOT",
|
33
|
+
:subunit_to_unit => 1,
|
34
|
+
}
|
35
|
+
Money::Currency.register(curr)
|
36
|
+
```
|
37
|
+
|
38
|
+
Initialize the bank, and call `exchange_to` as you normally would.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'money/bank/cryptocompare'
|
42
|
+
bank = Money::Bank::Cryptocompare.new
|
43
|
+
bank.exchange_with(Money.new(100_000_000,'BTC'), 'IOT')
|
44
|
+
|
45
|
+
# Set default bank to allow auto currency conversion
|
46
|
+
Money.default_bank = bank
|
47
|
+
Money.new(100_000_000,'BTC').exchange_to('IOT')
|
48
|
+
```
|
49
|
+
|
50
|
+
Cryptocompare offers some options, such as using specific exchange for rate lookup. This can be set when initializing the bank:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
Money::Bank::Cryptocompare.new(options: {'e' => 'Kraken'})
|
54
|
+
```
|
55
|
+
|
56
|
+
A list of supported exchanges are listed [here](https://github.com/alexanderdavidpan/cryptocompare#supported-exchanges).
|
57
|
+
|
58
|
+
If we want to set a rates store, pass it with the `:rates_store` key (different to standard bank method signature):
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Money::Bank::Cryptocompare.new(rates_store: rates_store)
|
62
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "money/bank/cryptocompare"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "money"
|
2
|
+
require "cryptocompare"
|
3
|
+
|
4
|
+
class Money
|
5
|
+
module Bank
|
6
|
+
class Cryptocompare < VariableExchange
|
7
|
+
def initialize(rates_store: nil, options: {}, &block)
|
8
|
+
@cyptocompare_options = options
|
9
|
+
|
10
|
+
rates_store ||= Money::RatesStore::Memory.new
|
11
|
+
super(rates_store, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_rate(from, to, opts = {})
|
15
|
+
rate = super
|
16
|
+
|
17
|
+
if rate
|
18
|
+
rate
|
19
|
+
else
|
20
|
+
# Fetch exchange rate
|
21
|
+
info = ::Cryptocompare::Price.find(from, to, @cyptocompare_options)
|
22
|
+
if info["Response"] == "Error"
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
add_rate(from, to, info[from.to_s][to.to_s])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "money-bank-cryptocompare"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.license = 'MIT'
|
8
|
+
spec.authors = ["lulalala"]
|
9
|
+
spec.email = ["mark@goodlife.tw"]
|
10
|
+
|
11
|
+
spec.summary = %q{Money Bank for fetch cryptocurrency exchange rates from Cryptocompare}
|
12
|
+
spec.description = %q{Money gem's Bank implementation to Cryptocompare API to do cryptocurrency exchange, like converting Bitcoin to Ethereum.}
|
13
|
+
spec.homepage = "https://github.com/lulalala/money-bank-cryptocompare"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'money'
|
23
|
+
spec.add_dependency 'cryptocompare'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.7.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: money-bank-cryptocompare
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lulalala
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: money
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cryptocompare
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.7.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.7.0
|
83
|
+
description: Money gem's Bank implementation to Cryptocompare API to do cryptocurrency
|
84
|
+
exchange, like converting Bitcoin to Ethereum.
|
85
|
+
email:
|
86
|
+
- mark@goodlife.tw
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/money/bank/cryptocompare.rb
|
100
|
+
- money-bank-cryptocompare.gemspec
|
101
|
+
homepage: https://github.com/lulalala/money-bank-cryptocompare
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Money Bank for fetch cryptocurrency exchange rates from Cryptocompare
|
125
|
+
test_files: []
|