cryptum 0.0.383 → 0.0.385
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/cryptum/api/orders.rb +2 -2
- data/lib/cryptum/event/buy.rb +11 -115
- data/lib/cryptum/event/exit.rb +1 -1
- data/lib/cryptum/event/order_book.rb +1 -1
- data/lib/cryptum/event/parse.rb +1 -1
- data/lib/cryptum/event/sell.rb +15 -96
- data/lib/cryptum/ui/matrix.rb +5 -3
- data/lib/cryptum/ui/order/execute.rb +2 -4
- data/lib/cryptum/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 458a0c463a08f598e1694034fbf077f46a8ba8b263c408fd574b35211c40a69b
|
4
|
+
data.tar.gz: 8b8bf8cf3ff0cd9dfa1ebb3609ad50e6f05d09aea705e726b840060e58d39c32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3963c369c745590402ff8943487eb057541b6eae6278cf67992981cbdb0919c847207fcfb43cac8b3cf991b5c1c866adc57035e6106a5715ed7f439ab4e92a8a
|
7
|
+
data.tar.gz: d6abdb55f67bab96545d5207c9d4e995edcbec9d9a85d49b13e01a4a2d4522c5e9b20529460f1b2e20a10dad7f3dc2edfc78376215f85888b2278f5d0131582f
|
data/Gemfile
CHANGED
@@ -11,7 +11,7 @@ gemspec
|
|
11
11
|
# In some circumstances custom flags are passed to gems in order
|
12
12
|
# to build appropriately. Defer to ./reinstall_coinbot_gemset.sh
|
13
13
|
# to review these custom flags
|
14
|
-
gem 'addressable', '2.8.
|
14
|
+
gem 'addressable', '2.8.2'
|
15
15
|
gem 'bundler', '>=2.4.10'
|
16
16
|
gem 'bundler-audit', '0.9.1'
|
17
17
|
gem 'curses', '1.4.4'
|
data/lib/cryptum/api/orders.rb
CHANGED
@@ -4,7 +4,7 @@ module Cryptum
|
|
4
4
|
# This plugin is used to interact withbtje Coinbase REST API
|
5
5
|
module API
|
6
6
|
module Orders
|
7
|
-
public_class_method def self.
|
7
|
+
public_class_method def self.submit_limit(opts = {})
|
8
8
|
option_choice = opts[:option_choice]
|
9
9
|
env = opts[:env]
|
10
10
|
price = opts[:price]
|
@@ -237,7 +237,7 @@ module Cryptum
|
|
237
237
|
|
238
238
|
public_class_method def self.help
|
239
239
|
puts "USAGE:
|
240
|
-
event_history = #{self}.
|
240
|
+
event_history = #{self}.submit_limit(
|
241
241
|
env: 'required - Coinbase::Option::Environment.get Object'
|
242
242
|
)
|
243
243
|
|
data/lib/cryptum/event/buy.rb
CHANGED
@@ -12,124 +12,20 @@ module Cryptum
|
|
12
12
|
public_class_method def self.crypto(opts = {})
|
13
13
|
option_choice = opts[:option_choice]
|
14
14
|
env = opts[:env]
|
15
|
-
|
15
|
+
price = opts[:price]
|
16
|
+
size = opts[:size]
|
16
17
|
event_history = opts[:event_history]
|
17
|
-
|
18
|
-
fiat_smallest_decimal = opts[:fiat_smallest_decimal]
|
19
|
-
# fiat_portfolio_file = opts[:fiat_portfolio_file]
|
20
|
-
order_history = opts[:order_history]
|
21
|
-
crypto_smallest_decimal = opts[:crypto_smallest_decimal]
|
22
|
-
# base_min_size = opts[:base_min_size]
|
23
|
-
min_market_funds = this_product[:min_market_funds]
|
24
|
-
indicator_status = opts[:indicator_status]
|
25
|
-
|
26
|
-
# Initialize some bot_conf variables
|
27
|
-
pie_in_sky_buy_percent = bot_conf[:pie_in_sky_buy_percent].to_f
|
28
|
-
autotrade_portfolio_percent = bot_conf[:autotrade_portfolio_percent].to_f
|
29
|
-
# target_profit_margin_percent = bot_conf[:target_profit_margin_percent].to_f
|
30
|
-
|
31
|
-
crypto_currency = option_choice.symbol.to_s.upcase.split('_').first
|
32
|
-
portfolio = event_history.order_book[:portfolio]
|
33
|
-
symbol_portfolio = portfolio.select do |this_portfolio|
|
34
|
-
this_portfolio if this_portfolio[:currency] == crypto_currency
|
35
|
-
end
|
36
|
-
|
37
|
-
symbol_balance = format(
|
38
|
-
'%0.8f',
|
39
|
-
symbol_portfolio.first[:balance].to_f
|
40
|
-
).to_f
|
41
|
-
|
42
|
-
# 2. Calculate Price, Size, Fees
|
43
|
-
# Get the middle of last 3 ticker prices
|
44
|
-
# to avoid over purcase blips.
|
45
|
-
last_three_prices_arr = []
|
46
|
-
last_ticker_price = event_history.order_book[:ticker_price].to_f
|
47
|
-
second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
|
48
|
-
third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
|
49
|
-
last_three_prices_arr.push(last_ticker_price)
|
50
|
-
last_three_prices_arr.push(second_to_last_ticker_price)
|
51
|
-
last_three_prices_arr.push(third_to_last_ticker_price)
|
52
|
-
|
53
|
-
case order_type
|
54
|
-
when :pie
|
55
|
-
limit_price = last_three_prices_arr.sort[1]
|
56
|
-
pie_in_sky_buy_percent_cast_as_decimal = format(
|
57
|
-
'%0.2f',
|
58
|
-
pie_in_sky_buy_percent * 0.01
|
59
|
-
).to_f
|
60
|
-
|
61
|
-
limit_price -= (limit_price * pie_in_sky_buy_percent_cast_as_decimal)
|
62
|
-
when :tpm
|
63
|
-
limit_price = last_three_prices_arr.sort[1]
|
64
|
-
when :gtfo
|
65
|
-
# price = format("%0.#{fiat_smallest_decimal}f", limit_price)
|
66
|
-
raise "ERROR: Why is a Buy Submitted for #{order_type}?"
|
67
|
-
else
|
68
|
-
raise "ERROR: Unknown order_type: #{order_type}"
|
69
|
-
end
|
70
|
-
|
71
|
-
price = format("%0.#{fiat_smallest_decimal}f", limit_price)
|
72
|
-
|
73
|
-
# TODO: Determine if our N% Autotrade
|
74
|
-
# Threshold has already been met
|
75
|
-
# Buying Crypto w/ Fiat
|
76
|
-
autotrade_portfolio_percent_cast_as_decimal = format(
|
77
|
-
'%0.7f',
|
78
|
-
autotrade_portfolio_percent * 0.01
|
79
|
-
).to_f
|
80
|
-
|
81
|
-
fiat_portfolio = event_history.order_book[:fiat_portfolio]
|
82
|
-
fiat_balance_available = format(
|
83
|
-
"%0.#{fiat_smallest_decimal}f",
|
84
|
-
fiat_portfolio.first[:available]
|
85
|
-
).to_f
|
86
|
-
|
87
|
-
# Make sure size is within constraints
|
88
|
-
# of autotrade_portfolio_percent
|
89
|
-
total_limit_buy_orders_open = order_history.select do |orders|
|
90
|
-
orders[:type] == 'limit' &&
|
91
|
-
orders[:side] == 'buy' &&
|
92
|
-
orders[:status] == 'open'
|
93
|
-
end
|
94
|
-
|
95
|
-
total_limit_buy_order_open_tot = total_limit_buy_orders_open.length
|
96
|
-
total_limit_buy_orders_open_size = total_limit_buy_orders_open.inject(0) do |sum, hash|
|
97
|
-
sum + hash[:size].to_f
|
98
|
-
end.to_f
|
18
|
+
bot_conf = opts[:bot_conf]
|
99
19
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
20
|
+
Cryptum::API::Orders.submit_limit(
|
21
|
+
option_choice: option_choice,
|
22
|
+
env: env,
|
23
|
+
price: price,
|
24
|
+
size: size,
|
25
|
+
buy_or_sell: :buy,
|
26
|
+
event_history: event_history,
|
27
|
+
bot_conf: bot_conf
|
105
28
|
)
|
106
|
-
|
107
|
-
if min_market_funds.to_i >= 1
|
108
|
-
size = (
|
109
|
-
(calc_fiat_to_buy - total_limit_buy_orders_open_size).to_i - min_market_funds.to_i
|
110
|
-
).to_s
|
111
|
-
end
|
112
|
-
|
113
|
-
if size.to_f >= min_market_funds.to_f &&
|
114
|
-
total_limit_buy_order_open_tot.zero? &&
|
115
|
-
price.to_f.positive?
|
116
|
-
# SUBMIT BUY ORDER
|
117
|
-
event_history.order_submitted = true
|
118
|
-
event_history.event_notes = "{ \"event_type\": \"#{event_history.event_type}\", \"cancel\": \"#{event_history.order_canceled}\", \"submitted\": \"#{event_history.order_submitted}\" }" if option_choice.proxy
|
119
|
-
|
120
|
-
event_history = Cryptum::API::Orders.submit_limit_order(
|
121
|
-
option_choice: option_choice,
|
122
|
-
env: env,
|
123
|
-
price: price,
|
124
|
-
size: size,
|
125
|
-
buy_or_sell: :buy,
|
126
|
-
order_type: order_type,
|
127
|
-
event_history: event_history,
|
128
|
-
indicator_status: indicator_status
|
129
|
-
)
|
130
|
-
end
|
131
|
-
|
132
|
-
event_history
|
133
29
|
rescue StandardError => e
|
134
30
|
raise e
|
135
31
|
end
|
data/lib/cryptum/event/exit.rb
CHANGED
data/lib/cryptum/event/parse.rb
CHANGED
data/lib/cryptum/event/sell.rb
CHANGED
@@ -12,103 +12,22 @@ module Cryptum
|
|
12
12
|
public_class_method def self.crypto(opts = {})
|
13
13
|
option_choice = opts[:option_choice]
|
14
14
|
env = opts[:env]
|
15
|
-
|
16
|
-
|
15
|
+
price = opts[:price]
|
16
|
+
size = opts[:size]
|
17
17
|
event_history = opts[:event_history]
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
portfolio = event_history.order_book[:portfolio]
|
31
|
-
symbol_portfolio = portfolio.select do |this_portfolio|
|
32
|
-
this_portfolio if this_portfolio[:currency] == crypto_currency
|
33
|
-
end
|
34
|
-
|
35
|
-
symbol_balance_available = format(
|
36
|
-
'%0.8f',
|
37
|
-
symbol_portfolio.first[:available].to_f
|
38
|
-
).to_f
|
39
|
-
|
40
|
-
# 2. Calculate Price, Size, Fees
|
41
|
-
# Get the middle of last 3 ticker prices
|
42
|
-
# to avoid over purcase blips.
|
43
|
-
last_three_prices_arr = []
|
44
|
-
last_ticker_price = event_history.order_book[:ticker_price].to_f
|
45
|
-
second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
|
46
|
-
third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
|
47
|
-
last_three_prices_arr.push(last_ticker_price)
|
48
|
-
last_three_prices_arr.push(second_to_last_ticker_price)
|
49
|
-
last_three_prices_arr.push(third_to_last_ticker_price)
|
50
|
-
# limit_price = last_three_prices_arr.min
|
51
|
-
# limit_price = last_three_prices_arr.max
|
52
|
-
|
53
|
-
# Obtain our Target Price based on TPM configurations
|
54
|
-
target_symbol_price = stuck_in_pos_status[:target_symbol_price].to_f
|
55
|
-
|
56
|
-
case order_type
|
57
|
-
when :pie
|
58
|
-
pie_in_sky_sell_percent_cast_as_decimal = format(
|
59
|
-
'%0.2f',
|
60
|
-
pie_in_sky_sell_percent * 0.01
|
61
|
-
).to_f
|
62
|
-
|
63
|
-
target_profit = target_symbol_price * pie_in_sky_sell_percent_cast_as_decimal
|
64
|
-
limit_price = target_symbol_price + target_profit
|
65
|
-
|
66
|
-
when :tpm
|
67
|
-
limit_price = target_symbol_price
|
68
|
-
# TODO: Ensure previous order price
|
69
|
-
# on last _open order_ if applicable
|
70
|
-
# is greater than this one.
|
71
|
-
order_type = :tpm
|
72
|
-
when :gtfo
|
73
|
-
# Attempt to get in front of falling price.
|
74
|
-
limit_price = last_three_prices_arr.sort[1]
|
75
|
-
gtfo_price = limit_price -= quote_increment.to_f
|
76
|
-
limit_price = gtfo_price if gtfo_price.positive?
|
77
|
-
else
|
78
|
-
raise "ERROR: Unknown order_type: #{order_type}"
|
79
|
-
end
|
80
|
-
|
81
|
-
price = format("%0.#{fiat_smallest_decimal}f", limit_price)
|
82
|
-
|
83
|
-
# Selling Available Crytpo Balance in its Entirety
|
84
|
-
# We Will Likely Want to Change this in the Future.
|
85
|
-
size = format(
|
86
|
-
"%0.#{crypto_smallest_decimal}f",
|
87
|
-
symbol_balance_available.floor(crypto_smallest_decimal)
|
18
|
+
bot_conf = opts[:bot_conf]
|
19
|
+
buy_order_id = opts[:buy_order_id]
|
20
|
+
|
21
|
+
Cryptum::API::Orders.submit_limit(
|
22
|
+
option_choice: option_choice,
|
23
|
+
env: env,
|
24
|
+
price: price,
|
25
|
+
size: size,
|
26
|
+
buy_or_sell: :sell,
|
27
|
+
event_history: event_history,
|
28
|
+
bot_conf: bot_conf,
|
29
|
+
buy_order_id: buy_order_id
|
88
30
|
)
|
89
|
-
|
90
|
-
size = symbol_balance_available if min_market_funds.to_i == 1
|
91
|
-
|
92
|
-
if size.to_f >= min_market_funds.to_f &&
|
93
|
-
price.to_f.positive?
|
94
|
-
|
95
|
-
# SUBMIT SELL ORDER
|
96
|
-
event_history.order_submitted = true
|
97
|
-
event_history.event_notes = "{ \"event_type\": \"#{event_history.event_type}\", \"cancel\": \"#{event_history.order_canceled}\", \"submitted\": \"#{event_history.order_submitted}\" }" if option_choice.proxy
|
98
|
-
|
99
|
-
event_history = Cryptum::API::Orders.submit_limit_order(
|
100
|
-
option_choice: option_choice,
|
101
|
-
env: env,
|
102
|
-
price: price,
|
103
|
-
size: size,
|
104
|
-
buy_or_sell: :sell,
|
105
|
-
order_type: order_type,
|
106
|
-
event_history: event_history,
|
107
|
-
indicator_status: indicator_status
|
108
|
-
)
|
109
|
-
end
|
110
|
-
|
111
|
-
event_history
|
112
31
|
rescue StandardError => e
|
113
32
|
raise e
|
114
33
|
end
|
@@ -116,7 +35,7 @@ module Cryptum
|
|
116
35
|
# Display Usage for this Module
|
117
36
|
public_class_method def self.help
|
118
37
|
puts "USAGE:
|
119
|
-
|
38
|
+
event_history = #{self}.crypto()
|
120
39
|
"
|
121
40
|
end
|
122
41
|
end
|
data/lib/cryptum/ui/matrix.rb
CHANGED
@@ -158,14 +158,16 @@ module Cryptum
|
|
158
158
|
', '
|
159
159
|
]
|
160
160
|
|
161
|
-
last_index = matrix_arr.length - 1
|
161
|
+
# last_index = matrix_arr.length - 1
|
162
162
|
|
163
163
|
matrix_row = ''
|
164
164
|
most_cols = cols - 1
|
165
165
|
most_cols.times.each do
|
166
|
-
matrix_row += "#{matrix_arr[Random.rand(0..last_index)]} "
|
166
|
+
# matrix_row += "#{matrix_arr[Random.rand(0..last_index)]} "
|
167
|
+
matrix_row += "#{matrix_arr.sample} "
|
167
168
|
end
|
168
|
-
matrix_row += matrix_arr[Random.rand(0..last_index)]
|
169
|
+
# matrix_row += matrix_arr[Random.rand(0..last_index)]
|
170
|
+
matrix_row += matrix_arr.sample
|
169
171
|
rescue Interrupt
|
170
172
|
# Exit Gracefully if CTRL+C is Pressed During Session
|
171
173
|
Cryptum::UI::Exit.gracefully(which_self: self)
|
@@ -126,12 +126,11 @@ module Cryptum
|
|
126
126
|
event_history.red_pill = true if fiat_invested_this_order > fiat_avail_to_trade.to_f
|
127
127
|
|
128
128
|
unless event_history.red_pill
|
129
|
-
event_history = Cryptum::
|
129
|
+
event_history = Cryptum::Event::Buy.crypto(
|
130
130
|
option_choice: option_choice,
|
131
131
|
env: env,
|
132
132
|
price: price,
|
133
133
|
size: size,
|
134
|
-
buy_or_sell: :buy,
|
135
134
|
event_history: event_history,
|
136
135
|
bot_conf: bot_conf
|
137
136
|
)
|
@@ -252,12 +251,11 @@ module Cryptum
|
|
252
251
|
|
253
252
|
size = order_ready_to_sell[:size]
|
254
253
|
|
255
|
-
Cryptum::
|
254
|
+
event_history = Cryptum::Event::Sell.crypto(
|
256
255
|
option_choice: option_choice,
|
257
256
|
env: env,
|
258
257
|
price: price,
|
259
258
|
size: size,
|
260
|
-
buy_or_sell: :sell,
|
261
259
|
event_history: event_history,
|
262
260
|
bot_conf: bot_conf,
|
263
261
|
buy_order_id: buy_order_id
|
data/lib/cryptum/version.rb
CHANGED
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.385
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 0day Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.8.
|
19
|
+
version: 2.8.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.8.
|
26
|
+
version: 2.8.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|