bitflyer 0.2.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96469fe331a89e6551b43e7224b0eb9dbe7e21a5f6c6811068d1fcbdc6d73472
4
- data.tar.gz: 4480a1a3aa087333adf60e31b60c90d568a403b43acd348aac0d60c3f8de1c65
3
+ metadata.gz: 6f49b4a666d8df93717c072384a5be911359f9374c323e06ed7ee50cc3780b22
4
+ data.tar.gz: 719a1bc27381f6cf81a560050f306b7adc5946e36ddbd30da2f60686e34af652
5
5
  SHA512:
6
- metadata.gz: 21ad55e0aedf232c88aa20ed7bc49ebe5f3a92acff3dfe18772bb4d4b6576f07f7fad79926372f6fe2ca840175064b75fef6db767e246d882d4624845082bd9c
7
- data.tar.gz: 95570ef23a9d6a6abb4667406a7fe19b41e81ec0b3e0cfd433d1d77b2df9a3f2224616eb5c4ae92abcc8ede4769953cd7c060ec0e7da4b5d35bc9ca6ab7e156f
6
+ metadata.gz: eb08f088aea6b006cef2f8b29c8d52c908653386909524cb3aed4057e1cba6f1a7992bc713b6726abb36c0f8a98d8581e13b712c6b665e69eda8565bb957bebc
7
+ data.tar.gz: 63a9357c4f45bd9f77604e9393d32c852daf682c6da54c8552b1eea4c3be22ab89b7abe9392f784e3cf6099e07a77b286f7583620ed008b8e44d405996fd3925
@@ -0,0 +1,33 @@
1
+ {
2
+ "files": [
3
+ "README.md"
4
+ ],
5
+ "imageSize": 100,
6
+ "commit": false,
7
+ "contributors": [
8
+ {
9
+ "login": "yemartin",
10
+ "name": "Yves-Eric Martin",
11
+ "avatar_url": "https://avatars.githubusercontent.com/u/139002?v=4",
12
+ "profile": "https://github.com/yemartin",
13
+ "contributions": [
14
+ "code"
15
+ ]
16
+ },
17
+ {
18
+ "login": "unhappychoice",
19
+ "name": "Yuji Ueki",
20
+ "avatar_url": "https://avatars.githubusercontent.com/u/5608948?v=4",
21
+ "profile": "http://blog.unhappychoice.com",
22
+ "contributions": [
23
+ "code"
24
+ ]
25
+ }
26
+ ],
27
+ "contributorsPerLine": 7,
28
+ "projectName": "bitflyer",
29
+ "projectOwner": "unhappychoice",
30
+ "repoType": "github",
31
+ "repoHost": "https://github.com",
32
+ "skipCi": true
33
+ }
@@ -0,0 +1,54 @@
1
+ version: 2.1
2
+
3
+ update_bundler: &update_bundler
4
+ run:
5
+ name: update bundler
6
+ command: gem update bundler
7
+
8
+ bundle_install: &bundle_install
9
+ run:
10
+ name: bundle install
11
+ command: bundle update --bundler && bundle install --path vendor/bundle --jobs 4
12
+
13
+ restore_bundle_cache: &restore_bundle_cache
14
+ restore_cache:
15
+ key: cache-bundler-{{ checksum "Gemfile.lock" }}
16
+
17
+ jobs:
18
+ build:
19
+ docker:
20
+ - image: circleci/ruby:2.7.2
21
+ steps:
22
+ - checkout
23
+ - *restore_bundle_cache
24
+ - *update_bundler
25
+ - *bundle_install
26
+ - save_cache:
27
+ key: cache-bundler-{{ checksum "Gemfile.lock" }}
28
+ paths:
29
+ - vendor/bundle
30
+ rubocop:
31
+ docker:
32
+ - image: circleci/ruby:2.7.2
33
+ steps:
34
+ - checkout
35
+ - *restore_bundle_cache
36
+ - *update_bundler
37
+ - *bundle_install
38
+ - run: bundle exec rubocop
39
+ rspec:
40
+ docker:
41
+ - image: circleci/ruby:2.7.2
42
+ steps:
43
+ - checkout
44
+ - *restore_bundle_cache
45
+ - *update_bundler
46
+ - *bundle_install
47
+ - run: bundle exec rspec
48
+ workflows:
49
+ version: 2.1
50
+ rspec:
51
+ jobs:
52
+ - build
53
+ - rubocop
54
+ - rspec
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+ Include:
6
+ - 'lib/**/*.rb'
7
+ Style/Documentation:
8
+ Enabled: false
9
+ Metrics/LineLength:
10
+ Max: 120
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,35 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-08-08 12:17:16 UTC using RuboCop version 0.89.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ # Configuration parameters: IgnoredMethods.
11
+ Metrics/AbcSize:
12
+ Max: 32
13
+
14
+ # Offense count: 2
15
+ # Configuration parameters: CountComments, CountAsOne.
16
+ Metrics/ClassLength:
17
+ Max: 146
18
+
19
+ # Offense count: 2
20
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
21
+ Metrics/MethodLength:
22
+ Max: 20
23
+
24
+ # Offense count: 3
25
+ # Configuration parameters: CountKeywordArgs.
26
+ Metrics/ParameterLists:
27
+ Max: 7
28
+
29
+ # Offense count: 1
30
+ # Cop supports --auto-correct.
31
+ # Configuration parameters: EnforcedStyle.
32
+ # SupportedStyles: always, always_true, never
33
+ Style/FrozenStringLiteralComment:
34
+ Exclude:
35
+ - 'bin/console'
data/Gemfile.lock CHANGED
@@ -1,36 +1,65 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitflyer (0.2.1)
5
- faraday (~> 0.14.0)
6
- faraday_middleware (~> 0.12.0)
4
+ bitflyer (1.1.0)
5
+ faraday (>= 0.14, < 1.4)
6
+ faraday_middleware (>= 0.12, < 1.1)
7
7
  websocket-client-simple (~> 0.3.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- diff-lcs (1.3)
12
+ ast (2.4.2)
13
+ coderay (1.1.3)
14
+ diff-lcs (1.4.4)
13
15
  event_emitter (0.2.6)
14
- faraday (0.14.0)
16
+ faraday (1.3.0)
17
+ faraday-net_http (~> 1.0)
15
18
  multipart-post (>= 1.2, < 3)
16
- faraday_middleware (0.12.2)
17
- faraday (>= 0.7.4, < 1.0)
18
- multipart-post (2.0.0)
19
- rake (12.3.0)
20
- rspec (3.7.0)
21
- rspec-core (~> 3.7.0)
22
- rspec-expectations (~> 3.7.0)
23
- rspec-mocks (~> 3.7.0)
24
- rspec-core (3.7.1)
25
- rspec-support (~> 3.7.0)
26
- rspec-expectations (3.7.0)
19
+ ruby2_keywords
20
+ faraday-net_http (1.0.1)
21
+ faraday_middleware (1.0.0)
22
+ faraday (~> 1.0)
23
+ method_source (1.0.0)
24
+ multipart-post (2.1.1)
25
+ parallel (1.20.1)
26
+ parser (3.0.0.0)
27
+ ast (~> 2.4.1)
28
+ pry (0.14.0)
29
+ coderay (~> 1.1)
30
+ method_source (~> 1.0)
31
+ rainbow (3.0.0)
32
+ rake (13.0.3)
33
+ regexp_parser (2.0.3)
34
+ rexml (3.2.4)
35
+ rspec (3.10.0)
36
+ rspec-core (~> 3.10.0)
37
+ rspec-expectations (~> 3.10.0)
38
+ rspec-mocks (~> 3.10.0)
39
+ rspec-core (3.10.1)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-expectations (3.10.1)
27
42
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.7.0)
29
- rspec-mocks (3.7.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-mocks (3.10.2)
30
45
  diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.7.0)
