Module: Cryptum::Portfolio::Balance
- Defined in:
- lib/cryptum/portfolio/balance.rb
Overview
Track Portfolio Balances
Class Method Summary collapse
-
.help ⇒ Object
Display Usage for this Module.
-
.refresh(opts = {}) ⇒ Object
- Supported Method Parameters
-
Cryptum::Event::Update.summary( ).
Class Method Details
.help ⇒ Object
Display Usage for this Module
115 116 117 118 119 |
# File 'lib/cryptum/portfolio/balance.rb', line 115 public_class_method def self.help puts "USAGE: event_history.order_book = #{self}.crypto() " end |
.refresh(opts = {}) ⇒ Object
- Supported Method Parameters
-
Cryptum::Event::Update.summary( )
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cryptum/portfolio/balance.rb', line 11 public_class_method def self.refresh(opts = {}) option_choice = opts[:option_choice] env = opts[:env] terminal_win = opts[:terminal_win] event_history = opts[:event_history] fiat_portfolio_file = opts[:fiat_portfolio_file] this_product = event_history.order_book[:this_product] crypto = this_product[:base_currency] fiat = this_product[:quote_currency] if event_history.first_event || event_history.reconnected || event_history.event_type == :received || event_history.event_type == :open || event_history.event_type == :done || event_history.event_type == :match || event_history.event_type == :change || event_history.event_type == :activate || terminal_win.key_press_event.key_u etype = event_history.event_type manual_refresh = terminal_win.key_press_event.key_u etype = :manual_refresh if manual_refresh etype = :first_event if event_history.first_event etype = :reconnected if event_history.reconnected event_history.event_type = etype # Prevent Multiple Order Events from Occuring --- # ocancel = event_history.order_canceled osubmit = event_history.order_submitted # POTENTIAL STOP IN ORDERS WHEN # event_history.order_canceled = true # Verify it's not due to EMA being red. # ocancel = false if (etype == :open || etype == :done) && # osubmit == false && # !manual_refresh ocancel = false if etype == :done && osubmit == true && !manual_refresh event_history.order_canceled = ocancel osubmit = false if etype == :done && !manual_refresh event_history.order_submitted = osubmit # ---------------------------------------------- # enotes = event_history.event_notes enotes = "{ \"event_type\": \"#{etype}\", \"cancel\": \"#{ocancel}\", \"submitted\": \"#{osubmit}\" }" if option_choice.proxy event_history.event_notes = enotes portfolio = Cryptum::API::Portfolio.get( option_choice: option_choice, env: env, crypto: crypto, fiat: fiat, fiat_portfolio_file: fiat_portfolio_file, event_notes: event_history.event_notes ) event_history.order_book[:portfolio] = portfolio unless portfolio.empty? order_history = Cryptum::API::OrderHistory.get( option_choice: option_choice, env: env ) event_history.order_book[:order_history] = order_history unless order_history.empty? fees = Cryptum::API::Fees.get( option_choice: option_choice, env: env ) event_history.order_book[:fees] = fees unless fees.empty? terminal_win.key_press_event.key_u = false if manual_refresh # First Event to Refresh No Longer Needed event_history.first_event = false # Reconnected Event to Refresh No Longer Needed event_history.reconnected = false end # Always reload fiat portfolio as it's shared # by all sessions (unless it's empty) fpf = '' fpf = File.read(fiat_portfolio_file) unless File.empty?( fiat_portfolio_file ) unless fpf.empty? event_history.order_book[:fiat_portfolio] = JSON.parse( fpf, symbolize_names: true ) end event_history rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end |