Module: Coincap::Assets

Defined in:
lib/coincap/assets.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

.history(asset_id, interval, start_at = nil, end_at = nil) ⇒ Hash

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

  • start_at (Integer) (defaults to: nil)

    Start time in milliseconds

  • end_at (Integer) (defaults to: nil)

    End time in milliseconds

Returns:

  • (Hash)


112
113
114
115
116
117
# File 'lib/coincap/assets.rb', line 112

def self.history(asset_id, interval, start_at = nil, end_at = nil)
  Helper.fetch_data("#{URI_API}/#{asset_id}/history",
                    interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval,
                    start: start_at,
                    end: end_at)
end

.list(search: nil, ids: nil, limit: nil, offset: nil) ⇒ Hash

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:

  • (Hash)


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

def self.list(search: nil, ids: nil, limit: nil, offset: nil)
  Helper.fetch_data(URI_API, search: search, ids: ids, limit: limit, offset: offset)
end

.markets(asset_id, limit: nil, offset: nil) ⇒ Hash

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:

  • (Hash)


150
151
152
# File 'lib/coincap/assets.rb', line 150

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

.single(asset_id) ⇒ Hash

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:

  • (Hash)


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

def self.single(asset_id)
  Helper.fetch_data("#{URI_API}/#{asset_id}")
end