ruby_bitbankcc 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 +3 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/lib/ruby_bitbankcc.rb +6 -0
- data/lib/ruby_bitbankcc/bitbankcc.rb +137 -0
- data/lib/ruby_bitbankcc/version.rb +3 -0
- data/ruby_bitbankcc.gemspec +31 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fe9cfdebba6eb608eefd4c72968e83acd99af65
|
4
|
+
data.tar.gz: 7de445fcc3e247fc92bc6c24a7962c256abe546a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54bbe7a5658fb3e3830b22e32fcad8c56fabb5cfed4a9782a1ba4b59eef7a9d0cd2fce5655f50bb8e8367d3759b306d765ebd313b8bc798e1d119cfa848ea3b9
|
7
|
+
data.tar.gz: 247b1aecaebb49ba0839dc7f700f3b5e84a01c31f36016abe7ffc47fa773f3ad16076e1c4f1fbc14b5effd9a242ef6bfcc79045fe4a9663ebe7e9ed4f37f0eb6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# RubyBitbankcc
|
2
|
+
|
3
|
+
This is ruby client implementation for Bitbankcc API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruby_bitbankcc'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruby_bitbankcc
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
#!/usr/bin/env ruby -Ilib
|
25
|
+
require 'ruby_bitbankcc'
|
26
|
+
|
27
|
+
bbcc = Bitbankcc.new("YOUR API KEY", "YOUR SECRET KEY")
|
28
|
+
bbcc.read_transactions('btc_jpy')
|
29
|
+
bbcc.read_ticker('btc_jpy')
|
30
|
+
bbcc.read_order_books('btc_jpy')
|
31
|
+
bbcc.read_balance()
|
32
|
+
bbcc.read_active_orders('btc_jpy')
|
33
|
+
bbcc.create_order('btc_jpy', "0.001", 130000, 'buy', 'limit')
|
34
|
+
bbcc.cancel_order('btc_jpy', order_id)
|
35
|
+
JSON.parse(response.body)
|
36
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby_bitbankcc_client"
|
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
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext'
|
7
|
+
require 'pp'
|
8
|
+
require 'rest_client'
|
9
|
+
|
10
|
+
class Bitbankcc
|
11
|
+
@@base_url = "https://api.bitbank.cc"
|
12
|
+
@@base_public_url = "https://public.bitbank.cc"
|
13
|
+
@@ssl = true
|
14
|
+
|
15
|
+
def initialize(key, secret, params = {})
|
16
|
+
@key = key
|
17
|
+
@secret = secret
|
18
|
+
if !params[:base_url].nil?
|
19
|
+
@@base_url = params[:base_url]
|
20
|
+
end
|
21
|
+
if !params[:ssl].nil?
|
22
|
+
@@ssl = params[:ssl]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_balance
|
27
|
+
path = "/v1/user/assets"
|
28
|
+
nonce = Time.now.to_i.to_s
|
29
|
+
request_for_get(path, nonce)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def read_active_orders(pair, count = nil, from_id = nil, end_id = nil, since = nil, _end = nil)
|
34
|
+
path = "/v1/user/spot/active_orders"
|
35
|
+
nonce = Time.now.to_i.to_s
|
36
|
+
params = {
|
37
|
+
pair: pair,
|
38
|
+
count: count,
|
39
|
+
from_id: from_id,
|
40
|
+
end_id: end_id,
|
41
|
+
since: since,
|
42
|
+
end: _end
|
43
|
+
}.compact
|
44
|
+
request_for_get(path, nonce, params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_order(pair, amount, price, side, type)
|
48
|
+
path = "/v1/user/spot/order"
|
49
|
+
nonce = Time.now.to_i.to_s
|
50
|
+
body = {
|
51
|
+
pair: pair,
|
52
|
+
amount: amount,
|
53
|
+
price: price,
|
54
|
+
side: side,
|
55
|
+
type: type
|
56
|
+
}.to_json
|
57
|
+
request_for_post(path, nonce, body)
|
58
|
+
end
|
59
|
+
|
60
|
+
def cancel_order(pair, order_id)
|
61
|
+
path = "/v1/user/spot/cancel_order"
|
62
|
+
nonce = Time.now.to_i.to_s
|
63
|
+
body = {
|
64
|
+
pair: pair,
|
65
|
+
order_id: order_id
|
66
|
+
}.to_json
|
67
|
+
request_for_post(path, nonce, body)
|
68
|
+
end
|
69
|
+
|
70
|
+
def read_ticker(pair)
|
71
|
+
RestClient.get @@base_public_url + "/#{pair}/ticker"
|
72
|
+
end
|
73
|
+
|
74
|
+
def read_order_books(pair)
|
75
|
+
RestClient.get @@base_public_url + "/#{pair}/depth"
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_transactions(pair, date = '')
|
79
|
+
RestClient.get @@base_public_url + "/#{pair}/transactions" + (date.empty? ? '' : '/' + date)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def http_request(uri, request)
|
84
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
https.use_ssl = true
|
86
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
87
|
+
response = https.start do |h|
|
88
|
+
h.request(request)
|
89
|
+
end
|
90
|
+
response.body
|
91
|
+
end
|
92
|
+
|
93
|
+
def request_for_get(path, nonce, query = {})
|
94
|
+
uri = URI.parse @@base_url + path
|
95
|
+
signature = get_get_signature(path, @secret, nonce, query)
|
96
|
+
|
97
|
+
headers = {
|
98
|
+
"Content-Type" => "application/json",
|
99
|
+
"ACCESS-KEY" => @key,
|
100
|
+
"ACCESS-NONCE" => nonce,
|
101
|
+
"ACCESS-SIGNATURE" => signature
|
102
|
+
}
|
103
|
+
|
104
|
+
uri.query = query.to_query
|
105
|
+
request = Net::HTTP::Get.new(uri.request_uri, initheader = headers)
|
106
|
+
http_request(uri, request)
|
107
|
+
end
|
108
|
+
|
109
|
+
def request_for_post(path, nonce, body)
|
110
|
+
uri = URI.parse @@base_url + path
|
111
|
+
signature = get_post_signature(@secret, nonce, body)
|
112
|
+
|
113
|
+
headers = {
|
114
|
+
"Content-Type" => "application/json",
|
115
|
+
"ACCESS-KEY" => @key,
|
116
|
+
"ACCESS-NONCE" => nonce,
|
117
|
+
"ACCESS-SIGNATURE" => signature,
|
118
|
+
"ACCEPT" => "application/json"
|
119
|
+
}
|
120
|
+
|
121
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = headers)
|
122
|
+
request.body = body
|
123
|
+
|
124
|
+
http_request(uri, request)
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_get_signature(path, secret_key, nonce, query = {})
|
128
|
+
query_string = query.present? ? '?' + query.to_query : ''
|
129
|
+
message = nonce + path + query_string
|
130
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret_key, message)
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_post_signature(secret_key, nonce, body = "")
|
134
|
+
message = nonce + body
|
135
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret_key, message)
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby_bitbankcc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby_bitbankcc"
|
8
|
+
spec.version = RubyBitbankcc::VERSION
|
9
|
+
spec.authors = ["bitbankcc"]
|
10
|
+
spec.email = ["system@bitcoinbank.co.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{This is ruby client of bitbankcc api}
|
13
|
+
spec.homepage = "https://github.com/bitbankinc/ruby_bitbankcc"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_bitbankcc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bitbankcc
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-24 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- system@bitcoinbank.co.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- lib/ruby_bitbankcc.rb
|
69
|
+
- lib/ruby_bitbankcc/bitbankcc.rb
|
70
|
+
- lib/ruby_bitbankcc/version.rb
|
71
|
+
- ruby_bitbankcc.gemspec
|
72
|
+
homepage: https://github.com/bitbankinc/ruby_bitbankcc
|
73
|
+
licenses: []
|
74
|
+
metadata:
|
75
|
+
allowed_push_host: https://rubygems.org
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: This is ruby client of bitbankcc api
|
96
|
+
test_files: []
|