Class: CounterTradeCommand

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

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bitflyer/cli/command/counter_trade_command.rb', line 6

def run
  position = Position.new(http_private_client.positions)
  size = position.size.abs.to_f
  type = position.size > 0 ? 'SELL' : 'BUY'
  response = http_private_client.send_child_order(
      product_code: 'FX_BTC_JPY',
      child_order_type: 'MARKET',
      side: type,
      size: size
  )
  if response['child_order_acceptance_id'].nil?
    puts 'An error has occurred' + response.to_s
  else
    puts "Clear position #{type} / #{size}"
  end
end