Module: CoingeckoRuby::Client::Derivatives

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

Instance Method Summary collapse

Instance Method Details

#derivative_exchange(id, **options) ⇒ Hash

Fetches data for a specific derivative exchange.

Examples:

Get data for the Binance Futures derivative exchange.

client.derivative_exchange('binance_futures')

Sample response object

{
  "name" => "Binance (Futures)",
  "open_interest_btc" => 237845.78,
  "trade_volume_24h_btc" => "2226117.02",
  "number_of_perpetual_pairs" => 132,
  "number_of_futures_pairs" => 32,
  "image" =>
  "https://assets.coingecko.com/markets/images/466/small/binance_futures.jpg?1568609512",
  "year_established" => 2019,
  "country" => nil,
  "description" => "",
  "url" => "https://www.binance.com/"
}

Parameters:

  • id (String)

    the id of the derivative exchange.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :include_tickers (String)

    determines whether to display all tickers or only show unexpired tickers. Does not return any ticker data if left blank. Valid values: all, unexpired

Returns:

  • (Hash)

    the derivative exchange’s information.



114
115
116
# File 'lib/coingecko_ruby/client/derivatives.rb', line 114

def derivative_exchange(id, **options)
  get "derivatives/exchanges/#{id}", **options
end

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

Fetches the list of derivative exchanges listed in CoinGecko.

Examples:

Get one derivative exchange.

client.derivative_exchanges(per_page: 1)

Sample response object

[{
  "name" => "Binance (Futures)",
  "id" => "binance_futures",
  "open_interest_btc" => 237845.78,
  "trade_volume_24h_btc" => "2209372.18",
  "number_of_perpetual_pairs" => 132,
  "number_of_futures_pairs" => 32,
  "image" =>
  "https://assets.coingecko.com/markets/images/466/small/binance_futures.jpg?1568609512",
  "year_established" => 2019,
  "country" => nil,
  "description" => "",
  "url" => "https://www.binance.com/"
}]

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :per_page (Integer)

    sets the number of results to return per page.

  • :page (Integer)

    sets the page for results.

  • :order (String)

    sets the sort order for results. Valid values: name_asc, name_desc, open_interest_btc_asc, open_interest_btc_desc, trade_volume_24h_btc_asc, trade_volume_24h_btc_desc.

Returns:

  • (Array<Hash>)

    each derivative exchange’s information.



81
82
83
# File 'lib/coingecko_ruby/client/derivatives.rb', line 81

def derivative_exchanges(**options)
  get 'derivatives/exchanges', **options
end

#derivative_exchanges_ids_and_namesArray<Hash>

Fetches the list ids and names of derivative exchanges listed in CoinGecko.

Examples:

Get all unexpired derivatives.

client.derivative_exchanges_ids_and_names

Sample response object (truncated)

[
  {
    "id" => "binance_futures",
    "name" => "Binance (Futures)"
  },
  {
    "id" => "huobi_dm",
    "name" => "Huobi Futures"
  },
  {
    "id" => "ftx",
    "name" => "FTX (Derivatives)"
  }
]

Returns:

  • (Array<Hash>)

    each derivative exchange’s id and name.



144
145
146
# File 'lib/coingecko_ruby/client/derivatives.rb', line 144

def derivative_exchanges_ids_and_names
  get 'derivatives/exchanges/list'
end

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

Fetches the list of derivative products listed in CoinGecko.

Examples:

Get all unexpired derivatives.

client.derivatives(include_tickers: 'unexpired')

Sample response object (truncated)

[
  {
    "market" => "Binance (Futures)",
    "symbol" => "BTCUSDT",
    "index_id" => "BTC",
    "price" => "44575.26",
    "price_percentage_change_24h" => -0.5892545887194689,
    "contract_type" => "perpetual",
    "index" => 44646.70155337,
    "basis" => -0.11242030301843862,
    "spread" => 0.01,
    "funding_rate" => 0.021205,
    "open_interest" => 1822639548.16,
    "volume_24h" => 27179643527.25483,
    "last_traded_at" => 1621341447,
    "expired_at" => nil
  },
  {
    "market" => "Bybit",
    "symbol" => "BTCUSD",
    "index_id" => "BTC",
    "price" => "44817.5",
    "price_percentage_change_24h" => -0.9426664309079656,
    "contract_type" => "perpetual",
    "index" => 44827.57,
    "basis" => 0.022468901656718915,
    "spread" => 0.01,
    "funding_rate" => 0.01,
    "open_interest" => 1664013731.0,
    "volume_24h" => 5725694670.15,
    "last_traded_at" => 1621340931,
    "expired_at" => nil
  },
]

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :include_tickers (String) — default: 'unexpired'

    determines whether to display all tickers or only show unexpired tickers. Valid values: all, unexpired

Returns:

  • (Array<Hash>)

    each derivative product’s information.



47
48
49
# File 'lib/coingecko_ruby/client/derivatives.rb', line 47

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

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

Deprecated.

Use #derivative_exchange instead



119
120
121
# File 'lib/coingecko_ruby/client/derivatives.rb', line 119

def get_derivative_exchange(id:, options: {})
  derivative_exchange(id, **options)
end

#get_derivative_exchanges(options: {}) ⇒ Object

Deprecated.

Use #derivative_exchanges instead



86
87
88
# File 'lib/coingecko_ruby/client/derivatives.rb', line 86

def get_derivative_exchanges(options: {})
  derivative_exchanges(**options)
end

#get_derivative_exchanges_ids_and_namesObject

Deprecated.


149
150
151
# File 'lib/coingecko_ruby/client/derivatives.rb', line 149

def get_derivative_exchanges_ids_and_names
  derivative_exchanges_ids_and_names
end

#get_derivatives(options: {}) ⇒ Object

Deprecated.

Use #derivatives instead



52
53
54
# File 'lib/coingecko_ruby/client/derivatives.rb', line 52

def get_derivatives(options: {})
  derivatives(**options)
end