mxvp-coinbase 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: aeea59f189c7eefcfc066a135ea5a02713db965d
4
- data.tar.gz: bd26123dfcee1fcc6ab4ecfff7d0f840837aabb7
3
+ metadata.gz: 664990c22a01165c0c8a83bf389fd85319f9891b
4
+ data.tar.gz: 7dfe475e6b8f04be4fa04ae1c6cc8048ab8fdd24
5
5
  SHA512:
6
- metadata.gz: 2e599151504b2c035c96e09f9df470c883d67d334952faa661939e844ec369d78302fae2d4072ad16b6436b99694a7dbd16b582d6c85239dffa4992f0114d793
7
- data.tar.gz: 547ef1b8fe09db6146f7ad6d3ad6d6ef0ba7f196e292d1dde057df7fa1a8cc5f5ac181bb19433ea71f018fb146d36fbf07bb4663876ecba808ba97cc367a8503
6
+ metadata.gz: 7e1f8abd19268ce7fca31f314c01184f10d527438b626d6637dd976851d42c2c95352e394afbab0a9bef1433bc33d49af47bb56dd844bbb2bcf24167d87ac824
7
+ data.tar.gz: 2485048ab33aed24f39e244f90649a66692704a13c61c2ea085bc77893bac9cfedbae1f87cca8a0658f3ce700bc8cfff2714b5756311e4b6137dfef35e1b38ee
@@ -5,7 +5,7 @@ require 'coinbase/exchange/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "mxvp-coinbase"
8
- spec.version = Coinbase::Exchange::VERSION
8
+ spec.version = "0.2.1"
9
9
  spec.authors = ["John Duhamel", "James Mock"]
10
10
  spec.email = ["james.willard.mock@gmail.com"]
11
11
 
@@ -4,7 +4,7 @@ module Coinbase
4
4
  class Websocket
5
5
  def initialize(options = {})
6
6
  @ws_url = options[:ws_url] || "wss://ws-feed.gdax.com"
7
- @product = options[:product_id] || 'BTC-USD'
7
+ @products = options[:product_ids] || ["BTC-USD"]
8
8
  @keepalive = options[:keepalive] || false
9
9
 
10
10
  @message_cb = ->(_data) { nil }
@@ -14,6 +14,10 @@ module Coinbase
14
14
  @change_cb = ->(_data) { nil }
15
15
  @done_cb = ->(_data) { nil }
16
16
  @error_cb = ->(_data) { nil }
17
+
18
+ @key = options[:key]
19
+ @secret = options[:secret]
20
+ @passphrase = options[:passphrase]
17
21
  end
18
22
 
19
23
  def start!
@@ -44,8 +48,19 @@ module Coinbase
44
48
  end
45
49
 
46
50
  def subscribe!(options = {})
47
- product = options[:product_id] || @product
48
- @socket.send({ type: 'subscribe', product_id: product }.to_json)
51
+ products = options[:product_ids] || @products
52
+ channels = options[:channels] || ["ticker", "user"]
53
+ timestamp = DateTime.now
54
+ payload = {
55
+ type: "subscribe",
56
+ product_ids: products,
57
+ "channels": channels,
58
+ "signature": ws_signature(timestamp: timestamp),
59
+ "key": @key,
60
+ "passphrase": @passphrase,
61
+ "timestamp": timestamp.to_i
62
+ }
63
+ @socket.send(payload.to_json)
49
64
  end
50
65
 
51
66
  def ping(options = {})
@@ -114,6 +129,21 @@ module Coinbase
114
129
  def ws_error(event)
115
130
  fail WebsocketError, event.data
116
131
  end
132
+
133
+ def ws_signature(request_path: '/users/self/verify', body: nil, timestamp: nil, method: 'GET')
134
+ raise "timestamp must not be nil" if timestamp.nil?
135
+
136
+ body = body.to_json if body.is_a?(Hash)
137
+ timestamp = Time.now.to_i if !timestamp
138
+ timestamp = timestamp.to_i if timestamp.is_a?(DateTime)
139
+
140
+ what = "#{timestamp}#{method}#{request_path}#{body}";
141
+
142
+ # create a sha256 hmac with the secret
143
+ secret = Base64.decode64(@secret)
144
+ hash = OpenSSL::HMAC.digest('sha256', secret, what)
145
+ Base64.strict_encode64(hash)
146
+ end
117
147
  end
118
148
  end
119
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mxvp-coinbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Duhamel