Module: CoingeckoRuby::Client::Exchanges

Included in:
CoingeckoRuby::Client
Defined in:
lib/coingecko_ruby/client/exchanges.rb

Instance Method Summary collapse

Instance Method Details

#exchange(id) ⇒ Hash

Fetches complete data for a specific exchange.

Examples:

Fetch complete exchange data for Binance.

client.exchange('binance')

Parameters:

  • id (String)

    the exchange id to fetch.

Returns:

  • (Hash)

    returns detailed data for the given exchange.



45
46
47
# File 'lib/coingecko_ruby/client/exchanges.rb', line 45

def exchange(id)
  get "exchanges/#{id}"
end

#exchange_idsArray<Hash>

Fetches exchange ids for every exchange currently supported by the CoinGecko API.

Examples:

Fetch all exchange ids.

client.exchange_ids

Sample response object

[{
  "id" => "aave",
  "name" => "Aave"
}, {
  "id" => "aax",
  "name" => "AAX"
}, {
  "id" => "aax_futures",
  "name" => "AAX Futures"
}]

Returns:

  • (Array<Hash>)

    returns an array of hashes of the exchange id and name.



71
72
73
# File 'lib/coingecko_ruby/client/exchanges.rb', line 71

def exchange_ids
  get 'exchanges/list'
end

#exchange_status(id, **options) ⇒ Hash

Fetches news,announcments, and updates from a specific exchange.

Examples:

Get the last 3 status updates from Binance.

client.exchange_status('binance', per_page: 1)

Sample response object

{
  "status_updates" => [{
    "description" => "Juventus and Paris Saint-Germain Fan Tokens on Binance Launchpool! \r\n\r\nFarm JUV and PSG tokens By Staking BNB, BUSD & CHZ Tokens\r\n\r\nClick here➡️ https://ter.li/JUV-and-PSG-tokens",
    "category" => "general",
    "created_at" => "2020-12-14T11:18:49.085Z",
    "user" => "Darc",
    "user_title" => "Marketing",
    "pin" => false,
    "project" => {
      "type" => "Market", "id" => "binance", "name" => "Binance", "image" => {
        "thumb" => "https://assets.coingecko.com/markets/images/52/thumb/binance.jpg?1519353250", "small" => "https://assets.coingecko.com/markets/images/52/small/binance.jpg?1519353250", "large" => "https://assets.coingecko.com/markets/images/52/large/binance.jpg?1519353250"
      }
    }
  }]
}

Parameters:

  • id (String)

    the exchange id to fetch.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :per_page (Integer) — default: 100

    sets the number of results to return per page.

  • :page (Integer)

    sets the page for results.

Returns:

  • (Hash)

    the status update data for the given exchange.



159
160
161
# File 'lib/coingecko_ruby/client/exchanges.rb', line 159

def exchange_status(id, **options)
  get "exchanges/#{id}/status_updates", **options
end

#exchange_tickers(id, **options) ⇒ Hash

Fetches coin tickers from a specific exchange.

Examples:

Get Bitcoin tickers from Binance.

client.exchange_tickers('binance', coin_ids: 'bitcoin')

Sample response object

{
  "name" => "Binance", "tickers" => [{
    "base" => "BTC",
    "target" => "USDT",
    "market" => {
      "name" => "Binance", "identifier" => "binance", "has_trading_incentive" => false
    },
    "last" => 48890.78,
    "volume" => 86837.96789156958,
    "converted_last" => {
      "btc" => 0.99871776, "eth" => 12.706618, "usd" => 48867
    },
    "converted_volume" => {
      "btc" => 86727, "eth" => 1103417, "usd" => 4243490314
    },
    "trust_score" => "green",
    "bid_ask_spread_percentage" => 0.01002,
    "timestamp" => "2021-05-16T07:37:00+00:00",
    "last_traded_at" => "2021-05-16T07:37:00+00:00",
    "last_fetch_at" => "2021-05-16T07:37:00+00:00",
    "is_anomaly" => false,
    "is_stale" => false,
    "trade_url" => "https://www.binance.com/en/trade/BTC_USDT?ref=37754157",
    "token_info_url" => nil,
    "coin_id" => "bitcoin",
    "target_coin_id" => "tether"
  }]
}

Parameters:

  • id (String)

    the exchange id to fetch.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :coin_ids (String)

    comma-separated list of tickers to fetch from the given exchange id (e.g. ‘bitcoin, eth, litecoin’).

  • :include_exchange_logo (String)

    includes the exchange’s logo.

  • :page (Integer)

    sets the page for results.

  • :order (String) — default: 'trust_score_desc'

    sets the sort order for results. Valid values: trust_score_desc’, ‘trust_score_asc’, ‘volume_desc.

  • :depth (Boolean) — default: false

    displays orderbook depth (2%).

Returns:

  • (Hash)

    the exchange name and tickers as provided or all tickers if coin_ids is not provided.



123
124
125
# File 'lib/coingecko_ruby/client/exchanges.rb', line 123

def exchange_tickers(id, **options)
  get "exchanges/#{id}/tickers", **options
end

#exchange_volume(id, days: 7, **options) ⇒ Array<Array<Float, String>>

Fetches trade volume data from a specific exchange.

Examples:

Get Binance’s trade volume from a day ago.

client.exchange_volume('binance', days: 1)

Sample response object (truncated)

[
  [1620550200000.0, "1005476.2667217359131632087795432176371669876601688256288859094077173967202827700534809705802"], # [UNIX timestamp for exchange trade volume data, trade volume]
  [1620553800000.0, "1018442.2775982988468591292487708941265043962519659923872972786095536137127193126138169804088"],
  [1620557400000.0, "1042158.4333253484568599192332614201045319574863305612009609211497295171074087677404153278624"]
]

Parameters:

  • id (String)

    the exchange id to fetch.

  • days (Integer) (defaults to: 7)

    number of days ago to fetch trade volume data. Defaults to 7 days.

Returns:

  • (Array<Array<Float, String>>)

    the exchange’s trade volume data in 10-minute intervals, hourly intervals, or daily intervals depending on the number of days given



183
184
185
# File 'lib/coingecko_ruby/client/exchanges.rb', line 183

def exchange_volume(id, days: 7, **options)
  get "exchanges/#{id}/volume_chart", days: days, **options
end

#exchanges(**options) ⇒ Array<Hash>

Fetches complete data for every exchange currently supported by the CoinGecko API.

Examples:

Fetch complete exchange data with 1 result per page.

client.exchanges(per_page: 1)

Sample response object

[{
  "id" => "binance",
  "name" => "Binance",
  "year_established" => 2017,
  "country" => "Cayman Islands",
  "description" => "",
  "url" => "https://www.binance.com/",
  "image" => "https://assets.coingecko.com/markets/images/52/small/binance.jpg?1519353250",
  "has_trading_incentive" => false,
  "trust_score" => 10,
  "trust_score_rank" => 1,
  "trade_volume_24h_btc" => 982949.3975723931,
  "trade_volume_24h_btc_normalized" => 982949.3975723931
}]

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :per_page (Integer) — default: 100

    sets the number of results to return per page.

  • :page (Integer)

    sets the page for results.

Returns:

  • (Array<Hash>)

    returns an array of hashes of detailed exchange data.



28
29
30
# File 'lib/coingecko_ruby/client/exchanges.rb', line 28

def exchanges(**options)
  get 'exchanges', **options
end

#get_exchange_data(id:) ⇒ Object

Deprecated.

Use #exchange instead



50
51
52
# File 'lib/coingecko_ruby/client/exchanges.rb', line 50

def get_exchange_data(id:)
  exchange(id)
end

#get_exchange_status_updates(id:, options: {}) ⇒ Object

Deprecated.

Use #exchange_status instead



164
165
166
# File 'lib/coingecko_ruby/client/exchanges.rb', line 164

def get_exchange_status_updates(id:, options: {})
  exchange_status(id, **options)
end

#get_exchange_tickers(id:, options: {}) ⇒ Object

Deprecated.

Use #exchange_tickers instead



128
129
130
# File 'lib/coingecko_ruby/client/exchanges.rb', line 128

def get_exchange_tickers(id:, options: {})
  exchange_tickers(id, **options)
end

#get_exchange_volume(id:, days:) ⇒ Object

Deprecated.

Use #exchange_volume instead



188
189
190
# File 'lib/coingecko_ruby/client/exchanges.rb', line 188

def get_exchange_volume(id:, days:)
  exchange_volume(id, days: days)
end

#get_exchanges(options: {}) ⇒ Object

Deprecated.

Use #exchanges instead



33
34
35
# File 'lib/coingecko_ruby/client/exchanges.rb', line 33

def get_exchanges(options: {})
  exchanges(**options)
end

#get_exchanges_idsObject

Deprecated.

Use #exchange_ids instead



76
77
78
# File 'lib/coingecko_ruby/client/exchanges.rb', line 76

def get_exchanges_ids
  exchange_ids
end