Class: IFDOCOByRangeCommand

Inherits:
Object
  • Object
show all
Includes:
HasHTTPClient
Defined in:
lib/bitflyer/cli/command/ifdoco_by_range_command.rb

Instance Method Summary collapse

Methods included from HasHTTPClient

#http_private_client, #http_public_client

Methods included from Authorization

#api_key, #api_secret

Instance Method Details

#run(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bitflyer/cli/command/ifdoco_by_range_command.rb', line 7

def run(options)
  side = options.type.upcase
  size = options.amount.abs
  ratio = options.percentage.to_f
  range = options.range.to_f

  current_price = http_public_client.ticker('FX_BTC_JPY')['ltp'].to_i
  profit_price = profit_line(side: side, current_price: current_price, range: range, ratio: ratio).to_i
  loss_price = loss_line(side: side, current_price: current_price, range: range, ratio: ratio).to_i
  request = request(side: side, size: size, profit_price: profit_price, loss_price: loss_price)
  response = http_private_client.send_parent_order(request)

  if response['parent_order_acceptance_id'].nil?
    puts 'An error has occurred' + response.to_s
  else
    puts "Send market order #{side} / #{size.to_f}"
    puts "Set limit order #{side} / #{profit_price} / #{size.to_f}"
    puts "Set stop order #{side} / #{loss_price} / #{size.to_f}"
  end
end