class DeGiro::CreateOrder

Constants

BUY_SELL
ORDER_TYPES
TIME_TYPES

Public Class Methods

new(connection) click to toggle source
# File lib/degiro_client/create_order.rb, line 9
def initialize(connection)
  @connection = connection
end

Public Instance Methods

create_buy_order(product_id:, size:, price:) click to toggle source
# File lib/degiro_client/create_order.rb, line 13
def create_buy_order(product_id:, size:, price:)
  create_order_with_confirmation(BUY_SELL[:buy], product_id, size, price)
end
create_sell_order(product_id:, size:, price:) click to toggle source
# File lib/degiro_client/create_order.rb, line 17
def create_sell_order(product_id:, size:, price:)
  create_order_with_confirmation(BUY_SELL[:sell], product_id, size, price)
end

Private Instance Methods

check_order(order) click to toggle source
# File lib/degiro_client/create_order.rb, line 41
def check_order(order)
  @connection.post(check_order_url) do |req|
    req.headers['Content-Type'] = 'application/json; charset=UTF-8'
    req.body = order.to_json
  end
end
check_order_url() click to toggle source
# File lib/degiro_client/create_order.rb, line 55
def check_order_url
  "#{@connection.urls_map['trading_url']}/v5/checkOrder" \
  ";jsessionid=#{@connection.session_id}" \
  "?intAccount=#{@connection.user_data['int_account']}" \
  "&sessionId=#{@connection.session_id}"
end
confirm_order(order, confirmation_id) click to toggle source
# File lib/degiro_client/create_order.rb, line 48
def confirm_order(order, confirmation_id)
  @connection.post(confirm_order_url(confirmation_id)) do |req|
    req.headers['Content-Type'] = 'application/json; charset=UTF-8'
    req.body = order.to_json
  end
end
confirm_order_url(confirmation_id) click to toggle source
# File lib/degiro_client/create_order.rb, line 62
def confirm_order_url(confirmation_id)
  "#{@connection.urls_map['trading_url']}/v5/order/#{confirmation_id}" \
  ";jsessionid=#{@connection.session_id}" \
  "?intAccount=#{@connection.user_data['int_account']}" \
  "&sessionId=#{@connection.session_id}"
end
create_order_with_confirmation(buy_sell, product_id, size, price) click to toggle source
# File lib/degiro_client/create_order.rb, line 23
def create_order_with_confirmation(buy_sell, product_id, size, price)
  order = order(buy_sell, product_id, size, price)
  response = check_order(order)
  confirmation_id = JSON.parse(response.body)['data']['confirmationId']
  confirm_order(order, confirmation_id)
end
order(type, product_id, size, price) click to toggle source
# File lib/degiro_client/create_order.rb, line 30
def order(type, product_id, size, price)
  {
    buySell:   type,
    orderType: ORDER_TYPES[:limited],
    productId: product_id.to_i,
    size:      size,
    timeType:  TIME_TYPES[:permanent],
    price:     price
  }
end