Class: Cryptopia::Api::Market

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cryptopia/api/market.rb

Constant Summary collapse

AVAILABLE_PARAMS =
{
  markets: [:baseParam, :hours],
  market: [:hours],
  history: [:hours],
  orders: [:orderCount],
  order_groups: [:orderCount]
}

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Market

Returns a new instance of Market.



14
15
16
# File 'lib/cryptopia/api/market.rb', line 14

def initialize(uri)
  self.class.base_uri uri
end

Instance Method Details

#all(options = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/cryptopia/api/market.rb', line 18

def all(options = {})
  if invalid_params?(:markets, options)
    raise ArgumentError, "Arguments must be #{params(:markets)}"
  end

  endpoint_call_handler("/GetMarkets", options)
end

#find(market, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cryptopia/api/market.rb', line 26

def find(market, options = {})
  if valid_market?(market)
    raise ArgumentError, 'The trade pair must be informed'
  end

  if invalid_params?(:market, options)
    raise ArgumentError, "Arguments must be #{params(:market)}"
  end

  endpoint_call_handler("/GetMarket/#{market}", options)
end

#history(market, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cryptopia/api/market.rb', line 38

def history(market, options = {})
  if valid_market?(market)
    raise ArgumentError, 'The trade pair must be informed'
  end

  if invalid_params?(:history, options)
    raise ArgumentError, "Arguments must be #{params(:history)}"
  end

  endpoint_call_handler("/GetMarketHistory/#{market}", options)
end

#order_groups(markets = [], options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cryptopia/api/market.rb', line 62

def order_groups(markets = [], options = {})
  if markets.nil? || (!markets.nil? && markets.empty?)
    raise ArgumentError, 'The trade pairs must be informed'
  end

  if invalid_params?(:order_groups, options)
    raise ArgumentError, "Arguments must be #{params(:order_groups)}"
  end

  handled_markets = markets.join('-')

  endpoint_call_handler("/GetMarketOrderGroups/#{handled_markets}", options)
end

#orders(market, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cryptopia/api/market.rb', line 50

def orders(market, options = {})
  if valid_market?(market)
    raise ArgumentError, 'The trade pair must be informed'
  end

  if invalid_params?(:orders, options)
    raise ArgumentError, "Arguments must be #{params(:orders)}"
  end

  endpoint_call_handler("/GetMarketOrders/#{market}", options)
end