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
#initialize(api_key: nil, secret_key: nil) ⇒ WS
Returns a new instance of WS.
5 6 7 8 9 |
# File 'lib/okcoin/ws.rb', line 5 def initialize(api_key: nil, secret_key: nil) @driver = Celluloid::WebSocket::Client.new(BASE_URI, Celluloid::Actor.current) @api_key = api_key @secret_key = secret_key end |
Instance Method Details
#close ⇒ Object
close WebSocket connection
30 31 32 |
# File 'lib/okcoin/ws.rb', line 30 def close @driver.close end |
#futures_userinfo ⇒ Object
43 44 45 46 |
# File 'lib/okcoin/ws.rb', line 43 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
23 24 25 26 27 |
# File 'lib/okcoin/ws.rb', line 23 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
18 19 20 |
# File 'lib/okcoin/ws.rb', line 18 def (msg) puts "Message received: #{msg}" end |
#on_open ⇒ Object
When WebSocket is opened, register callbacks
13 14 15 |
# File 'lib/okcoin/ws.rb', line 13 def on_open puts "Websocket connection to #{BASE_URI} established succesfully" end |
#pingpong ⇒ Object
34 35 36 |
# File 'lib/okcoin/ws.rb', line 34 def pingpong every(5){ @driver.text "{'event':'ping'}" } end |
#price_api(data) ⇒ Object
48 49 50 |
# File 'lib/okcoin/ws.rb', line 48 def price_api(data) @driver.text data end |
#userinfo ⇒ Object
38 39 40 41 |
# File 'lib/okcoin/ws.rb', line 38 def userinfo post_data = initial_post_data emit(event: 'addChannel', channel: 'ok_spotusd_userinfo', post_data: post_data) end |