orderbook 3.0.0 → 4.0.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
  SHA1:
3
- metadata.gz: 20a70a3b134b39779181f6f4137a5200f003593e
4
- data.tar.gz: 269d90ef37d27f7925e10f241326cf65c41ad3e1
3
+ metadata.gz: 63a277ee323ea8765e296998ab126b1e88f18d70
4
+ data.tar.gz: ea1fabde9aabc5d3b7793e8828add7fa2b6bf0b0
5
5
  SHA512:
6
- metadata.gz: 255c3b44bb6cb4bee6bd90975bac52f51401d79d0e4374250545e438f2348223ca01e78a348f23bffa1e444d1d0aa479b024872fcdd40b3ec3ff17e415d5e426
7
- data.tar.gz: a1581ff672f3e345c5745171754a399f6b552203fa73828976468445d36883a79f72a05d2eaddbe67176c1fc57dd33ff21dea919ec16ab71f649c9944c2f1444
6
+ metadata.gz: ea24534d04f263018c60e4a1454d4d1eb285edbc7465b71d4480b8a8a7fd13f8e2b82f372a07cb246e8328322430aa621f7c1563eddb50554377138bdf17846b
7
+ data.tar.gz: 5d968635fc6fdcfb23edbea5db60d0e8b7ed6906a08b0ac47204accd96269ab6419b1bff08195f0ef99226d681d73d4e36d1d09296ba9bcf9488d78ff7b86768
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # Orderbook 3.0.0
1
+ # Orderbook
2
2
  <a href="https://codeclimate.com/github/mikerodrigues/orderbook"><img src="https://codeclimate.com/github/mikerodrigues/orderbook/badges/gpa.svg" /></a>
3
3
 
4
+ A gem for creating a realtime order book for the Coinbase Exchange.
5
+
6
+ Version 4.0.0 switches to keyword arguments, supports other currencies.
7
+
4
8
  Version 3.0.0 has a slightly different interface and properly queues messages
5
9
  for an accurate Orderbook.
6
10
 
7
- A gem for creating a realtime order book for the Coinbase Exchange.
8
-
9
11
  Version 1.0.0 and greater now use the official Coinbase Exchange Ruby Gem's
10
12
  EventMachine-driven client. It should be more reliable than the previous socket
11
13
  code.
@@ -43,24 +45,40 @@ ob = Orderbook.new
43
45
  * Create an Orderbook object but don't fetch an orderbook or start live
44
46
  updating.
45
47
  ```ruby
46
- ob = Orderbook.new(false)
48
+ ob = Orderbook.new(start: false)
47
49
 
48
50
  # When you want it to go live:
49
51
 
50
52
  ob.start!
53
+
54
+ # When you want to stop it:
55
+
56
+ ob.stop!
57
+
58
+ # Reset the orderbook by fetching a fresh orderbook snapshot. This just calls
59
+ # `stop!` and then `start!` again:
60
+
61
+ ob.reset!
62
+ ```
63
+
64
+ * Get the "BTC-GBP" orderbook instead of "BTC-USD":
65
+ ```ruby
66
+ ob = Orderbook.new(product_id: "BTC-GBP")
51
67
  ```
52
68
 
53
69
  * Create a live Orderbook with a callback to fire on each message:
54
70
  ```ruby
55
71
  ob = Orderbook.new do |message|
56
- puts message.fetch 'type'
72
+ if message.fetch 'type' == 'match'
73
+ puts ob.spread.to_f('s')
74
+ end
57
75
  end
58
76
  ```
59
77
 
60
78
  * Create or reset the message callback:
61
79
  ```ruby
62
80
  ob.on_message do |message|
63
- puts message.fetch 'sequence'
81
+ puts ob.count
64
82
  end
65
83
  ```
66
84
 
@@ -23,6 +23,10 @@ class Orderbook
23
23
  #
24
24
  attr_reader :asks
25
25
 
26
+ # Product ID of the orderbook
27
+ #
28
+ attr_reader :product_id
29
+
26
30
  # Sequence number from the initial level 3 snapshot
27
31
  #
28
32
  attr_reader :snapshot_sequence
@@ -61,14 +65,15 @@ class Orderbook
61
65
  #
62
66
  # If a +block+ is given it is passed each message as it is received.
63
67
  #
64
- def initialize(start = true, &block)
68
+ def initialize(product_id: "BTC-USD", start: true, &block)
69
+ @product_id = product_id
65
70
  @bids = []
66
71
  @asks = []
67
72
  @snapshot_sequence = 0
68
73
  @last_sequence = 0
69
74
  @queue = Queue.new
70
- @websocket = Coinbase::Exchange::Websocket.new(keepalive: true)
71
- @client = Coinbase::Exchange::Client.new
75
+ @websocket = Coinbase::Exchange::Websocket.new(keepalive: true, product_id: @product_id)
76
+ @client = Coinbase::Exchange::Client.new('', '', '', product_id: @product_id)
72
77
  @on_message = block if block_given?
73
78
  start && start!
74
79
  end
@@ -1,5 +1,5 @@
1
1
  # Orderbook version number. I try to keep it semantic.
2
2
  #
3
3
  class Orderbook
4
- VERSION = '3.0.0'
4
+ VERSION = '4.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orderbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rodrigues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler