bitfinex-rb 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bitfinex.rb +28 -30
  3. data/lib/{bitfinex/errors.rb → errors.rb} +2 -2
  4. data/lib/models/alert.rb +27 -0
  5. data/lib/models/balance_info.rb +25 -0
  6. data/lib/models/candle.rb +29 -0
  7. data/lib/models/currency.rb +27 -0
  8. data/lib/models/funding_credit.rb +41 -0
  9. data/lib/models/funding_info.rb +40 -0
  10. data/lib/models/funding_loan.rb +40 -0
  11. data/lib/models/funding_offer.rb +38 -0
  12. data/lib/models/funding_ticker.rb +50 -0
  13. data/lib/models/funding_trade.rb +31 -0
  14. data/lib/models/ledger_entry.rb +33 -0
  15. data/lib/models/margin_info.rb +67 -0
  16. data/lib/models/model.rb +56 -0
  17. data/lib/models/movement.rb +33 -0
  18. data/lib/models/notification.rb +30 -0
  19. data/lib/models/order.rb +197 -0
  20. data/lib/models/order_book.rb +265 -0
  21. data/lib/models/position.rb +33 -0
  22. data/lib/models/public_trade.rb +27 -0
  23. data/lib/models/trade.rb +34 -0
  24. data/lib/models/trading_ticker.rb +33 -0
  25. data/lib/models/user_info.rb +27 -0
  26. data/lib/models/wallet.rb +28 -0
  27. data/lib/rest/rest_client.rb +103 -0
  28. data/lib/rest/v1.rb +63 -0
  29. data/lib/rest/v1/account_info.rb +23 -0
  30. data/lib/{bitfinex → rest}/v1/deposit.rb +2 -3
  31. data/lib/{bitfinex → rest}/v1/funding_book.rb +2 -4
  32. data/lib/{bitfinex → rest}/v1/historical_data.rb +2 -2
  33. data/lib/{bitfinex → rest}/v1/lends.rb +1 -2
  34. data/lib/{bitfinex → rest}/v1/margin_funding.rb +1 -2
  35. data/lib/rest/v1/order_book.rb +17 -0
  36. data/lib/{bitfinex → rest}/v1/orders.rb +6 -8
  37. data/lib/{bitfinex → rest}/v1/positions.rb +6 -2
  38. data/lib/{bitfinex → rest}/v1/stats.rb +1 -3
  39. data/lib/{bitfinex → rest}/v1/symbols.rb +1 -2
  40. data/lib/rest/v1/ticker.rb +13 -0
  41. data/lib/{bitfinex → rest}/v1/trades.rb +1 -16
  42. data/lib/{bitfinex → rest}/v1/wallet.rb +1 -2
  43. data/lib/rest/v2.rb +47 -0
  44. data/lib/{bitfinex → rest}/v2/margin.rb +1 -2
  45. data/lib/{bitfinex → rest}/v2/personal.rb +2 -18
  46. data/lib/{bitfinex → rest}/v2/stats.rb +1 -4
  47. data/lib/rest/v2/ticker.rb +20 -0
  48. data/lib/{bitfinex → rest}/v2/trading.rb +3 -49
  49. data/lib/{bitfinex → rest}/v2/utils.rb +1 -3
  50. data/lib/ws/ws2.rb +529 -0
  51. metadata +74 -56
  52. data/lib/bitfinex-api-rb.rb +0 -1
  53. data/lib/bitfinex-rb.rb +0 -1
  54. data/lib/bitfinex/api_versions.rb +0 -7
  55. data/lib/bitfinex/authenticated_rest.rb +0 -57
  56. data/lib/bitfinex/client.rb +0 -38
  57. data/lib/bitfinex/configurable.rb +0 -48
  58. data/lib/bitfinex/connection.rb +0 -52
  59. data/lib/bitfinex/v1/account_info.rb +0 -38
  60. data/lib/bitfinex/v1/orderbook.rb +0 -36
  61. data/lib/bitfinex/v1/ticker.rb +0 -27
  62. data/lib/bitfinex/v2/ticker.rb +0 -58
  63. data/lib/bitfinex/version.rb +0 -3
  64. data/lib/bitfinex/websocket_connection.rb +0 -231
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfinex-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitfinex
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2018-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,152 +16,170 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.2
19
+ version: 0.15.3
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.9.2
22
+ version: 0.15.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 0.9.2
29
+ version: 0.15.3
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.9.2
32
+ version: 0.15.3
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: eventmachine
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.0'
39
+ version: 1.2.7
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.0.9.1
42
+ version: 1.2.7
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '1.0'
49
+ version: 1.2.7
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 1.0.9.1
52
+ version: 1.2.7
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: faraday-detailed_logger
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: 1.0.0
59
+ version: 2.1.2
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.0.0
62
+ version: 2.1.2
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 1.0.0
69
+ version: 2.1.2
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.0.0
72
+ version: 2.1.2
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: faye-websocket
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: 0.10.3
79
+ version: 0.10.7
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: 0.10.3
86
+ version: 0.10.7
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: json
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: 1.8.3
93
+ version: 2.1.0
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: 1.8.3
96
+ version: 2.1.0
97
97
  type: :runtime
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.8.3
103
+ version: 2.1.0
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 1.8.3
106
+ version: 2.1.0
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: faraday_middleware
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: '0.10'
113
+ version: 0.12.2
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 0.10.0
116
+ version: 0.12.2
117
117
  type: :runtime
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '0.10'
123
+ version: 0.12.2
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- version: 0.10.0
127
- description: Simple Bitfinex API ruby wrapper
126
+ version: 0.12.2
127
+ description: Official Bitfinex API ruby wrapper
128
128
  email:
