bitflyer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -2
- data/lib/bitflyer.rb +2 -2
- data/lib/bitflyer/http.rb +24 -2
- data/lib/bitflyer/http/private.rb +18 -2
- data/lib/bitflyer/http/public.rb +6 -6
- data/lib/bitflyer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b05e11050f706d4c1e443bd007df0caba0a704
|
4
|
+
data.tar.gz: d045ce96354b64e51289a672cefc948ec89c0400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b69cc601884de67623c571b471981f9498920e39ef6953aae1801b3f93fe5034a58ebc908ad2313b60e1ac186b42fd68371f40e0c47e82b71d632de4fdd63442
|
7
|
+
data.tar.gz: a543de9dacd759423eba7f331adaa389c149a94b01dd596f6f7c19f09ad2fb8522ae4769f6b656ff8d0beaacb02275040fc2404379b5a525aea5040c5bda7c88
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
# bitflyer
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/bitflyer.svg)](https://badge.fury.io/rb/bitflyer)
|
3
|
+
[![Circle CI](https://circleci.com/gh/unhappychoice/bitflyer.svg?style=shield)](https://circleci.com/gh/unhappychoice/bitflyer)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/unhappychoice/bitflyer/badges/gpa.svg)](https://codeclimate.com/github/unhappychoice/bitflyer)
|
5
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/unhappychoice/bitflyer.svg)](https://gemnasium.com/github.com/unhappychoice/bitflyer)
|
6
|
+
![](http://ruby-gem-downloads-badge.herokuapp.com/bitflyer?type=total)
|
2
7
|
|
3
8
|
bitflyer is a wrapper interface of [Bitflyer lightning API](https://lightning.bitflyer.jp/docs)
|
4
9
|
|
@@ -12,7 +17,15 @@ gem install bitflyer
|
|
12
17
|
|
13
18
|
### HTTP API
|
14
19
|
|
15
|
-
|
20
|
+
#### Example
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
public_client = Bitflyer.http_public_client
|
24
|
+
p public_client.board # will print board snapshot
|
25
|
+
|
26
|
+
private_client = Bitflyer.http_private_client('YOUR_API_KEY', 'YOUR_API_SECRET')
|
27
|
+
p private_client.positions # will print your positions
|
28
|
+
```
|
16
29
|
|
17
30
|
### Realtime API
|
18
31
|
|
@@ -32,7 +45,7 @@ API format is like `{event_name}_{product_code}`.
|
|
32
45
|
#### Example
|
33
46
|
|
34
47
|
```ruby
|
35
|
-
client = Bitflyer
|
48
|
+
client = Bitflyer.realtime_client
|
36
49
|
client.ticker_btc_jpy = ->(json){ p json } # will print json object
|
37
50
|
client.executions_btc_jpy = ->(json){ p json }
|
38
51
|
# ...
|
data/lib/bitflyer.rb
CHANGED
@@ -11,8 +11,8 @@ module Bitflyer
|
|
11
11
|
Bitflyer::HTTP::Public::Client.new
|
12
12
|
end
|
13
13
|
|
14
|
-
def http_private_client
|
15
|
-
Bitflyer::HTTP::Private::Client.new
|
14
|
+
def http_private_client(key, secret)
|
15
|
+
Bitflyer::HTTP::Private::Client.new(key, secret)
|
16
16
|
end
|
17
17
|
|
18
18
|
module_function :realtime_client, :http_public_client, :http_private_client
|
data/lib/bitflyer/http.rb
CHANGED
@@ -3,6 +3,7 @@ require 'bitflyer/http/public'
|
|
3
3
|
require 'bitflyer/http/private'
|
4
4
|
require 'faraday'
|
5
5
|
require 'faraday_middleware'
|
6
|
+
require 'openssl'
|
6
7
|
|
7
8
|
module Bitflyer
|
8
9
|
module HTTP
|
@@ -11,13 +12,34 @@ module Bitflyer
|
|
11
12
|
|
12
13
|
def_delegators :@connection, :get, :post
|
13
14
|
|
14
|
-
def initialize
|
15
|
-
@connection = Faraday::Connection.new(:url => 'https://api.bitflyer.jp
|
15
|
+
def initialize(key, secret)
|
16
|
+
@connection = Faraday::Connection.new(:url => 'https://api.bitflyer.jp') do |f|
|
16
17
|
f.request :json
|
17
18
|
f.response :json
|
19
|
+
f.use Authentication, key, secret
|
18
20
|
f.adapter Faraday.default_adapter
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
24
|
+
|
25
|
+
class Authentication < Faraday::Middleware
|
26
|
+
def initialize(app, key, secret)
|
27
|
+
super(app)
|
28
|
+
@key = key
|
29
|
+
@secret = secret
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(env)
|
33
|
+
timestamp = Time.now.to_i.to_s
|
34
|
+
method = env[:method].to_s.upcase
|
35
|
+
path = env[:url].path + (env[:url].query ? '?' + env[:url].query : '')
|
36
|
+
body = env[:body] || ''
|
37
|
+
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, timestamp + method + path + body)
|
38
|
+
env[:request_headers]['ACCESS-KEY'] = @key if @key
|
39
|
+
env[:request_headers]['ACCESS-TIMESTAMP'] = timestamp
|
40
|
+
env[:request_headers]['ACCESS-SIGN'] = signature
|
41
|
+
@app.call env
|
42
|
+
end
|
43
|
+
end
|
22
44
|
end
|
23
45
|
end
|
@@ -2,8 +2,24 @@ module Bitflyer
|
|
2
2
|
module HTTP
|
3
3
|
module Private
|
4
4
|
class Client
|
5
|
-
def initialize
|
6
|
-
@connection = Connection.new
|
5
|
+
def initialize(key, secret)
|
6
|
+
@connection = Connection.new(key, secret)
|
7
|
+
end
|
8
|
+
|
9
|
+
def permissions
|
10
|
+
@connection.get('/v1/me/getpermissions').body
|
11
|
+
end
|
12
|
+
|
13
|
+
def balance
|
14
|
+
@connection.get('/v1/me/getbalance').body
|
15
|
+
end
|
16
|
+
|
17
|
+
def collateral
|
18
|
+
@connection.get('/v1/me/getcollateral').body
|
19
|
+
end
|
20
|
+
|
21
|
+
def positions
|
22
|
+
@connection.get('/v1/me/getpositions', { product_code: 'FX_BTC_JPY' }).body
|
7
23
|
end
|
8
24
|
end
|
9
25
|
end
|
data/lib/bitflyer/http/public.rb
CHANGED
@@ -7,27 +7,27 @@ module Bitflyer
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def health
|
10
|
-
@connection.get('gethealth').body
|
10
|
+
@connection.get('/v1/gethealth').body
|
11
11
|
end
|
12
12
|
|
13
13
|
def markets
|
14
|
-
@connection.get('markets').body
|
14
|
+
@connection.get('/v1/markets').body
|
15
15
|
end
|
16
16
|
|
17
17
|
def board(product_code = 'BTC_JPY')
|
18
|
-
@connection.get('board', { product_code: product_code }).body
|
18
|
+
@connection.get('/v1/board', { product_code: product_code }).body
|
19
19
|
end
|
20
20
|
|
21
21
|
def ticker(product_code = 'BTC_JPY')
|
22
|
-
@connection.get('ticker', { product_code: product_code }).body
|
22
|
+
@connection.get('/v1/ticker', { product_code: product_code }).body
|
23
23
|
end
|
24
24
|
|
25
25
|
def executions(product_code = 'BTC_JPY')
|
26
|
-
@connection.get('executions', { product_code: product_code }).body
|
26
|
+
@connection.get('/v1/executions', { product_code: product_code }).body
|
27
27
|
end
|
28
28
|
|
29
29
|
def chats(from_date = (Time.now - 5 * 24 * 60 * 60))
|
30
|
-
@connection.get('getchats', { from_date: from_date }).body
|
30
|
+
@connection.get('/v1/getchats', { from_date: from_date }).body
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/bitflyer/version.rb
CHANGED