Module: Cryptum::UI::Order::ExecuteDetails

Defined in:
lib/cryptum/ui/order/execute_details.rb

Overview

Update the ExecuteDetails Section of the UI (When Active)

Class Method Summary collapse

Class Method Details

.helpObject

Display Usage for this Module



295
296
297
298
299
300
# File 'lib/cryptum/ui/order/execute_details.rb', line 295

public_class_method def self.help
  puts "USAGE:
   #{self}.refresh(
   )
  "
end

.refresh(opts = {}) ⇒ Object

Supported Method Parameters

Cryptum::UI::Order::ExecuteDetails.refresh( )



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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/cryptum/ui/order/execute_details.rb', line 15

public_class_method def self.refresh(opts = {})
  event_history = opts[:event_history]
  order_execute_details_win = opts[:order_execute_details_win]

   = event_history.order_execute_selected_data

  order_color = [:color].to_sym
  order_id = case order_color
             when :cyan, :red
               [:buy_order_id]
             when :green, :magenta, :yellow
               [:sell_order_id]
             when :white
               'Expired'
             else
               'N/A'
             end

  order_id_details = "- ID: #{order_id}"

  order_history_arr = event_history.order_book[:order_history].select do |order|
    order if order[:id] == order_id
  end

  if order_history_arr.empty? && order_color == :yellow
    .delete(:sell_order_id)
    order_id = [:buy_order_id]
    [:color] = :cyan
    order_history_arr = event_history.order_book[:order_history].select do |order|
      order if order[:id] == order_id
    end
  end

  order_type_ln = '- Type: N/A'
  order_status_ln = '- Status: N/A'
  fill_fees = 'N/A'
  fill_size = 'N/A'
  executed_value = 'N/A'
  market_type = 'N/A'
  settled = 'N/A'
  unless order_history_arr.empty?
    order_history = order_history_arr.first
    order_type = order_history[:type].capitalize
    time_in_force = order_history[:time_in_force].upcase
    order_status = order_history[:status].upcase
    created_at = order_history[:created_at]
    fill_fees = order_history[:fill_fees]
    fill_size = order_history[:filled_size]
    executed_value = order_history[:executed_value]
    market_type = order_history[:market_type]
    settled = order_history[:settled]

    order_side = order_history[:side].capitalize
    case order_side.to_sym
    when :Buy
      expire_time = order_history[:expire_time]
      done_at = order_history[:done_at]
      [:color] = :cyan if done_at
    when :Sell
      done_at = order_history[:done_at]
    end

    order_type_ln = "- Type: #{order_type} #{order_side} #{time_in_force}"
    order_type_ln = "- Type: #{order_type} #{order_side} #{time_in_force} 1m" if time_in_force == 'GTT'
    order_status_ln = "- Status: #{order_status}"
  end

  order_hist_created_finished_ln = if created_at && !expire_time && !done_at
                                     "- Creation Date: #{created_at} | Finished Date: N/A"
                                   elsif created_at && expire_time && !done_at
                                     "- Creation Date: #{created_at} | Expiring Date: #{expire_time}"
                                   elsif created_at && done_at
                                     "- Creation Date: #{created_at} | Finished Date: #{done_at}"
                                   else
                                     '- Creation Date: N/A | Finished Date: N/A'
                                   end

  invest_out = Cryptum.beautify_large_number(
    value: [:invest]
  )
  price_out = Cryptum.beautify_large_number(
    value: [:price]
  )
  size_out = Cryptum.beautify_large_number(
    value: [:size]
  )
  target_price_out = Cryptum.beautify_large_number(
    value: [:target_price]
  )

  invest = "$#{invest_out} @ "
  tick = "$#{price_out} = "
  size = "*#{size_out} + "
  tpm_out = "#{[:tpm]}% = "
  targ_tick = "$#{target_price_out}"
  profit = " | Profit: $#{[:profit]}"

  details_ln1 = "- Slice Plan: #{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}"
  details_ln2 = "- Fees: $#{fill_fees} | Fill Size: *#{fill_size}"
  details_ln3 = "- Executed Value: $#{executed_value} | Market Type: #{market_type} | Settled: #{settled}"

  # UI
  col_just1 = (Curses.cols - Cryptum::UI.col_first)

  # ROW 1
  out_line_no = 0
  line_color = order_color
  header_color = order_color
  header_style = :bold
  style = :bold
  header_style = :reverse if event_history.order_execute_details_win_active

  Cryptum::UI.line(
    ui_win: order_execute_details_win,
    out_line_no: out_line_no,
    color: line_color
  )

  # ROW 2
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol
  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: header_color,
    style: header_style,
    string: ''.ljust(col_just1, ' ')
  )

  header_str = "- ORDER ##{[:plan_no]} DETAILS -"
  order_execute_details_win.setpos(
    out_line_no,
    Cryptum::UI.col_center(str: header_str)
  )

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: header_style,
    string: header_str
  )

  # ROW 3
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: order_id_details.ljust(col_just1, ' ')
  )

  # ROW 4
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: order_type_ln.ljust(col_just1, ' ')
  )

  # ROW 5
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: order_status_ln.ljust(col_just1, ' ')
  )

  # ROW 6
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: order_hist_created_finished_ln.ljust(col_just1, ' ')
  )

  # ROW 7
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: details_ln1.ljust(col_just1, ' ')
  )

  # ROW 8
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: details_ln2.ljust(col_just1, ' ')
  )

  # ROW 9
  out_line_no += 1
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: style,
    string: details_ln3.ljust(col_just1, ' ')
  )

  # ROW 10
  out_line_no += 1
  Cryptum::UI.line(
    ui_win: order_execute_details_win,
    out_line_no: out_line_no,
    color: line_color
  )

  # Clear to OK ROW
  ok_row = 10
  out_line_no += 1
  to_ok_row = ok_row - 1
  (out_line_no..to_ok_row).each do |clr_line|
    order_execute_details_win.setpos(clr_line, Cryptum::UI.col_first)
    Cryptum::UI.colorize(
      ui_win: order_execute_details_win,
      color: order_color,
      style: :normal,
      string: ''.ljust(col_just1, ' ')
    )
  end

  # OK ROW
  out_line_no = ok_row
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_execute_details_win.clrtoeol
  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    string: ''.ljust(col_just1, ' ')
  )

  header_str = '- OK -'
  order_execute_details_win.setpos(
    out_line_no,
    Cryptum::UI.col_center(str: header_str)
  )

  Cryptum::UI.colorize(
    ui_win: order_execute_details_win,
    color: order_color,
    style: :reverse,
    string: header_str
  )

  order_execute_details_win.refresh

  event_history
rescue Interrupt, StandardError => e
  Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history)
end