coin_tracking 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/coin_tracking.gemspec +29 -0
- data/lib/coin_tracking.rb +7 -0
- data/lib/coin_tracking/api.rb +92 -0
- data/lib/coin_tracking/response.rb +43 -0
- data/lib/coin_tracking/version.rb +4 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 25b3b09209a558aa8bbd12b2d1a8f9693fe90f8039f5c596c6b3f87c8f5b2eac
|
4
|
+
data.tar.gz: 337894dc2a92085ce95259b2f486ea0ac193f1353bf850cf843975bd599d7f4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db46156e62b85b04990a078c79a1a5054835c8e97480c4f24cda48bfc6ef1422798d3e4bbe85c86ed8885665a3aefdb735bb9abcd73374b065ebae0fbd9ff885
|
7
|
+
data.tar.gz: 9f8f009b5b77236b8728b61aa315f7abcf3873dbefa63e53105124b691e4691eaf813aca695498a9f6b6b0b9b3e86f35d94084c3d25202804a9c007727b30f0f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
coin_tracking (1.0.0)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
httparty (0.16.2)
|
12
|
+
multi_xml (>= 0.5.2)
|
13
|
+
multi_xml (0.6.0)
|
14
|
+
rake (10.5.0)
|
15
|
+
rspec (3.7.0)
|
16
|
+
rspec-core (~> 3.7.0)
|
17
|
+
rspec-expectations (~> 3.7.0)
|
18
|
+
rspec-mocks (~> 3.7.0)
|
19
|
+
rspec-core (3.7.1)
|
20
|
+
rspec-support (~> 3.7.0)
|
21
|
+
rspec-expectations (3.7.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-mocks (3.7.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-support (3.7.1)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.16)
|
34
|
+
coin_tracking!
|
35
|
+
rake (~> 10.0)
|
36
|
+
rspec (~> 3.0)
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Carl Mercier
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# CoinTracking.rb
|
2
|
+
|
3
|
+
A Ruby client for CoinTracking.info
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'coin_tracking'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install coin_tracking
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'coin_tracking'
|
25
|
+
api = CoinTracking::Api.new API_KEY, SECRET_KEY
|
26
|
+
|
27
|
+
api.trades
|
28
|
+
api.balance
|
29
|
+
api.historical_summary
|
30
|
+
api.historical_currency
|
31
|
+
api.grouped_balance
|
32
|
+
api.gains
|
33
|
+
|
34
|
+
# Optionally, you can pass a Hash with additional parameters, as documented at https://cointracking.info/api/api.php.
|
35
|
+
# Note that `start` and `end` are special parameters that accept DateTime, Time or a Unix timestamp. This gem does the conversion for you.
|
36
|
+
|
37
|
+
api.trades(limit: 100, order: 'DESC', start: 1.year.ago, end: 1525486520)
|
38
|
+
|
39
|
+
# Each call returns a CoinTracking::Response object. Here are some of the methods that are available:
|
40
|
+
|
41
|
+
response.success? # => true/false
|
42
|
+
response.data # => Hash
|
43
|
+
response.http_response # => Raw response from HTTParty
|
44
|
+
response.foobar # => Syntactic sugar. Same as `response.data['foobar']`.
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cmer/coin_tracking_rb.
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "coin_tracking"
|
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,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "coin_tracking/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coin_tracking"
|
8
|
+
spec.version = CoinTracking::VERSION
|
9
|
+
spec.authors = ["Carl Mercier"]
|
10
|
+
spec.email = ["foss@carlmercier.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby client for CoinTracking.info}
|
13
|
+
spec.description = %q{A Ruby client for CoinTracking.info}
|
14
|
+
spec.homepage = "https://github.com/cmer/coin_tracking_rb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_dependency "httparty"
|
29
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'httparty'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module CoinTracking
|
6
|
+
class Api
|
7
|
+
API_URL = 'https://cointracking.info/api/v1/'
|
8
|
+
DEBUG = false
|
9
|
+
|
10
|
+
def initialize(api_key, secret_key)
|
11
|
+
@api_key, @secret_key = api_key, secret_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def trades(params = {})
|
15
|
+
api_query('getTrades', sanitize_params(params))
|
16
|
+
end
|
17
|
+
|
18
|
+
def balance(params = {})
|
19
|
+
api_query('getBalance', sanitize_params(params))
|
20
|
+
end
|
21
|
+
|
22
|
+
def historical_summary(params = {})
|
23
|
+
api_query('getHistoricalSummary', sanitize_params(params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def historical_currency(params = {})
|
27
|
+
api_query('getHistoricalCurrency', sanitize_params(params))
|
28
|
+
end
|
29
|
+
|
30
|
+
def grouped_balance(params = {})
|
31
|
+
api_query('getGroupedBalance', sanitize_params(params))
|
32
|
+
end
|
33
|
+
|
34
|
+
def gains(params = {})
|
35
|
+
api_query('getGains', sanitize_params(params))
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def sanitize_params(params = {})
|
41
|
+
%w(start end).each do |key|
|
42
|
+
sym = key.to_sym
|
43
|
+
params[key] = time_to_unix(params[key]) if params.include?(key)
|
44
|
+
params[sym] = time_to_unix(params[sym]) if params.include?(sym)
|
45
|
+
end
|
46
|
+
params
|
47
|
+
end
|
48
|
+
|
49
|
+
def time_to_unix(v)
|
50
|
+
case v
|
51
|
+
when DateTime, Date
|
52
|
+
v.to_time.to_i
|
53
|
+
when Time, String
|
54
|
+
v.to_i
|
55
|
+
when Integer
|
56
|
+
v
|
57
|
+
else
|
58
|
+
raise ArgumentError.new("Invalid timestamp type: #{v.class}.")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def api_query(action, params = {})
|
63
|
+
params = { method: action, nonce: nonce }.merge(params)
|
64
|
+
response = HTTParty.post API_URL, body: params, headers: http_headers(params), debug_output: DEBUG ? $stdout : nil
|
65
|
+
puts params
|
66
|
+
CoinTracking::Response.new(response)
|
67
|
+
end
|
68
|
+
|
69
|
+
def encoded_params(params)
|
70
|
+
HTTParty::HashConversions.to_params(params)
|
71
|
+
end
|
72
|
+
|
73
|
+
def signed_params(params)
|
74
|
+
OpenSSL::HMAC.hexdigest('sha512', @secret_key, encoded_params(params))
|
75
|
+
end
|
76
|
+
|
77
|
+
def nonce
|
78
|
+
Time.now.to_i
|
79
|
+
end
|
80
|
+
|
81
|
+
def http_headers(params)
|
82
|
+
{ 'Key' => @api_key,
|
83
|
+
'Sign' => signed_params(params),
|
84
|
+
'Connection' => 'close',
|
85
|
+
'User-Agent' => user_agent }
|
86
|
+
end
|
87
|
+
|
88
|
+
def user_agent
|
89
|
+
"CoinTracking.rb/#{CoinTracking::VERSION} (#{CoinTracking::SOURCE_URL})"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module CoinTracking
|
4
|
+
class Response
|
5
|
+
attr_reader :http_response
|
6
|
+
|
7
|
+
def initialize(http_response)
|
8
|
+
@http_response = http_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_h
|
12
|
+
if @http_response.parsed_response.is_a?(String)
|
13
|
+
JSON.parse(@http_response.parsed_response)
|
14
|
+
else
|
15
|
+
@http_response.parsed_response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
to_h
|
21
|
+
end
|
22
|
+
|
23
|
+
def body
|
24
|
+
@http_response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def success?
|
28
|
+
data['success'].to_i == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
def error?
|
32
|
+
!success?
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_missing(method_sym, *arguments, &block)
|
36
|
+
data.include?(method_sym.to_s) ? data[method_sym.to_s] : super
|
37
|
+
end
|
38
|
+
|
39
|
+
def respond_to?(method_sym, include_private = false)
|
40
|
+
data.include?(method_sym.to_s) ? true : super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coin_tracking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carl Mercier
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Ruby client for CoinTracking.info
|
70
|
+
email:
|
71
|
+
- foss@carlmercier.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- coin_tracking.gemspec
|
87
|
+
- lib/coin_tracking.rb
|
88
|
+
- lib/coin_tracking/api.rb
|
89
|
+
- lib/coin_tracking/response.rb
|
90
|
+
- lib/coin_tracking/version.rb
|
91
|
+
homepage: https://github.com/cmer/coin_tracking_rb
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: A Ruby client for CoinTracking.info
|
115
|
+
test_files: []
|