class Cryptopia::Api::Market
Constants
- AVAILABLE_PARAMS
Public Class Methods
new(uri)
click to toggle source
# File lib/cryptopia/api/market.rb, line 14 def initialize(uri) self.class.base_uri uri end
Public Instance Methods
all(options = {})
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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
Private Instance Methods
endpoint_call_handler(url, options = {})
click to toggle source
# File lib/cryptopia/api/market.rb, line 78 def endpoint_call_handler(url, options = {}) if options.keys.length.zero? self.class.get(url) else self.class.get("#{url}/#{options.values.join('/')}") end end
invalid_params?(endpoint, options = {})
click to toggle source
# File lib/cryptopia/api/market.rb, line 86 def invalid_params?(endpoint, options = {}) return false if options.keys.length.zero? (options.keys - AVAILABLE_PARAMS[endpoint]).length >= 1 end
params(endpoint)
click to toggle source
# File lib/cryptopia/api/market.rb, line 96 def params(endpoint) AVAILABLE_PARAMS[endpoint].join(' or ') end
valid_market?(market)
click to toggle source
# File lib/cryptopia/api/market.rb, line 92 def valid_market?(market) market.nil? || (market != nil && market == '') end