class BitsDealer::Helper

Attributes

formatter[R]
prompt[R]

Public Class Methods

new(prompt:, formatter:) click to toggle source
# File lib/bits_dealer/helper.rb, line 5
def initialize(prompt:, formatter:)
  @prompt = prompt
  @formatter = formatter
end

Public Instance Methods

ask_book(books: nil) click to toggle source
# File lib/bits_dealer/helper.rb, line 10
def ask_book(books: nil)
  book_options = books || BitsDealer::Books::PLACE_ORDER_BOOKS

  book = prompt.select("Choose the book?") do |menu|
    menu.enum '.'

    book_options.each do |book|
      menu.choice book.name, book
    end
  end
end
ask_order(orders:) click to toggle source
# File lib/bits_dealer/helper.rb, line 22
def ask_order(orders:)
  book = prompt.select("Choose the order?") do |menu|
    menu.enum '.'

    orders.each do |order|
      side_formatted = order[:side] == 'buy' ? formatter.green(order[:side]) : formatter.red(order[:side])
      help_text = formatter.magenta("(#{order[:original_value]})")
      menu.choice "#{side_formatted} #{order[:original_amount]} at #{order[:price]} #{help_text}", order
    end
  end
end
exchange_order(book, minor, price) click to toggle source
# File lib/bits_dealer/helper.rb, line 75
def exchange_order(book, minor, price)
  with_retries(:max_tries => 3) {
    Bitsor.place_order(book: book.id, side: :sell, type: :limit, major: minor.to_s, price: price.to_s)
  }
end
place_order(book, side, minor, price) click to toggle source
# File lib/bits_dealer/helper.rb, line 67
def place_order(book, side, minor, price)
  major = (minor/price).round(6)

  with_retries(:max_tries => 3) {
    Bitsor.place_order(book: book.id, side: side, type: :limit, major: major.to_s, price: price.to_s)
  }
end
print_account_balance(balance:, filter: nil) click to toggle source
print_tickers_table(tickers:) click to toggle source