Class: Okcoin::WS
Constant Summary collapse
- BASE_URI =
'wss://real.okcoin.com:10440/websocket/okcoinapi'
Instance Method Summary collapse
-
#close ⇒ Object
close WebSocket connection.
- #futures_userinfo ⇒ Object
-
#initialize(api_key: nil, secret_key: nil) ⇒ WS
constructor
A new instance of WS.
-
#on_close(code, reason) ⇒ Object
When WebSocket is closed.
-
#on_message(msg) ⇒ Object
When raw WebSocket message is received.
-
#on_open ⇒ Object
When WebSocket is opened, register callbacks.
- #pingpong ⇒ Object
- #price_api(data) ⇒ Object
- #userinfo ⇒ Object
Constructor Details
Instance Method Details
#close ⇒ Object
close WebSocket connection
31 32 33 |
# File 'lib/okcoin/ws.rb', line 31 def close @driver.close end |
#futures_userinfo ⇒ Object
44 45 46 47 |
# File 'lib/okcoin/ws.rb', line 44 def futures_userinfo post_data = initial_post_data emit(event: 'addChannel', channel: 'ok_futureusd_userinfo', post_data: post_data) end |
#on_close(code, reason) ⇒ Object
When WebSocket is closed
24 25 26 27 28 |
# File 'lib/okcoin/ws.rb', line 24 def on_close(code, reason) puts "WebSocket connection closed: #{code.inspect}, #{reason.inspect}" @driver.terminate terminate end |
#on_message(msg) ⇒ Object
When raw WebSocket message is received
19 20 21 |
# File 'lib/okcoin/ws.rb', line 19 def (msg) puts "Message received: #{msg}" end |
#on_open ⇒ Object
When WebSocket is opened, register callbacks
14 15 16 |
# File 'lib/okcoin/ws.rb', line 14 def on_open puts "Websocket connection to #{BASE_URI} established succesfully" end |
#pingpong ⇒ Object
35 36 37 |
# File 'lib/okcoin/ws.rb', line 35 def pingpong every(5){ @driver.text "{'event':'ping'}" } end |
#price_api(data) ⇒ Object
49 50 51 |
# File 'lib/okcoin/ws.rb', line 49 def price_api(data) @driver.text data end |
#userinfo ⇒ Object
39 40 41 42 |
# File 'lib/okcoin/ws.rb', line 39 def userinfo post_data = initial_post_data emit(event: 'addChannel', channel: 'ok_spotusd_userinfo', post_data: post_data) end |