bitmex-api 0.0.3 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92b401dc2774b95aa169e7ed7406eb7c1674f4a88b5ceb1920a268f1d7a129d3
4
- data.tar.gz: b2cd44806b551a6f8fa4cec72988975013ccd5799779b1bf58e2e796e792a0d2
3
+ metadata.gz: 8ee2c822d6d71a05339a02ea14e4e17f58afafd5e9775ed48f5db89025b914fe
4
+ data.tar.gz: 523ee210b7a17955eeaeffafb19bb00ac3dce49a789842545b0f0a7a0faeecd1
5
5
  SHA512:
6
- metadata.gz: 32b1eb95bfd3724338df77958076a9237c895bb32c207a0b5e0801a1283928a795a1cbf5a1e7cbcde6ddda967452b3d7615cf769140696a80594382991238f29
7
- data.tar.gz: 6b06e1c950f1b1e82e87612f3b03deffdec2819a5043d1ec11baa67098e701cf7bf22fced940d2269f75f37177f2dac005f6e4761fb956b9fc5367e858cda83d
6
+ metadata.gz: 5fe0a780b415aee7e35c4a4a7b95d4e3236e10533206325f77e4ba719d231e340c5861d60a95a6fb1b5937d7e0be1973db85831143e13fcc8c82231f89884796
7
+ data.tar.gz: 7ef74976acb9bbad03b75fde8750b399b0486f475e8714742250bffc2d57bf08331fbb23cfa5ee03001780410ba998b69696881ed0a0d9dead0deba7487d9870
@@ -5,6 +5,15 @@
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.0] - 2019-02-11
9
+ ### Added
10
+ - authentication via websocket
11
+ - idiomatic websocket support for all resources
12
+ - license and badge
13
+ - examples and APIs endpoints in README
14
+ ### Changed
15
+ - extract REST API implementation into its own class
16
+
8
17
  ## [0.0.3] - 2019-01-31
9
18
  ### Added
10
19
  - Chat, instrument, apikey resources
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitmex-api (0.0.3)
4
+ bitmex-api (0.1.0)
5
5
  eventmachine
6
6
  faye-websocket
7
7
  hashie
@@ -11,21 +11,34 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  ast (2.4.0)
14
+ axiom-types (0.1.1)
15
+ descendants_tracker (~> 0.0.4)
16
+ ice_nine (~> 0.11.0)
17
+ thread_safe (~> 0.3, >= 0.3.1)
14
18
  bump (0.7.0)
19
+ codeclimate-engine-rb (0.4.1)
20
+ virtus (~> 1.0)
15
21
  coderay (1.1.2)
22
+ coercible (1.0.0)
23
+ descendants_tracker (~> 0.0.1)
24
+ descendants_tracker (0.0.4)
25
+ thread_safe (~> 0.3, >= 0.3.1)
16
26
  diff-lcs (1.3)
17
27
  docile (1.3.1)
18
28
  dotenv (2.6.0)
29
+ equalizer (0.0.11)
19
30
  eventmachine (1.2.7)
20
31
  faye-websocket (0.10.7)
21
32
  eventmachine (>= 0.12.0)
22
33
  websocket-driver (>= 0.5.1)
23
34
  hashie (3.6.0)
24
- httparty (0.16.3)
35
+ httparty (0.16.4)
25
36
  mime-types (~> 3.0)
26
37
  multi_xml (>= 0.5.2)
38
+ ice_nine (0.11.2)
27
39
  jaro_winkler (1.5.2)
28
40
  json (2.1.0)
41
+ kwalify (0.7.2)
29
42
  method_source (0.9.2)
30
43
  mime-types (3.2.2)
31
44
  mime-types-data (~> 3.2015)
@@ -41,13 +54,15 @@ GEM
41
54
  pry-doc (1.0.0)
42
55
  pry (~> 0.11)
43
56
  yard (~> 0.9.11)
57
+ psych (3.1.0)
44
58
  rainbow (3.0.0)
45
59
  rake (12.3.2)
