Module: Paytunia::Api

Included in:
Connection
Defined in:
lib/paytunia/api/account.rb,
lib/paytunia/api/trading.rb,
lib/paytunia/models/base.rb,
lib/paytunia/models/depth.rb,
lib/paytunia/models/trade.rb,
lib/paytunia/api/transfers.rb,
lib/paytunia/models/ticker.rb,
lib/paytunia/models/trade_order.rb,
lib/paytunia/models/account_operation.rb

Defined Under Namespace

Classes: AccountOperation, Base, Depth, Ticker, Trade, TradeOrder

Instance Method Summary collapse

Instance Method Details

#get_depth(currency = :eur) ⇒ Object

Returns the full market depth



20
21
22
23
24
25
26
27
28
# File 'lib/paytunia/api/trading.rb', line 20

def get_depth(currency = :eur)
  depth = get("/depth/#{currency}").parsed_response

  %w{ bids asks }.each do |category|
    depth[category].map! { |order| Depth.new(order) }
  end

  depth
end

#get_ledgerObject

Returns the list of account operations



5
6
7
8
9
# File 'lib/paytunia/api/account.rb', line 5

def get_ledger
  .get('/account_operations').map do |ao|
    AccountOperation.new(ao)
  end
end

#get_operation(operation_id) ⇒ Object

Returns a single account operation



12
13
14
# File 'lib/paytunia/api/account.rb', line 12

def get_operation(operation_id)
  AccountOperation.new(.get("/account_operations/#{operation_id}"))
end

#get_tickerObject

Returns the ticker



15
16
17
# File 'lib/paytunia/api/trading.rb', line 15

def get_ticker
  Ticker.new(get('/ticker'))
end

#get_trade_order(uuid) ⇒ Object

Gets a trade order

Attributes

  • trade_order_id - UUID of the trade order to fetch



61
62
63
# File 'lib/paytunia/api/trading.rb', line 61

def get_trade_order(uuid)
  TradeOrder.new(.get("/trade_orders/#{uuid}"))
end

#get_trades_for_order(uuid) ⇒ Object

Gets the trades that happened in relation to a specific order

Attributes

  • trade_order_id - UUID of the trade order



71
72
73
# File 'lib/paytunia/api/trading.rb', line 71

def get_trades_for_order(uuid)
  .get("/trade_orders/#{uuid}/trades").map { |trade| Trade.new(trade) }
end

#list_active_ordersObject

Returns the active trade orders (pending_execution, active, or insufficient_funds)



5
6
7
# File 'lib/paytunia/api/trading.rb', line 5

def list_active_orders
  .get('/trade_orders/active')
end

#list_ordersObject

Returns a paginated list of orders



10
11
12
# File 'lib/paytunia/api/trading.rb', line 10

def list_orders
  .get('/trade_orders')
end

#post_trade_order(amount, currency, type, price = nil) ⇒ Object

Posts a trade order

Attributes

  • amount - The amount of Bitcoins to buy or sell

  • currency - The currency against which to trade

  • type - Whether your order is to buy or sell Bitcoins, legal values are :buy and :sell

  • price - Limit price, creates a market order if omitted



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/paytunia/api/trading.rb', line 39

def post_trade_order(amount, currency, type, price = nil)
  if !amount.kind_of?(BigDecimal) || (price && !price.kind_of?(BigDecimal))
    raise TypeError, "Expected BigDecimal, got #{amount.class.name} instead."
  end

  unless %w{ eur usd gbp }.include?(currency.to_s.downcase)
    raise 'Illegal currency'
  end

  unless %w{ buy sell }.include?(type.to_s.downcase)
    raise 'Illegal type'
  end

  TradeOrder.new(.post('/trade_orders', { amount: amount, currency: currency, type: type, price: price } ))
end

#send_bitcoins(address, amount) ⇒ Object

Requests Bitcoins to be sent

Raises:

  • (TypeError)


5
6
7
8
# File 'lib/paytunia/api/transfers.rb', line 5

def send_bitcoins(address, amount)
  raise(TypeError, "Expected BigDecimal, got #{amount.class.name} instead.") unless amount.kind_of? BigDecimal
  .post('/transfers/send_bitcoins', amount: amount, address: address)['uuid']
end