ruby_coincheck_client 0.1.4 → 0.2.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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/README.md +3 -1
- data/examples/private.rb +11 -0
- data/examples/public.rb +8 -0
- data/lib/ruby_coincheck_client.rb +2 -2
- data/lib/ruby_coincheck_client/coincheck_client.rb +41 -21
- data/lib/ruby_coincheck_client/currency.rb +46 -0
- data/lib/ruby_coincheck_client/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af78bebd9f64fd5a85f1ac166ed7ad291c2e1b13
|
4
|
+
data.tar.gz: dffac86a20bd0927ec96a106a443a4946effcc10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef43cb51970db8e0cfbbbec76ba429ce46ebf0b6e81cdec8144f543b4d31021fd06482f35ef769846bbf561f17afe85afa9843435dd2ac8e5992024cb9602c21
|
7
|
+
data.tar.gz: 0ee09d20ef28340565143179e7ec85b28d468fc0c69b3128e4094ccb3322982e69f5218c0ceea98a622f049ecb0b14acef610051166e15ecb0d13b3f740cbb4d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -31,6 +31,7 @@ response = cc.read_accounts
|
|
31
31
|
response = cc.read_transactions
|
32
32
|
response = cc.read_positions
|
33
33
|
response = cc.read_orders
|
34
|
+
response = cc.read_orders_rate(order_type: 'buy', amount: "0.01")
|
34
35
|
response = cc.create_orders(rate: "40001", amount: "0.01", order_type: "buy")
|
35
36
|
response = cc.create_orders(rate: "50001", amount: "0.001", order_type: "sell")
|
36
37
|
response = cc.create_orders(market_buy_amount: 100, order_type: "market_buy")
|
@@ -46,6 +47,7 @@ response = cc.read_deposit_money
|
|
46
47
|
response = cc.create_deposit_money_fast(id: "2222")
|
47
48
|
response = cc.read_ticker
|
48
49
|
response = cc.read_trades
|
50
|
+
response = cc.read_rate
|
49
51
|
response = cc.read_order_books
|
50
52
|
response = cc.read_bank_accounts
|
51
53
|
response = cc.delete_bank_accounts(id: "2222")
|
@@ -67,7 +69,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
67
69
|
|
68
70
|
## Contributing
|
69
71
|
|
70
|
-
1. Fork it ( https://github.com/
|
72
|
+
1. Fork it ( https://github.com/coincheckjp/ruby_coincheck_client/fork )
|
71
73
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
74
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
75
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/examples/private.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../lib/ruby_coincheck_client'
|
2
|
+
require 'dotenv'
|
3
|
+
Dotenv.load ".env"
|
4
|
+
|
5
|
+
cc = CoincheckClient.new(ENV['API_KEY'], ENV['SECRET_KEY'])
|
6
|
+
puts cc.read_balance.body
|
7
|
+
puts cc.read_leverage_balance.body
|
8
|
+
puts cc.read_accounts.body
|
9
|
+
puts cc.read_transactions.body
|
10
|
+
puts cc.read_positions.body
|
11
|
+
puts cc.read_orders.body
|
data/examples/public.rb
ADDED
@@ -2,12 +2,15 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'openssl'
|
4
4
|
require 'json'
|
5
|
+
require_relative './currency'
|
5
6
|
|
6
7
|
class CoincheckClient
|
7
|
-
|
8
|
+
include Currency
|
9
|
+
|
10
|
+
@@base_url = "https://coincheck.com/"
|
8
11
|
@@ssl = true
|
9
12
|
|
10
|
-
def initialize(key, secret, params = {})
|
13
|
+
def initialize(key = nil, secret = nil, params = {})
|
11
14
|
@key = key
|
12
15
|
@secret = secret
|
13
16
|
if !params[:base_url].nil?
|
@@ -42,10 +45,10 @@ class CoincheckClient
|
|
42
45
|
request_for_get(uri, headers)
|
43
46
|
end
|
44
47
|
|
45
|
-
def read_positions(
|
48
|
+
def read_positions(params = {})
|
46
49
|
uri = URI.parse @@base_url + "api/exchange/leverage/positions"
|
47
|
-
headers = get_signature(uri, @key, @secret
|
48
|
-
request_for_get(uri, headers,
|
50
|
+
headers = get_signature(uri, @key, @secret)
|
51
|
+
request_for_get(uri, headers, params)
|
49
52
|
end
|
50
53
|
|
51
54
|
def read_orders
|
@@ -54,7 +57,7 @@ class CoincheckClient
|
|
54
57
|
request_for_get(uri, headers)
|
55
58
|
end
|
56
59
|
|
57
|
-
def create_orders(order_type:, rate: nil, amount: nil, market_buy_amount: nil, position_id: nil, pair:
|
60
|
+
def create_orders(order_type:, rate: nil, amount: nil, market_buy_amount: nil, position_id: nil, pair: Pair::BTC_JPY)
|
58
61
|
body = {
|
59
62
|
rate: rate,
|
60
63
|
amount: amount,
|
@@ -74,6 +77,12 @@ class CoincheckClient
|
|
74
77
|
request_for_delete(uri, headers)
|
75
78
|
end
|
76
79
|
|
80
|
+
def read_orders_rate(order_type:, pair: Pair::BTC_JPY, price: nil, amount: nil)
|
81
|
+
uri = URI.parse @@base_url + "api/exchange/orders/rate"
|
82
|
+
params = { order_type: order_type, pair: pair, price: price, amount: amount }
|
83
|
+
request_for_get(uri, {}, params)
|
84
|
+
end
|
85
|
+
|
77
86
|
def create_send_money(address:, amount:)
|
78
87
|
body = {
|
79
88
|
address: address,
|
@@ -85,17 +94,17 @@ class CoincheckClient
|
|
85
94
|
end
|
86
95
|
|
87
96
|
def read_send_money(currency: "BTC")
|
88
|
-
|
97
|
+
params = { currency: currency }
|
89
98
|
uri = URI.parse @@base_url + "api/send_money"
|
90
|
-
headers = get_signature(uri, @key, @secret
|
91
|
-
request_for_get(uri, headers,
|
99
|
+
headers = get_signature(uri, @key, @secret)
|
100
|
+
request_for_get(uri, headers, params)
|
92
101
|
end
|
93
102
|
|
94
103
|
def read_deposit_money(currency: "BTC")
|
95
|
-
|
104
|
+
params = { currency: currency }
|
96
105
|
uri = URI.parse @@base_url + "api/deposit_money"
|
97
|
-
headers = get_signature(uri, @key, @secret
|
98
|
-
request_for_get(uri, headers,
|
106
|
+
headers = get_signature(uri, @key, @secret)
|
107
|
+
request_for_get(uri, headers, params)
|
99
108
|
end
|
100
109
|
|
101
110
|
def create_deposit_money_fast(id: )
|
@@ -114,6 +123,11 @@ class CoincheckClient
|
|
114
123
|
request_for_get(uri)
|
115
124
|
end
|
116
125
|
|
126
|
+
def read_rate(pair: Pair::BTC_JPY)
|
127
|
+
uri = URI.parse @@base_url + "/api/rate/#{pair}"
|
128
|
+
request_for_get(uri)
|
129
|
+
end
|
130
|
+
|
117
131
|
def read_order_books
|
118
132
|
uri = URI.parse @@base_url + "api/order_books"
|
119
133
|
request_for_get(uri)
|
@@ -179,7 +193,7 @@ class CoincheckClient
|
|
179
193
|
request_for_post(uri, headers, body)
|
180
194
|
end
|
181
195
|
|
182
|
-
def transfer_to_leverage(amount:, currency:
|
196
|
+
def transfer_to_leverage(amount:, currency: JPY)
|
183
197
|
body = {
|
184
198
|
amount: amount,
|
185
199
|
currency: currency
|
@@ -189,7 +203,7 @@ class CoincheckClient
|
|
189
203
|
request_for_post(uri, headers, body)
|
190
204
|
end
|
191
205
|
|
192
|
-
def transfer_from_leverage(amount:, currency:
|
206
|
+
def transfer_from_leverage(amount:, currency: JPY)
|
193
207
|
body = {
|
194
208
|
amount: amount,
|
195
209
|
currency: currency
|
@@ -212,29 +226,35 @@ class CoincheckClient
|
|
212
226
|
end
|
213
227
|
end
|
214
228
|
|
215
|
-
def request_for_get(uri, headers = {},
|
216
|
-
|
217
|
-
request
|
229
|
+
def request_for_get(uri, headers = {}, params = nil)
|
230
|
+
uri.query = URI.encode_www_form(params) if params
|
231
|
+
request = Net::HTTP::Get.new(uri.request_uri, initheader = custom_header(headers))
|
218
232
|
http_request(uri, request)
|
219
233
|
end
|
220
234
|
|
221
235
|
def request_for_delete(uri, headers)
|
222
|
-
request = Net::HTTP::Delete.new(uri.request_uri, initheader = headers)
|
236
|
+
request = Net::HTTP::Delete.new(uri.request_uri, initheader = custom_header(headers))
|
223
237
|
http_request(uri, request)
|
224
238
|
end
|
225
239
|
|
226
240
|
def request_for_post(uri, headers, body)
|
227
|
-
request = Net::HTTP::Post.new(uri.request_uri, initheader = headers)
|
241
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = custom_header(headers))
|
228
242
|
request.body = body.to_json
|
229
243
|
http_request(uri, request)
|
230
244
|
end
|
231
245
|
|
246
|
+
def custom_header(headers = {})
|
247
|
+
headers.merge!({
|
248
|
+
"Content-Type" => "application/json",
|
249
|
+
"User-Agent" => "RubyCoincheckClient v#{RubyCoincheckClient::VERSION}"
|
250
|
+
})
|
251
|
+
end
|
252
|
+
|
232
253
|
def get_signature(uri, key, secret, body = "")
|
233
|
-
nonce = Time.now.to_i.to_s
|
254
|
+
nonce = (Time.now.to_f * 1000000).to_i.to_s
|
234
255
|
message = nonce + uri.to_s + body
|
235
256
|
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret, message)
|
236
257
|
headers = {
|
237
|
-
"Content-Type" => "application/json",
|
238
258
|
"ACCESS-KEY" => key,
|
239
259
|
"ACCESS-NONCE" => nonce,
|
240
260
|
"ACCESS-SIGNATURE" => signature
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Currency
|
2
|
+
JPY = "JPY"
|
3
|
+
BTC = "BTC"
|
4
|
+
ETH = "ETH"
|
5
|
+
ETC = "ETC"
|
6
|
+
DAO = "DAO"
|
7
|
+
LSK = "LSK"
|
8
|
+
FCT = "FCT"
|
9
|
+
XMR = "XMR"
|
10
|
+
REP = "REP"
|
11
|
+
XRP = "XRP"
|
12
|
+
ZEC = "ZEC"
|
13
|
+
XEM = "XEM"
|
14
|
+
LTC = "LTC"
|
15
|
+
DASH = "DASH"
|
16
|
+
BCH = "BCH"
|
17
|
+
|
18
|
+
module Pair
|
19
|
+
BTC_JPY = "btc_jpy"
|
20
|
+
ETH_JPY = "eth_jpy"
|
21
|
+
ETC_JPY = "etc_jpy"
|
22
|
+
DAO_JPY = "dao_jpy"
|
23
|
+
LSK_JPY = "lsk_jpy"
|
24
|
+
FCT_JPY = "fct_jpy"
|
25
|
+
XMR_JPY = "xmr_jpy"
|
26
|
+
REP_JPY = "rep_jpy"
|
27
|
+
XRP_JPY = "xrp_jpy"
|
28
|
+
ZEC_JPY = "zec_jpy"
|
29
|
+
XEM_JPY = "xem_jpy"
|
30
|
+
LTC_JPY = "ltc_jpy"
|
31
|
+
DASH_JPY = "dash_jpy"
|
32
|
+
BCH_JPY = "bch_jpy"
|
33
|
+
ETH_BTC = "eth_btc"
|
34
|
+
ETC_BTC = "etc_btc"
|
35
|
+
LSK_BTC = "lsk_btc"
|
36
|
+
FCT_BTC = "fct_btc"
|
37
|
+
XMR_BTC = "xmr_btc"
|
38
|
+
REP_BTC = "rep_btc"
|
39
|
+
XRP_BTC = "xrp_btc"
|
40
|
+
ZEC_BTC = "zec_btc"
|
41
|
+
XEM_BTC = "xem_btc"
|
42
|
+
LTC_BTC = "ltc_btc"
|
43
|
+
DASH_BTC = "dash_btc"
|
44
|
+
BCH_BTC = "bch_btc"
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_coincheck_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- coincheck
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,13 +62,17 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- bin/console
|
69
70
|
- bin/setup
|
71
|
+
- examples/private.rb
|
72
|
+
- examples/public.rb
|
70
73
|
- lib/ruby_coincheck_client.rb
|
71
74
|
- lib/ruby_coincheck_client/coincheck_client.rb
|
75
|
+
- lib/ruby_coincheck_client/currency.rb
|
72
76
|
- lib/ruby_coincheck_client/version.rb
|
73
77
|
- ruby_coincheck_client.gemspec
|
74
78
|
homepage: https://github.com/coincheckjp/ruby_coincheck_client
|
@@ -96,4 +100,3 @@ signing_key:
|
|
96
100
|
specification_version: 4
|
97
101
|
summary: This is ruby client of coincheck api
|
98
102
|
test_files: []
|
99
|
-
has_rdoc:
|