wazirx 1.0.1 → 1.0.4

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
  SHA256:
3
- metadata.gz: 202c04f431dbe03f2f8246d77e71bc061e7f3436b2518f756569661c926c5d4c
4
- data.tar.gz: 45ab7233b6eef9ed845c11ef5db3a12eaa0face74108e5c79ec27f59d5d4e78d
3
+ metadata.gz: 01c782f112885c2acdc69e8702285ddfba65affea3905b9d6db70418b69d6079
4
+ data.tar.gz: f22e877e2871543b3d3ac8c6ed417b7582c302f4e014be06ba9f4ec04127a178
5
5
  SHA512:
6
- metadata.gz: 0959115fd4127b6baf7da074568c3acd767c8dd18d68c6a50996345a4503d174c55f40547e64671062b9188f1e9389325299fa27aca89b80b88514cc33029a64
7
- data.tar.gz: 59d761aad842d32d4262b4dc47b34662c0fbbf00ca6acb17e475207e19e7d25b2d376b434696064c06368a8fdea18564a033f7bc80d8a2e615032fe78c18272d
6
+ metadata.gz: b8d23e24f0020484a5f253bcf8bafd32b6dccfca0a904e96ad6da60bf39044912e69a4af15e33118608d5600450667f63baae83e9ed78406ddf8a331789724a2
7
+ data.tar.gz: d36ff416c540bc43bad33c3151459c792f49fab19fb7067ff7ec20efedac924efc59f8058a71703119bf27ba050d2df70fe733a212fe8b2454d637fea27c8435
@@ -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,19 +67,23 @@ 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, auth_key:'')
77
- @ws = Faye::WebSocket::Client.new(BASE_URL)
77
+ def create_stream(streams:, id:, action:, methods: {}, auth_key: '')
78
+ @ws = Faye::WebSocket::Client.new(BASE_URL, nil)
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
+ EM.add_periodic_timer 300 do
84
+ @ws.send('ping')
85
+ puts [:message, 'Pinging websocket every 5 minutes']
86
+ end
82
87
  else
83
88
  puts unsubscribeEvent(streams, id, auth_key)
84
89
  end
@@ -86,6 +91,7 @@ module Wazirx
86
91
 
87
92
  @ws.on :message do |event|
88
93
  puts [:message, JSON.load(event.data)]
94
+ methods[:message].call(event)
89
95
  end
90
96
 
91
97
  @ws.on :close do |event|
@@ -1,3 +1,3 @@
1
1
  module Wazirx
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.4'.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.1
4
+ version: 1.0.4
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-22 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.0.9
134
+ rubygems_version: 3.0.3.1
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: API Wrapper for the Wazirx cryptocurrency exchange.