cryptum 0.0.383 → 0.0.384

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: 06a29115dd8895dca86ef8c6a0e8b506248dfdaa52c1a09b8d2625dd308a2b36
4
- data.tar.gz: 41da5d973faa245b504288b2bee338b30ec50ed3b5688de053e6e588c28bb904
3
+ metadata.gz: 5d8298d19d8db14b27d22dc465df09455fb209218ebbeeddf1987e66042af09d
4
+ data.tar.gz: 4e19eb6374a6161b0a72c8d42da7897868252efffb886a414d22a173368a6238
5
5
  SHA512:
6
- metadata.gz: b5f4925c93e418214bdc03923823224c124abee2acbb88ff6a8b29aba5d5072135bd2ee66639334eb6929edf94a0f4bd9b44c44d9bc7d00be5d4b2959e5f9e11
7
- data.tar.gz: 671b415f45233e4719396ae939fbcd7cefa39ba04ef2d1a18024e5591d6aa8b98548fd6dfc443a961aabb164826381a1a9af0554ce1f009f79d06213486038d6
6
+ metadata.gz: 1fdf711cf9326842f480b14b37f4b9c826d164b8f64965cfdc25269165c97e7e2b1de2f48b0238b239da45903232117dba59cb65b59028e7057410fdb3ee3be5
7
+ data.tar.gz: fb896a3349b440c7ab8010fb6d2a95d30bfa13683000250f4ca7deb7ab538ce42a89164ff41941805e54f8d2331d717833ec00ca093965e466d55dc6b9304610
@@ -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.submit_limit_order(opts = {})
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}.submit_limit_order(
240
+ event_history = #{self}.submit_limit(
241
241
  env: 'required - Coinbase::Option::Environment.get Object'
242
242
  )
243
243
 
@@ -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
- bot_conf = opts[:bot_conf]
15
+ price = opts[:price]
16
+ size = opts[:size]
16
17
  event_history = opts[:event_history]
17
- order_type = opts[:order_type]
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
- fiat_to_autotrade = fiat_balance_available * autotrade_portfolio_percent_cast_as_decimal
101
- calc_fiat_to_buy = (fiat_to_autotrade / last_ticker_price) - symbol_balance
102
- size = format(
103
- "%0.#{crypto_smallest_decimal}f",
104
- calc_fiat_to_buy - total_limit_buy_orders_open_size
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
@@ -5,7 +5,7 @@ module Cryptum
5
5
  module Event
6
6
  module Exit
7
7
  # Supported Method Parameters::
8
- # Cryptum::Event::BotConf.gracefully(
8
+ # Cryptum::Event::Exit.gracefully(
9
9
  # )
10
10
  public_class_method def self.gracefully(opts = {})
11
11
  terminal_win = opts[:terminal_win]
@@ -6,7 +6,7 @@ module Cryptum
6
6
  module Event
7
7
  module OrderBook
8
8
  # Supported Method Parameters::
9
- # Cryptum::Event::BotConf.write(
9
+ # Cryptum::Event::OrderBook.write(
10
10
  # )
11
11
  public_class_method def self.write(opts = {})
12
12
  terminal_win = opts[:terminal_win]
@@ -5,7 +5,7 @@ module Cryptum
5
5
  module Event
6
6
  module Parse
7
7
  # Supported Method Parameters::
8
- # Cryptum::Event::Pane.websocket_msg(
8
+ # Cryptum::Event::Parse.websocket_msg(
9
9
  # )
10
10
  public_class_method def self.websocket_msg(opts = {})
11
11
  env = opts[:env]
@@ -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
- bot_conf = opts[:bot_conf]
16
- stuck_in_pos_status = opts[:stuck_in_pos_status]
15
+ price = opts[:price]
16
+ size = opts[:size]
17
17
  event_history = opts[:event_history]
18
- order_type = opts[:order_type]
19
- fiat_smallest_decimal = opts[:fiat_smallest_decimal]
20
- crypto_smallest_decimal = opts[:crypto_smallest_decimal]
21
- # base_min_size = opts[:base_min_size]
22
- min_market_funds = this_product[:min_market_funds]
23
- indicator_status = opts[:indicator_status]
24
- quote_increment = opts[:quote_increment]
25
-
26
- # Initialize some bot_conf variables
27
- pie_in_sky_sell_percent = bot_conf[:pie_in_sky_sell_percent].to_f
28
-
29
- crypto_currency = option_choice.symbol.to_s.upcase.split('_').first
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
- order_book = #{self}.crypto()
38
+ event_history = #{self}.crypto()
120
39
  "
121
40
  end
122
41
  end
@@ -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::API::Orders.submit_limit_order(
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::API::Orders.submit_limit_order(
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cryptum
4
- VERSION = '0.0.383'
4
+ VERSION = '0.0.384'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.383
4
+ version: 0.0.384
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.