wazirx 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: 8f3fe59a49d2c88b73a3a7141e5bd5c3c2ee989d1f0e9fc506c957c7186a4272
4
- data.tar.gz: aa28a281b05f1323dae86fccec3b75522d569c6ae998b72116b047c00fe4ecb3
3
+ metadata.gz: 50831a494d7b1403f54eb39b75e1b4b725def789f51105a0a7187f62d9b9e6d5
4
+ data.tar.gz: 8065c9e4ae429997d49a00e2a5b9774ae577e7f3dffef709742660a1275dec87
5
5
  SHA512:
6
- metadata.gz: 8b0783a976b70d1672d4c20a87b5e5fbee6bf7869e5cdd8e8682ddca597cf3568ca18dfec34fe07f9d417536afe349841f4c9809f9ae34d31c8c35e35f547a25
7
- data.tar.gz: 5048809c05a59bbcc7b50e3375fae64f5e1ba490e87cc15bb5e6092ddac6cc9bf7e62969c516f3f6d7ed421415f68417378bf6c0f11241ca53b52878dc42878b
6
+ metadata.gz: e83b1ccbe3b59a819a4ff312a8ab28353f6201053569f0d20f8598fa0a8e6385f7023bfd0967bf213e6af3b2fc43507046d6ce796dbb4db92b531e30ff67972a
7
+ data.tar.gz: 9e05060b90bc35eb64dd5ed1506c7af7c1b9dc8cb1520f02e29c3a2fe71d9b278a523522f0a310a817d71b04bfbb51fc172f6416934b02f4e26d909463b02576
@@ -9,29 +9,30 @@ module Wazirx
9
9
  # Public: String base url for WebSocket client to use
10
10
  BASE_URL = 'wss://stream.wazirx.com/stream'.freeze
11
11
  SUBSCRIBE = 'subscribe'
12
+ UNSUBSCRIBE = 'unsubscribe'
12
13
 
13
14
  def initialize(api_key='', secret_key='')
14
15
  @api_key = api_key
15
16
  @secret_key = secret_key
16
17
  end
17
18
 
18
- def trades(symbol:, id: 0, action:SUBSCRIBE)
19
+ def trades(symbol:, id: 0, action: SUBSCRIBE, methods: {})
19
20
  stream = get_mapped_streams(symbol, 'trades')
20
- create_stream(streams: stream, id: id, action: action)
21
+ create_stream(streams: stream, id: id, action: action, methods: methods)
21
22
  end
22
23
 
23
- def all_market_ticker(id: 0,action:SUBSCRIBE)
24
+ def all_market_ticker(id: 0,action: SUBSCRIBE, methods: {})
24
25
  stream = "!ticker@arr"
25
- create_stream(streams: stream, id: id, action: action)
26
+ create_stream(streams: stream, id: id, action: action, methods: methods)
26
27
  end
27
28
 
28
- def depth(symbol:, id: 0, action:SUBSCRIBE)
29
+ def depth(symbol:, id: 0, action: SUBSCRIBE, methods: {})
29
30
  stream = get_mapped_streams(symbol, 'depth')
30
- create_stream(streams: stream, id: id, action: action)
31
+ create_stream(streams: stream, id: id, action: action, methods: methods)
31
32
  end
32
33
 
33
- def user_stream(streams:, id: 0, action: SUBSCRIBE)
34
- create_stream(streams: streams, id: id, action: action, auth_key: get_auth_key)
34
+ def user_stream(streams:, id: 0, action: SUBSCRIBE, methods: {})
35
+ create_stream(streams: streams, id: id, action: action, methods: methods, auth_key: get_auth_key)
35
36
  end
36
37
 
37
38
  def multi_stream(streams:, id: 0, action: SUBSCRIBE)
@@ -66,21 +67,22 @@ module Wazirx
66
67
  end
67
68
 
68
69
  def subscribeEvent(streams=[], id=0, auth_key='')
69
- @ws.send(JSON.dump({'event':SUBSCRIBE, 'streams':streams.flatten,'id':id, 'auth_key':auth_key}))
70
+ @ws.send(JSON.dump({'event': SUBSCRIBE, 'streams': streams.flatten, 'id': id, 'auth_key': auth_key}))
70
71
  end
71
72
 
72
73
  def unsubscribeEvent(streams=[], id=0, auth_key='')
73
- @ws.send(JSON.dump({'event':'unsubscribe', 'streams':streams.flatten,'id':id}))
74
+ @ws.send(JSON.dump({'event': UNSUBSCRIBE, 'streams': streams.flatten, 'id': id}))
74
75
  end
75
76
 
76
- def create_stream(streams: streams, id: id, action: action, methods: methods, auth_key:'')
77
+ def create_stream(streams: streams, id: id, action: action, methods: {}, auth_key:'')
77
78
  @ws = Faye::WebSocket::Client.new(BASE_URL)
78
79
  @ws.on :open do |event|
79
80
  puts [:open]
80
81
  if action == SUBSCRIBE
81
82
  puts subscribeEvent(streams, id, auth_key)
83
+ methods[:message].call(event)
82
84
  EM.add_periodic_timer 300 do
83
- @ws.ping BASE_URL
85
+ @ws.send('ping', BASE_URL)
84
86
  puts [:message, 'pinged every 5 minutes']
85
87
  end
86
88
  else
@@ -95,6 +97,7 @@ module Wazirx
95
97
 
96
98
  @ws.on :close do |event|
97
99
  puts [:close, event.code, event.reason]
100
+ methods[:message].call(event)
98
101
  @ws = nil
99
102
  end
100
103
  end
@@ -1,3 +1,3 @@
1
1
  module Wazirx
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wazirx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dibyajit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-30 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler