Class: Ubea::Exchange::BtcEBase

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

Direct Known Subclasses

BtcEEur, BtcEUsd

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
# File 'lib/ubea/exchanges/btc_e_base.rb', line 32

def balance
  balance = post_private("getInfo")

  OpenStruct.new(
    fiat: Money.new(balance["funds"][fiat_currency.downcase].to_s, fiat_currency),
    xbt: BigDecimal.new(balance["funds"]["btc"].to_s),
  ).freeze
end

#exchange_settingsObject

Raises:

  • (NotImplementedError)


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

def exchange_settings
  raise NotImplementedError
end

#fiat_currencyObject

Raises:

  • (NotImplementedError)


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

def fiat_currency
  raise NotImplementedError
end

#nameObject



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

def name
  "BTC-E (#{fiat_currency})"
end

#open_ordersObject



54
55
56
# File 'lib/ubea/exchanges/btc_e_base.rb', line 54

def open_orders
  post_private("ActiveOrders", {}, false)
end

#open_orders?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/ubea/exchanges/btc_e_base.rb', line 58

def open_orders?
  open_orders["error"] != "no orders"
end

#refresh_order_book!Object



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

def refresh_order_book!
  json = get_json("https://btc-e.com/api/2/btc_#{fiat_currency.downcase}/depth") 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



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ubea/exchanges/btc_e_base.rb', line 41

def trade!(args)
  params = {
    pair: "btc_#{fiat_currency.downcase}",
    type: args.fetch(:type),
    rate: args.fetch(:price),
    amount: args.fetch(:volume),
  }

  Log.debug params
  trade = post_private("Trade", params)
  Log.info trade
end

#trade_feeObject



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

def trade_fee
  BigDecimal.new("0.002").freeze # 0.2%
end