intrinio-realtime 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/intrinio-realtime.rb +33 -21
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2f407c4a6d0106dd796298be25bc1b3ead868b5
4
- data.tar.gz: f56b5baffae68de9c2a4f4b9d400f7d8d40c0186
3
+ metadata.gz: 8497dc68920695f11423732586e634e07a9ca379
4
+ data.tar.gz: 804e72a40fe0508eb811238dc73d4ad87dbd5b4e
5
5
  SHA512:
6
- metadata.gz: 8d565d209e22ee9528429f1f2c56797463dfaec55e1e2a386c50cbc3858b2bd02075fde2206e5c81ec083d3672a551a3f8c7f8b46b1fd8a34998eaed07517185
7
- data.tar.gz: 205ad51869711a39efa5c0234cc6a61258f8153a4a074f249afbbfc73d1c71d9589f2e12f71ccc6c3b84fd26ec9f5ec5fa1d8a7247dc8d4034eea57221f88e0d
6
+ metadata.gz: 57f5a46f51a43f1d1f78bca21469d36792677aa076b6382c95a06dc840f604a5c02c4dca8d1d3edb02236ad50a224dd92085333867e8dbb43c19733ab4f92ce3
7
+ data.tar.gz: 59492a3113360407b9ee253956a7f05c2c71e6760a232740fc109802efdc3ce072588ecc9630b3fbc4e019d579872b1d4f1db6e83f93342020ed0f6bfa7e5e7a
@@ -11,7 +11,8 @@ module Intrinio
11
11
  IEX = "iex".freeze
12
12
  QUODD = "quodd".freeze
13
13
  CRYPTOQUOTE = "cryptoquote".freeze
14
- PROVIDERS = [IEX, QUODD, CRYPTOQUOTE].freeze
14
+ FXCM = "fxcm".freeze
15
+ PROVIDERS = [IEX, QUODD, CRYPTOQUOTE, FXCM].freeze
15
16
 
16
17
  def self.connect(options, &b)
17
18
  EM.run do
@@ -36,7 +37,7 @@ module Intrinio
36
37
  end
37
38
 
38
39
  @provider = options[:provider]
39
- raise "Provider must be 'quodd' or 'iex'" unless PROVIDERS.include?(@provider)
40
+ raise "Provider must be 'CRYPTOQUOTE', 'FXCM', 'IEX', or 'QUODD'" unless PROVIDERS.include?(@provider)
40
41
 
41
42
  @channels = []
42
43
  @channels = parse_channels(options[:channels]) if options[:channels]
@@ -152,6 +153,7 @@ module Intrinio
152
153
  when IEX then url = "https://realtime.intrinio.com/auth"
153
154
  when QUODD then url = "https://api.intrinio.com/token?type=QUODD"
154
155
  when CRYPTOQUOTE then url = "https://crypto.intrinio.com/auth"
156
+ when FXCM then url = "https://fxcm.intrinio.com/auth"
155
157
  end
156
158
 
157
159
  url = api_auth_url(url) if @api_key
@@ -174,6 +176,7 @@ module Intrinio
174
176
  when IEX then URI.escape("wss://realtime.intrinio.com/socket/websocket?vsn=1.0.0&token=#{@token}")
175
177
  when QUODD then URI.escape("wss://www5.quodd.com/websocket/webStreamer/intrinio/#{@token}")
176
178
  when CRYPTOQUOTE then URI.escape("wss://crypto.intrinio.com/socket/websocket?vsn=1.0.0&token=#{@token}")
179
+ when FXCM then URI.escape("wss://fxcm.intrinio.com/socket/websocket?vsn=1.0.0&token=#{@token}")
177
180
  end
178
181
  end
179
182
 
@@ -190,7 +193,7 @@ module Intrinio
190
193
  ws.on :open do
191
194
  me.send :info, "Connection established"
192
195
  me.send :ready, true
193
- if me.send(:provider) == IEX || me.send(:provider) == CRYPTOQUOTE
196
+ if [IEX, CRYPTOQUOTE, FXCM].include?(me.send(:provider))
194
197
  me.send :refresh_channels
195
198
  end
196
199
  me.send :start_heartbeat
@@ -204,22 +207,31 @@ module Intrinio
204
207
  begin
205
208
  json = JSON.parse(message)
206
209
 
207
- quote = case me.send(:provider)
208
- when IEX
209
- if json["event"] == "quote"
210
- json["payload"]
211
- end
212
- when QUODD
213
- if json["event"] == "info" && json["data"]["message"] == "Connected"
214
- me.send :refresh_channels
215
- elsif json["event"] == "quote" || json["event"] == "trade"
216
- json["data"]
217
- end
218
- when CRYPTOQUOTE
219
- if json["event"] == "book_update" || json["event"] == "ticker" || json["event"] == "trade"
220
- json["payload"]
221
- end
210
+ if json["event"] == "phx_reply" && json["payload"]["status"] == "error"
211
+ me.send :error, json["payload"]["response"]
222
212
  end
213
+
214
+ quote =
215
+ case me.send(:provider)
216
+ when IEX
217
+ if json["event"] == "quote"
218
+ json["payload"]
219
+ end
220
+ when QUODD
221
+ if json["event"] == "info" && json["data"]["message"] == "Connected"
222
+ me.send :refresh_channels
223
+ elsif json["event"] == "quote" || json["event"] == "trade"
224
+ json["data"]
225
+ end
226
+ when CRYPTOQUOTE
227
+ if json["event"] == "book_update" || json["event"] == "ticker" || json["event"] == "trade"
228
+ json["payload"]
229
+ end
230
+ when FXCM
231
+ if json["event"] == "price_update"
232
+ json["payload"]
233
+ end
234
+ end
223
235
 
224
236
  if quote && quote.is_a?(Hash)
225
237
  me.send :process_quote, quote
@@ -279,7 +291,7 @@ module Intrinio
279
291
  case @provider
280
292
  when IEX then {topic: 'phoenix', event: 'heartbeat', payload: {}, ref: nil}.to_json
281
293
  when QUODD then {event: 'heartbeat', data: {action: 'heartbeat', ticker: (Time.now.to_f * 1000).to_i}}.to_json
282
- when CRYPTOQUOTE then {topic: 'phoenix', event: 'heartbeat', payload: {}, ref: nil}.to_json
294
+ when CRYPTOQUOTE, FXCM then {topic: 'phoenix', event: 'heartbeat', payload: {}, ref: nil}.to_json
283
295
  end
284
296
  end
285
297
 
@@ -376,7 +388,7 @@ module Intrinio
376
388
  action: "subscribe"
377
389
  }
378
390
  }
379
- when CRYPTOQUOTE
391
+ when CRYPTOQUOTE, FXCM
380
392
  {
381
393
  topic: channel,
382
394
  event: "phx_join",
@@ -403,7 +415,7 @@ module Intrinio
403
415
  action: "unsubscribe"
404
416
  }
405
417
  }
406
- when CRYPTOQUOTE
418
+ when CRYPTOQUOTE, FXCM
407
419
  {
408
420
  topic: channel,
409
421
  event: "phx_leave",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intrinio-realtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Intrinio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-29 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http