Module: Deribit::Naming

Included in:
Client
Defined in:
lib/deribit/naming.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#book_channel(options) ⇒ Object



20
21
22
# File 'lib/deribit/naming.rb', line 20

def book_channel(options)
  'book' + for_instrument(options) + with_group_and_depth(options) + with_interval(options)
end

#by_currency(options) ⇒ Object



52
53
54
# File 'lib/deribit/naming.rb', line 52

def by_currency(options)
  options[:currency] ? '_by_currency' : ''
end

#by_instrument(options) ⇒ Object



48
49
50
# File 'lib/deribit/naming.rb', line 48

def by_instrument(options)
  options[:instrument_name] ? '_by_instrument' : ''
end

#cancel_uri(options) ⇒ Object



40
41
42
# File 'lib/deribit/naming.rb', line 40

def cancel_uri(options)
  '/private/cancel_all' + by_instrument(options) + by_currency(options)
end

#channel(prefix, options) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/deribit/naming.rb', line 24

def channel(prefix, options)
  channel = prefix
  channel += for_instrument(options) if options[:instrument_name]
  channel += for_currency(options) if options[:currency]
  channel += with_interval(options)
  channel
end

#channel_for_instrument(prefix, options) ⇒ Object



32
33
34
# File 'lib/deribit/naming.rb', line 32

def channel_for_instrument(prefix, options)
  prefix + for_instrument(options)
end

#for_currency(options) ⇒ Object



62
63
64
65
66
67
# File 'lib/deribit/naming.rb', line 62

def for_currency(options)
  raise 'currency param is required' unless options[:currency]

  kind = options[:kind] || 'any'
  ".#{kind}.#{options[:currency]}"
end

#for_instrument(options) ⇒ Object



56
57
58
59
60
# File 'lib/deribit/naming.rb', line 56

def for_instrument(options)
  raise 'instrument_name param is required' unless options[:instrument_name]

  ".#{options[:instrument_name]}"
end

#instrument_with_interval(prefix, options) ⇒ Object



36
37
38
# File 'lib/deribit/naming.rb', line 36

def instrument_with_interval(prefix, options)
  prefix + for_instrument(options) + with_interval(options)
end

#orders_uri(options) ⇒ Object



44
45
46
# File 'lib/deribit/naming.rb', line 44

def orders_uri(options)
  '/private/get_open_orders' + by_instrument(options) + by_currency(options)
end

#trades_channel(options) ⇒ Object



6
7
8
9
10
# File 'lib/deribit/naming.rb', line 6

def trades_channel(options)
  private = options.delete :private
  trades = private ? 'user.trades' : 'trades'
  channel trades, options
end

#trades_uri(options) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/deribit/naming.rb', line 12

def trades_uri(options)
  private = options.delete :private
  uri = private ? 'private/get_user_trades' : 'public/get_last_trades'
  uri += by_instrument(options) + by_currency(options)
  uri += options[:end_timestamp] ? '_and_time' : ''
  uri
end

#with_group_and_depth(options) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/deribit/naming.rb', line 74

def with_group_and_depth(options)
  if options[:group] || options[:depth]
    group = options[:group] || '5'
    depth = options[:depth] || '10'
    ".#{group}.#{depth}"
  else
    ''
  end
end

#with_interval(options) ⇒ Object



69
70
71
72
# File 'lib/deribit/naming.rb', line 69

def with_interval(options)
  interval = options[:interval] || '100ms'
  ".#{interval}"
end