Class: Wazirx::Client::WebSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/wazirx/client/websocket.rb

Overview

Public: Client with methods mirroring the Wazirx WebSocket API

Constant Summary collapse

BASE_URL =

Public: String base url for WebSocket client to use

'wss://stream.wazirx.com/stream'.freeze
SUBSCRIBE =
'subscribe'
UNSUBSCRIBE =
'unsubscribe'

Instance Method Summary collapse

Constructor Details

#initialize(api_key = '', secret_key = '') ⇒ WebSocket

Returns a new instance of WebSocket.



14
15
16
17
# File 'lib/wazirx/client/websocket.rb', line 14

def initialize(api_key='', secret_key='')
  @api_key = api_key
  @secret_key = secret_key
end

Instance Method Details

#all_market_ticker(id: 0, action: SUBSCRIBE, methods: {}) ⇒ Object



24
25
26
27
# File 'lib/wazirx/client/websocket.rb', line 24

def all_market_ticker(id: 0,action: SUBSCRIBE, methods: {})
  stream = "!ticker@arr"
  create_stream(streams: stream, id: id, action: action, methods: methods)
end

#depth(symbol:, id: 0, action: SUBSCRIBE, methods: {}) ⇒ Object



29
30
31
32
# File 'lib/wazirx/client/websocket.rb', line 29

def depth(symbol:, id: 0, action: SUBSCRIBE, methods: {})
  stream = get_mapped_streams(symbol, 'depth')
  create_stream(streams: stream, id: id, action: action, methods: methods)
end

#multi_stream(streams:, id: 0, action: SUBSCRIBE) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/wazirx/client/websocket.rb', line 38

def multi_stream(streams:, id: 0, action: SUBSCRIBE)
  return "Streams should be an array!" if streams.class != Array
  format_stream = []
  streams.each do | stream |
    format_stream += get_mapped_streams(stream[:symbol], stream[:type]) if stream[:type].to_s == 'trades'
    format_stream += get_mapped_streams(stream[:symbol], stream[:type]) if stream[:type].to_s == 'depth'
    format_stream << "!ticker@arr" if stream[:type].to_s == 'ticker'
  end
  create_stream(streams: format_stream, id: id, action: action)
end

#subscribe(streams: [], id: 0, auth_key: '') ⇒ Object



49
50
51
# File 'lib/wazirx/client/websocket.rb', line 49

def subscribe(streams:[], id:0, auth_key:'')
  puts subscribeEvent(streams, id, auth_key)
end

#trades(symbol:, id: 0, action: SUBSCRIBE, methods: {}) ⇒ Object



19
20
21
22
# File 'lib/wazirx/client/websocket.rb', line 19

def trades(symbol:, id: 0, action: SUBSCRIBE, methods: {})
  stream = get_mapped_streams(symbol, 'trades')
  create_stream(streams: stream, id: id, action: action, methods: methods)
end

#unsubscribe(streams: [], id: 0, auth_key: '') ⇒ Object



53
54
55
# File 'lib/wazirx/client/websocket.rb', line 53

def unsubscribe(streams:[], id:0, auth_key:'')
  puts unsubscribeEvent(streams, id, auth_key)
end

#user_stream(streams:, id: 0, action: SUBSCRIBE, methods: {}) ⇒ Object



34
35
36
# File 'lib/wazirx/client/websocket.rb', line 34

def user_stream(streams:, id: 0, action: SUBSCRIBE, methods: {})
  create_stream(streams: streams, id: id, action: action, methods: methods, auth_key: get_auth_key)
end