cryptum 0.0.270 → 0.0.272

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f112246033a05eecb95d6b71d0ce96e7206d9aaef1cf7b675ddd453baafd8de
4
- data.tar.gz: 399946d0c1100458ef8adcf300c190271af2cd936181c5f259153310c52e1eff
3
+ metadata.gz: 33789e9885b695c15c6910051688172381d800d5621266ff531d0b7445478b2a
4
+ data.tar.gz: 84ec9383263bb2e98d4aa9b7e53535581e8c1a879062ff6cbef25f98fb19d475
5
5
  SHA512:
6
- metadata.gz: d6d3a544bcbca635371547cf272a051f24585c0d8530f7356c5c466fb5202ca2c03cd75fde6ca42baafd410fd03c1ebc6f315e4666942cab00769e5982f568e9
7
- data.tar.gz: af57efd0263bb5ead63ddb9a8e5b5c9e289d234a71183a727ee56f10cbb2139df62df7858335379f487208dd7a5d8a5f8d0d5b1b345d9efc2ce73b6d07550b72
6
+ metadata.gz: 6ffa742a34ef7e6bd05bc1464c469d2e0767657d30957ff87a4b8762b248fdfe6b619f1c2f6b04f1e3c2c48f70002cf6b4b833bfd4df867496036c0d5c60bab6
7
+ data.tar.gz: b4986392cfdfffd83b09e17ca37515fb5264521cc2c5f0d64695e344c793e99947e065cd11c6fe2f250d24159a84877c9503d81371a14de27b26d6281545475b
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-12-05 22:19:37 UTC using RuboCop version 1.39.0.
3
+ # on 2022-12-06 15:52:44 UTC using RuboCop version 1.39.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -87,7 +87,7 @@ Layout/TrailingWhitespace:
87
87
  - 'lib/cryptum/ui/order_plan.rb'
88
88
  - 'lib/cryptum/ui/order_timer.rb'
89
89
 
90
- # Offense count: 84
90
+ # Offense count: 85
91
91
  Lint/UselessAssignment:
92
92
  Enabled: false
93
93
 
@@ -100,7 +100,7 @@ Metrics/AbcSize:
100
100
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, AllowedMethods, AllowedPatterns, IgnoredMethods.
101
101
  # AllowedMethods: refine
102
102
  Metrics/BlockLength:
103
- Max: 145
103
+ Max: 146
104
104
 
105
105
  # Offense count: 4
106
106
  # Configuration parameters: CountBlocks.
@@ -222,4 +222,4 @@ Style/TrailingCommaInArrayLiteral:
222
222
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
223
223
  # URISchemes: http, https
224
224
  Layout/LineLength:
225
- Max: 221
225
+ Max: 216
data/bin/cryptum CHANGED
@@ -28,6 +28,9 @@ begin
28
28
  # Exist and Initialize Automated Trading Parameters
29
29
  bot_conf = Cryptum::BotConf.read(option_choice: option_choice)
30
30
 
31
+ # Initialize Curses UI
32
+ terminal_win = Cryptum::UI.init
33
+
31
34
  # Generate an Order Book for Session Tracking
32
35
  # Load previous order_book_justification from
33
36
  # Order Book File (if it exists) to preserve
@@ -37,12 +40,10 @@ begin
37
40
  start_time: start_time,
38
41
  option_choice: option_choice,
39
42
  env: env,
40
- bot_conf: bot_conf
43
+ bot_conf: bot_conf,
44
+ terminal_win: terminal_win
41
45
  )
42
46
 
43
- # Initialize Curses UI
44
- terminal_win = Cryptum::UI.init
45
-
46
47
  # Connect to WebSocket
47
48
  # Trigger Events as Event Data
48
49
  # is Generated via Coinbase Pro
@@ -9,8 +9,10 @@ module Cryptum
9
9
  # )
10
10
  public_class_method def self.reload(opts = {})
11
11
  terminal_win = opts[:terminal_win]
12
+ event_history = opts[:event_history]
12
13
  option_choice = opts[:option_choice]
13
14
 
15
+ event_history.recalculate_order_plan = true
14
16
  terminal_win.key_press_event.key_r = false
15
17
  Cryptum.read_bot_conf(option_choice: option_choice)
16
18
  rescue StandardError => e
@@ -35,7 +35,8 @@ module Cryptum
35
35
  :order_execute_index_offset,
