bitstamp-client 0.1.0 → 0.2.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: 277a98625be62200060a4f297f2f2bc7bb29afa6
4
- data.tar.gz: 709f85f9b64331d4fee44c47bf9b8273ca52a389
3
+ metadata.gz: 68718e31ee993310d025891b8900eb9eab314ac7
4
+ data.tar.gz: 3f0cc7a9f8ec7b939951f8de45bde8357a696ea9
5
5
  SHA512:
6
- metadata.gz: e96ba05efb1ea4eb4b62dff5974060a0cc8bf4e1b118f5f8a3555554f5b3577a184076f1e6366166da5fe6bce6b0c3a5cede411a0e65f03fe62e75d9b8de7ba2
7
- data.tar.gz: ff6473e3df8d94e583c35dc327e36ae7d7f02863c72c477e7b2ff48a5bff6f2e042e346a91b7c431b93b71f657d59a537375473fb7e1e1ddc215f341a9feaa86
6
+ metadata.gz: f0fae35f3bb75f5bbde75dd5e391df478446b6cdf7b5597fdbd3331ce9a51c732c868653818cfbbc015db5ba4e6d74e64125e87610e12296ac931ec609440138
7
+ data.tar.gz: 65b74db6cc22aa81c52dae6f24b8b027f92bece7d65e7136f2efaab609ae5549fddbdc652149bb9dab57d5499651d6d5fdd2f02afecef9b2726852022c8141fe
data/lib/bitstamp.rb CHANGED
@@ -1,2 +1,3 @@
1
- require_relative './bitstamp/version'
2
1
  require_relative './bitstamp/client'
2
+ require_relative './bitstamp/version'
3
+ require_relative './bitstamp/websocket'
@@ -1,3 +1,3 @@
1
1
  module Bitstamp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,67 @@
1
+ require 'faye/websocket'
2
+ require 'eventmachine'
3
+ require 'json'
4
+
5
+ module Bitstamp
6
+ class Websocket
7
+ BASE_URI = 'wss://ws.pusherapp.com/app/de504dc5763aeef9ff52'
8
+ CLIENT_ID = 'bitstamp-client'
9
+ PROTOCOL = 7
10
+ PARAMS = "?#{CLIENT_ID}&version=#{Bitstamp::VERSION}&protocol=#{PROTOCOL}"
11
+
12
+ def initialize(logger)
13
+ @logger = logger
14
+ end
15
+
16
+ def live_trades(currency_pair:, &block)
17
+ channel = "live_trades_#{currency_pair}"
18
+ event = 'trade'
19
+
20
+ listen(channel, event, block)
21
+ end
22
+
23
+ private
24
+
25
+ def listen(channel, event, block)
26
+ EM.run do
27
+ websocket = Faye::WebSocket::Client.new(BASE_URI + PARAMS)
28
+
29
+ websocket.on(:open) do |message|
30
+ subscribe(websocket, channel)
31
+ @logger.debug("Opened connection and subscribed to #{channel}")
32
+ end
33
+
34
+ websocket.on(:message) do |message|
35
+ parsed_message = JSON.parse(message.data)
36
+
37
+ case parsed_message.fetch('event')
38
+ when event
39
+ data = JSON.parse(parsed_message.fetch('data'))
40
+ block.call(data)
41
+ when 'pusher:connection_established'
42
+ @logger.debug('Connection established')
43
+ when 'pusher_internal:subscription_succeeded'
44
+ @logger.debug("Subscription to channel '#{channel}' succeeded")
45
+ else
46
+ @logger.debug("Received unhandled message: #{message.data.to_s}")
47
+ end
48
+ end
49
+
50
+ websocket.on(:close) do |message|
51
+ @logger.debug("Closed websocket connection: #{message.data.to_s}")
52
+
53
+ return
54
+ end
55
+ end
56
+ end
57
+
58
+ def subscribe(websocket, channel)
59
+ subscribe_message = {
60
+ event: "pusher:subscribe",
61
+ data: { channel: channel }
62
+ }
63
+
64
+ websocket.send(subscribe_message.to_json)
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitstamp-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -84,6 +84,66 @@ dependencies:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
86
  version: 0.8.2
87
+ - !ruby/object:Gem::Dependency
88
+ name: eventmachine
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '1.2'
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.0
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.2'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.2.0
107
+ - !ruby/object:Gem::Dependency
108
+ name: faye
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.2'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 1.2.0
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.2'
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 1.2.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: json
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '2.1'
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.1.0
137
+ type: :runtime
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '2.1'
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 2.1.0
87
147
  - !ruby/object:Gem::Dependency
88
148
  name: typhoeus
89
149
  requirement: !ruby/object:Gem::Requirement
@@ -125,6 +185,7 @@ files:
125
185
  - lib/bitstamp/transactions.rb
126
186
  - lib/bitstamp/user_transactions.rb
127
187
  - lib/bitstamp/version.rb
188
+ - lib/bitstamp/websocket.rb
128
189
  - lib/bitstamp/withdrawal.rb
129
190
  homepage: https://github.com/tobischo/bitstamp
130
191
  licenses: