cryptum 0.0.324 → 0.0.326
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/cryptum +1 -0
- data/lib/cryptum/event.rb +0 -173
- data/lib/cryptum/option/choice.rb +1 -0
- data/lib/cryptum/option.rb +6 -0
- data/lib/cryptum/order_book/generate.rb +10 -0
- data/lib/cryptum/order_book/indicator.rb +0 -1
- data/lib/cryptum/order_book/market_trend.rb +51 -51
- data/lib/cryptum/version.rb +1 -1
- data/lib/cryptum/web_sock/event_machine.rb +139 -3
- metadata +2 -3
- data/lib/cryptum/order_book/weighted_avg.rb +0 -157
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d8c54730d0149d694842e5297e5507aa11fd7c2da04db91a21a1ec0e8c05330
|
|
4
|
+
data.tar.gz: 481624b37f1ac33a111bd0feb7f4767f981ed0af5eea741d52a4ca6cb812a803
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 331909ca683994e595a9021d3ffcdb5c16b602a3a442bd4f9a922ebc9f6bf2998945795d9ec1e4f45ddc1e8ea8eb12a8084e471a4e803a0d3f8a6656a81557b6
|
|
7
|
+
data.tar.gz: f1c7da8bcde3d6d379fcb7192041c36f11881d787cd4232c14195b23cb7f2c66970b8c5a093961c979b0d44bd22b5b1041f0b6f1c2f9a6b74c020e18ee35b8d3
|
data/bin/cryptum
CHANGED
data/lib/cryptum/event.rb
CHANGED
|
@@ -17,179 +17,6 @@ module Cryptum
|
|
|
17
17
|
autoload :Scroll, 'cryptum/event/scroll'
|
|
18
18
|
autoload :Sell, 'cryptum/event/sell'
|
|
19
19
|
|
|
20
|
-
# Supported Method Parameters::
|
|
21
|
-
# Cryptum::Event.parse(
|
|
22
|
-
# )
|
|
23
|
-
|
|
24
|
-
public_class_method def self.parse(opts = {})
|
|
25
|
-
option_choice = opts[:option_choice]
|
|
26
|
-
env = opts[:env]
|
|
27
|
-
terminal_win = opts[:terminal_win]
|
|
28
|
-
event_history = opts[:event_history]
|
|
29
|
-
indicator_status = opts[:indicator_status]
|
|
30
|
-
# indicator_history = opts[:indicator_history]
|
|
31
|
-
bot_conf = opts[:bot_conf]
|
|
32
|
-
# ai_enabled = opts[:ai_enabled]
|
|
33
|
-
|
|
34
|
-
# candles = event_history.order_book[:candles]
|
|
35
|
-
# order_history = event_history.order_book[:order_history]
|
|
36
|
-
this_product = event_history.order_book[:this_product]
|
|
37
|
-
fiat = this_product[:quote_currency]
|
|
38
|
-
fiat_portfolio_file = "#{option_choice.session_root}/order_books/#{fiat}_PORTFOLIO.json"
|
|
39
|
-
|
|
40
|
-
# Determine if Summary UI needs updated data
|
|
41
|
-
event_history = Cryptum::Portfolio::Balance.refresh(
|
|
42
|
-
env: env,
|
|
43
|
-
option_choice: option_choice,
|
|
44
|
-
terminal_win: terminal_win,
|
|
45
|
-
event_history: event_history,
|
|
46
|
-
fiat_portfolio_file: fiat_portfolio_file
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
# If the Terminal Window has been Resized, Resize the UI
|
|
50
|
-
if Curses.cols != terminal_win.cols
|
|
51
|
-
terminal_win.cols = Curses.cols
|
|
52
|
-
terminal_win.ticker_ui_resize = true
|
|
53
|
-
terminal_win.market_trend_ui_resize = true
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
event_history = Cryptum::UI::Portfolio.refresh(
|
|
57
|
-
option_choice: option_choice,
|
|
58
|
-
portfolio_win: terminal_win.portfolio_section,
|
|
59
|
-
event_history: event_history,
|
|
60
|
-
key_press_event: terminal_win.key_press_event,
|
|
61
|
-
indicator_status: indicator_status,
|
|
62
|
-
bot_conf: bot_conf,
|
|
63
|
-
fiat_portfolio_file: fiat_portfolio_file
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
if event_history.event_type == :ticker ||
|
|
67
|
-
terminal_win.ticker_ui_resize
|
|
68
|
-
|
|
69
|
-
ticker_event = event_history.ticker_event = event_history.event if event_history.event_type == :ticker
|
|
70
|
-
ticker_event = event_history.ticker_event if terminal_win.ticker_ui_resize
|
|
71
|
-
Cryptum::UI::Ticker.refresh(
|
|
72
|
-
option_choice: option_choice,
|
|
73
|
-
start_time: event_history.start_time,
|
|
74
|
-
ticker_win: terminal_win.ticker_section,
|
|
75
|
-
key_press_event: terminal_win.key_press_event,
|
|
76
|
-
order_book: event_history.order_book,
|
|
77
|
-
event: ticker_event
|
|
78
|
-
)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
Cryptum::UI::OrderTimer.refresh(
|
|
82
|
-
option_choice: option_choice,
|
|
83
|
-
event_history: event_history,
|
|
84
|
-
order_timer_win: terminal_win.order_timer_section,
|
|
85
|
-
indicator_status: indicator_status,
|
|
86
|
-
key_press_event: terminal_win.key_press_event
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
if event_history.event_type == :l2update ||
|
|
90
|
-
terminal_win.market_trend_ui_resize
|
|
91
|
-
|
|
92
|
-
market_trend_event = event_history.market_trend_event = event_history.event if event_history.event_type == :l2update
|
|
93
|
-
market_trend_event = event_history.market_trend_event if terminal_win.market_trend_ui_resize
|
|
94
|
-
event_history = Cryptum::UI::MarketTrend.refresh(
|
|
95
|
-
option_choice: option_choice,
|
|
96
|
-
market_trend_win: terminal_win.market_trend_section,
|
|
97
|
-
event_history: event_history,
|
|
98
|
-
key_press_event: terminal_win.key_press_event,
|
|
99
|
-
event: market_trend_event,
|
|
100
|
-
indicator_status: indicator_status,
|
|
101
|
-
bot_conf: bot_conf
|
|
102
|
-
)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
indicator_status = Cryptum::UI::SignalEngine.refresh(
|
|
106
|
-
option_choice: option_choice,
|
|
107
|
-
signal_engine_win: terminal_win.signal_engine_section,
|
|
108
|
-
event_history: event_history,
|
|
109
|
-
key_press_event: terminal_win.key_press_event,
|
|
110
|
-
indicator_status: indicator_status,
|
|
111
|
-
bot_conf: bot_conf,
|
|
112
|
-
fiat_portfolio_file: fiat_portfolio_file
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
unless event_history.order_plan_details_win_active
|
|
116
|
-
event_history = Cryptum::UI::OrderPlan.refresh(
|
|
117
|
-
option_choice: option_choice,
|
|
118
|
-
order_plan_win: terminal_win.order_plan_section,
|
|
119
|
-
env: env,
|
|
120
|
-
event_history: event_history,
|
|
121
|
-
key_press_event: terminal_win.key_press_event,
|
|
122
|
-
indicator_status: indicator_status,
|
|
123
|
-
bot_conf: bot_conf,
|
|
124
|
-
fiat_portfolio_file: fiat_portfolio_file
|
|
125
|
-
)
|
|
126
|
-
recalc_op = event_history.recalculate_order_plan
|
|
127
|
-
order_plan = event_history.order_book[:order_plan]
|
|
128
|
-
terminal_win.key_press_event.key_w = true if (recalc_op || order_plan.empty?) &&
|
|
129
|
-
!event_history.red_pill
|
|
130
|
-
event_history.recalculate_order_plan = false
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
if event_history.order_plan_details_win_active
|
|
134
|
-
event_history = Cryptum::UI::OrderPlanDetails.refresh(
|
|
135
|
-
option_choice: option_choice,
|
|
136
|
-
order_plan_details_win: terminal_win.order_plan_details_section,
|
|
137
|
-
event_history: event_history,
|
|
138
|
-
key_press_event: terminal_win.key_press_event
|
|
139
|
-
)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
unless event_history.order_execute_details_win_active
|
|
143
|
-
event_history = Cryptum::UI::OrderExecution.refresh(
|
|
144
|
-
option_choice: option_choice,
|
|
145
|
-
order_execute_win: terminal_win.order_execute_section,
|
|
146
|
-
env: env,
|
|
147
|
-
event_history: event_history,
|
|
148
|
-
key_press_event: terminal_win.key_press_event,
|
|
149
|
-
indicator_status: indicator_status,
|
|
150
|
-
bot_conf: bot_conf,
|
|
151
|
-
fiat_portfolio_file: fiat_portfolio_file
|
|
152
|
-
)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
if event_history.order_execute_details_win_active
|
|
156
|
-
event_history = Cryptum::UI::OrderExecuteDetails.refresh(
|
|
157
|
-
option_choice: option_choice,
|
|
158
|
-
order_execute_details_win: terminal_win.order_execute_details_section,
|
|
159
|
-
event_history: event_history,
|
|
160
|
-
key_press_event: terminal_win.key_press_event
|
|
161
|
-
)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
# Refresh Command Section for Cryptum Session Usage
|
|
165
|
-
Cryptum::UI::Command.refresh(
|
|
166
|
-
command_win: terminal_win.command_section,
|
|
167
|
-
key_press_event: terminal_win.key_press_event
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
# last_ticker_price = event_history.order_book[:ticker_price].to_f
|
|
171
|
-
# second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
|
|
172
|
-
# third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
|
|
173
|
-
|
|
174
|
-
event_history
|
|
175
|
-
rescue LoadError => e
|
|
176
|
-
# This happens when autoloading modules fail.
|
|
177
|
-
File.open('/tmp/cryptum-errors.txt', 'a') do |f|
|
|
178
|
-
f.puts Time.now.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
|
179
|
-
f.puts "Module: #{self}"
|
|
180
|
-
f.puts "#{e}\n\n\n"
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
retry
|
|
184
|
-
rescue Interrupt
|
|
185
|
-
# Exit Gracefully if CTRL+C is Pressed During Session
|
|
186
|
-
Cryptum.exit_gracefully(which_self: self)
|
|
187
|
-
rescue StandardError => e
|
|
188
|
-
raise e
|
|
189
|
-
ensure
|
|
190
|
-
$stdout.flush
|
|
191
|
-
end
|
|
192
|
-
|
|
193
20
|
# Display Usage for this Module
|
|
194
21
|
|
|
195
22
|
public_class_method def self.help
|
data/lib/cryptum/option.rb
CHANGED
|
@@ -41,6 +41,12 @@ module Cryptum
|
|
|
41
41
|
'<Optional - HTTP Proxy e.g. "http://127.0.0.1:8080">'
|
|
42
42
|
) { |p| option_choice.proxy = p }
|
|
43
43
|
|
|
44
|
+
options.on(
|
|
45
|
+
'-R',
|
|
46
|
+
'--[no-]reset-session-countdown',
|
|
47
|
+
'<Optional - Reset Timers / Market Trend Stats at Session Init (Defaults to false)>'
|
|
48
|
+
) { |t| option_choice.reset_session_countdown = t }
|
|
49
|
+
|
|
44
50
|
options.on(
|
|
45
51
|
'-rPATH',
|
|
46
52
|
'--session-root=PATH',
|
|
@@ -82,6 +82,16 @@ module Cryptum
|
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
event_history.order_book = order_book
|
|
85
|
+
if option_choice.reset_session_countdown
|
|
86
|
+
event_history.order_book[:market_trend][:buy] = 0
|
|
87
|
+
event_history.order_book[:market_trend][:sell] = 0
|
|
88
|
+
event_history.order_book[:last_trend_reset] = Time.now.strftime(
|
|
89
|
+
'%Y-%m-%d %H:%M:%S.%N%z'
|
|
90
|
+
)
|
|
91
|
+
event_history.order_book[:last_order_exec] = Time.now.strftime(
|
|
92
|
+
'%Y-%m-%d %H:%M:%S.%N%z'
|
|
93
|
+
)
|
|
94
|
+
end
|
|
85
95
|
|
|
86
96
|
event_history
|
|
87
97
|
rescue StandardError => e
|
|
@@ -62,57 +62,57 @@ module Cryptum
|
|
|
62
62
|
raise e
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
public_class_method def self.reset(opts = {})
|
|
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
|
-
rescue StandardError => e
|
|
114
|
-
|
|
115
|
-
end
|
|
65
|
+
# public_class_method def self.reset(opts = {})
|
|
66
|
+
# # IT IS ABSOLUTELY CRITICAL THIS METHOD IS AS FAST AS POSSIBLE
|
|
67
|
+
# # TO AVOID TICKER PRICE SYNCING ISSUES.
|
|
68
|
+
# event_history = opts[:event_history]
|
|
69
|
+
|
|
70
|
+
# # order_history = event_history.order_book[:order_history]
|
|
71
|
+
# # order_history_meta = event_history.order_book[:order_history_meta]
|
|
72
|
+
|
|
73
|
+
# # Only retain past 24 hours of
|
|
74
|
+
# # order history meta for bought, sold, and expired
|
|
75
|
+
# # keep open limit sell orders indefintely
|
|
76
|
+
# # before_twenty_four_hrs_ago = Time.now - 86_400
|
|
77
|
+
# # order_history_meta.delete_if do |ohm|
|
|
78
|
+
# # order_history.find do |oh|
|
|
79
|
+
# # next unless oh[:done_at]
|
|
80
|
+
|
|
81
|
+
# # Time.parse(oh[:done_at]) < before_twenty_four_hrs_ago && (
|
|
82
|
+
# # oh[:id] == ohm[:buy_order_id] ||
|
|
83
|
+
# # oh[:id] == ohm[:sell_order_id]
|
|
84
|
+
# # ) && (
|
|
85
|
+
# # ohm[:color].to_sym == :white ||
|
|
86
|
+
# # ohm[:color].to_sym == :green ||
|
|
87
|
+
# # ohm[:color].to_sym == :cyan ||
|
|
88
|
+
# # ohm[:color].to_sym == :red
|
|
89
|
+
# # )
|
|
90
|
+
# # end
|
|
91
|
+
# # end
|
|
92
|
+
|
|
93
|
+
# # Only keep order history meta for those
|
|
94
|
+
# # hashes that exist in the last order history
|
|
95
|
+
# # response
|
|
96
|
+
# # order_history_meta.keep_if do |ohm|
|
|
97
|
+
# # order_history.find do |oh|
|
|
98
|
+
# # (oh[:id] == ohm[:buy_order_id] || oh[:id] == ohm[:sell_order_id]) && (
|
|
99
|
+
# # ohm[:color].to_sym == :white ||
|
|
100
|
+
# # ohm[:color].to_sym == :green ||
|
|
101
|
+
# # ohm[:color].to_sym == :yellow
|
|
102
|
+
# # )
|
|
103
|
+
# # end
|
|
104
|
+
# # end
|
|
105
|
+
# # event_history.order_book[:order_history_meta] = order_history_meta
|
|
106
|
+
|
|
107
|
+
# # Reset Market Trend Counter
|
|
108
|
+
# event_history.order_book[:market_trend][:buy] = 0
|
|
109
|
+
# event_history.order_book[:market_trend][:sell] = 0
|
|
110
|
+
# event_history.order_book[:last_trend_reset] = Time.now.strftime(
|
|
111
|
+
# '%Y-%m-%d %H:%M:%S.%N%z'
|
|
112
|
+
# )
|
|
113
|
+
# rescue StandardError => e
|
|
114
|
+
# raise e
|
|
115
|
+
# end
|
|
116
116
|
|
|
117
117
|
# Display Usage for this Module
|
|
118
118
|
|
data/lib/cryptum/version.rb
CHANGED
|
@@ -55,23 +55,157 @@ module Cryptum
|
|
|
55
55
|
# Explore another way to decouple required events
|
|
56
56
|
# (such as keypresses) from only being triggered
|
|
57
57
|
# when messages come through.
|
|
58
|
-
ai_enabled = bot_conf[:artifical_intelligence]
|
|
59
58
|
|
|
60
59
|
event_history.event = JSON.parse(
|
|
61
60
|
event.data,
|
|
62
61
|
symbolize_names: true
|
|
63
62
|
)
|
|
64
63
|
event_history.event_type = event_history.event[:type].to_s.to_sym
|
|
65
|
-
|
|
64
|
+
|
|
65
|
+
this_product = event_history.order_book[:this_product]
|
|
66
|
+
fiat = this_product[:quote_currency]
|
|
67
|
+
fiat_portfolio_file = "#{option_choice.session_root}/order_books/#{fiat}_PORTFOLIO.json"
|
|
68
|
+
|
|
69
|
+
# Determine if Summary UI needs updated data
|
|
70
|
+
event_history = Cryptum::Portfolio::Balance.refresh(
|
|
66
71
|
env: env,
|
|
72
|
+
option_choice: option_choice,
|
|
67
73
|
terminal_win: terminal_win,
|
|
74
|
+
event_history: event_history,
|
|
75
|
+
fiat_portfolio_file: fiat_portfolio_file
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# If the Terminal Window has been Resized, Resize the UI
|
|
79
|
+
if Curses.cols != terminal_win.cols
|
|
80
|
+
terminal_win.cols = Curses.cols
|
|
81
|
+
terminal_win.ticker_ui_resize = true
|
|
82
|
+
terminal_win.market_trend_ui_resize = true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
event_history = Cryptum::UI::Portfolio.refresh(
|
|
68
86
|
option_choice: option_choice,
|
|
87
|
+
portfolio_win: terminal_win.portfolio_section,
|
|
69
88
|
event_history: event_history,
|
|
89
|
+
key_press_event: terminal_win.key_press_event,
|
|
70
90
|
indicator_status: indicator_status,
|
|
71
91
|
bot_conf: bot_conf,
|
|
72
|
-
|
|
92
|
+
fiat_portfolio_file: fiat_portfolio_file
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
if event_history.event_type == :ticker ||
|
|
96
|
+
terminal_win.ticker_ui_resize
|
|
97
|
+
|
|
98
|
+
ticker_event = event_history.ticker_event = event_history.event if event_history.event_type == :ticker
|
|
99
|
+
ticker_event = event_history.ticker_event if terminal_win.ticker_ui_resize
|
|
100
|
+
Cryptum::UI::Ticker.refresh(
|
|
101
|
+
option_choice: option_choice,
|
|
102
|
+
start_time: event_history.start_time,
|
|
103
|
+
ticker_win: terminal_win.ticker_section,
|
|
104
|
+
key_press_event: terminal_win.key_press_event,
|
|
105
|
+
order_book: event_history.order_book,
|
|
106
|
+
event: ticker_event
|
|
107
|
+
)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
Cryptum::UI::OrderTimer.refresh(
|
|
111
|
+
option_choice: option_choice,
|
|
112
|
+
event_history: event_history,
|
|
113
|
+
order_timer_win: terminal_win.order_timer_section,
|
|
114
|
+
indicator_status: indicator_status,
|
|
115
|
+
key_press_event: terminal_win.key_press_event
|
|
73
116
|
)
|
|
74
117
|
|
|
118
|
+
if event_history.event_type == :l2update ||
|
|
119
|
+
terminal_win.market_trend_ui_resize
|
|
120
|
+
|
|
121
|
+
market_trend_event = event_history.market_trend_event = event_history.event if event_history.event_type == :l2update
|
|
122
|
+
market_trend_event = event_history.market_trend_event if terminal_win.market_trend_ui_resize
|
|
123
|
+
event_history = Cryptum::UI::MarketTrend.refresh(
|
|
124
|
+
option_choice: option_choice,
|
|
125
|
+
market_trend_win: terminal_win.market_trend_section,
|
|
126
|
+
event_history: event_history,
|
|
127
|
+
key_press_event: terminal_win.key_press_event,
|
|
128
|
+
event: market_trend_event,
|
|
129
|
+
indicator_status: indicator_status,
|
|
130
|
+
bot_conf: bot_conf
|
|
131
|
+
)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
indicator_status = Cryptum::UI::SignalEngine.refresh(
|
|
135
|
+
option_choice: option_choice,
|
|
136
|
+
signal_engine_win: terminal_win.signal_engine_section,
|
|
137
|
+
event_history: event_history,
|
|
138
|
+
key_press_event: terminal_win.key_press_event,
|
|
139
|
+
indicator_status: indicator_status,
|
|
140
|
+
bot_conf: bot_conf,
|
|
141
|
+
fiat_portfolio_file: fiat_portfolio_file
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
unless event_history.order_plan_details_win_active
|
|
145
|
+
event_history = Cryptum::UI::OrderPlan.refresh(
|
|
146
|
+
option_choice: option_choice,
|
|
147
|
+
order_plan_win: terminal_win.order_plan_section,
|
|
148
|
+
env: env,
|
|
149
|
+
event_history: event_history,
|
|
150
|
+
key_press_event: terminal_win.key_press_event,
|
|
151
|
+
indicator_status: indicator_status,
|
|
152
|
+
bot_conf: bot_conf,
|
|
153
|
+
fiat_portfolio_file: fiat_portfolio_file
|
|
154
|
+
)
|
|
155
|
+
recalc_op = event_history.recalculate_order_plan
|
|
156
|
+
order_plan = event_history.order_book[:order_plan]
|
|
157
|
+
terminal_win.key_press_event.key_w = true if (recalc_op || order_plan.empty?) &&
|
|
158
|
+
!event_history.red_pill
|
|
159
|
+
event_history.recalculate_order_plan = false
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
if event_history.order_plan_details_win_active
|
|
163
|
+
event_history = Cryptum::UI::OrderPlanDetails.refresh(
|
|
164
|
+
option_choice: option_choice,
|
|
165
|
+
order_plan_details_win: terminal_win.order_plan_details_section,
|
|
166
|
+
event_history: event_history,
|
|
167
|
+
key_press_event: terminal_win.key_press_event
|
|
168
|
+
)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
unless event_history.order_execute_details_win_active
|
|
172
|
+
event_history = Cryptum::UI::OrderExecution.refresh(
|
|
173
|
+
option_choice: option_choice,
|
|
174
|
+
order_execute_win: terminal_win.order_execute_section,
|
|
175
|
+
env: env,
|
|
176
|
+
event_history: event_history,
|
|
177
|
+
key_press_event: terminal_win.key_press_event,
|
|
178
|
+
indicator_status: indicator_status,
|
|
179
|
+
bot_conf: bot_conf,
|
|
180
|
+
fiat_portfolio_file: fiat_portfolio_file
|
|
181
|
+
)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
if event_history.order_execute_details_win_active
|
|
185
|
+
event_history = Cryptum::UI::OrderExecuteDetails.refresh(
|
|
186
|
+
option_choice: option_choice,
|
|
187
|
+
order_execute_details_win: terminal_win.order_execute_details_section,
|
|
188
|
+
event_history: event_history,
|
|
189
|
+
key_press_event: terminal_win.key_press_event
|
|
190
|
+
)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Refresh Command Section for Cryptum Session Usage
|
|
194
|
+
Cryptum::UI::Command.refresh(
|
|
195
|
+
command_win: terminal_win.command_section,
|
|
196
|
+
key_press_event: terminal_win.key_press_event
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# event_history = Cryptum::Event.parse(
|
|
200
|
+
# env: env,
|
|
201
|
+
# terminal_win: terminal_win,
|
|
202
|
+
# option_choice: option_choice,
|
|
203
|
+
# event_history: event_history,
|
|
204
|
+
# indicator_status: indicator_status,
|
|
205
|
+
# bot_conf: bot_conf,
|
|
206
|
+
# ai_enabled: ai_enabled
|
|
207
|
+
# )
|
|
208
|
+
|
|
75
209
|
# Detect Key Press Events
|
|
76
210
|
Cryptum::Event::KeyPress.detect(terminal_win: terminal_win)
|
|
77
211
|
|
|
@@ -249,6 +383,8 @@ module Cryptum
|
|
|
249
383
|
|
|
250
384
|
sleep 1
|
|
251
385
|
retry
|
|
386
|
+
ensure
|
|
387
|
+
$stdout.flush
|
|
252
388
|
end
|
|
253
389
|
rescue Interrupt
|
|
254
390
|
# Exit Gracefully if CTRL+C is Pressed During Session
|
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.
|
|
4
|
+
version: 0.0.326
|
|
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-
|
|
11
|
+
date: 2022-12-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|
|
@@ -401,7 +401,6 @@ files:
|
|
|
401
401
|
- lib/cryptum/order_book/indicator.rb
|
|
402
402
|
- lib/cryptum/order_book/market_trend.rb
|
|
403
403
|
- lib/cryptum/order_book/profit_margin.rb
|
|
404
|
-
- lib/cryptum/order_book/weighted_avg.rb
|
|
405
404
|
- lib/cryptum/portfolio.rb
|
|
406
405
|
- lib/cryptum/portfolio/balance.rb
|
|
407
406
|
- lib/cryptum/ui.rb
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Cryptum
|
|
4
|
-
# This plugin is used to indicate if the Weighted Executed Buy Orders are less than the Weighted Excuted Sell Orders
|
|
5
|
-
|
|
6
|
-
module OrderBook
|
|
7
|
-
module WeightedAvg
|
|
8
|
-
# Supported Method Parameters::
|
|
9
|
-
# Cryptum::OrderBook::WeightedAvg.status(
|
|
10
|
-
# order_book: 'required - order_book data structure'
|
|
11
|
-
# )
|
|
12
|
-
|
|
13
|
-
public_class_method def self.status(opts = {})
|
|
14
|
-
order_book = opts[:order_book]
|
|
15
|
-
order_history = order_book[:order_history]
|
|
16
|
-
indicator_status = opts[:indicator_status]
|
|
17
|
-
invested = opts[:invested]
|
|
18
|
-
|
|
19
|
-
indicator_hash = {}
|
|
20
|
-
indicator_hash[:invested] = invested
|
|
21
|
-
|
|
22
|
-
buy_orders_done = order_history.select do |orders|
|
|
23
|
-
orders[:side] == 'buy' &&
|
|
24
|
-
orders[:status] == 'done' &&
|
|
25
|
-
orders[:done_reason] == 'filled'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
total_buy_orders_done = buy_orders_done.length
|
|
29
|
-
avg_buy_exec = format('%0.7f', 0.00).to_f
|
|
30
|
-
# total_buy_executed = 0.00
|
|
31
|
-
# total_invested = 0.00
|
|
32
|
-
# buy_fees = 0.00
|
|
33
|
-
if total_buy_orders_done.positive?
|
|
34
|
-
# Calculate Weighted Avg. of Completed Buy Orders
|
|
35
|
-
weighted_buy_prices_arr = []
|
|
36
|
-
buy_orders_done.each do |order|
|
|
37
|
-
weighted_hash = {}
|
|
38
|
-
executed_value = order[:executed_value].to_f
|
|
39
|
-
filled_size = order[:filled_size].to_f
|
|
40
|
-
weighted_hash[:price] = (executed_value / filled_size).to_f
|
|
41
|
-
weighted_hash[:filled_size] = filled_size
|
|
42
|
-
weighted_hash[:price_times_filled_size] = weighted_hash[:price] * filled_size
|
|
43
|
-
weighted_buy_prices_arr.push(weighted_hash)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
price_times_filled_size = weighted_buy_prices_arr.sum do |orders|
|
|
47
|
-
orders[:price_times_filled_size].to_f
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
this_filled_size = weighted_buy_prices_arr.sum do |orders|
|
|
51
|
-
orders[:filled_size]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
calc_avg_buy_exec = price_times_filled_size / this_filled_size
|
|
55
|
-
avg_buy_exec = format('%0.7f', calc_avg_buy_exec).to_f
|
|
56
|
-
|
|
57
|
-
executed_value = buy_orders_done.sum do |orders|
|
|
58
|
-
orders[:executed_value].to_f
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# total_buy_executed = format('%0.7f', executed_value).to_f
|
|
62
|
-
|
|
63
|
-
# fill_fees = buy_orders_done.sum do |orders|
|
|
64
|
-
# orders[:fill_fees].to_f
|
|
65
|
-
# end
|
|
66
|
-
|
|
67
|
-
# buy_fees = format('%0.7f', fill_fees).to_f
|
|
68
|
-
|
|
69
|
-
# calc_total_invested = total_buy_executed.to_f - buy_fees.to_f
|
|
70
|
-
# total_invested = format('%0.7f', calc_total_invested).to_f
|
|
71
|
-
end
|
|
72
|
-
order_book[:avg_buy_exec] = avg_buy_exec
|
|
73
|
-
|
|
74
|
-
sell_orders_done = order_history.select do |orders|
|
|
75
|
-
orders[:side] == 'sell' &&
|
|
76
|
-
orders[:status] == 'done' &&
|
|
77
|
-
orders[:done_reason] == 'filled'
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
total_sell_orders_done = sell_orders_done.length
|
|
81
|
-
avg_sell_exec = format('%0.7f', 0.00).to_f
|
|
82
|
-
# total_sell_executed = format('%0.7f', 0.00).to_f
|
|
83
|
-
# total_return = format('%0.7f', 0.00).to_f
|
|
84
|
-
# sell_fees = format('%0.7f', 0.00).to_f
|
|
85
|
-
if total_sell_orders_done.positive?
|
|
86
|
-
# Calculate Weighted Avg. of Completed Sell Orders
|
|
87
|
-
weighted_sell_prices_arr = []
|
|
88
|
-
sell_orders_done.each do |order|
|
|
89
|
-
weighted_hash = {}
|
|
90
|
-
executed_value = order[:executed_value].to_f
|
|
91
|
-
filled_size = order[:filled_size].to_f
|
|
92
|
-
weighted_hash[:price] = (executed_value / filled_size).to_f
|
|
93
|
-
weighted_hash[:filled_size] = filled_size
|
|
94
|
-
weighted_hash[:price_times_filled_size] = weighted_hash[:price] * filled_size
|
|
95
|
-
weighted_sell_prices_arr.push(weighted_hash)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
price_times_filled_size = weighted_sell_prices_arr.sum do |orders|
|
|
99
|
-
orders[:price_times_filled_size].to_f
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
this_filled_size = weighted_sell_prices_arr.sum do |orders|
|
|
103
|
-
orders[:filled_size]
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
calc_avg_sell_exec = price_times_filled_size / this_filled_size
|
|
107
|
-
avg_sell_exec = format('%0.7f', calc_avg_sell_exec).to_f
|
|
108
|
-
|
|
109
|
-
executed_value = sell_orders_done.sum do |orders|
|
|
110
|
-
orders[:executed_value].to_f
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# total_sell_executed = format('%0.7f', executed_value).to_f
|
|
114
|
-
|
|
115
|
-
# fill_fees = sell_orders_done.sum do |orders|
|
|
116
|
-
# orders[:fill_fees].to_f
|
|
117
|
-
# end
|
|
118
|
-
|
|
119
|
-
# sell_fees = format('%0.7f', fill_fees).to_f
|
|
120
|
-
# calc_total_made = total_sell_executed.to_f - sell_fees.to_f
|
|
121
|
-
# total_return = format('%0.7f', calc_total_made).to_f
|
|
122
|
-
end
|
|
123
|
-
order_book[:avg_sell_exec] = avg_sell_exec
|
|
124
|
-
|
|
125
|
-
if avg_buy_exec < avg_sell_exec
|
|
126
|
-
indicator_hash[:color] = :green
|
|
127
|
-
weight_op = '<'
|
|
128
|
-
elsif avg_buy_exec > avg_sell_exec
|
|
129
|
-
indicator_hash[:color] = :red
|
|
130
|
-
weight_op = '>'
|
|
131
|
-
else
|
|
132
|
-
indicator_hash[:color] = :yellow
|
|
133
|
-
weight_op = '=='
|
|
134
|
-
end
|
|
135
|
-
weighted_avg_status_out = "VWAPB #{weight_op} VWAPS"
|
|
136
|
-
order_book[:candles].last[:weighted_avg_status] = weighted_avg_status_out
|
|
137
|
-
indicator_hash[:status] = weighted_avg_status_out
|
|
138
|
-
# indicator_hash[:order_book] = order_book
|
|
139
|
-
|
|
140
|
-
indicator_status.weighted_avg = indicator_hash
|
|
141
|
-
# indicator_hash
|
|
142
|
-
rescue StandardError => e
|
|
143
|
-
raise e
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
# Display Usage for this Module
|
|
147
|
-
|
|
148
|
-
public_class_method def self.help
|
|
149
|
-
puts "USAGE:
|
|
150
|
-
weighted_avg_indicator_hash = #{self}.status(
|
|
151
|
-
order_book: 'required - order_book data structure'
|
|
152
|
-
)
|
|
153
|
-
"
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|