cointrader.net 0.1.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 +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/cointrader.net.gemspec +25 -0
- data/lib/cointrader.net/client/account.rb +7 -0
- data/lib/cointrader.net/client/request.rb +67 -0
- data/lib/cointrader.net/client/stats.rb +7 -0
- data/lib/cointrader.net/client.rb +11 -0
- data/lib/cointrader.net/version.rb +3 -0
- data/lib/cointrader.net.rb +22 -0
- data/spec/client_spec.rb +29 -0
- data/spec/fixtures/vcr_cassettes/balance.yml +74 -0
- data/spec/fixtures/vcr_cassettes/symbol.yml +70 -0
- data/spec/spec_helper.rb +25 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 06faca52e66387069a411622c54514022fd22e89
|
4
|
+
data.tar.gz: 2b5b820f4423cfe52de60035fd81839d46cda26c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f522b08109561e2b554e87e8931e223505d154f063850a55f377b4fcee26deb01a7d64a48020933e3288e23a156abddff49e835c0a1fa6d240cba5bade2b359
|
7
|
+
data.tar.gz: 7e07339c4890911e19d5feb9b17576d9721bf11a605c1597872ecccb202778410c67e3316b0919a8cf53d9faca1d1cb2f5969809b89fd0f7e5a46eb85b288b3e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Maros Hluska
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Cointrader.net
|
2
|
+
|
3
|
+
Ruby wrapper for the Cointrader.net API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cointrader.net'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cointrader.net
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Cointrader.configure do |c|
|
25
|
+
c.api_key = 'API_KEY'
|
26
|
+
c.api_secret = 'API_SECRET'
|
27
|
+
end
|
28
|
+
|
29
|
+
client = Cointrader::Client.new
|
30
|
+
puts client.balance
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/cointrader.net/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cointrader.net/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cointrader.net"
|
8
|
+
spec.version = Cointrader::VERSION
|
9
|
+
spec.authors = ["Maros Hluska"]
|
10
|
+
spec.email = ["mhluska@gmail.com"]
|
11
|
+
spec.summary = %q{Cointrader.net API wrapper}
|
12
|
+
spec.description = %q{Ruby wrapper for the Cointrader.net API}
|
13
|
+
spec.homepage = "https://github.com/mhluska/cointrader.net"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "vcr", "~> 2.9"
|
24
|
+
spec.add_development_dependency "dotenv", "~> 1.0"
|
25
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'openssl'
|
4
|
+
require 'date'
|
5
|
+
require 'uri'
|
6
|
+
require 'digest'
|
7
|
+
|
8
|
+
module Cointrader
|
9
|
+
module Request
|
10
|
+
API_URL = "https://www.cointrader.net/api4"
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def request(method, path, body={})
|
15
|
+
response = hmac_request(method, path, body)
|
16
|
+
|
17
|
+
# The API sucks and we need to repair JSON sometimes.
|
18
|
+
case path
|
19
|
+
when '/account/balance'
|
20
|
+
response.gsub!(/\s/, '') # Remove whitespace.
|
21
|
+
response.gsub!(/}}(?!$)/, '},') # Replace bracket with comma not at the end.
|
22
|
+
response.gsub!(/}}$/, '}}}') # Add a bracket at the end.
|
23
|
+
end
|
24
|
+
|
25
|
+
JSON.parse(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def hmac_request method, path, body={}
|
29
|
+
payload = {}
|
30
|
+
headers = { :content_type => 'application/json' }
|
31
|
+
base = Cointrader.configuration.api_url || API_URL
|
32
|
+
url = base + path
|
33
|
+
|
34
|
+
if method == :get
|
35
|
+
url += '?' + URI.encode_www_form(body)
|
36
|
+
else
|
37
|
+
api_key = Cointrader.configuration.api_key
|
38
|
+
api_secret = Cointrader.configuration.api_secret
|
39
|
+
|
40
|
+
raise 'API key and API secret are required!' unless api_key && api_secret
|
41
|
+
|
42
|
+
nonce = DateTime.now.strftime('%Q')
|
43
|
+
payload = body.merge({
|
44
|
+
secret: api_secret,
|
45
|
+
t: nonce,
|
46
|
+
})
|
47
|
+
|
48
|
+
secret = Digest::MD5.hexdigest(api_secret)
|
49
|
+
data = payload.to_json + api_secret
|
50
|
+
digest = OpenSSL::Digest.new('sha256')
|
51
|
+
signature = OpenSSL::HMAC.hexdigest(digest, secret, data)
|
52
|
+
|
53
|
+
headers.merge!({
|
54
|
+
'X-Auth' => api_key,
|
55
|
+
'X-Auth-Hash' => signature,
|
56
|
+
})
|
57
|
+
end
|
58
|
+
|
59
|
+
RestClient::Request.execute(
|
60
|
+
url: url,
|
61
|
+
method: method,
|
62
|
+
payload: payload.to_json,
|
63
|
+
headers: headers,
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "cointrader.net/version"
|
2
|
+
require "cointrader.net/client"
|
3
|
+
|
4
|
+
module Cointrader
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :api_key, :api_secret, :api_url
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.api_key = nil
|
10
|
+
self.api_secret = nil
|
11
|
+
self.api_url = nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield(configuration) if block_given?
|
21
|
+
end
|
22
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cointrader::Client do
|
4
|
+
describe 'stats' do
|
5
|
+
describe '#symbol' do
|
6
|
+
it 'returns supported currencies' do
|
7
|
+
VCR.use_cassette('symbol') do
|
8
|
+
response = subject.symbol
|
9
|
+
|
10
|
+
expect_success(response)
|
11
|
+
expect(response['data'][0]['name']).to eq 'Bitcoin (BTC)'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'account' do
|
18
|
+
describe '#balance' do
|
19
|
+
it 'returns a balance' do
|
20
|
+
VCR.use_cassette('balance') do
|
21
|
+
response = subject.balance
|
22
|
+
|
23
|
+
expect_success(response)
|
24
|
+
expect(response['data']['BTC']['available']).not_to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://private-anon-b5aa2a7bf-cointrader.apiary-mock.com/api4/account/balance
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"secret":"9KZifEvwZDp4ORSEXRFhp16o7okkCAJUpNXurEpx6a5F","t":"1424628637323"}'
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
X-Auth:
|
17
|
+
- gl42QPKWBCb03xFVMvZXrD3lH4zUv5fUbhE12XV2HWc3
|
18
|
+
X-Auth-Hash:
|
19
|
+
- 3985fc74c5cfe9343b4074e36f5b8864714a7781ae16fd19147d2dbdeb37ad48
|
20
|
+
Content-Length:
|
21
|
+
- '77'
|
22
|
+
User-Agent:
|
23
|
+
- Ruby
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
Server:
|
30
|
+
- Cowboy
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
X-Apiary-Ratelimit-Limit:
|
34
|
+
- '120'
|
35
|
+
X-Apiary-Ratelimit-Remaining:
|
36
|
+
- '114'
|
37
|
+
X-Apiary-Transaction-Id:
|
38
|
+
- 54ea1b6a9301760300cf70fd
|
39
|
+
Date:
|
40
|
+
- Sun, 22 Feb 2015 18:09:46 GMT
|
41
|
+
Transfer-Encoding:
|
42
|
+
- chunked
|
43
|
+
Via:
|
44
|
+
- 1.1 vegur
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: |2-
|
48
|
+
{
|
49
|
+
"success":true,
|
50
|
+
"message":"Account Balances",
|
51
|
+
"data":
|
52
|
+
{
|
53
|
+
"BTC":
|
54
|
+
{
|
55
|
+
"available":"199.99500000",
|
56
|
+
"on_hold":"0.00000000",
|
57
|
+
"total":"199.99500000"
|
58
|
+
},
|
59
|
+
"USD":
|
60
|
+
{
|
61
|
+
"available":"49923.94",
|
62
|
+
"on_hold":"0.00",
|
63
|
+
"total":"49923.94"}
|
64
|
+
}
|
65
|
+
"CAD":
|
66
|
+
{
|
67
|
+
"available":"1233.00",
|
68
|
+
"on_hold":"0.00",
|
69
|
+
"total":"1233.00"
|
70
|
+
}
|
71
|
+
}
|
72
|
+
http_version:
|
73
|
+
recorded_at: Sun, 22 Feb 2015 18:10:37 GMT
|
74
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://private-anon-b5aa2a7bf-cointrader.apiary-mock.com/api4/stats/symbol
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{}"
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
Content-Length:
|
17
|
+
- '2'
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- Cowboy
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
X-Apiary-Ratelimit-Limit:
|
30
|
+
- '120'
|
31
|
+
X-Apiary-Ratelimit-Remaining:
|
32
|
+
- '115'
|
33
|
+
X-Apiary-Transaction-Id:
|
34
|
+
- 54ea1b699301760300cf70fc
|
35
|
+
Date:
|
36
|
+
- Sun, 22 Feb 2015 18:09:45 GMT
|
37
|
+
Transfer-Encoding:
|
38
|
+
- chunked
|
39
|
+
Via:
|
40
|
+
- 1.1 vegur
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |-
|
44
|
+
{
|
45
|
+
"success":true,
|
46
|
+
"message":"Supported Symbols",
|
47
|
+
"data":
|
48
|
+
[
|
49
|
+
{
|
50
|
+
"name":"Bitcoin (BTC)",
|
51
|
+
"symbol":"XBT",
|
52
|
+
"description":"Basic Bitcoin-demoninated account",
|
53
|
+
"decimals":"8"
|
54
|
+
},
|
55
|
+
{
|
56
|
+
"name":"U.S. Dollar (USD)",
|
57
|
+
"symbol":"USD","description":"Basic USD-denominated account",
|
58
|
+
"decimals":"2"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"name":"Canadian Dollar (CAD)",
|
62
|
+
"symbol":"CAD",
|
63
|
+
"description":"Basic CAD-denominated account",
|
64
|
+
"decimals":"2"
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
http_version:
|
69
|
+
recorded_at: Sun, 22 Feb 2015 18:10:37 GMT
|
70
|
+
recorded_with: VCR 2.9.3
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
require 'dotenv'
|
3
|
+
require_relative '../lib/cointrader.net'
|
4
|
+
|
5
|
+
Dotenv.load
|
6
|
+
|
7
|
+
def expect_success response
|
8
|
+
expect(response).not_to be_nil
|
9
|
+
expect(response['success']).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.color = true
|
14
|
+
end
|
15
|
+
|
16
|
+
VCR.configure do |config|
|
17
|
+
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
18
|
+
config.hook_into :webmock
|
19
|
+
end
|
20
|
+
|
21
|
+
Cointrader.configure do |config|
|
22
|
+
config.api_key = ENV['API_KEY']
|
23
|
+
config.api_secret = ENV['API_SECRET']
|
24
|
+
config.api_url = 'https://private-anon-b5aa2a7bf-cointrader.apiary-mock.com/api4'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cointrader.net
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maros Hluska
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-22 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: vcr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
description: Ruby wrapper for the Cointrader.net API
|
70
|
+
email:
|
71
|
+
- mhluska@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- cointrader.net.gemspec
|
82
|
+
- lib/cointrader.net.rb
|
83
|
+
- lib/cointrader.net/client.rb
|
84
|
+
- lib/cointrader.net/client/account.rb
|
85
|
+
- lib/cointrader.net/client/request.rb
|
86
|
+
- lib/cointrader.net/client/stats.rb
|
87
|
+
- lib/cointrader.net/version.rb
|
88
|
+
- spec/client_spec.rb
|
89
|
+
- spec/fixtures/vcr_cassettes/balance.yml
|
90
|
+
- spec/fixtures/vcr_cassettes/symbol.yml
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/mhluska/cointrader.net
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Cointrader.net API wrapper
|
116
|
+
test_files:
|
117
|
+
- spec/client_spec.rb
|
118
|
+
- spec/fixtures/vcr_cassettes/balance.yml
|
119
|
+
- spec/fixtures/vcr_cassettes/symbol.yml
|
120
|
+
- spec/spec_helper.rb
|