Class: Bitmex::Chat

Inherits:
Base
  • Object
show all
Defined in:
lib/bitmex/chat.rb

Overview

Trollbox Data

Author:

  • Iulian Costan

Instance Attribute Summary

Attributes inherited from Base

#rest, #websocket

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bitmex::Base

Instance Method Details

#channelsArray

Get available channels

Returns:

  • (Array)

    the available channels



25
26
27
# File 'lib/bitmex/chat.rb', line 25

def channels
  rest.get chat_path(:channels)
end

#messages(options = { count: 100, reverse: true }) {|Hash| ... } ⇒ Array

Get chat messages

Examples:

Get last 10 messages for channel 1

messages = client.chat.messages channelID: 1, count: 10, reverse: true

Parameters:

  • options (Hash) (defaults to: { count: 100, reverse: true })

    options to filter by

Options Hash (options):

  • :count (Integer) — default: 100

    number of results to fetch.

  • :start (Integer)

    starting ID for results

  • :reverse (Boolean)

    If true, will sort results newest first

  • :channelID (Integer)

    Channel id. GET /chat/channels for ids. Leave blank for all.

Yields:

  • (Hash)

    the message

Returns:

  • (Array)

    the messages



15
16
17
18
19
20
21
# File 'lib/bitmex/chat.rb', line 15

def messages(options = { count: 100, reverse: true }, &ablock)
  if block_given?
    websocket.listen chat: options[:channelID], &ablock
  else
    rest.get chat_path, params: options
  end
end

#send(message, options = { channelID: 1 }) ⇒ Object

Send a chat message

Parameters:

  • message (String)

    the message to send

  • options (Hash) (defaults to: { channelID: 1 })

    filter options

Options Hash (options):

  • :channelID (Integer) — default: 1

    channel to post to



44
45
46
47
# File 'lib/bitmex/chat.rb', line 44

def send(message, options = { channelID: 1 })
  params = { message: message, channelID: options[:channelID] }
  rest.post chat_path, params: params
end

#stats {|Hash| ... } ⇒ Bitmex::Mash

Get connected users

Yields:

  • (Hash)

    the stats

Returns:

  • (Bitmex::Mash)

    an array with browser users in the first position and API users (bots) in the second position.



32
33
34
35
36
37
38
# File 'lib/bitmex/chat.rb', line 32

def stats(&ablock)
  if block_given?
    websocket.listen connected: nil, &ablock
  else
    rest.get chat_path(:connected)
  end
end