cryptopia 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 +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cryptopia.gemspec +28 -0
- data/lib/cryptopia.rb +6 -0
- data/lib/cryptopia/api.rb +35 -0
- data/lib/cryptopia/api/market.rb +101 -0
- data/lib/cryptopia/api/private.rb +200 -0
- data/lib/cryptopia/api/public.rb +39 -0
- data/lib/cryptopia/version.rb +3 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e7c0b028e2801dd60092072392e20a11d84dd3f8
|
4
|
+
data.tar.gz: dfd7ba008af45fb76d970ff01d0a37071b6cad22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae51cd1546a0db289ce53ee9365e6e30aa1e4dde32ca94e532d603cfd4a38b2ce9f5f87b18f59eaf49b19a69c56f532b84fb2e468317fdad1168f5a147630c3f
|
7
|
+
data.tar.gz: 20de7f238428bedec4f988dda7fb068171e0364deaa666ccdba41ac334d2426eedd4234b812eb43959e771e7529a36ca559ce23b90f4ed42410e4c316dbd4260
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at contato@brunoarueira.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Bruno Arueira
|
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,38 @@
|
|
1
|
+
# Cryptopia
|
2
|
+
|
3
|
+
This is a crytopia's api wrapper gem. This gem implements all the public api
|
4
|
+
(see https://www.cryptopia.co.nz/Forum/Thread/255) and part of the private api
|
5
|
+
(see #5).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cryptopia'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cryptopia
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Must of the api endpoints follow a camel case name and for the endpoints which
|
26
|
+
have prefixed with ```Get```, was removed e.g GetMarkets => markets
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/brunoarueira/cryptopia. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
35
|
+
|
36
|
+
## Code of Conduct
|
37
|
+
|
38
|
+
Everyone interacting in the Cryptopia project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/brunoarueira/cryptopia/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cryptopia"
|
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
data/cryptopia.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "cryptopia/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cryptopia"
|
7
|
+
spec.version = Cryptopia::VERSION
|
8
|
+
spec.authors = ["Bruno Arueira"]
|
9
|
+
spec.email = ["contato@brunoarueira.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Cryptopia wrapper api}
|
12
|
+
spec.description = %q{Cryptopia wrapper api}
|
13
|
+
spec.homepage = "https://github.com/brunoarueira/cryptopia"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty", "0.15.6"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "vcr", "4.0.0"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
end
|
data/lib/cryptopia.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'cryptopia/api/market'
|
3
|
+
require 'cryptopia/api/public'
|
4
|
+
require 'cryptopia/api/private'
|
5
|
+
|
6
|
+
module Cryptopia
|
7
|
+
module Api
|
8
|
+
class Base
|
9
|
+
include ::HTTParty
|
10
|
+
include Public
|
11
|
+
include Private
|
12
|
+
|
13
|
+
base_uri 'https://www.cryptopia.co.nz/api'
|
14
|
+
format :json
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def for_uri(uri, &block)
|
19
|
+
current_uri = self.class.base_uri
|
20
|
+
|
21
|
+
self.class.base_uri uri
|
22
|
+
|
23
|
+
result = block.call
|
24
|
+
ensure
|
25
|
+
self.class.base_uri current_uri
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_response(response)
|
31
|
+
response.code == 200 ? response.to_h : {}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Cryptopia
|
2
|
+
module Api
|
3
|
+
class Market
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
AVAILABLE_PARAMS = {
|
7
|
+
markets: [:baseParam, :hours],
|
8
|
+
market: [:hours],
|
9
|
+
history: [:hours],
|
10
|
+
orders: [:orderCount],
|
11
|
+
order_groups: [:orderCount]
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(uri)
|
15
|
+
self.class.base_uri uri
|
16
|
+
end
|
17
|
+
|
18
|
+
def all(options = {})
|
19
|
+
if invalid_params?(:markets, options)
|
20
|
+
raise ArgumentError, "Arguments must be #{params(:markets)}"
|
21
|
+
end
|
22
|
+
|
23
|
+
endpoint_call_handler("/GetMarkets", options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find(market, options = {})
|
27
|
+
if valid_market?(market)
|
28
|
+
raise ArgumentError, 'The trade pair must be informed'
|
29
|
+
end
|
30
|
+
|
31
|
+
if invalid_params?(:market, options)
|
32
|
+
raise ArgumentError, "Arguments must be #{params(:market)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
endpoint_call_handler("/GetMarket/#{market}", options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def history(market, options = {})
|
39
|
+
if valid_market?(market)
|
40
|
+
raise ArgumentError, 'The trade pair must be informed'
|
41
|
+
end
|
42
|
+
|
43
|
+
if invalid_params?(:history, options)
|
44
|
+
raise ArgumentError, "Arguments must be #{params(:history)}"
|
45
|
+
end
|
46
|
+
|
47
|
+
endpoint_call_handler("/GetMarketHistory/#{market}", options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def orders(market, options = {})
|
51
|
+
if valid_market?(market)
|
52
|
+
raise ArgumentError, 'The trade pair must be informed'
|
53
|
+
end
|
54
|
+
|
55
|
+
if invalid_params?(:orders, options)
|
56
|
+
raise ArgumentError, "Arguments must be #{params(:orders)}"
|
57
|
+
end
|
58
|
+
|
59
|
+
endpoint_call_handler("/GetMarketOrders/#{market}", options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def order_groups(markets = [], options = {})
|
63
|
+
if markets.nil? || (!markets.nil? && markets.empty?)
|
64
|
+
raise ArgumentError, 'The trade pairs must be informed'
|
65
|
+
end
|
66
|
+
|
67
|
+
if invalid_params?(:order_groups, options)
|
68
|
+
raise ArgumentError, "Arguments must be #{params(:order_groups)}"
|
69
|
+
end
|
70
|
+
|
71
|
+
handled_markets = markets.join('-')
|
72
|
+
|
73
|
+
endpoint_call_handler("/GetMarketOrderGroups/#{handled_markets}", options)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def endpoint_call_handler(url, options = {})
|
79
|
+
if options.keys.length.zero?
|
80
|
+
self.class.get(url)
|
81
|
+
else
|
82
|
+
self.class.get("#{url}/#{options.values.join('/')}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def invalid_params?(endpoint, options = {})
|
87
|
+
return false if options.keys.length.zero?
|
88
|
+
|
89
|
+
(options.keys - AVAILABLE_PARAMS[endpoint]).length >= 1
|
90
|
+
end
|
91
|
+
|
92
|
+
def valid_market?(market)
|
93
|
+
market.nil? || (market != nil && market == '')
|
94
|
+
end
|
95
|
+
|
96
|
+
def params(endpoint)
|
97
|
+
AVAILABLE_PARAMS[endpoint].join(' or ')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'json'
|
3
|
+
require 'base64'
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
module Cryptopia
|
7
|
+
module Api
|
8
|
+
module Private
|
9
|
+
ENDPOINT = 'https://www.cryptopia.co.nz/Api'
|
10
|
+
|
11
|
+
AVAILABLE_PARAMS = {
|
12
|
+
balance: [:Currency, :CurrencyId],
|
13
|
+
deposit_address: [:Currency, :CurrencyId],
|
14
|
+
open_orders: [:Market, :TradePairId],
|
15
|
+
trade_history: [:Market, :TradePairId],
|
16
|
+
transactions: [:Type],
|
17
|
+
submit_trade: [:Market, :TradePairId],
|
18
|
+
cancel_trade: [:OrderId, :TradeId]
|
19
|
+
}
|
20
|
+
|
21
|
+
OPTIONAL_PARAMS = {
|
22
|
+
open_orders: [:Count]
|
23
|
+
}
|
24
|
+
|
25
|
+
EXACT_PARAMS = {
|
26
|
+
submit_trade: [:Type, :Rate, :Amount],
|
27
|
+
cancel_trade: [:Type]
|
28
|
+
}
|
29
|
+
|
30
|
+
def initialize(api_key = nil, api_secret = nil)
|
31
|
+
@api_key = api_key
|
32
|
+
@api_secret = api_secret
|
33
|
+
end
|
34
|
+
|
35
|
+
def balance(options = {})
|
36
|
+
for_uri(Private::ENDPOINT) do
|
37
|
+
if invalid_params?(:balance, options)
|
38
|
+
raise ArgumentError, "Arguments must be #{params(:balance)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
handle_response(auth_post('/GetBalance', options))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def deposit_address(options = {})
|
46
|
+
for_uri(Private::ENDPOINT) do
|
47
|
+
if invalid_params?(:deposit_address, options)
|
48
|
+
raise ArgumentError, "Arguments must be #{params(:deposit_address)}"
|
49
|
+
end
|
50
|
+
|
51
|
+
handle_response(auth_post('/GetDepositAddress', options))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def open_orders(options = {})
|
56
|
+
for_uri(Private::ENDPOINT) do
|
57
|
+
if invalid_params?(:deposit_address, options)
|
58
|
+
raise ArgumentError, "Arguments must be #{params(:deposit_address)}"
|
59
|
+
end
|
60
|
+
|
61
|
+
handle_response(auth_post('/GetOpenOrders', options))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def trade_history(options = {})
|
66
|
+
for_uri(Private::ENDPOINT) do
|
67
|
+
if invalid_params?(:trade_history, options)
|
68
|
+
raise ArgumentError, "Arguments must be #{params(:trade_history)}"
|
69
|
+
end
|
70
|
+
|
71
|
+
handle_response(auth_post('/GetTradeHistory', options))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def transactions(options = {})
|
76
|
+
for_uri(Private::ENDPOINT) do
|
77
|
+
if invalid_params?(:transactions, options)
|
78
|
+
raise ArgumentError, "Arguments must be #{params(:transactions)}"
|
79
|
+
end
|
80
|
+
|
81
|
+
if invalid_transaction_type?(options)
|
82
|
+
raise ArgumentError, "Type must be 'Deposit' or 'Withdraw'"
|
83
|
+
end
|
84
|
+
|
85
|
+
handle_response(auth_post('/GetTransactions', options))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def submit_trade(options = {})
|
90
|
+
for_uri(Private::ENDPOINT) do
|
91
|
+
if invalid_params?(:submit_trade, options, true)
|
92
|
+
raise ArgumentError, "Arguments must be #{params(:submit_trade)}"
|
93
|
+
end
|
94
|
+
|
95
|
+
handle_response(auth_post('/SubmitTrade', options))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def cancel_trade(options = {})
|
100
|
+
for_uri(Private::ENDPOINT) do
|
101
|
+
if invalid_params?(:cancel_trade, options, true)
|
102
|
+
raise ArgumentError, "Arguments must be #{params(:cancel_trade)}"
|
103
|
+
end
|
104
|
+
|
105
|
+
handle_response(auth_post('/CancelTrade', options))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
attr_reader :api_key, :api_secret, :url, :options
|
112
|
+
|
113
|
+
def auth_post(endpoint, options = {})
|
114
|
+
if keys_is_not_present?
|
115
|
+
raise ArgumentError, "The api key and/or api secret must be informed"
|
116
|
+
end
|
117
|
+
|
118
|
+
@url = self.class.base_uri + endpoint
|
119
|
+
@options = options.to_json
|
120
|
+
|
121
|
+
self.class.post(
|
122
|
+
endpoint,
|
123
|
+
body: @options,
|
124
|
+
headers: {
|
125
|
+
'Authorization' => "amx #{authorization_formatted_value}",
|
126
|
+
'Content-Type' => 'application/json'
|
127
|
+
})
|
128
|
+
end
|
129
|
+
|
130
|
+
def keys_is_not_present?
|
131
|
+
(api_key.nil? || (!api_key.nil? && api_key == '')) ||
|
132
|
+
(api_secret.nil? || (!api_secret.nil? && api_secret == ''))
|
133
|
+
end
|
134
|
+
|
135
|
+
def authorization_formatted_value
|
136
|
+
[
|
137
|
+
api_key,
|
138
|
+
hmacsignature,
|
139
|
+
nonce
|
140
|
+
].join(':')
|
141
|
+
end
|
142
|
+
|
143
|
+
def hmacsignature
|
144
|
+
hmac = OpenSSL::HMAC.digest(
|
145
|
+
OpenSSL::Digest.new('sha256'),
|
146
|
+
Base64.strict_decode64(api_secret),
|
147
|
+
signature
|
148
|
+
)
|
149
|
+
|
150
|
+
Base64.strict_encode64(hmac).strip
|
151
|
+
end
|
152
|
+
|
153
|
+
def signature
|
154
|
+
[
|
155
|
+
api_key,
|
156
|
+
'POST',
|
157
|
+
CGI::escape(url).downcase,
|
158
|
+
nonce,
|
159
|
+
hashed_post_params
|
160
|
+
].join.strip
|
161
|
+
end
|
162
|
+
|
163
|
+
def hashed_post_params
|
164
|
+
md5 = Digest::MD5.new.digest(options.to_s)
|
165
|
+
|
166
|
+
Base64.strict_encode64(md5)
|
167
|
+
end
|
168
|
+
|
169
|
+
def nonce
|
170
|
+
@nonce ||= Time.now.to_i.to_s
|
171
|
+
end
|
172
|
+
|
173
|
+
def invalid_transaction_type?(options)
|
174
|
+
return false if options.keys.length.zero?
|
175
|
+
|
176
|
+
options.key?(:Type) && (options[:Type] != 'Deposit' && options[:Type] != 'Withdraw')
|
177
|
+
end
|
178
|
+
|
179
|
+
def invalid_params?(endpoint, options = {}, exact = false)
|
180
|
+
return false if options.keys.length.zero?
|
181
|
+
|
182
|
+
available_keys = options.keys - AVAILABLE_PARAMS[endpoint]
|
183
|
+
available_keys.length == 1 &&
|
184
|
+
(
|
185
|
+
OPTIONAL_PARAMS.key?(endpoint) &&
|
186
|
+
(OPTIONAL_PARAMS[endpoint] - available_keys) >= 1
|
187
|
+
) &&
|
188
|
+
(
|
189
|
+
exact &&
|
190
|
+
EXACT_PARAMS.key?(endpoint) &&
|
191
|
+
EXACT_PARAMS[endpoint]
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
def params(endpoint)
|
196
|
+
AVAILABLE_PARAMS[endpoint].join(' or ')
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Cryptopia
|
2
|
+
module Api
|
3
|
+
module Public
|
4
|
+
def currencies
|
5
|
+
handle_response(self.class.get('/GetCurrencies'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def trade_pairs
|
9
|
+
handle_response(self.class.get('/GetTradePairs'))
|
10
|
+
end
|
11
|
+
|
12
|
+
def markets(options = {})
|
13
|
+
handle_response(Market.new(self.class.base_uri).all(options))
|
14
|
+
end
|
15
|
+
|
16
|
+
def market(market, options = {})
|
17
|
+
handle_response(Market.new(self.class.base_uri).find(market, options))
|
18
|
+
end
|
19
|
+
|
20
|
+
def market_history(market, options = {})
|
21
|
+
handle_response(Market.new(self.class.base_uri).history(market, options))
|
22
|
+
end
|
23
|
+
|
24
|
+
def market_orders(market, options = {})
|
25
|
+
handle_response(Market.new(self.class.base_uri).orders(market, options))
|
26
|
+
end
|
27
|
+
|
28
|
+
def market_order_groups(markets = [], options = {})
|
29
|
+
handle_response(Market.new(self.class.base_uri).order_groups(markets, options))
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def handle_response(response)
|
35
|
+
response.code == 200 ? response.to_h : {}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cryptopia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Arueira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Cryptopia wrapper api
|
98
|
+
email:
|
99
|
+
- contato@brunoarueira.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- cryptopia.gemspec
|
115
|
+
- lib/cryptopia.rb
|
116
|
+
- lib/cryptopia/api.rb
|
117
|
+
- lib/cryptopia/api/market.rb
|
118
|
+
- lib/cryptopia/api/private.rb
|
119
|
+
- lib/cryptopia/api/public.rb
|
120
|
+
- lib/cryptopia/version.rb
|
121
|
+
homepage: https://github.com/brunoarueira/cryptopia
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.5.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Cryptopia wrapper api
|
145
|
+
test_files: []
|