Class: StopByRangeCommand
- Inherits:
-
Object
- Object
- StopByRangeCommand
- Includes:
- HasHTTPClient
- Defined in:
- lib/bitflyer/cli/command/stop_by_range_command.rb
Instance Method Summary collapse
Methods included from HasHTTPClient
#http_private_client, #http_public_client
Methods included from Authorization
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 27 28 29 30 |
# File 'lib/bitflyer/cli/command/stop_by_range_command.rb', line 7 def run() position = Position.new(http_private_client.positions) return puts "You don't have any position now." if position.size == 0 side = position.average > 0 ? 'SELL' : 'BUY' price = position.average.abs + .range * (side == 'BUY' ? 1.0 : -1.0) response = http_private_client.send_parent_order( order_method: 'SIMPLE', parameters: [{ product_code: 'FX_BTC_JPY', condition_type: 'STOP', side: side, trigger_price: price, size: position.size.to_f }] ) if response['parent_order_acceptance_id'].nil? puts 'An error has occurred' + response.to_s else puts "Set limit order #{side} / #{price} / #{position.size.to_f}" end end |