129
129
  - developers@bitfinex.com
130
130
  executables: []
131
131
  extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
- - lib/bitfinex-api-rb.rb
135
- - lib/bitfinex-rb.rb
136
134
  - lib/bitfinex.rb
137
- - lib/bitfinex/api_versions.rb
138
- - lib/bitfinex/authenticated_rest.rb
139
- - lib/bitfinex/client.rb
140
- - lib/bitfinex/configurable.rb
141
- - lib/bitfinex/connection.rb
142
- - lib/bitfinex/errors.rb
143
- - lib/bitfinex/v1/account_info.rb
144
- - lib/bitfinex/v1/deposit.rb
145
- - lib/bitfinex/v1/funding_book.rb
146
- - lib/bitfinex/v1/historical_data.rb
147
- - lib/bitfinex/v1/lends.rb
148
- - lib/bitfinex/v1/margin_funding.rb
149
- - lib/bitfinex/v1/orderbook.rb
150
- - lib/bitfinex/v1/orders.rb
151
- - lib/bitfinex/v1/positions.rb
152
- - lib/bitfinex/v1/stats.rb
153
- - lib/bitfinex/v1/symbols.rb
154
- - lib/bitfinex/v1/ticker.rb
155
- - lib/bitfinex/v1/trades.rb
156
- - lib/bitfinex/v1/wallet.rb
157
- - lib/bitfinex/v2/margin.rb
158
- - lib/bitfinex/v2/personal.rb
159
- - lib/bitfinex/v2/stats.rb
160
- - lib/bitfinex/v2/ticker.rb
161
- - lib/bitfinex/v2/trading.rb
162
- - lib/bitfinex/v2/utils.rb
163
- - lib/bitfinex/version.rb
164
- - lib/bitfinex/websocket_connection.rb
135
+ - lib/errors.rb
136
+ - lib/models/alert.rb
137
+ - lib/models/balance_info.rb
138
+ - lib/models/candle.rb
139
+ - lib/models/currency.rb
140
+ - lib/models/funding_credit.rb
141
+ - lib/models/funding_info.rb
142
+ - lib/models/funding_loan.rb
143
+ - lib/models/funding_offer.rb
144
+ - lib/models/funding_ticker.rb
145
+ - lib/models/funding_trade.rb
146
+ - lib/models/ledger_entry.rb
147
+ - lib/models/margin_info.rb
148
+ - lib/models/model.rb
149
+ - lib/models/movement.rb
150
+ - lib/models/notification.rb
151
+ - lib/models/order.rb
152
+ - lib/models/order_book.rb
153
+ - lib/models/position.rb
154
+ - lib/models/public_trade.rb
155
+ - lib/models/trade.rb
156
+ - lib/models/trading_ticker.rb
157
+ - lib/models/user_info.rb
158
+ - lib/models/wallet.rb
159
+ - lib/rest/rest_client.rb
160
+ - lib/rest/v1.rb
161
+ - lib/rest/v1/account_info.rb
162
+ - lib/rest/v1/deposit.rb
163
+ - lib/rest/v1/funding_book.rb
164
+ - lib/rest/v1/historical_data.rb
165
+ - lib/rest/v1/lends.rb
166
+ - lib/rest/v1/margin_funding.rb
167
+ - lib/rest/v1/order_book.rb
168
+ - lib/rest/v1/orders.rb
169
+ - lib/rest/v1/positions.rb
170
+ - lib/rest/v1/stats.rb
171
+ - lib/rest/v1/symbols.rb
172
+ - lib/rest/v1/ticker.rb
173
+ - lib/rest/v1/trades.rb
174
+ - lib/rest/v1/wallet.rb
175
+ - lib/rest/v2.rb
176
+ - lib/rest/v2/margin.rb
177
+ - lib/rest/v2/personal.rb
178
+ - lib/rest/v2/stats.rb
179
+ - lib/rest/v2/ticker.rb
180
+ - lib/rest/v2/trading.rb
181
+ - lib/rest/v2/utils.rb
182
+ - lib/ws/ws2.rb
165
183
  homepage: https://www.bitfinex.com/
