Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

HG Finance

Welcome to official HG Finance's Ruby Gem!

Now you can simple get finance data (currencies exchange, cryptocurrencies exchanges, brazilian government taxes and stocks markets) from HG Finance API directly on your Ruby Application!

Available data

Cryptocurrencies exchange

    • BTC to USD Dollar
  • Coinbase
    • BTC to USD Dollar
  • BitStamp
    • BTC to USD Dollar
  • FoxBit
    • BTC to BRL Brazilian Real
  • Mercado Bitcoin
    • BTC to BRL Brazilian Real
  • OmniTrade
    • BTC to BRL Brazilian Real

Stock markets

  • BM&F BOVESPA Sao Paulo, Brazil
  • NASDAQ New York City, United States
  • CAC 40 Paris, French
  • Nikkei 225 Tokyo, Japan

Currencies exchange

  • USD Dollar to BRL Brazilian Real
  • EUR Euro to BRL Brazilian Real
  • GBP Pound Sterling to BRL Brazilian Real
  • ARS Argentine Peso to BRL Brazilian Real
  • BTC Bitcoin ( to BRL Brazilian Real


  • Brazilian CDI
  • Brazilian Selic


Add this line to your application's Gemfile:

gem 'hg-finance'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hg-finance



You can configure all of HG Finance params, but not all of them are required.

require 'hg/finance'

HG::Finance.setup do |config|
  # You can generate your key on
  # Key is required for get some data.
  config.api_key = 'my-key'

  # Set locale for response, default is english, available: pt-br, en
  config.locale = :en

  # Use SSL on request, default and recommended is true
  config.use_ssl = true

  # Coming... If you are using Rails, request can be cached on cache engine
  config.use_rails_cache = true

# You also can change setup parameters directly
HG::Finance.api_key = 'my-key'
HG::Finance.locale = 'pt-br'


require 'hg/finance'

# You can set any search API parameter here
finance = HG::Finance.get

finance.key_status # => :empty (can be :empty, :valid or :invalid)

# Will return a HG::Finance::Taxes object
# 16/06 - CDI: 10.14 - SELIC: 10.15 - Fator diário: 1.00038334 # => 2017-06-16 00:00:00 -0300
finance.taxes.cdi # => 10.14
finance.taxes.selic # => 10.15
finance.taxes.daily_factor # => 1.00038334

# Will return an hash with HG::Finance::Currency object, with currencies exchange from BRL
# {"USD"=>Dollar (USD) - Compra: BRL 3.2849 - Venda: BRL 3.2843 - Variação: -0.07, "EUR"=>Eu...

finance.currencies.each do |currency| # => "Dollar"
  currency.iso_code # => "USD"
  currency.source # => "BRL" # => 3.2849
  currency.sell # => 3.2843
  currency.variation # => -0.07

# Will return an hash with HG::Finance::CryptoCurrency object, with currencies exchanges as symbols keys
# {:blockchain_info=>{:btcusd=> (BTC to USD) - Last: USD 7446.0000905 - Buy: USD 7446.0000905 - Sell

# Will return a HG::Finance::CryptoCurrency object
# => OmniTrade (BTC to BRL) - Last: BRL 28800.0 - Buy: BRL 28500.01 - Sell: BRL 29200.0 - Variation: 0.699

finance.cryptocurrencies.each do |exchange, markets|
  markets.each do |data, market| # => "OmniTrade" # => "Bitcoin"
    market.iso_code # => "BTC"
    market.to_currency # => "BRL"
    market.last # => 28800.0 # => 28500.01
    market.sell # => 29200.0
    market.variation # => 0.699

# Will return an hash with HG::Finance::Stock object, with variation of some stock markets
# {"IBOVESPA"=>BM&F BOVESPA - Sao Paulo, Brazil - Variação: 0.63, "NASDAQ"=>NASD...

finance.stocks.each do |stock| # => "BM&F BOVESPA"
  stock.location # => "Sao Paulo, Brazil"
  stock.variation # => 0.63

Você é Brasileiro? (Are you Brazilian?)

Se você é brasileiro, basta configurar o idioma para 'pt-br' que todos os dados de data e hora, são convertidos para o padrão brasileiro.

Você pode definir inline ou por bloco:

require 'hg/finance'

# Definir por bloco:
HG::Finance.setup do |config|
  config.locale = 'pt-br'

# Definir inline:
HG::Finance.locale = 'pt-br'

API Key and Status of Service

Some features like search by geolocation or geoIP requires an API Key.

You can generate your key on official webpage of HG Finance. There you also find the status of API service.

Upcoming features

Gem level

  • Improvements on timezone
  • Cache with Rails cache engine


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at[USERNAME]/hg-finance.


The gem is available as open source under the terms of the MIT License.


Get finance data like cryptocurrencies exchange, CDI, SELIC, dollar and stock markets data using HG Finance API.




No releases published


No packages published