Module: Cryptum::Event

Defined in:
lib/cryptum/event.rb,
lib/cryptum/event/buy.rb,
lib/cryptum/event/exit.rb,
lib/cryptum/event/gtfo.rb,
lib/cryptum/event/pane.rb,
lib/cryptum/event/sell.rb,
lib/cryptum/event/cancel.rb,
lib/cryptum/event/scroll.rb,
lib/cryptum/event/history.rb,
lib/cryptum/event/bot_conf.rb,
lib/cryptum/event/key_press.rb,
lib/cryptum/event/order_book.rb

Overview

This plugin is used to Write the Order Book from Memory to File When the “w” Key is Pressed

Defined Under Namespace

Modules: BotConf, Buy, Cancel, Exit, GTFO, KeyPress, OrderBook, Pane, Scroll, Sell Classes: History

Class Method Summary collapse

Class Method Details

.helpObject

Display Usage for this Module



194
195
196
# File 'lib/cryptum/event.rb', line 194

public_class_method def self.help
  constants.sort
end

.parse(opts = {}) ⇒ Object

Supported Method Parameters

Cryptum::Event.parse( )



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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/cryptum/event.rb', line 24

public_class_method def self.parse(opts = {})
  option_choice = opts[:option_choice]
  env = opts[:env]
  terminal_win = opts[:terminal_win]
  event_history = opts[:event_history]
  indicator_status = opts[:indicator_status]
  indicator_history = opts[:indicator_history]
  bot_conf = opts[:bot_conf]
  ai_enabled = opts[:ai_enabled]

  candles = event_history.order_book[:candles]
  order_history = event_history.order_book[:order_history]
  this_product = event_history.order_book[:this_product]
  fiat = this_product[:quote_currency]
  fiat_portfolio_file = "#{option_choice.repo_root}/order_books/#{fiat}_PORTFOLIO.json"

  # Determine if Summary UI needs updated data
  Cryptum::Portfolio::Balance.refresh(
    env: env,
    option_choice: option_choice,
    terminal_win: terminal_win,
    event_history: event_history,
    fiat_portfolio_file: fiat_portfolio_file
  )

  # If the Terminal Window has been Resized, Resize the UI
  if Curses.cols != terminal_win.cols
    terminal_win.cols = Curses.cols
    terminal_win.ticker_ui_resize = true
    terminal_win.market_trend_ui_resize = true
  end

  Cryptum::UI::Portfolio.refresh(
    option_choice: option_choice,
    portfolio_win: terminal_win.portfolio_section,
    event_history: event_history,
    key_press_event: terminal_win.key_press_event,
    indicator_status: indicator_status,
    bot_conf: bot_conf,
    fiat_portfolio_file: fiat_portfolio_file
  )

  if event_history.event_type == :ticker ||
     terminal_win.ticker_ui_resize

    ticker_event = event_history.ticker_event = event_history.event if event_history.event_type == :ticker
    ticker_event = event_history.ticker_event if terminal_win.ticker_ui_resize
    Cryptum::UI::Ticker.refresh(
      option_choice: option_choice,
      start_time: event_history.start_time,
      ticker_win: terminal_win.ticker_section,
      key_press_event: terminal_win.key_press_event,
      order_book: event_history.order_book,
      event: ticker_event
    )
  end

  order_countdown = Cryptum::UI::OrderTimer.refresh(
    option_choice: option_choice,
    event_history: event_history,
    order_timer_win: terminal_win.order_timer_section,
    indicator_status: indicator_status,
    key_press_event: terminal_win.key_press_event
  )

  if event_history.event_type == :l2update ||
     terminal_win.market_trend_ui_resize

    market_trend_event = event_history.market_trend_event = event_history.event if event_history.event_type == :l2update
    market_trend_event = event_history.market_trend_event if terminal_win.market_trend_ui_resize
    Cryptum::UI::MarketTrend.refresh(
      option_choice: option_choice,
      market_trend_win: terminal_win.market_trend_section,
      event_history: event_history,
      key_press_event: terminal_win.key_press_event,
      event: market_trend_event,
      indicator_status: indicator_status,
      bot_conf: bot_conf
    )
  end

  indicator_status = Cryptum::UI::SignalEngine.refresh(
    option_choice: option_choice,
    signal_engine_win: terminal_win.signal_engine_section,
    event_history: event_history,
    key_press_event: terminal_win.key_press_event,
    indicator_status: indicator_status,
    bot_conf: bot_conf,
    fiat_portfolio_file: fiat_portfolio_file
  )

  unless event_history.order_plan_details_win_active
    Cryptum::UI::OrderPlan.refresh(
      option_choice: option_choice,
      order_plan_win: terminal_win.order_plan_section,
      env: env,
      event_history: event_history,
      key_press_event: terminal_win.key_press_event,
      indicator_status: indicator_status,
      bot_conf: bot_conf,
      fiat_portfolio_file: fiat_portfolio_file
    )
    recalc_op = event_history.recalculate_order_plan
    order_plan = event_history.order_book[:order_plan]
    terminal_win.key_press_event.key_w = true if recalc_op || order_plan.empty?
    event_history.recalculate_order_plan = false
  end

  if event_history.order_plan_details_win_active
    Cryptum::UI::OrderPlanDetails.refresh(
      option_choice: option_choice,
      order_plan_details_win: terminal_win.order_plan_details_section,
      event_history: event_history,
      key_press_event: terminal_win.key_press_event
    )
  end

  unless event_history.order_execute_details_win_active
    Cryptum::UI::OrderExecution.refresh(
      option_choice: option_choice,
      order_execute_win: terminal_win.order_execute_section,
      env: env,
      event_history: event_history,
      key_press_event: terminal_win.key_press_event,
      indicator_status: indicator_status,
      bot_conf: bot_conf,
      fiat_portfolio_file: fiat_portfolio_file
    )
  end

  if event_history.order_execute_details_win_active
    Cryptum::UI::OrderExecuteDetails.refresh(
      option_choice: option_choice,
      order_execute_details_win: terminal_win.order_execute_details_section,
      event_history: event_history,
      key_press_event: terminal_win.key_press_event
    )
  end

  # Refresh Command Section for Cryptum Session Usage
  Cryptum::UI::Command.refresh(
    command_win: terminal_win.command_section,
    key_press_event: terminal_win.key_press_event
  )

  # last_ticker_price = event_history.order_book[:ticker_price].to_f
  # second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
  # third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f

  event_history
rescue LoadError => e
  # This happens when autoloading modules fail.
  File.open('/tmp/cryptum-errors.txt', 'a') do |f|
    f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
    f.puts "Module: #{self}"
    f.puts "#{e}\n\n\n"
  end

  retry
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Cryptum.exit_gracefully(which_self: self)
rescue StandardError => e
  raise e
ensure
  $stdout.flush
end