Class: OrderByBestCommand

Inherits:
Object
  • Object
show all
Includes:
HasHTTPClient
Defined in:
lib/bitflyer/cli/command/order_by_best_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



6
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/order_by_best_command.rb', line 6

def run(options)
  amount = options.amount
  type = options.type

  ticker = http_public_client.ticker('FX_BTC_JPY')
  price = type == 'buy' ? ticker['best_bid'] : ticker['best_ask']

  response = http_private_client.send_child_order(
      product_code: 'FX_BTC_JPY',
      child_order_type: 'LIMIT',
      side: type.upcase,
      price: price,
      size: amount
  )

  if response['child_order_acceptance_id'].nil?
    puts 'An error has occurred' + response.to_s
  else
    puts "An order is created #{type} / #{price} / #{amount}"
  end
end