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 =

Patterns are unanchored (except regional_restriction) because the consumer may pass a sentence-joined error string. transient_nonce is matched first as it is the more specific/actionable case.

[
  {
    code: :regional_restriction,
    pattern: /\AEAccount:Invalid permissions:(?<asset>\S+) trading restricted for (?<country>\w+)\.?\z/
  },
  {
    code: :transient_nonce,
    pattern: /EAPI:Invalid nonce/
  },
  {
    code: :transient_unavailable,
    pattern: /EGeneral:Internal error|EService:(?:Unavailable|Busy|Deadline elapsed)/
  }
].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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/honeymaker/exchanges/kraken.rb', line 80

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/honeymaker/exchanges/kraken.rb', line 49

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