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 +4 -4
- data/coinbase-exchange.gemspec +1 -1
- data/lib/coinbase/exchange/websocket.rb +33 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 664990c22a01165c0c8a83bf389fd85319f9891b
|
4
|
+
data.tar.gz: 7dfe475e6b8f04be4fa04ae1c6cc8048ab8fdd24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e1f8abd19268ce7fca31f314c01184f10d527438b626d6637dd976851d42c2c95352e394afbab0a9bef1433bc33d49af47bb56dd844bbb2bcf24167d87ac824
|
7
|
+
data.tar.gz: 2485048ab33aed24f39e244f90649a66692704a13c61c2ea085bc77893bac9cfedbae1f87cca8a0658f3ce700bc8cfff2714b5756311e4b6137dfef35e1b38ee
|
data/coinbase-exchange.gemspec
CHANGED
@@ -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 =
|
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
|
-
@
|
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
|
-
|
48
|
-
|
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
|