Class: Binance::Api::MarketStream

Inherits:
Object
  • Object
show all
Defined in:
lib/binance/api/market_stream.rb

Class Method Summary collapse

Class Method Details

.connect(api_key: nil, api_secret_key: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/binance/api/market_stream.rb', line 5

def connect(api_key: nil, api_secret_key: nil)
  EM.run {
    ws = Faye::WebSocket::Client.new("wss://stream.binance.com:9443/stream?streams=<streamName1>/<streamName2>/<streamName3>")

    ws.on :open do |event|
      p [:open]
      ws.send("Hello, world!")
    end

    ws.on :message do |event|
      p [:message, event.data]
    end

    ws.on :close do |event|
      p [:close, event.code, event.reason]
      ws = nil
    end
  }
end

.keepalive!(listen_key: nil, api_key: nil, api_secret_key: nil) ⇒ Object

It’s recommended to send a ping about every 30 minutes.

Raises:



26
27
28
29
30
# File 'lib/binance/api/market_stream.rb', line 26

def keepalive!(listen_key: nil, api_key: nil, api_secret_key: nil)
  raise Error.new(message: "listen_key is required") if listen_key.nil?
  Request.send!(api_key_type: :none, method: :put, path: "/api/v1/userDataStream",
                params: { listenKey: listen_key }, security_type: :user_stream)
end

.start!(api_key: nil, api_secret_key: nil) ⇒ Object



32
33
34
35
# File 'lib/binance/api/market_stream.rb', line 32

def start!(api_key: nil, api_secret_key: nil)
  Request.send!(api_key_type: :none, method: :post, path: "/api/v1/userDataStream",
                security_type: :user_stream, api_key: api_key, api_secret_key: api_secret_key)
end

.stop!(listen_key: nil, api_key: nil, api_secret_key: nil) ⇒ Object

Raises:



37
38
39
40
41
42
# File 'lib/binance/api/market_stream.rb', line 37

def stop!(listen_key: nil, api_key: nil, api_secret_key: nil)
  raise Error.new(message: "listen_key is required") if listen_key.nil?
  Request.send!(api_key_type: :none, method: :delete, path: "/api/v1/userDataStream",
                params: { listenKey: listen_key }, security_type: :user_stream,
                api_key: api_key, api_secret_key: api_secret_key)
end