Class: DeGiro::CreateOrder

Inherits:
Object
  • Object
show all
Defined in:
lib/degiro/create_order.rb

Constant Summary collapse

BUY_SELL =
{ buy: 0, sell: 1 }.freeze
ORDER_TYPES =
{ limited: 0, stop_limited: 1, market_order: 2, stop_loss: 3 }.freeze
TIME_TYPES =
{ day: 1, permanent: 3 }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ CreateOrder

Returns a new instance of CreateOrder.



9
10
11
# File 'lib/degiro/create_order.rb', line 9

def initialize(connection)
  @connection = connection
end

Instance Method Details

#create_buy_order(product_id:, size:, price:) ⇒ Object



13
14
15
16
17
# File 'lib/degiro/create_order.rb', line 13

def create_buy_order(product_id:, size:, price:)
  order = order(BUY_SELL[:buy], product_id, size, price)
  confirmation_id = JSON.parse(check_order(order).body)['confirmationId']
  confirm_order(order, confirmation_id)
end

#create_sell_order(product_id:, size:, price:) ⇒ Object



19
20
21
22
23
# File 'lib/degiro/create_order.rb', line 19

def create_sell_order(product_id:, size:, price:)
  order = order(BUY_SELL[:sell], product_id, size, price)
  confirmation_id = JSON.parse(check_order(order).body)['confirmationId']
  confirm_order(order, confirmation_id)
end