Module: Cryptum::API::Portfolio
- Defined in:
- lib/cryptum/api/portfolio.rb
Overview
Module specifically related to orders history retrieval.
Class Method Summary collapse
-
.get(opts = {}) ⇒ Object
Obtain latest order history.
-
.help ⇒ Object
Display Usage for this Module.
Class Method Details
.get(opts = {}) ⇒ Object
Obtain latest order history
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cryptum/api/portfolio.rb', line 9 public_class_method def self.get(opts = {}) option_choice = opts[:option_choice] env = opts[:env] crypto = opts[:crypto] fiat = opts[:fiat] fiat_portfolio_file = opts[:fiat_portfolio_file] event_notes = opts[:event_notes] # Retrieve Exchange Rates exchange_rates_resp = Cryptum::API::ExchangeRates.get( option_choice: option_choice, env: env ) exchange_rates = exchange_rates_resp[:data][:rates] portfolio_complete_arr = Cryptum::API::Rest.call( option_choice: option_choice, env: env, http_method: :GET, api_call: '/accounts', event_notes: event_notes ) portfolio_complete_arr ||= [] all_products = portfolio_complete_arr.select do |products| products if products[:balance].to_f.positive? end total_holdings = 0.00 all_products.each do |product| currency = product[:currency].to_sym this_exchange_rate = exchange_rates[currency].to_f total_holdings += product[:balance].to_f / this_exchange_rate end crypto_portfolio = portfolio_complete_arr.select do |product| product if product[:currency] == crypto end fiat_portfolio = portfolio_complete_arr.select do |product| product if product[:currency] == fiat end fiat_portfolio.last[:total_holdings] = format( '%0.8f', total_holdings ) File.write( fiat_portfolio_file, JSON.pretty_generate(fiat_portfolio) ) crypto_portfolio rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self) end |
.help ⇒ Object
Display Usage for this Module
67 68 69 70 71 72 73 74 |
# File 'lib/cryptum/api/portfolio.rb', line 67 public_class_method def self.help puts "USAGE: fees = #{self}.get( env: 'required - Coinbase::Option::Environment.get Object', option_choice: 'required - Coinbase::Option::Choice Object' ) " end |