32
- rspec-support (3.7.1)
33
- websocket (1.2.8)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-support (3.10.2)
48
+ rubocop (1.10.0)
49
+ parallel (~> 1.10)
50
+ parser (>= 3.0.0.0)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ regexp_parser (>= 1.8, < 3.0)
53
+ rexml
54
+ rubocop-ast (>= 1.2.0, < 2.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 1.4.0, < 3.0)
57
+ rubocop-ast (1.4.1)
58
+ parser (>= 2.7.1.5)
59
+ ruby-progressbar (1.11.0)
60
+ ruby2_keywords (0.0.4)
61
+ unicode-display_width (2.0.0)
62
+ websocket (1.2.9)
34
63
  websocket-client-simple (0.3.0)
35
64
  event_emitter
36
65
  websocket
@@ -40,9 +69,11 @@ PLATFORMS
40
69
 
41
70
  DEPENDENCIES
42
71
  bitflyer!
43
- bundler (~> 1.12)
72
+ bundler (~> 2.0)
73
+ pry
44
74
  rake
45
75
  rspec
76
+ rubocop
46
77
 
47
78
  BUNDLED WITH
48
- 1.17.2
79
+ 2.2.4
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # bitflyer
2
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
3
+ [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
4
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
2
5
  [![Gem Version](https://badge.fury.io/rb/bitflyer.svg)](https://badge.fury.io/rb/bitflyer)
3
6
  [![Circle CI](https://circleci.com/gh/unhappychoice/bitflyer.svg?style=shield)](https://circleci.com/gh/unhappychoice/bitflyer)
4
7
  [![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)
8
+ [![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/unhappychoice/bitflyer.svg)](https://libraries.io/github/unhappychoice/bitflyer)
6
9
  ![](http://ruby-gem-downloads-badge.herokuapp.com/bitflyer?type=total)
10
+ ![GitHub](https://img.shields.io/github/license/unhappychoice/bitflyer.svg)
7
11
 
8
12
  bitflyer is a wrapper interface of [Bitflyer lightning API](https://lightning.bitflyer.jp/docs)
9
13
 
@@ -19,6 +23,8 @@ See https://lightning.bitflyer.jp/docs for details.
19
23
 
20
24
  ### HTTP API
21
25
 
26
+ See [public.rb](./lib/bitflyer/http/public.rb) / [private.rb](./lib/bitflyer/http/private.rb) for method definition.
27
+
22
28
  #### Example
23
29
 
24
30
  ```ruby
@@ -34,17 +40,7 @@ p private_client.positions # will print your positions
34
40
  Accessor format is like `{event_name}_{product_code}`.
35
41
  You can set lambda to get realtime events.
36
42
 
37
- #### `event_name`
38
- - board_snapshot
39
- - board
40
- - ticker
41
- - executions
42
-
43
- #### `product_code`
44
- - btc_jpy
45
- - fx_btc_jpy
46
- - eth_btc
47
- - bch_btc
43
+ `{event_name}` and `{product_code}` is defined at [client.rb](./lib/bitflyer/realtime/client.rb).
48
44
 
49
45
  #### Example
50
46
 
@@ -64,3 +60,24 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/unhapp
64
60
 
65
61
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
66
62
 
63
+
64
+ ## Contributors ✨
65
+
66
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
67
+
68
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
69
+ <!-- prettier-ignore-start -->
70
+ <!-- markdownlint-disable -->
71
+ <table>
72
+ <tr>
73
+ <td align="center"><a href="http://blog.unhappychoice.com"><img src="https://avatars.githubusercontent.com/u/5608948?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yuji Ueki</b></sub></a><br /><a href="https://github.com/unhappychoice/bitflyer/commits?author=unhappychoice" title="Code">💻</a></td>
74
+ <td align="center"><a href="https://github.com/yemartin"><img src="https://avatars.githubusercontent.com/u/139002?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yves-Eric Martin</b></sub></a><br /><a href="https://github.com/unhappychoice/bitflyer/commits?author=yemartin" title="Code">💻</a></td>
75
+ </tr>
76
+ </table>
77
+
78
+ <!-- markdownlint-restore -->
79
+ <!-- prettier-ignore-end -->
80
+
81
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
82
+
83
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
data/bitflyer.gemspec CHANGED
@@ -17,10 +17,12 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'faraday', '~> 0.14.0'
21
- spec.add_dependency 'faraday_middleware', '~> 0.12.0'
20
+ spec.add_dependency 'faraday', '>= 0.14', '< 1.4'
21
+ spec.add_dependency 'faraday_middleware', '>= 0.12', '< 1.1'
22
22
  spec.add_dependency 'websocket-client-simple', '~> 0.3.0'
23
- spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'bundler', '~> 2.0'
24
+ spec.add_development_dependency 'pry'
24
25
  spec.add_development_dependency 'rake'
25
26
  spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rubocop'
26
28
  end
data/lib/bitflyer.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bitflyer/version'
2
4
  require 'bitflyer/http'
3
5
  require 'bitflyer/realtime'
data/lib/bitflyer/http.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bitflyer'
2
4
  require 'bitflyer/http/public'
3
5
  require 'bitflyer/http/private'
@@ -13,7 +15,7 @@ module Bitflyer
13
15
  def_delegators :@connection, :get, :post
14
16
 
15
17
  def initialize(key, secret)
16
- @connection = Faraday::Connection.new(:url => 'https://api.bitflyer.jp') do |f|
18
+ @connection = Faraday::Connection.new(url: 'https://api.bitflyer.jp') do |f|
17
19
  f.request :json
18
20
  f.response :json
19
21
  f.use Authentication, key, secret
@@ -34,9 +36,9 @@ module Bitflyer
34
36
 
35
37
  timestamp = Time.now.to_i.to_s
36
38
  method = env[:method].to_s.upcase
37
- path = env[:url].path + (env[:url].query ? '?' + env[:url].query : '')
39
+ path = env[:url].path + (env[:url].query ? "?#{env[:url].query}" : '')
38
40
  body = env[:body] || ''
39
- signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, timestamp + method + path + body)
41
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret, timestamp + method + path + body)
40
42
  env[:request_headers]['ACCESS-KEY'] = @key if @key
41
43
  env[:request_headers]['ACCESS-TIMESTAMP'] = timestamp
42
44
  env[:request_headers]['ACCESS-SIGN'] = signature
@@ -44,4 +46,4 @@ module Bitflyer
44
46
  end
45
47
  end
46
48
  end
47
- end
49
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bitflyer
2
4
  module HTTP
3
5
  module Private
@@ -40,10 +42,10 @@ module Bitflyer
40
42
 
41
43
  def withdraw(currency_code: 'JPY', bank_account_id: nil, amount: nil, code: nil)
42
44
  body = {
43
- currency_code: currency_code,
44
- bank_account_id: bank_account_id,
45
- amount: amount,
46
- code: code
45
+ currency_code: currency_code,
46
+ bank_account_id: bank_account_id,
47
+ amount: amount,
48
+ code: code
47
49
  }.delete_if { |_, v| v.nil? }
48
50
  @connection.post('/v1/me/withdraw', body).body
49
51
  end
@@ -52,102 +54,124 @@ module Bitflyer
52
54
  @connection.get('/v1/me/getwithdrawals').body
53
55
  end
54
56
 
55
- def send_child_order(product_code: 'BTC_JPY', child_order_type: nil, side: nil, price: nil, size: nil, minute_to_expire: nil, time_in_force: 'GTC')
57
+ def send_child_order(
58
+ product_code: 'BTC_JPY',
59
+ child_order_type: nil,
60
+ side: nil,
61
+ price: nil,
62
+ size: nil,
63
+ minute_to_expire: nil,
64
+ time_in_force: 'GTC'
65
+ )
56
66
  body = {
57
- product_code: product_code,
58
- child_order_type: child_order_type,
59
- side: side,
60
- price: price,
61
- size: size,
62
- minute_to_expire: minute_to_expire,
63
- time_in_force: time_in_force
67
+ product_code: product_code,
68
+ child_order_type: child_order_type,
69
+ side: side,
70
+ price: price,
71
+ size: size,
72
+ minute_to_expire: minute_to_expire,
73
+ time_in_force: time_in_force
64
74
  }.delete_if { |_, v| v.nil? }
65
75
  @connection.post('/v1/me/sendchildorder', body).body
66
76
  end
67
77
 
68
78
  def cancel_child_order(product_code: 'BTC_JPY', child_order_id: nil, child_order_acceptance_id: nil)
69
79
  body = {
70
- product_code: product_code,
71
- child_order_id: child_order_id,
72
- child_order_acceptance_id: child_order_acceptance_id
80
+ product_code: product_code,
81
+ child_order_id: child_order_id,
82
+ child_order_acceptance_id: child_order_acceptance_id
73
83
  }.delete_if { |_, v| v.nil? }
74
84
  @connection.post('/v1/me/cancelchildorder', body).body
75
85
  end
76
86
 
77
87
  def send_parent_order(order_method: nil, minute_to_expire: nil, time_in_force: 'GTC', parameters: {})
78
88
  body = {
79
- order_method: order_method,
80
- minute_to_expire: minute_to_expire,
81
- time_in_force: time_in_force,
82
- parameters: parameters
89
+ order_method: order_method,
90
+ minute_to_expire: minute_to_expire,
91
+ time_in_force: time_in_force,
92
+ parameters: parameters
83
93
  }.delete_if { |_, v| v.nil? }
84
94
  @connection.post('/v1/me/sendparentorder', body).body
85
95
  end
86
96
 
87
97
  def cancel_parent_order(product_code: 'BTC_JPY', parent_order_id: nil, parent_order_acceptance_id: nil)
88
98
  body = {
89
- product_code: product_code,
90
- parent_order_id: parent_order_id,
91
- parent_order_acceptance_id: parent_order_acceptance_id
99
+ product_code: product_code,
100
+ parent_order_id: parent_order_id,
101
+ parent_order_acceptance_id: parent_order_acceptance_id
92
102
  }.delete_if { |_, v| v.nil? }
93
103
  @connection.post('/v1/me/cancelparentorder', body).body
94
104
  end
95
105
 
96
106
  def cancel_all_child_orders(product_code: 'BTC_JPY')
97
- @connection.post('/v1/me/cancelallchildorders', { product_code: product_code }).body
107
+ @connection.post('/v1/me/cancelallchildorders', product_code: product_code).body
98
108
  end
99
109
 
100
- def child_orders(product_code: 'BTC_JPY', count: nil, before: nil, after: nil, child_order_state: nil, parent_order_id: nil)
110
+ def child_orders(
111
+ product_code: 'BTC_JPY',
112
+ count: nil,
113
+ before: nil,
114
+ after: nil,
115
+ child_order_state: nil,
116
+ parent_order_id: nil
117
+ )
101
118
  query = {
102
- product_code: product_code,
103
- count: count,
104
- before: before,
105
- after: after,
106
- child_order_state: child_order_state,
107
- parent_order_id: parent_order_id
119
+ product_code: product_code,
120
+ count: count,
121
+ before: before,
122
+ after: after,
123
+ child_order_state: child_order_state,
124
+ parent_order_id: parent_order_id
108
125
  }.delete_if { |_, v| v.nil? }
109
126
  @connection.get('/v1/me/getchildorders', query).body
110
127
  end
111
128
 
112
129
  def parent_orders(product_code: 'BTC_JPY', count: nil, before: nil, after: nil, parent_order_state: nil)
113
130
  query = {
114
- product_code: product_code,
115
- count: count,
116
- before: before,
117
- after: after,
118
- parent_order_state: parent_order_state
131
+ product_code: product_code,
132
+ count: count,
133
+ before: before,
134
+ after: after,
135
+ parent_order_state: parent_order_state
119
136
  }.delete_if { |_, v| v.nil? }
120
137
  @connection.get('/v1/me/getparentorders', query).body
121
138
  end
122
139
 
123
140
  def parent_order(parent_order_id: nil, parent_order_acceptance_id: nil)
124
141
  query = {
125
- parent_order_id: parent_order_id,
126
- parent_order_acceptance_id: parent_order_acceptance_id
142
+ parent_order_id: parent_order_id,
143
+ parent_order_acceptance_id: parent_order_acceptance_id
127
144
  }.delete_if { |_, v| v.nil? }
128
145
  @connection.get('/v1/me/getparentorder', query).body
129
146
  end
130
147
 
131
- def executions(product_code: 'BTC_JPY', count: nil, before: nil, after: nil, child_order_id: nil, child_order_acceptance_id: nil)
148
+ def executions(
149
+ product_code: 'BTC_JPY',
150
+ count: nil,
151
+ before: nil,
152
+ after: nil,
153
+ child_order_id: nil,
154
+ child_order_acceptance_id: nil
155
+ )
132
156
  query = {
133
- product_code: product_code,
134
- count: count,
135
- before: before,
136
- after: after,
137
- child_order_id: child_order_id,
138
- child_order_acceptance_id: child_order_acceptance_id,
157
+ product_code: product_code,
158
+ count: count,
159
+ before: before,
160
+ after: after,
161
+ child_order_id: child_order_id,
162
+ child_order_acceptance_id: child_order_acceptance_id
139
163
  }.delete_if { |_, v| v.nil? }
140
164
  @connection.get('/v1/me/getexecutions', query).body
141
165
  end
142
166
 
143
167
  def positions(product_code: 'FX_BTC_JPY')
144
- @connection.get('/v1/me/getpositions', { product_code: product_code }).body
168
+ @connection.get('/v1/me/getpositions', product_code: product_code).body
145
169
  end
146
170
 
147
171
  def trading_commission(product_code: 'BTC_JPY')
148
- @connection.get('v1/me/gettradingcommission', { product_code: product_code }).body
172
+ @connection.get('v1/me/gettradingcommission', product_code: product_code).body
149
173
  end
150
174
  end
151
175
  end
152
176
  end
153
- end
177
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bitflyer
2
4
  module HTTP
3
5
  module Public
@@ -14,22 +16,28 @@ module Bitflyer
14
16
  @connection.get('/v1/markets').body
15
17
  end
16
18
 
17
- def board(product_code = 'BTC_JPY')
18
- @connection.get('/v1/board', { product_code: product_code }).body
19
+ def board(product_code: 'BTC_JPY')
20
+ @connection.get('/v1/board', product_code: product_code).body
19
21
  end
20
22
 
21
- def ticker(product_code = 'BTC_JPY')
22
- @connection.get('/v1/ticker', { product_code: product_code }).body
23
+ def ticker(product_code: 'BTC_JPY')
24
+ @connection.get('/v1/ticker', product_code: product_code).body
23
25
  end
24
26
 
25
- def executions(product_code = 'BTC_JPY')
26
- @connection.get('/v1/executions', { product_code: product_code }).body
27
+ def executions(product_code: 'BTC_JPY', count: nil, before: nil, after: nil)
28
+ query = {
29
+ product_code: product_code,
30
+ count: count,
31
+ before: before,
32
+ after: after
33
+ }.delete_if { |_, v| v.nil? }
34
+ @connection.get('/v1/executions', query).body
27
35
  end
28
36
 
29
- def chats(from_date = (Time.now - 5 * 24 * 60 * 60))
30
- @connection.get('/v1/getchats', { from_date: from_date }).body
37
+ def chats(from_date: (Time.now - 5 * 24 * 60 * 60))
38
+ @connection.get('/v1/getchats', from_date: from_date).body
31
39
  end
32
40
  end
33
41
  end
34
42
  end
35
- end
43
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bitflyer'
2
4
  require 'bitflyer/realtime/client'
3
5
 
4
6
  module Bitflyer
5
7
  module Realtime
6
8
  end
7
- end
9
+ end
@@ -1,25 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './websocket'
2
4
 
3
5
  module Bitflyer
4
6
  module Realtime
5
- CHANNEL_NAMES = [
6
- 'lightning_board_snapshot_BTC_JPY',
7
- 'lightning_board_snapshot_FX_BTC_JPY',
8
- 'lightning_board_snapshot_ETH_BTC',
9
- 'lightning_board_snapshot_BCH_BTC',
10
- 'lightning_board_BTC_JPY',
11
- 'lightning_board_FX_BTC_JPY',
12
- 'lightning_board_ETH_BTC',
13
- 'lightning_board_BCH_BTC',
14
- 'lightning_ticker_BTC_JPY',
15
- 'lightning_ticker_FX_BTC_JPY',
16
- 'lightning_ticker_ETH_BTC',
17
- 'lightning_ticker_BCH_BTC',
18
- 'lightning_executions_BTC_JPY',
19
- 'lightning_executions_FX_BTC_JPY',
20
- 'lightning_executions_ETH_BTC',
21
- 'lightning_executions_BCH_BTC'
22
- ].freeze
7
+ EVENT_NAMES = %w[lightning_board_snapshot lightning_board lightning_ticker lightning_executions].freeze
8
+ MARKETS = %w[BTC_JPY FX_BTC_JPY ETH_BTC BCH_BTC BTCJPY_MAT3M BTCJPY_MAT1WK BTCJPY_MAT2WK].freeze
9
+ CHANNEL_NAMES = EVENT_NAMES.product(MARKETS).map { |e, m| "#{e}_#{m}" }
23
10
 
24
11
  SOCKET_HOST = 'https://io.lightstream.bitflyer.com'
25
12
 
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'websocket-client-simple'
4
+ require 'json'
2
5
 
3
6
  module Bitflyer
4
7
  module Realtime
5
8
  class WebSocketClient
6
9
  attr_accessor :websocket_client, :channel_name, :channel_callbacks, :ping_interval, :ping_timeout,
7
- :last_ping_at, :last_pong_at, :error
10
+ :last_ping_at, :last_pong_at, :error
8
11
 
9
12
  def initialize(host:, debug: false)
10
13
  @host = host
@@ -29,7 +32,7 @@ module Bitflyer
29
32
  Thread.new do
30
33
  loop do
31
34
  sleep 1
32
- if @websocket_client && @websocket_client.open?
35
+ if @websocket_client&.open?
33
36
  send_ping
34
37
  wait_pong
35
38
  end
@@ -40,6 +43,7 @@ module Bitflyer
40
43
  loop do
41
44
  sleep 1
42
45
  next unless @error
46
+
43
47
  reconnect
44
48
  end
45
49
  end
@@ -53,13 +57,13 @@ module Bitflyer
53
57
  return unless Time.now.to_i - @last_ping_at > @ping_interval / 1000
54
58
 
55
59
  debug_log 'Sent ping'
56
- @websocket_client.send "2"
60
+ @websocket_client.send '2'
57
61
  @last_ping_at = Time.now.to_i
58
62
  end
59
63
 
60
64
  def wait_pong
61
65
  return unless @last_pong_at && @ping_timeout
62
- return unless Time.now.to_i - @last_pong_at > @ping_timeout / 1000
66
+ return unless Time.now.to_i - @last_pong_at > (@ping_interval + @ping_timeout) / 1000
63
67
 
64
68
  debug_log 'Timed out waiting pong'
65
69
  @websocket_client.close
@@ -67,6 +71,7 @@ module Bitflyer
67
71
 
68
72
  def reconnect
69
73
  return unless @error
74
+
70
75
  debug_log 'Reconnecting...'
71
76
 
72
77
  @error = nil
@@ -80,13 +85,15 @@ module Bitflyer
80
85
 
81
86
  def handle_error(error:)
82
87
  debug_log error
83
- return unless error.kind_of? Errno::ECONNRESET
88
+ return unless error.is_a? Errno::ECONNRESET
89
+
84
90
  reconnect
85
91
  end
86
92
 
87
93
  def handle_message(payload:)
88
94
  debug_log payload.data
89
95
  return unless payload.data =~ /^\d+/
96
+
90
97
  code, body = payload.data.scan(/^(\d+)(.*)$/)[0]
91
98
 
92
99
  case code.to_i
@@ -95,15 +102,15 @@ module Bitflyer
95
102
  when 41 then disconnect
96
103
  when 42 then emit_message(json: body)
97
104
  end
98
- rescue => e
105
+ rescue StandardError => e
99
106
  puts e
100
107
  puts e.backtrace.join("\n")
101
108
  end
102
109
 
103
110
  def setup_by_response(json:)
104
111
  body = JSON.parse json
105
- @ping_interval = body["pingInterval"].to_i || 25000
106
- @ping_timeout = body["pingTimeout"].to_i || 60000
112
+ @ping_interval = body['pingInterval'].to_i || 25_000
113
+ @ping_timeout = body['pingTimeout'].to_i || 60_000
107
114
  @last_ping_at = Time.now.to_i
108
115
  @last_pong_at = Time.now.to_i
109
116
  channel_callbacks.each do |channel_name, _|
@@ -124,11 +131,13 @@ module Bitflyer
124
131
  def emit_message(json:)
125
132
  channel_name, *messages = JSON.parse json
126
133
  return unless channel_name
134
+
127
135
  messages.each { |message| @channel_callbacks[channel_name.to_sym]&.call(message) }
128
136
  end
129
137
 
130
138
  def debug_log(message)
131
139
  return unless @debug
140
+
132
141
  p message
133
142
  end
134
143
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bitflyer
2
- VERSION = '0.2.1'
4
+ VERSION = '1.1.0'
3
5
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitflyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Ueki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-06 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 0.14.0
22
+ version: '1.4'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 0.14.0
29
+ version: '0.14'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.4'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: faraday_middleware
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: 0.12.0
39
+ version: '0.12'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.1'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0.12'
50
+ - - "<"
39
51
  - !ruby/object:Gem::Version
40
- version: 0.12.0
52
+ version: '1.1'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: websocket-client-simple
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +70,28 @@ dependencies:
58
70
  requirements:
59
71
  - - "~>"
60
72
  - !ruby/object:Gem::Version
61
- version: '1.12'
73
+ version: '2.0'
62
74
  type: :development
63
75
  prerelease: false
64
76
  version_requirements: !ruby/object:Gem::Requirement
65
77
  requirements:
66
78
  - - "~>"
67
79
  - !ruby/object:Gem::Version
68
- version: '1.12'
80
+ version: '2.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: pry
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
69
95
  - !ruby/object:Gem::Dependency
70
96
  name: rake
71
97
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +120,20 @@ dependencies:
94
120
  - - ">="
95
121
  - !ruby/object:Gem::Version
96
122
  version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rubocop
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
97
137
  description: Bitflyer API wrapper
98
138
  email:
99
139
  - unhappychoice@gmail.com
@@ -101,6 +141,10 @@ executables: []
101
141
  extensions: []
102
142
  extra_rdoc_files: []
103
143
  files:
144
+ - ".all-contributorsrc"
145
+ - ".circleci/config.yml"
146
+ - ".rubocop.yml"
147
+ - ".rubocop_todo.yml"
104
148
  - CODE_OF_CONDUCT.md
105
149
  - Gemfile
106
150
  - Gemfile.lock
@@ -135,8 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
179
  - !ruby/object:Gem::Version
136
180
  version: '0'
137
181
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.7.6
182
+ rubygems_version: 3.0.3
140
183
  signing_key:
141
184
  specification_version: 4
142
185
  summary: Bitflyer API wrapper