36
36
  :order_execute_max_rows_to_display,
37
37
  :order_execute_row_to_select,
38
- :order_execute_selected_data
38
+ :order_execute_selected_data,
39
+ :recalculate_order_plan
39
40
 
40
41
  def initialize(opts = {})
41
42
  # option_choice = opts[:option_choice]
@@ -48,7 +49,7 @@ module Cryptum
48
49
  self.order_submitted = false
49
50
  self.order_ready = false
50
51
  self.order_book = order_book
51
- self.plan_no = 0
52
+ self.plan_no = 1
52
53
  self.start_time = start_time
53
54
  self.reconnected = false
54
55
  self.red_pill = false
@@ -64,6 +65,7 @@ module Cryptum
64
65
  self.order_execute_max_rows_to_display = 6
65
66
  self.order_execute_row_to_select = order_execute_index_offset
66
67
  self.order_execute_selected_data = { color: :white }
68
+ self.recalculate_order_plan = false
67
69
 
68
70
  # TODO: Implement market_trend_reset / 144
69
71
  # Default = 10 minutes
@@ -14,9 +14,11 @@ module Cryptum
14
14
 
15
15
  terminal_win.key_press_event.key_w = false
16
16
  order_book_file = event_history.order_book[:path]
17
- File.open(order_book_file, 'w') do |f|
18
- f.puts event_history.order_book.to_json
19
- end
17
+
18
+ File.write(
19
+ order_book_file,
20
+ JSON.pretty_generate(event_history.order_book)
21
+ )
20
22
  rescue StandardError => e
21
23
  raise e
22
24
  end
data/lib/cryptum/event.rb CHANGED
@@ -122,6 +122,7 @@ module Cryptum
122
122
  bot_conf: bot_conf,
123
123
  fiat_portfolio_file: fiat_portfolio_file
124
124
  )
125
+ # event_history.recalculate_order_plan = false
125
126
  end
126
127
 
127
128
  if event_history.order_plan_details_win_active
@@ -20,6 +20,7 @@ module Cryptum
20
20
  option_choice = opts[:option_choice]
21
21
  env = opts[:env]
22
22
  bot_conf = opts[:bot_conf]
23
+ terminal_win = opts[:terminal_win]
23
24
 
24
25
  order_book_file = "#{option_choice.repo_root}/order_books/#{option_choice.symbol}.ORDER_BOOK.json"
25
26
 
@@ -85,12 +86,16 @@ module Cryptum
85
86
  )
86
87
 
87
88
  # Write order_book to file at session initiation
88
- File.open(order_book_file, 'w') do |f|
89
- f.puts order_book.to_json
90
- end
91
-
89
+ # File.open(order_book_file, 'w') do |f|
90
+ # f.puts order_book.to_json
91
+ # end
92
92
  event_history.order_book = order_book
93
93
 
94
+ Cryptum::Event::OrderBook.write(
95
+ terminal_win: terminal_win,
96
+ event_history: event_history
97
+ )
98
+
94
99
  event_history
95
100
  rescue StandardError => e
96
101
  raise e
@@ -21,7 +21,55 @@ module Cryptum
21
21
  order = event_history.order_execute_selected_data
22
22
  tpm = order[:tpm]
23
23
  autotrade_percent = order[:autotrade_percent]
24
- order_color = order[:color]
24
+ order_color = order[:color].to_sym
25
+
26
+ order_plan_no = order[:plan_no]
27
+ case order_color
28
+ when :cyan, :red
29
+ order_id = order[:buy_order_id]
30
+ order_type = 'Buy'
31
+ when :green, :magenta, :yellow
32
+ order_id = order[:sell_order_id]
33
+ order_type = 'Sell'
34
+ when :black
35
+ order_id = 'Expired'
36
+ order_type = 'Expired'
37
+ else
38
+ order_id = 'N/A'
39
+ order_type = 'N/A'
40
+ end
41
+
42
+ risk_alloc_out = Cryptum.beautify_large_number(
43
+ value: order[:risk_alloc]
44
+ )
45
+ invest_out = Cryptum.beautify_large_number(
46
+ value: order[:invest]
47
+ )
48
+ price_out = Cryptum.beautify_large_number(
49
+ value: order[:price]
50
+ )
51
+ size_out = Cryptum.beautify_large_number(
52
+ value: order[:size]
53
+ )
54
+ target_price_out = Cryptum.beautify_large_number(
55
+ value: order[:target_price]
56
+ )
57
+ profit_out = Cryptum.beautify_large_number(
58
+ value: order[:profit]
59
+ )
60
+ plan_no = "#{order[:plan_no]}|"
61
+
62
+ created_at = order[:created_at]
63
+
64
+ invest = "$#{invest_out} @ "
65
+ tick = "$#{price_out} = "
66
+ size = "*#{size_out} + "
67
+ tpm_out = "#{order[:tpm]}% = "
68
+ targ_tick = "$#{target_price_out}"
69
+ profit = "|Profit: $#{order[:profit]}"
70
+
71
+ order_id_details = "#{order_type} Order ID: #{order_id}"
72
+ order_exec_ln = "Details: #{created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}"
25
73
 
