Class: Wazirx::Client::WebSocket
- Inherits:
-
Object
- Object
- Wazirx::Client::WebSocket
- Defined in:
- lib/wazirx_official/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'
Instance Method Summary collapse
- #all_market_ticker(id: 0, action: SUBSCRIBE) ⇒ Object
- #depth(symbol:, id: 0, action: SUBSCRIBE) ⇒ Object
-
#initialize(api_key = '', secret_key = '') ⇒ WebSocket
constructor
A new instance of WebSocket.
- #multi_stream(streams:, id: 0, action: SUBSCRIBE) ⇒ Object
- #subscribe(streams: [], id: 0, auth_key: '') ⇒ Object
- #trades(symbol:, id: 0, action: SUBSCRIBE) ⇒ Object
- #unsubscribe(streams: [], id: 0, auth_key: '') ⇒ Object
- #user_stream(streams:, id: 0, action: SUBSCRIBE) ⇒ Object
Constructor Details
#initialize(api_key = '', secret_key = '') ⇒ WebSocket
Returns a new instance of WebSocket.
13 14 15 16 |
# File 'lib/wazirx_official/client/websocket.rb', line 13 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) ⇒ Object
23 24 25 26 |
# File 'lib/wazirx_official/client/websocket.rb', line 23 def all_market_ticker(id: 0,action:SUBSCRIBE) stream = ["!ticker@arr"] create_stream(streams: stream, id: id, action: action) end |
#depth(symbol:, id: 0, action: SUBSCRIBE) ⇒ Object
28 29 30 31 |
# File 'lib/wazirx_official/client/websocket.rb', line 28 def depth(symbol:, id: 0, action:SUBSCRIBE) stream = get_mapped_streams(symbol, 'depth') create_stream(streams: stream, id: id, action: action) end |
#multi_stream(streams:, id: 0, action: SUBSCRIBE) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wazirx_official/client/websocket.rb', line 37 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
48 49 50 |
# File 'lib/wazirx_official/client/websocket.rb', line 48 def subscribe(streams:[], id:0, auth_key:'') puts subscribeEvent(streams, id, auth_key) end |
#trades(symbol:, id: 0, action: SUBSCRIBE) ⇒ Object
18 19 20 21 |
# File 'lib/wazirx_official/client/websocket.rb', line 18 def trades(symbol:, id: 0, action:SUBSCRIBE) stream = get_mapped_streams(symbol, 'trades') create_stream(streams: stream, id: id, action: action) end |
#unsubscribe(streams: [], id: 0, auth_key: '') ⇒ Object
52 53 54 |
# File 'lib/wazirx_official/client/websocket.rb', line 52 def unsubscribe(streams:[], id:0, auth_key:'') puts unsubscribeEvent(streams, id, auth_key) end |
#user_stream(streams:, id: 0, action: SUBSCRIBE) ⇒ Object
33 34 35 |
# File 'lib/wazirx_official/client/websocket.rb', line 33 def user_stream(streams:, id: 0, action: SUBSCRIBE) create_stream(streams: streams, id: id, action: action, auth_key: get_auth_key) end |