Module: Coinbot

Defined in:
lib/coinbot.rb,
lib/coinbot/ui.rb,
lib/coinbot/api.rb,
lib/coinbot/log.rb,
lib/coinbot/event.rb,
lib/coinbot/option.rb,
lib/coinbot/version.rb,
lib/coinbot/bot_conf.rb,
lib/coinbot/ui/timer.rb,
lib/coinbot/web_sock.rb,
lib/coinbot/event/buy.rb,
lib/coinbot/portfolio.rb,
lib/coinbot/ui/candle.rb,
lib/coinbot/ui/status.rb,
lib/coinbot/ui/ticker.rb,
lib/coinbot/event/sell.rb,
lib/coinbot/order_book.rb,
lib/coinbot/ui/command.rb,
lib/coinbot/ui/summary.rb,
lib/coinbot/event/cancel.rb,
lib/coinbot/ui/portfolio.rb,
lib/coinbot/event/history.rb,
lib/coinbot/option/choice.rb,
lib/coinbot/order_book/ema.rb,
lib/coinbot/order_book/rsi.rb,
lib/coinbot/order_book/sma.rb,
lib/coinbot/event/key_press.rb,
lib/coinbot/order_book/macd.rb,
lib/coinbot/portfolio/balance.rb,
lib/coinbot/web_sock/coinbase.rb,
lib/coinbot/order_book/wrap_up.rb,
lib/coinbot/portfolio/invested.rb,
lib/coinbot/probability_engine.rb,
lib/coinbot/ui/key_press_event.rb,
lib/coinbot/ui/terminal_window.rb,
lib/coinbot/order_book/generate.rb,
lib/coinbot/order_book/ema_cross.rb,
lib/coinbot/order_book/indicator.rb,
lib/coinbot/ui/action_probability.rb,
lib/coinbot/order_book/order_trend.rb,
lib/coinbot/order_book/synchronize.rb,
lib/coinbot/web_sock/event_machine.rb,
lib/coinbot/order_book/weighted_avg.rb,
lib/coinbot/order_book/profit_margin.rb,
lib/coinbot/order_book/indicator_history.rb,
lib/coinbot/order_book/stuck_in_position.rb

Overview

Root-Level Namespace for coinbot

Defined Under Namespace

Modules: API, BotConf, Event, Log, Option, OrderBook, Portfolio, ProbabilityEngine, UI, WebSock

Constant Summary collapse

VERSION =
'0.2.261'

Class Method Summary collapse

Class Method Details

.binObject



27
28
29
# File 'lib/coinbot.rb', line 27

public_class_method def self.bin
  File.join root, 'bin'
end

.derive_session_init(opts = {}) ⇒ Object

Initialize Session at the Beginning of the Next Candle Period



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
# File 'lib/coinbot.rb', line 64

public_class_method def self.derive_session_init(opts = {})
  option_choice = opts[:option_choice]
  env = opts[:env]
  event_history = opts[:event_history]

  candle_duration = option_choice.candle_duration

  last_candle = event_history.order_book[:candles].last
  last_begin_time_epoch = Time.parse(
    last_candle[:begin_time]
  ).strftime('%s').to_i

  now_epoch = Time.now.strftime('%s').to_i
  next_begin_time_epoch = last_begin_time_epoch + candle_duration
  target_session_disp_time = Time.at(
    next_begin_time_epoch
  ).strftime('%Y-%m-%d %H:%M:%S%z')

  spinner = TTY::Spinner.new(
    "[:spinner] Session Starts @ #{target_session_disp_time}",
    format: :arrow_pulse,
    hide_cursor: true
  )

  spinner.success('[READY]')
  event_history.start_time = Time.at(
    next_begin_time_epoch
  ).strftime('%Y-%m-%d %H:%M:%S%z')
  if option_choice.proxy
    event_history.start_time = Time.now.strftime(
      '%Y-%m-%d %H:%M:%S%z'
    )
  end

  event_history
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Coinbot.exit_gracefully(which_self: self)
rescue StandardError => e
  # Produce a Stacktrace for anything else
  raise e
end

.down_arrowObject



55
56
57
# File 'lib/coinbot.rb', line 55

public_class_method def self.down_arrow
  "\u2193"
end

.etcObject



31
32
33
# File 'lib/coinbot.rb', line 31

public_class_method def self.etc
  File.join root, 'etc'
end

.exit_gracefully(opts = {}) ⇒ Object



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
# File 'lib/coinbot.rb', line 107

public_class_method def self.exit_gracefully(opts = {})
  which_self = opts[:which_self]
  event_history = opts[:event_history]
  option_choice = opts[:option_choice]
  env = opts[:env]

  # Clear out candle data to ensure
  # Coinbot Statistics Only Apply to
  # Live Sessions
  if event_history
    event_history.order_book[:highest_pie_in_sky_buy_percent] = 0.00
    event_history.order_book[:highest_pie_in_sky_sell_percent] = 0.00
    event_history.order_book[:candles] = []
    order_book_file = event_history.order_book[:path]
    File.open(order_book_file, 'w') do |f|
      f.puts event_history.order_book.to_json
    end

    # Cancel any open orders for respective symbol
    # Coinbot::API.cancel_all_open_orders(
    #   option_choice: option_choice,
    #   env: env,
    #   order_type: :session_termination
    # )
  end

  Curses.close_screen
  puts "Interrupt detected in #{which_self}...goodbye."

  exit 0
rescue NameError
  puts "\nInterrupt detected in #{which_self}...goodbye."

  exit 0
rescue StandardError => e
  # Produce a Stacktrace for anything else
  raise e
end

.flat_arrowObject



59
60
61
# File 'lib/coinbot.rb', line 59

public_class_method def self.flat_arrow
  '_'
end

.helpObject



146
147
148
# File 'lib/coinbot.rb', line 146

public_class_method def self.help
  constants.sort
end

.libObject



35
36
37
# File 'lib/coinbot.rb', line 35

public_class_method def self.lib
  File.join root, 'lib'
end

.open_symbolObject



47
48
49
# File 'lib/coinbot.rb', line 47

public_class_method def self.open_symbol
  "\u00f8"
end

.order_bookObject



39
40
41
# File 'lib/coinbot.rb', line 39

public_class_method def self.order_book
  File.join root, 'order_book'
end

.rootObject



43
44
45
# File 'lib/coinbot.rb', line 43

public_class_method def self.root
  File.dirname __dir__
end

.up_arrowObject



51
52
53
# File 'lib/coinbot.rb', line 51

public_class_method def self.up_arrow
  "\u2191"
end