Class: Ubea::Exchange::BitcoinCoIdIdr
- Inherits:
-
Base
- Object
- Base
- Ubea::Exchange::BitcoinCoIdIdr
show all
- Defined in:
- lib/ubea/exchanges/bitcoin_co_id_idr.rb
Constant Summary
collapse
- BadResponseError =
Class.new(Exception)
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
#balance ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 30
def balance
balance = post_private("getInfo")
OpenStruct.new(
fiat: Money.new(balance["balance"][fiat_currency.downcase].to_s, fiat_currency),
xbt: BigDecimal.new(balance["balance"]["btc"].to_s),
).freeze
end
|
#fiat_currency ⇒ Object
12
13
14
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 12
def fiat_currency
"IDR"
end
|
#name ⇒ Object
8
9
10
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 8
def name
"Bitcoin.co.id (#{fiat_currency})"
end
|
#open_orders ⇒ Object
59
60
61
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 59
def open_orders
post_private("openOrders")["orders"]
end
|
#open_orders? ⇒ Boolean
63
64
65
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 63
def open_orders?
!open_orders.nil?
end
|
#refresh_order_book! ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 20
def refresh_order_book!
json = get_json("https://vip.bitcoin.co.id/api/btc_#{fiat_currency.downcase}/depth") or return
asks = format_asks_bids(json["sell"])
bids = format_asks_bids(json["buy"])
mark_as_refreshed
@order_book = OrderBook.new(asks: asks, bids: bids)
end
|
#trade!(args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 39
def trade!(args)
amount_key, amount_value = if args.fetch(:type) == "buy"
idr = Money.new(args.fetch(:price), fiat_currency) * BigDecimal.new(args.fetch(:volume))
[:idr, idr.to_s(with_currency: false)]
else
[:btc, args.fetch(:volume)]
end
params = {
pair: "btc_#{fiat_currency.downcase}",
type: args.fetch(:type),
price: args.fetch(:price),
amount_key => amount_value,
}
Log.debug params
trade = post_private("trade", params)
Log.info trade
end
|
#trade_fee ⇒ Object
16
17
18
|
# File 'lib/ubea/exchanges/bitcoin_co_id_idr.rb', line 16
def trade_fee
BigDecimal.new("0.003").freeze end
|