Module: ViaBTC::Helpers

Included in:
ViaBTC::HTTP::Client
Defined in:
lib/viabtc/helpers.rb

Instance Method Summary collapse

Instance Method Details

#amount_valid?(amount) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/viabtc/helpers.rb', line 9

def amount_valid?(amount)
  amount.is_a?(Numeric) && amount.positive? && (amount.is_a?(Integer) || amount.is_a?(Float))
end

#fee_rate_valid?(fee_rate) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/viabtc/helpers.rb', line 13

def fee_rate_valid?(fee_rate)
  (0...1).cover?(fee_rate)
end

#nowObject



17
18
19
# File 'lib/viabtc/helpers.rb', line 17

def now
  Time.now.to_i
end

#raise_exchange_error(response) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/viabtc/helpers.rb', line 21

def raise_exchange_error(response)
  error_code = response["error"]["code"]
  error_message = response["error"]["message"]

  case error_code
  when 1 then raise ViaBTC::Error::InvalidArgument, response
  when 2 then raise ViaBTC::Error::InternalError, response
  when 3 then raise ViaBTC::Error::ServiceUnavailable, response
  when 4 then raise ViaBTC::Error::MethodNotFound, response
  when 5 then raise ViaBTC::Error::ServiceTimeout, response
  when 6 then raise ViaBTC::Error::RequireAuthentication, response
  when 10
    case error_message
    when "balance not enough" then raise ViaBTC::Error::LimitOrderBalanceNotEnough, response
    when "repeat update" then raise ViaBTC::Error::RepeatBalanceUpdate, response
    else raise ViaBTC::Error::ExchangeError, response
    end
  when 11
    case error_message
    when "amount too small" then raise ViaBTC::Error::LimitOrderAmountTooSmall, response
    when "balance not enough" then raise ViaBTC::Error::BalanceNotEnough, response
    end
  when 12 then raise ViaBTC::Error::LimitOrderNoEnoughTrader, response
  else raise ViaBTC::Error::ExchangeError, response
  end
end

#response_invalid?(response) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/viabtc/helpers.rb', line 5

def response_invalid?(response)
  !response["error"].nil?
end