Class: Honeymaker::Exchanges::Kraken

Inherits:
Honeymaker::Exchange show all
Defined in:
lib/honeymaker/exchanges/kraken.rb

Constant Summary collapse

BASE_URL =
"https://api.kraken.com"
ASSET_BLACKLIST =
[
  "COPM" # has the same external_id (ecomi) as OMI
].freeze
ERROR_PATTERNS =
[
  {
    code: :regional_restriction,
    pattern: /\AEAccount:Invalid permissions:(?<asset>\S+) trading restricted for (?<country>\w+)\.?\z/
  }
].freeze
REAL_COSTMIN =
{
  "AUD" => 10,
  "CAD" => 5,
  "CHF" => 5,
  "DAI" => 5,
  "ETH" => 0.002,
  "EUR" => 0.5,
  "GBP" => 5,
  "JPY" => 500,
  "PYUSD" => 5,
  "RLUSD" => 5,
  "USD" => 5,
  "USDC" => 5,
  "USDQ" => 5,
  "USDR" => 5,
  "USDT" => 5,
  "XBT" => 0.00005
}.freeze

Constants inherited from Honeymaker::Exchange

Honeymaker::Exchange::OPTIONS

Instance Method Summary collapse

Methods inherited from Honeymaker::Exchange

#cache_ttl, #classify_error, #find_ticker, #get_price, #symbols, #tickers_info

Instance Method Details

#get_bid_ask(symbol) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/honeymaker/exchanges/kraken.rb', line 69

def get_bid_ask(symbol)
  with_rescue do
    response = connection.get("/0/public/Ticker") do |req|
      req.params = { pair: symbol }
    end

    error = response.body["error"]
    raise StandardError, error.first if error.is_a?(Array) && error.any?

    _key, data = response.body["result"].first
    {
      bid: BigDecimal(data["b"][0]),
      ask: BigDecimal(data["a"][0])
    }
  end
end

#get_tickers_infoObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/honeymaker/exchanges/kraken.rb', line 38

def get_tickers_info
  with_rescue do
    response = connection.get("/0/public/AssetPairs")

    error = response.body["error"]
    return Result::Failure.new(*error) if error.is_a?(Array) && error.any?

    response.body["result"].filter_map do |_, info|
      wsname = info["wsname"]
      next unless wsname && !wsname.empty?

      base, quote = wsname.split("/")

      {
        ticker: info["altname"],
        base: base,
        quote: quote,
        minimum_base_size: info["ordermin"],
        minimum_quote_size: (REAL_COSTMIN[quote] || info["costmin"] || 0).to_s,
        maximum_base_size: nil,
        maximum_quote_size: nil,
        base_decimals: info["lot_decimals"],
        quote_decimals: info["cost_decimals"],
        price_decimals: info["pair_decimals"],
        available: true,
        trading_enabled: info.key?("status") ? info["status"] == "online" : true
      }
    end
  end
end