26
74
  # UI
27
75
  col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
@@ -71,42 +119,23 @@ module Cryptum
71
119
  order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
72
120
  order_execute_details_win.clrtoeol
73
121
 
74
- risk_alloc_out = Cryptum.beautify_large_number(
75
- value: order[:risk_alloc]
76
- )
77
- invest_out = Cryptum.beautify_large_number(
78
- value: order[:invest]
79
- )
80
- price_out = Cryptum.beautify_large_number(
81
- value: order[:price]
82
- )
83
- size_out = Cryptum.beautify_large_number(
84
- value: order[:size]
85
- )
86
- target_price_out = Cryptum.beautify_large_number(
87
- value: order[:target_price]
88
- )
89
- profit_out = Cryptum.beautify_large_number(
90
- value: order[:profit]
122
+ Cryptum::UI.colorize(
123
+ ui_win: order_execute_details_win,
124
+ color: order_color,
125
+ style: style,
126
+ string: order_id_details.ljust(col_just1, ' ')
91
127
  )
92
- plan_no = "#{order[:plan_no]}|"
93
-
94
- created_at = order[:created_at]
95
-
96
- invest = "$#{invest_out} @ "
97
- tick = "$#{price_out} = "
98
- size = "*#{size_out} + "
99
- tpm_out = "#{order[:tpm]}% = "
100
- targ_tick = "$#{target_price_out}"
101
- profit = "|Profit: $#{order[:profit]}"
102
128
 
103
- order_exec_ln = "#{created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}"
129
+ # ROW 5
130
+ out_line_no += 1
131
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
132
+ order_execute_details_win.clrtoeol
104
133
 
105
134
  Cryptum::UI.colorize(
106
135
  ui_win: order_execute_details_win,
107
136
  color: order_color,
108
137
  style: style,
109
- string: order_exec_ln.ljust(col_just1, '.')
138
+ string: order_exec_ln.ljust(col_just1, ' ')
110
139
  )
111
140
 
112
141
  # Clear to OK ROW
@@ -80,21 +80,27 @@ module Cryptum
80
80
 
81
81
  event_history.red_pill = true if crypto_invested_percent.to_f > autotrade_percent
82
82
 
83
- if crypto_invested_percent.to_f <= autotrade_percent &&
84
- autotrade_percent.positive? && (
85
- order_plan.empty? || (
86
- indicator_status.action_signal == :buy &&
87
- indicator_status.last_action_signal == :sell
83
+ if event_history.recalculate_order_plan || (
84
+ crypto_invested_percent.to_f <= autotrade_percent &&
85
+ autotrade_percent.positive? && (
86
+ order_plan.empty? || (
87
+ indicator_status.action_signal == :buy &&
88
+ indicator_status.last_action_signal == :sell
89
+ )
88
90
  )
89
91
  )
90
92
 
91
93
  event_history.red_pill = false
92
- # Reset time between orders when generating new order plan
93
- event_history.time_between_orders = event_history.time_between_orders_reset if order_plan.empty?
94
+ if indicator_status.action_signal == :buy &&
95
+ indicator_status.last_action_signal == :sell
96
+
97
+ order_plan = []
98
+ # Reset time between orders
99
+ event_history.time_between_orders = event_history.time_between_orders_reset
100
+ event_history.plan_no += 1
101
+ end
94
102
 
95
- order_plan = []
96
103
  plan_no_slice = 1
97
- event_history.plan_no += 1
98
104
  plan_no = event_history.plan_no
99
105
  # Sum up currently invested amount so we don't
100
106
  # exceed autotrade % for next order plan generation
@@ -124,8 +130,14 @@ module Cryptum
124
130
  next unless fiat_budget >= min_market_funds.to_f
125
131
 
126
132
  slice_alloc = risk_alloc * allocation_decimal
127
- order_slice = {}
128
- order_slice[:plan_no] = "#{plan_no}.#{plan_no_slice}"
133
+ this_plan_no = "#{plan_no}.#{plan_no_slice}"
134
+ if event_history.recalculate_order_plan
135
+ order_slice = order_plan.find do |order|
136
+ order[:plan_no] == this_plan_no
137
+ end
138
+ end
139
+ order_slice ||= {}
140
+ order_slice[:plan_no] = this_plan_no
129
141
  order_slice[:fiat_available] = format('%0.2f', fiat_budget)
130
142
  order_slice[:risk_alloc] = format('%0.2f', risk_alloc)
131
143
  order_slice[:allocation_decimal] = format(
@@ -142,11 +154,12 @@ module Cryptum
142
154
  order_slice[:return] = format('%0.2f', fiat_returning)
143
155
  order_slice[:profit] = format('%0.2f', profit)
144
156
 
145
- order_plan.push(order_slice)
157
+ order_plan.push(order_slice) unless event_history.recalculate_order_plan
146
158
  fiat_budget -= fiat_investing
147
159
  plan_no_slice += 1
148
160
  end
149
161
  event_history.order_book[:order_plan] = order_plan
162
+ event_history.recalculate_order_plan = false
150
163
  end
151
164
 
152
165
  red_pill_alert = '| RED PILL ALERT |'
@@ -42,12 +42,11 @@ module Cryptum
42
42
  return_out = Cryptum.beautify_large_number(
43
43
  value: order[:return]
44
44
  )
45
- autotrade_details = "1. bot_conf[:autotrade_portfolio_percent] is set to #{autotrade_percent}% of $#{fiat_avail_out},"
46
- risk_alloc_details = " making $#{risk_alloc_out} available for this slice in the order plan cycle."
47
- slice_alloc_details = "2. With $#{risk_alloc_out} available and a slice allocation of #{order[:allocation_percent]}%, $#{slice_alloc_out} OR AN ORDER MINIMUM"
48
- invest_details = " of $#{invest_out} will be allocated for this slice (whichever is highest)."
49
- tpm_details = "3. With a slice allocation of $#{invest_out} plus bot_conf[:target_profit_margin_percent] (TPM)"
50
- profit = " equal to #{tpm_out}% $#{return_out} will be returned. With $#{invest_out} invested the profit equals $#{profit_out}."
45
+ autotrade_details = "1. Autotrade is set to #{autotrade_percent}% of $#{fiat_avail_out}, making $#{risk_alloc_out} available for this slice in the order plan."
46
+ slice_alloc_details = "2. With $#{risk_alloc_out} available and a slice allocation of #{order[:allocation_percent]}%, $#{slice_alloc_out} OR AN ORDER MINIMUM of $#{invest_out} will"
47
+ invest_details = ' be allocated for this slice (whichever is highest).'
48
+ tpm_details = "3. With a slice allocation of $#{invest_out}, plus a TPM equal to #{tpm_out}%, $#{return_out} will be returned once sold."
49
+ profit = " With $#{invest_out} invested the gross profit equals $#{profit_out}, minus any transaction fees."
51
50
 
52
51
  # UI
53
52
  col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
@@ -104,18 +103,6 @@ module Cryptum
104
103
  string: autotrade_details.ljust(col_just1, ' ')
105
104
  )
106
105
 
107
- # ROW 4
108
- out_line_no += 1
109
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
110
- order_plan_details_win.clrtoeol
111
-
112
- Cryptum::UI.colorize(
113
- ui_win: order_plan_details_win,
114
- color: order_color,
115
- style: style,
116
- string: risk_alloc_details.ljust(col_just1, ' ')
117
- )
118
-
119
106
  # ROW 5
120
107
  out_line_no += 1
121
108
  order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- VERSION = '0.0.270'
4
+ VERSION = '0.0.272'
5
5
  end
@@ -104,6 +104,7 @@ module Cryptum
104
104
  if terminal_win.key_press_event.key_r
105
105
  bot_conf = Cryptum::Event::BotConf.reload(
106
106
  terminal_win: terminal_win,
107
+ event_history: event_history,
107
108
  option_choice: option_choice
108
109
  )
109
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.270
4
+ version: 0.0.272
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable