Class: Coinbase::Products

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/coinbase/products.rb

Overview

Product APIs

Instance Method Summary collapse

Methods included from Util

#base_uri, #build_query_params, #format_response, #pagination_params, #send_request

Instance Method Details

#daily_stats(product_id) ⇒ Hash

Get 24 hr stats for the product.

Parameters:

  • product_id (String)

Returns:

  • (Hash)

    stats for product.



72
73
74
# File 'lib/coinbase/products.rb', line 72

def daily_stats(product_id)
  send_request("/products/#{product_id}/stats")
end

#fetch(product_id) ⇒ Hash

Get market data for a specific currency pair

Parameters:

  • product_id (String)

Returns:

  • (Hash)

    specific currency pair trading.



19
20
21
# File 'lib/coinbase/products.rb', line 19

def fetch(product_id)
  send_request("/products/#{product_id}")
end

#last_trade(product_id) ⇒ Hash

Get information about the last trade

Parameters:

  • product_id (String)

Returns:

  • (Hash)

    trade info.



39
40
41
# File 'lib/coinbase/products.rb', line 39

def last_trade(product_id)
  send_request("/products/#{product_id}/ticker")
end

#listArray of Hashes

Get a list of available currency pairs for trading.

Returns:

  • (Array of Hashes)

    a list of currency pair trading.



11
12
13
# File 'lib/coinbase/products.rb', line 11

def list
  send_request('/products')
end

#orderbook(product_id, level = 1) ⇒ Hash

Get a list of open orders for a product

1 Only the best bid and ask 2 Top 50 bids and asks (aggregated) 3 Full order book (non aggregated)

Parameters:

  • product_id (String)
  • level (Number) (defaults to: 1)

    Defualt is 1 below is description about same

Returns:

  • (Hash)

    orders for product.



31
32
33
# File 'lib/coinbase/products.rb', line 31

def orderbook(product_id, level = 1)
  send_request("/products/#{product_id}/book?level=#{level}")
end

#price_history(product_id, options = {}) ⇒ Array

Get historic rates for a product.

Parameters:

  • product_id (String)
  • options (Hash) (defaults to: {})

Returns:

  • (Array)

    rates for product.



62
63
64
65
66
# File 'lib/coinbase/products.rb', line 62

def price_history(product_id, options = {})
  query = build_query_params(options) unless options.blank?

  send_request("/products/#{product_id}/candles?#{query}")
end

#trade_history(product_id, paginate_options = {}) ⇒ Array of Hashes

List the latest trades for a product.

before [String] Request page before (newer) this pagination id (optional). after [String] Request page after (older) this pagination id (optional). limit [Integer] Number of results per request. Maximum 1000, default is 1000 (optional).

Parameters:

  • product_id (String)
  • paginate_options (Hash) (defaults to: {})

    an hash with the following parameters

Returns:

  • (Array of Hashes)

    trades for product.



52
53
54
55
# File 'lib/coinbase/products.rb', line 52

def trade_history(product_id, paginate_options = {})
  query_params = build_query_params(paginate_options)
  send_request("/products/#{product_id}/trades?#{query_params}")
end