Class: Ubea::Exchange::HitBtcBase

Inherits:
Base
  • Object
show all
Defined in:
lib/ubea/exchanges/hit_btc_base.rb

Direct Known Subclasses

HitBtcEur, HitBtcUsd

Instance Attribute Summary

Attributes inherited from Base

#last_rtt, #order_book, #updated_at

Instance Method Summary collapse

Methods inherited from Base

#id, #short_name

Instance Method Details

#balanceObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 32

def balance
  balance = get_private("trading/balance")

  balances = balance["balance"]
  if balances.nil?
    p balance
    raise
  end
  fiat = balances.detect { |bal| bal["currency_code"] == fiat_currency }["cash"]
  xbt = balances.detect { |bal| bal["currency_code"] == "BTC" }["cash"]

  OpenStruct.new(
    fiat: Money.new(fiat.to_s, fiat_currency),
    xbt: BigDecimal.new(xbt.to_s),
  ).freeze
end

#exchange_settingsObject

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 10

def exchange_settings
  raise NotImplementedError
end

#fiat_currencyObject



14
15
16
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 14

def fiat_currency
  "EUR"
end

#nameObject



6
7
8
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 6

def name
  "HitBTC (#{fiat_currency})"
end

#open_ordersObject



64
65
66
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 64

def open_orders
  get_private("trading/orders/active")["orders"]
end

#open_orders?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 68

def open_orders?
  !open_orders.empty?
end

#refresh_order_book!Object



22
23
24
25
26
27
28
29
30
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 22

def refresh_order_book!
  json = get_json("https://api.hitbtc.com/api/1/public/BTC#{fiat_currency}/orderbook") or return

  asks = format_asks_bids(json["asks"])
  bids = format_asks_bids(json["bids"])

  mark_as_refreshed
  @order_book = OrderBook.new(asks: asks, bids: bids)
end

#trade!(args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 49

def trade!(args)
  params = {
    clientOrderId: SecureRandom.hex(32),
    symbol: "BTC#{fiat_currency}",
    side: args.fetch(:type),
    price: args.fetch(:price),
    quantity: (BigDecimal.new(args.fetch(:volume)) * 100).to_f.to_s,
    type: "limit",
  }

  Log.debug params
  trade = post_private("trading/new_order", params)
  Log.info trade
end

#trade_feeObject



18
19
20
# File 'lib/ubea/exchanges/hit_btc_base.rb', line 18

def trade_fee
  BigDecimal.new("0.001").freeze # 0.1% - see https://hitbtc.com/fees-and-limits
end