46
- reek (1.3.7)
47
- rainbow
48
- ruby2ruby (~> 2.0.8)
49
- ruby_parser (~> 3.3)
50
- sexp_processor
60
+ reek (5.3.1)
61
+ codeclimate-engine-rb (~> 0.4.0)
62
+ kwalify (~> 0.7.0)
63
+ parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
64
+ psych (~> 3.1.0)
65
+ rainbow (>= 2.0, < 4.0)
51
66
  rspec (3.8.0)
52
67
  rspec-core (~> 3.8.0)
53
68
  rspec-expectations (~> 3.8.0)
@@ -70,18 +85,18 @@ GEM
70
85
  ruby-progressbar (~> 1.7)
71
86
  unicode-display_width (~> 1.4.0)
72
87
  ruby-progressbar (1.10.0)
73
- ruby2ruby (2.0.8)
74
- ruby_parser (~> 3.1)
75
- sexp_processor (~> 4.0)
76
- ruby_parser (3.12.0)
77
- sexp_processor (~> 4.9)
78
- sexp_processor (4.11.0)
79
88
  simplecov (0.16.1)
80
89
  docile (~> 1.1)
81
90
  json (>= 1.8, < 3)
82
91
  simplecov-html (~> 0.10.0)
83
92
  simplecov-html (0.10.2)
93
+ thread_safe (0.3.6)
84
94
  unicode-display_width (1.4.1)
95
+ virtus (1.0.5)
96
+ axiom-types (~> 0.1)
97
+ coercible (~> 1.0)
98
+ descendants_tracker (~> 0.0, >= 0.0.3)
99
+ equalizer (~> 0.0, >= 0.0.9)
85
100
  websocket-driver (0.7.0)
86
101
  websocket-extensions (>= 0.1.0)
87
102
  websocket-extensions (0.1.3)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Iulian Costan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -3,8 +3,10 @@
