Class: SummaryCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/bitflyer/cli/command/summary_command.rb

Constant Summary collapse

BUFFER_SIZE =
30.freeze

Instance Method Summary collapse

Constructor Details

#initializeSummaryCommand

Returns a new instance of SummaryCommand.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bitflyer/cli/command/summary_command.rb', line 8

def initialize
  @current_price = 0.0
  @http_clinet = Bitflyer.http_private_client(api_key, api_secret)
  @realtime_client = Bitflyer.realtime_client

  @realtime_client.executions_fx_btc_jpy = ->(message) {
    message.each { |m| @current_price = m['price'].to_f }
  }

  update_balance
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bitflyer/cli/command/summary_command.rb', line 20

def run
  $stdout.sync = true

  Thread.new do
    while true
      update_balance
      sleep 5
    end
  end

  while true
    print "\e[3F\e[0J"
    print "Current:  " + @current_price.to_i.to_s.split_by_comma
    print "\nPosition: " + "#{@position.average} * #{@position.size}".to_s.split_by_comma
    print "\nSpread:   " + spread.to_s.split_by_comma.color_with_number(spread)
    print "\nBalance:  " + (@balance + profit).to_s.split_by_comma.ljust(15, ' ') + "(#{profit.to_s.split_by_comma.color_with_number(profit)})"
    sleep 0.1
  end
end