166
184
  licenses:
167
185
  - MIT
@@ -182,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
200
  version: '0'
183
201
  requirements: []
184
202
  rubyforge_project:
185
- rubygems_version: 2.4.5.1
203
+ rubygems_version: 2.6.14
186
204
  signing_key:
187
205
  specification_version: 4
188
206
  summary: Bitfinex API Wrapper
@@ -1 +0,0 @@
1
- require_relative "./bitfinex.rb"
@@ -1 +0,0 @@
1
- require_relative "./bitfinex.rb"
@@ -1,7 +0,0 @@
1
- module Bitfinex
2
- # API logic for Version 1
3
- module V1; end
4
-
5
- # API logic for Version 2
6
- module V2; end
7
- end
@@ -1,57 +0,0 @@
1
- module Bitfinex
2
- module AuthenticatedConnection
3
-
4
- private
5
- def authenticated_post(url, options = {})
6
- raise Bitfinex::InvalidAuthKeyError unless valid_key?
7
- complete_url = build_url(url)
8
- body = options[:params] || {}
9
- nonce = new_nonce
10
-
11
- payload = if config.api_version == 1
12
- build_payload("/v1/#{url}", options[:params], nonce)
13
- else
14
- "/api#{complete_url}#{nonce}#{body.to_json}"
15
- end
16
-
17
- response = rest_connection.post do |req|
18
- req.url complete_url
19
- req.body = body.to_json
20
- req.options.timeout = config.rest_timeout
21
- req.options.open_timeout = config.rest_open_timeout
22
- req.headers['Content-Type'] = 'application/json'
23
- req.headers['Accept'] = 'application/json'
24
-
25
- if config.api_version == 1
26
- req.headers['X-BFX-PAYLOAD'] = payload
27
- req.headers['X-BFX-SIGNATURE'] = sign(payload)
28
- req.headers['X-BFX-APIKEY'] = config.api_key
29
- else
30
- req.headers['bfx-nonce'] = nonce
31
- req.headers['bfx-signature'] = sign(payload)
32
- req.headers['bfx-apikey'] = config.api_key
33
- end
34
- end
35
- end
36
-
37
- def build_payload(url, params = {}, nonce)
38
- payload = {}
39
- payload['nonce'] = nonce
40
- payload['request'] = url
41
- payload.merge!(params) if params
42
- Base64.strict_encode64(payload.to_json)
43
- end
44
-
45
- def new_nonce
46
- (Time.now.to_f * 10_000).to_i.to_s
47
- end
48
-
49
- def sign(payload)
50
- OpenSSL::HMAC.hexdigest('sha384', config.secret, payload)
51
- end
52
-
53
- def valid_key?
54
- !! (config.api_key && config.secret)
55
- end
56
- end
57
- end
@@ -1,38 +0,0 @@
1
- module Bitfinex
2
- class Client
3
- include Bitfinex::RestConnection
4
- include Bitfinex::WebsocketConnection
5
- include Bitfinex::AuthenticatedConnection
6
- include Bitfinex::Configurable
7
-
8
-
9
- def initialize
10
- if config.api_version == 1
11
- extend Bitfinex::V1::TickerClient
12
- extend Bitfinex::V1::TradesClient
13
- extend Bitfinex::V1::FundingBookClient
14
- extend Bitfinex::V1::OrderbookClient
15
- extend Bitfinex::V1::StatsClient
16
- extend Bitfinex::V1::LendsClient
17
- extend Bitfinex::V1::SymbolsClient
18
- extend Bitfinex::V1::AccountInfoClient
19
- extend Bitfinex::V1::DepositClient
20
- extend Bitfinex::V1::OrdersClient
21
- extend Bitfinex::V1::PositionsClient
22
- extend Bitfinex::V1::HistoricalDataClient
23
- extend Bitfinex::V1::MarginFundingClient
24
- extend Bitfinex::V1::WalletClient
25
- else
26
- extend Bitfinex::V2::TickerClient
27
- extend Bitfinex::V2::StatsClient
28
- extend Bitfinex::V2::UtilsClient
29
- extend Bitfinex::V2::PersonalClient
30
- extend Bitfinex::V2::TradingClient
31
- extend Bitfinex::V2::MarginClient
32
- end
33
-
34
- @mutex = Mutex.new
35
- @c_counter = 1
36
- end
37
- end
38
- end
@@ -1,48 +0,0 @@
1
- module Bitfinex
2
- module Configurable
3
- def self.included(base)
4
- base.extend(ClassMethods)
5
- end
6
-
7
- def config
8
- self.class.config
9
- end
10
-
11
- module ClassMethods
12
- def configure
13
- yield config
14
- end
15
-
16
- def config
17
- @configuration ||= Configuration.new
18
- end
19
- end
20
- end
21
-
22
- class Configuration
23
- attr_accessor :api_endpoint, :debug, :debug_connection, :secret
24
- attr_accessor :api_key, :websocket_api_endpoint, :rest_timeout
25
- attr_accessor :reconnect, :reconnect_after, :rest_open_timeout
26
- attr_accessor :api_version
27
-
28
- def initialize
29
- self.api_endpoint = "https://api.bitfinex.com/v1/"
30
- self.websocket_api_endpoint = "wss://api.bitfinex.com/ws"
31
- self.debug = false
32
- self.reconnect = true
33
- self.reconnect_after = 60
34
- self.rest_timeout = 30
35
- self.rest_open_timeout = 30
36
- self.debug_connection = false
37
- self.api_version = 1
38
- end
39
-
40
- # Helper that configure to version 2
41
- def use_api_v2
42
- self.api_version = 2
43
- self.api_endpoint = "https://api.bitfinex.com/v2/"
44
- self.websocket_api_endpoint = "wss://api.bitfinex.com/ws/2/"
45
- end
46
- end
47
-
48
- end
@@ -1,52 +0,0 @@
1
- require 'logger'
2
- module Bitfinex
3
- # Network Layer for API Rest client
4
- module RestConnection
5
- private
6
- # Make an HTTP GET request
7
- def get(url, params={})
8
- rest_connection.get do |req|
9
- req.url build_url(url)
10
- req.headers['Content-Type'] = 'application/json'
11
- req.headers['Accept'] = 'application/json'
12
- params.each do |k,v|
13
- req.params[k] = v
14
- end
15
- req.options.timeout = config.rest_timeout
16
- req.options.open_timeout = config.rest_open_timeout
17
- end
18
- end
19
-
20
- # Make sure parameters are allowed for the HTTP call
21
- def check_params(params, allowed_params)
22
- if (params.keys - allowed_params).empty?
23
- return params
24
- else
25
- raise Bitfinex::ParamsError
26
- end
27
- end
28
-
29
- def rest_connection
30
- @conn ||= new_rest_connection
31
- end
32
-
33
- def build_url(url)
34
- URI.join(config.api_endpoint, url).path
35
- end
36
-
37
- def new_rest_connection
38
- Faraday.new(url: base_api_endpoint) do |conn|
39
- conn.use Bitfinex::CustomErrors
40
- conn.response :logger, Logger.new(STDOUT) , bodies: true if config.debug_connection
41
- conn.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
42
- conn.adapter :net_http
43
- end
44
- end
45
-
46
- def base_api_endpoint
47
- url = URI.parse config.api_endpoint
48
- "#{url.scheme}://#{url.host}:#{url.port}"
49
- end
50
-
51
- end
52
- end