Class: Watchcow::MarketDepth

Inherits:
Object
  • Object
show all
Defined in:
lib/watchcow/market_depth.rb

Constant Summary collapse

URLDM =
"https://api.hbdm.com/market/depth"
URLPRO =
"https://api.huobi.pro/market/depth"

Class Method Summary collapse

Class Method Details

.call(params:, k:) ⇒ Object

Spot market or Futures market all goes here



9
10
11
12
# File 'lib/watchcow/market_depth.rb', line 9

def call(params:, k:)
  url = target_url(params, k)
  HTTParty.get(url)
end

.prepared_params(params, k) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/watchcow/market_depth.rb', line 14

def prepared_params(params, k)
  return '' if params.nil?
  step =
    if k == :future
      "&type=step6"
    else
      "&type=step2"
    end
  arr = []
  params.each_pair do |k,v|
    arr.push "#{k}=#{v}"
  end
  return "#{arr.join('&')}#{step}"
end

.target_url(params, k) ⇒ Object



29
30
31
32
# File 'lib/watchcow/market_depth.rb', line 29

def target_url(params, k)
  prefix = k == :future ? URLDM : URLPRO
  "#{prefix}?#{prepared_params(params, k)}"
end