btcmrb 0.1.1
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/Gemfile +4 -0
- data/LICENSE.md +7 -0
- data/README.md +44 -0
- data/lib/btcmrb/account.rb +14 -0
- data/lib/btcmrb/client.rb +94 -0
- data/lib/btcmrb/marketdata.rb +35 -0
- data/lib/btcmrb/version.rb +3 -0
- data/lib/btcmrb.rb +14 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8491ba94baa083d21f1df89c845bf25f97d98814
|
4
|
+
data.tar.gz: 123e5f4c4638963fdb0e60fe1157a3bd0f732f5a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb29dd93280e6a348b3a8d0bf9c30da946c3f8faedf52d95ca1277ef4dcb002e8d462421ac11a61daa8de111d7718e54a7631b6231ff0f881c6e634f00c5e2a9
|
7
|
+
data.tar.gz: dc2f326f309e511b14b6cb05a02aebecd79c9980aed6f98eaf41352c541ca444c05f8cc67aebdd66383df3a198b4c813bec1aa5f88b4acc81f1771286c7b149a
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2016 Jeremy Tennant
|
2
|
+
|
3
|
+
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:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
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,44 @@
|
|
1
|
+
# BTCMarkets API Wrapper
|
2
|
+
|
3
|
+
## Description
|
4
|
+
Unofficial Ruby Gem for btcmarkets.net API and is still very much a work in progress.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
### Install the gem
|
8
|
+
```sh
|
9
|
+
gem install btcmrb
|
10
|
+
```
|
11
|
+
### Create some environment variables
|
12
|
+
https://btcmarkets.net/account/apikey
|
13
|
+
```
|
14
|
+
export BTCM_ACCESS_KEY="YOUR ACCESS KEY"
|
15
|
+
export BTCM_SECRET="YOUR SECRET"
|
16
|
+
```
|
17
|
+
|
18
|
+
### Account Management API
|
19
|
+
https://github.com/BTCMarkets/API/wiki/Account-API
|
20
|
+
```ruby
|
21
|
+
# Example
|
22
|
+
balance_request = Btcmrb::Account.balance
|
23
|
+
client = Btcmrb.new(balance_request)
|
24
|
+
# => [{"balance":1000000000,"pendingFunds":0,"currency":"AUD"},{"balance":1000000000,"pendingFunds":0,"currency":"BTC"},{"balance":1000000000,"pendingFunds":0,"currency":"LTC"}]
|
25
|
+
```
|
26
|
+
|
27
|
+
### Market Data API
|
28
|
+
https://github.com/BTCMarkets/API/wiki/Market-data-API
|
29
|
+
```ruby
|
30
|
+
# Example
|
31
|
+
ticker_request = Btcmrb::Marketdata.balance
|
32
|
+
client = Btcmrb.new(ticker_request)
|
33
|
+
# => {"bestBid":844.0,"bestAsk":844.98,"lastPrice":845.0,"currency":"AUD","instrument":"BTC","timestamp":1476242958,"volume24h":172.60804}
|
34
|
+
|
35
|
+
orderbook_request = Btcmrb::Marketdata.orderbook
|
36
|
+
client = Btcmrb.new(orderbook_request)
|
37
|
+
# => {"currency":"AUD","instrument":"BTC","timestamp":1476243360,"asks":[[844.98,0.45077821],[845.0,2.7069457],[848.68,2.58512],[848.76,0.29745]],"bids":[[844.0,0.00489636],[840.21,0.060724],[840.16,0.1180803],[840.1,0.32130103]]}
|
38
|
+
|
39
|
+
trades_requst = Btcmrb::Marketdata.trades
|
40
|
+
client = Btcmrb.new(trades_requst)
|
41
|
+
# => [{"tid":4432702312,"amount":0.01959674,"price":845.0,"date":1378878093},{"tid":59861212129,"amount":1.21434000,"price":845.15,"date":1377840783}]
|
42
|
+
```
|
43
|
+
## License
|
44
|
+
MIT - For terms refer to LICENSE.md
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
# require 'pry-byebug'
|
4
|
+
|
5
|
+
module Btcmrb
|
6
|
+
|
7
|
+
class Client
|
8
|
+
BTCM_ACCESS_KEY = ENV['BTCM_ACCESS_KEY']
|
9
|
+
BTCM_SECRET_KEY = ENV['BTCM_SECRET']
|
10
|
+
DC_BTCM_ACCESS_KEY = Base64.decode64(BTCM_ACCESS_KEY)
|
11
|
+
DC_BTCM_SECRET_KEY = Base64.decode64(BTCM_SECRET_KEY)
|
12
|
+
BASE_URI = 'https://api.btcmarkets.net'
|
13
|
+
include HTTParty
|
14
|
+
|
15
|
+
attr_accessor :base_uri, :timestamp
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@base_uri = BASE_URI
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_request(object)
|
22
|
+
if object[:auth] == false
|
23
|
+
# Hooray! We can write less code, authentication is not necessary.
|
24
|
+
response = send(object[:uri])
|
25
|
+
else
|
26
|
+
# Extra work is necessary, we need to prepare and sign the request
|
27
|
+
timestamp = create_timestamp
|
28
|
+
options = {
|
29
|
+
:uri => object[:uri],
|
30
|
+
:timestamp => timestamp,
|
31
|
+
:body => object[:body]
|
32
|
+
}
|
33
|
+
request = format_request(options)
|
34
|
+
signature = sign_request(request)
|
35
|
+
encoded_signature = Base64.encode64(signature).to_s.gsub("\n",'')
|
36
|
+
|
37
|
+
send(object[:uri],
|
38
|
+
{ :method => object[:verb],
|
39
|
+
:authentication => object[:auth],
|
40
|
+
:timestamp => timestamp,
|
41
|
+
:encoded_signature => encoded_signature
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def create_timestamp
|
50
|
+
(Time.now.to_f * 1000).to_i.to_s
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_request(options)
|
54
|
+
default = options[:uri] + "\n" + options[:timestamp] + "\n"
|
55
|
+
unless options[:body].empty?
|
56
|
+
default = primary + options[:body]
|
57
|
+
end
|
58
|
+
default
|
59
|
+
end
|
60
|
+
|
61
|
+
def send(uri, options={})
|
62
|
+
response = nil
|
63
|
+
default_headers = {
|
64
|
+
'Accept-Charset' => 'UTF-8',
|
65
|
+
'Accept' => 'application/json',
|
66
|
+
'Content-Type' => 'application/json',
|
67
|
+
'User-Agent' => "BTCMRB Ruby Gem v#{Btcmrb::VERSION}"
|
68
|
+
}
|
69
|
+
|
70
|
+
if options[:authentication] && options[:method] == "POST"
|
71
|
+
default_headers.merge!(
|
72
|
+
{ 'apikey' => BTCM_ACCESS_KEY ,
|
73
|
+
'signature' => options[:encoded_signature],
|
74
|
+
'timestamp' => options[:timestamp]
|
75
|
+
}).to_json
|
76
|
+
# TODO
|
77
|
+
elsif options[:authentication] && options[:method] == "GET"
|
78
|
+
default_headers.merge!(
|
79
|
+
{ 'apikey' => BTCM_ACCESS_KEY ,
|
80
|
+
'signature' => options[:encoded_signature],
|
81
|
+
'timestamp' => options[:timestamp]
|
82
|
+
}).to_json
|
83
|
+
HTTParty.get(BASE_URI + uri, headers: default_headers)
|
84
|
+
else
|
85
|
+
response = HTTParty.get(BASE_URI + uri)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def sign_request(str)
|
90
|
+
OpenSSL::HMAC.digest('sha512', DC_BTCM_SECRET_KEY, str)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Btcmrb
|
2
|
+
class Marketdata
|
3
|
+
|
4
|
+
def self.tick
|
5
|
+
{
|
6
|
+
:uri => "/market/BTC/AUD/tick",
|
7
|
+
:body => {},
|
8
|
+
:verb => "GET",
|
9
|
+
:auth => false
|
10
|
+
}
|
11
|
+
#=> {"bestBid":844.0,"bestAsk":844.98,"lastPrice":845.0,"currency":"AUD","instrument":"BTC","timestamp":1476242958,"volume24h":172.60804}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.orderbook
|
15
|
+
{
|
16
|
+
:uri => "/market/BTC/AUD/orderbook",
|
17
|
+
:body => {},
|
18
|
+
:verb => "GET",
|
19
|
+
:auth => false
|
20
|
+
}
|
21
|
+
#=> {"currency":"AUD","instrument":"BTC","timestamp":1476243360,"asks":[[844.98,0.45077821],[845.0,2.7069457],[848.68,2.58512],[848.76,0.29745]],"bids":[[844.0,0.00489636],[840.21,0.060724],[840.16,0.1180803],[840.1,0.32130103]]}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.trades
|
25
|
+
{
|
26
|
+
:uri => "/market/BTC/AUD/trades",
|
27
|
+
:body => {},
|
28
|
+
:verb => "GET",
|
29
|
+
:auth => false
|
30
|
+
}
|
31
|
+
#=> [{"tid":4432702312,"amount":0.01959674,"price":845.0,"date":1378878093},{"tid":59861212129,"amount":1.21434000,"price":845.15,"date":1377840783}]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/lib/btcmrb.rb
ADDED
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: btcmrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Tennant
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-12 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.14.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.14.0
|
27
|
+
description: Unofficial Ruby Gem for btcmarkets.net API
|
28
|
+
email: tennantje@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE.md
|
35
|
+
- README.md
|
36
|
+
- lib/btcmrb.rb
|
37
|
+
- lib/btcmrb/account.rb
|
38
|
+
- lib/btcmrb/client.rb
|
39
|
+
- lib/btcmrb/marketdata.rb
|
40
|
+
- lib/btcmrb/version.rb
|
41
|
+
homepage: http://rubygems.org/gems/btcmrb
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.5.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Unofficial Ruby Gem for btcmarkets.net API
|
65
|
+
test_files: []
|