Module: Coincap::AssetsPrice

Defined in:
lib/coincap/assets_price.rb

Overview

The asset price is a volume-weighted average calculated by collecting ticker data from exchanges. Each exchange contributes to this price in relation to their volume, meaning higher volume exchanges have more affect on this global price. All values are translated into USD (United States Dollar) and can be translated into other units of measurement through the /rates endpoint.

Constant Summary collapse

URI_API =
"#{BASE_URI}#{VERSION_API}/assets"
TIME_INTERVAL =
{
  one_minute: 'm1',
  five_minutes: 'm5',
  fifteen_minutes: 'm15',
  thirty_minutes: 'm30',
  one_hour: 'h1',
  two_hours: 'h2',
  six_hours: 'h6',
  twelve_hours: 'h12',
  one_day: 'd1'
}.freeze

Class Method Summary collapse

Class Method Details

.cryptocurrencies(search: nil, ids: nil, limit: nil, offset: nil) ⇒ String

Get all cryptocurrencies

{
  "data": [
    {
    "id": "bitcoin",
    "rank": "1",
    "symbol": "BTC",
    "name": "Bitcoin",
    "supply": "17193925.0000000000000000",
    "maxSupply": "21000000.0000000000000000",
    "marketCapUsd": "119150835874.4699281625807300",
    "volumeUsd24Hr": "2927959461.1750323310959460",
    "priceUsd": "6929.8217756835584756",
    "changePercent24Hr": "-0.8101417214350335",
    "vwap24Hr": "7175.0663247679233209"
    },
 ...
  ],
  "timestamp": 1533581088278
}

Parameters:

  • search (String) (defaults to: nil)

    (nil) Search by asset id (bitcoin) or symbol (BTC)

  • ids (String) (defaults to: nil)

    (nil) Query with multiple ids=bitcoin,ethereum,monero

  • limit (Integer) (defaults to: nil)

    (nil) Max limit of 2000

  • offset (Integer) (defaults to: nil)

    (nil) Offset

Returns:

  • (String)


53
54
55
# File 'lib/coincap/assets_price.rb', line 53

def self.cryptocurrencies(search: nil, ids: nil, limit: nil, offset: nil)
  Helper.request_to_read_data(URI_API, search: search, ids: ids, limit: limit, offset: offset)
end

.cryptocurrency(asset_id) ⇒ String

Get single cryptocurrency

{
  "data": {
    "id": "bitcoin",
    "rank": "1",
    "symbol": "BTC",
    "name": "Bitcoin",
    "supply": "17193925.0000000000000000",
    "maxSupply": "21000000.0000000000000000",
    "marketCapUsd": "119179791817.6740161068269075",
    "volumeUsd24Hr": "2928356777.6066665425687196",
    "priceUsd": "6931.5058555666618359",
    "changePercent24Hr": "-0.8101417214350335",
    "vwap24Hr": "7175.0663247679233209"
  },
  "timestamp": 1533581098863
}

Parameters:

  • asset_id (String)

    Asset id, for example, bitcoin

Returns:

  • (String)


78
79
80
# File 'lib/coincap/assets_price.rb', line 78

def self.cryptocurrency(asset_id)
  Helper.request_to_read_data("#{URI_API}/#{asset_id}")
end

.cryptocurrency_history(asset_id, interval) ⇒ String

Get cryptocurrency history price

{
  "data": [
   {
      "priceUsd": "6379.3997635993342453",
      "time": 1530403200000
    },
  ...
  ],
  "timestamp": 1533581103627
}

You can call the method like this:

Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)

Coincap::AssetsPrice.cryptocurrency_history('bitcoin', 'm1')

Or like this:

Coincap::AssetsPrice.cryptocurrency_history_one_minute('bitcoin')

Parameters:

  • asset_id (String)

    Asset id, for example, bitcoin

  • interval (Symbol|String)

    Select one from the list of TIME_INTERVAL values for example, a string ‘m1’ or a symbol :one_minute

Returns:

  • (String)


110
111
112
113
# File 'lib/coincap/assets_price.rb', line 110

def self.cryptocurrency_history(asset_id, interval)
  Helper.request_to_read_data("#{URI_API}/#{asset_id}/history",
                              interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval)
end

.cryptocurrency_with_markets(asset_id, limit: nil, offset: nil) ⇒ String

Get price cryptocurrency with markets

{
  "data": [
    {
      "exchangeId": "Binance",
      "baseId": "bitcoin",
      "quoteId": "tether",
      "baseSymbol": "BTC",
      "quoteSymbol": "USDT",
      "volumeUsd24Hr": "277775213.1923032624064566",
      "priceUsd": "6263.8645034633024446",
      "volumePercent": "7.4239157877678087"
    },
    ...
  ],
  "timestamp": 1539289444052
}

Parameters:

  • asset_id (String)

    Asset id, for example, bitcoin

  • limit (Integer) (defaults to: nil)

    Max limit of 2000

  • offset (Integer) (defaults to: nil)

    Offset

Returns:

  • (String)


146
147
148
# File 'lib/coincap/assets_price.rb', line 146

def self.cryptocurrency_with_markets(asset_id, limit: nil, offset: nil)
  Helper.request_to_read_data("#{URI_API}/#{asset_id}/markets", limit: limit, offset: offset)
end