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

rubocop:disable Metrics/MethodLength



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

def run(options) # rubocop:disable Metrics/MethodLength
  amount = options.amount
  type = options.type

  ticker = http_public_client.ticker(product_code: '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}"
  else
    puts "An order is created #{type} / #{price} / #{amount}"
  end
end