class DeGiro::CreateOrder
Constants
- BUY_SELL
- ORDER_TYPES
- TIME_TYPES
Public Class Methods
new(connection)
click to toggle source
# File lib/degiro/create_order.rb, line 9 def initialize(connection) @connection = connection end
Public Instance Methods
create_limit_buy_order(product_id:, size:, price:)
click to toggle source
# File lib/degiro/create_order.rb, line 25 def create_limit_buy_order(product_id:, size:, price:) order = limit_order(BUY_SELL[:buy], product_id, size, price) confirmation_id = JSON.parse(check_order(order).body)['data']['confirmationId'] confirm_order(order, confirmation_id) end
create_limit_sell_order(product_id:, size:, price:)
click to toggle source
# File lib/degiro/create_order.rb, line 31 def create_limit_sell_order(product_id:, size:, price:) order = limit_order(BUY_SELL[:sell], product_id, size, price) confirmation_id = JSON.parse(check_order(order).body)['data']['confirmationId'] confirm_order(order, confirmation_id) end
create_market_buy_order(product_id:, size:)
click to toggle source
# File lib/degiro/create_order.rb, line 13 def create_market_buy_order(product_id:, size:) order = market_order(BUY_SELL[:buy], product_id, size) confirmation_id = JSON.parse(check_order(order).body)['data']['confirmationId'] confirm_order(order, confirmation_id) end
create_market_sell_order(product_id:, size:)
click to toggle source
# File lib/degiro/create_order.rb, line 19 def create_market_sell_order(product_id:, size:) order = market_order(BUY_SELL[:sell], product_id, size) confirmation_id = JSON.parse(check_order(order).body)['data']['confirmationId'] confirm_order(order, confirmation_id) end
Private Instance Methods
check_order(order)
click to toggle source
# File lib/degiro/create_order.rb, line 60 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/create_order.rb, line 74 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/create_order.rb, line 67 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/create_order.rb, line 81 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
limit_order(type, product_id, size, price)
click to toggle source
# File lib/degiro/create_order.rb, line 49 def limit_order(type, product_id, size, price) { buySell: type, orderType: ORDER_TYPES[:limited], productId: product_id, size: size, timeType: TIME_TYPES[:permanent], price: price } end
market_order(type, product_id, size)
click to toggle source
# File lib/degiro/create_order.rb, line 39 def market_order(type, product_id, size) { buySell: type, orderType: ORDER_TYPES[:market], productId: product_id, size: size, timeType: TIME_TYPES[:permanent] } end