3
3
  [![Build Status](https://travis-ci.org/icostan/bitmex-api-ruby.svg?branch=master)](https://travis-ci.org/icostan/bitmex-api-ruby)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/85c3eb58ef31dabc9159/maintainability)](https://codeclimate.com/github/icostan/bitmex-api-ruby/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/85c3eb58ef31dabc9159/test_coverage)](https://codeclimate.com/github/icostan/bitmex-api-ruby/test_coverage)
6
- [![Gem Version](https://badge.fury.io/rb/bitmex-api.svg)](https://badge.fury.io/rb/bitmex-api)
7
6
  [![Inline docs](http://inch-ci.org/github/icostan/bitmex-api-ruby.svg?branch=master)](http://inch-ci.org/github/icostan/bitmex-api-ruby)
7
+ [![Gem Version](https://badge.fury.io/rb/bitmex-api.svg)](https://badge.fury.io/rb/bitmex-api)
8
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/bitmex-api)
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/icostan/bitmex-api-ruby/blob/master/LICENSE)
8
10
 
9
11
  Fully featured, idiomatic Ruby library for [BitMEX API](https://www.bitmex.com/app/apiOverview).
10
12
 
@@ -26,74 +28,205 @@ Or install it yourself as:
26
28
 
27
29
  ## Usage
28
30
 
29
- ### Bitmex client
31
+ ### Overview
32
+
33
+ #### Bitmex client
30
34
 
31
35
  ```ruby
32
36
  require 'bitmex-api'
33
37
 
34
38
  client = Bitmex::Client.new
35
39
 
36
- # or add key and secret args if you want to access private APIs
40
+ # or add api_key, api_secret if you want to access private APIs
37
41
  client = Bitmex::Client.new api_key: 'KEY', api_secret: 'SECRET'
38
42
  ```
39
43
 
40
- ### REST and Websocket API
41
-
42
- #### Using REST API
44
+ #### REST API
43
45
 
44
46
  Get last 10 messages in English channel:
45
47
 
46
48
  ```ruby
47
- messages = client.chat.messages channel_id: 1, count: 10, reverse: true
49
+ messages = client.chat.messages channelID: 1, count: 10, reverse: true
48
50
  puts messages.first.name
49
51
  ```
50
52
 
51
- #### Using Websocket API
53
+ All REST API requests return either an `Array` or `Bitmex::Mash`, a pseudo-object that extends `Hashie::Mash`.
54
+
55
+ #### Websocket API
56
+
57
+ Generic Websocket API is implemented in `#listen` method. See the list of available [Topics](https://www.bitmex.com/app/wsAPI#Subscriptions "Topics") to subscribe to.
58
+
59
+ Listen to XBTUSD trades:
52
60
 
53
- Generic Websocket API is implemented in `Bitmex::Client#listen` method. See the list of available [Topics](https://www.bitmex.com/app/wsAPI#Subscriptions "Topics") to subscribe to.
61
+ ```ruby
62
+ client.websocket.listen trade: 'XBTUSD' do |trade|
63
+ puts trade.homeNotional
64
+ end
65
+ ```
54
66
 
55
- Listen to chat messages.
67
+ Or multiple topics at the same time:
56
68
 
57
69
  ```ruby
58
- client.listen chat: 1 do |message|
70
+ client.websocket.listen liquidation: 'XBTUSD', trade: 'XBTUSD' do |data|
71
+ puts data
72
+ end
73
+ ```
74
+
75
+ Pass blocks to methods to receive data via Websocket API.
76
+
77
+ ```ruby
78
+ client.chat.messages channelID: 1 do |message|
59
79
  puts "#{message.user}: #{message.message}"
60
80
  end
61
81
  ```
62
82
 
63
- Listen to XBTUSD trades.
83
+ All Websocket API blocks yield a pseudo-object `Bitmex::Mash`.
84
+
85
+ ### Examples
86
+
87
+ #### Whales watching
88
+
89
+ Filtering traders bigger than 10 XBT {file:bin/whales-watching.rb}
64
90
 
65
91
  ```ruby
66
- client.listen trade: 'XBTUSD' do |trade|
67
- puts trade.homeNotional
92
+ client = Bitmex::Client.new
93
+ client.trades.all symbol: 'XBTUSD' do |trade|
94
+ puts "#{trade.side} #{trade.homeNotional} #{trade.symbol} @ #{trade.price}" if trade.homeNotional > 10
68
95
  end
69
96
  ```
70
97
 
71
- Or multiple topics at the same time.
98
+ #### Trolls listening
99
+
100
+ Listen to trollbox chat in realtime {file:bin/chat.rb}
72
101
 
73
102
  ```ruby
74
- client.listen liquidation: 'XBTUSD', trade: 'XBTUSD' do |data|
75
- puts data
103
+ client = Bitmex::Client.new
104
+ client.chat.messages channelID: 1 do |message|
105
+ puts "#{message.user}: #{message.message}"
76
106
  end
77
107
  ```
78
108
 
79
109
  ### API Endpoints
80
110
 
111
+ #### Announcement
112
+
113
+ Public announcements:
114
+
115
+ ```ruby
116
+ announcements = client.announcements
117
+ puts announcements.first.title
118
+
119
+ client.announcements do |announcement|
120
+ puts announcement.content
121
+ end
122
+ ```
123
+
124
+ #### API Keys
125
+
126
+ Persistent API keys for developers:
127
+
128
+ ```ruby
129
+ keys = client.apikey.all
130
+ puts keys.first
131
+ ```
132
+
133
+ #### Chat
134
+
135
+ Trollbox channels:
136
+
137
+ ```ruby
138
+ channels = client.chat.channels
139
+ puts channels.first
140
+
141
+ client.chat.messages channelID: 1 do |message|
142
+ puts message.user
143
+ end
144
+ ```
145
+
146
+ #### Execution
147
+
148
+ Raw order and balance data:
149
+
150
+ ```ruby
151
+ executions = client.user.executions count: 5
152
+ puts executions.first
153
+
154
+ client.user.executions symbol: 'XBTUSD' do |execution|
155
+ puts execution
156
+ end
157
+ ```
158
+
159
+ #### Funding
160
+
161
+ ```ruby
162
+ funding = client.funding symbol: 'XBTUSD', count: 5
163
+ puts funding.first
164
+
165
+ client.funding do |funding|
166
+ puts funding
167
+ end
168
+ ```
169
+
170
+ #### Instrument
171
+
172
+ Tradeable instruments:
173
+
174
+ ```ruby
175
+ instruments = client.instrument.active
176
+ puts instruments.first
177
+
178
+
179
+ client.instrument.all symbol: 'XBTUSD' do |instrument|
180
+ puts instrument
181
+ end
182
+ ```
183
+
184
+ #### Insurance
185
+
186
+ Insurance fund:
187
+
188
+ ```ruby
189
+ insurance = client.insurance count: 10
190
+ puts insurance
191
+
192
+ client.insurance do |insurance|
193
+ puts insurance.walletBalance
194
+ end
195
+ ```
196
+
81
197
  #### Leaderboard
82
198
 
83
- See the rock stars.
199
+ Top users:
84
200
 
85
201
  ```ruby
86
202
  leaders = client.leaderboard
87
203
  puts leaders.first.name
88
204
  ```
89
205
 
206
+ #### Liquidation
207
+
208
+ Active liquidation:
209
+
210
+ ```ruby
211
+ liquidations = client.liquidations
212
+ puts liquidations.first
213
+
214
+ client.liquidations symbol: 'XBTUSD' do |liquidation|
215
+ puts liquidation.qty
216
+ end
217
+ ```
218
+
90
219
  #### Order
91
220
 
92
221
  Get your orders.
93
222
 
94
223
  ```ruby
95
224
  orders = client.orders.all
96
- puts orders.size
225
+ puts orders.first.side
226
+
227
+ client.orders.all symbol: 'XBTUSD' do |order|
228
+ puts order.orderQty
229
+ end
97
230
  ```
98
231
 
99
232
  Create new order, update and cancel.
@@ -106,37 +239,81 @@ order = client.order(clOrdID: order.clOrdID).cancel
106
239
 
107
240
  #### Orderbook
108
241
 
109
- Get first bid and ask.
242
+ Get first bid and ask:
110
243
 
111
244
  ```ruby
112
245
  orderbook = client.orderbook 'XBTUSD', depth: 1
113
246
  puts orderbook.first.side
247
+
248
+ client.orderbook 'XBTUSD' do |orderbook|
249
+ puts orderbook
250
+ end
114
251
  ```
115
252
 
116
253
  #### Position
117
254
 
118
- Get all open positions or change leverage for an open position.
255
+ Get all open positions or change leverage for an open position:
119
256
 
120
257
  ```ruby
121
258
  positions = client.positions
122
259
  puts positions.size
123
260
 
261
+ client.positions.all do |position|
262
+ puts position.currentQty
263
+ end
264
+
124
265
  position = client.position('XBTUSD').leverage 25
125
266
  puts position.leverage
126
267
  ```
127
268
 
269
+ #### Quote
270
+
271
+ Best bid/ask snapshot and historical bins:
272
+
273
+ ```ruby
274
+ client.quotes.all symbol: 'XBTUSD' do |quote|
275
+ puts quote.askPrice
276
+ end
277
+
278
+ client.quotes.bucketed '1h', symbol: 'XBTUSD' do |bucket|
279
+ puts bucket.bidSize
280
+ end
281
+ ```
282
+
283
+ #### Schema
284
+
285
+ Dynamic schema for developers:
286
+
287
+ ```ruby
288
+ schema = client.schema
289
+ puts schema
290
+ ```
291
+
292
+ #### Settlement
293
+
294
+ Historical settlement:
295
+
296
+ ```ruby
297
+ settlements = client.settlements
298
+ puts settlements.first.settlementType
299
+
300
+ client.settlements do |settlements|
301
+ puts settlement.settledPrice
302
+ end
303
+ ```
304
+
128
305
  #### Stats
129
306
 
130
- Exchange statistics.
307
+ Exchange history:
131
308
 
132
309
  ```ruby
133
310
  history = subject.stats.history
134
- puts history
311
+ puts history.turnover
135
312
  ```
136
313
 
137
314
  #### Trade
138
315
 
139
- Load first 15 trades after Jan 1st for XBTUSD.
316
+ Load first 10 trades after Jan 1st for XBTUSD.
140
317
 
141
318
  ```ruby
142
319
  trades = client.trades.all symbol: 'XBTUSD', startTime: '2019-01-01', count: 10