Class: QuestradeApi::REST::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/questrade_api/rest/order.rb

Constant Summary

Constants inherited from Base

Base::BASE_ENDPOINT

Instance Attribute Summary

Attributes inherited from Base

#account_id, #authorization, #connection, #data, #id, #raw_body

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#build_attributes, #build_data, connection, #fetch, post, #url

Constructor Details

#initialize(authorization, params = {}) ⇒ Order

Returns a new instance of Order.



6
7
8
9
10
11
12
13
14
# File 'lib/questrade_api/rest/order.rb', line 6

def initialize(authorization, params = {})
  super(authorization)

  @id = params[:id]
  @account_id = params[:account_id]

  @raw_body = params[:data]
  build_data(params[:data]) if @raw_body
end

Class Method Details

.create(authorization, account_number, params = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/questrade_api/rest/order.rb', line 29

def self.create(authorization, , params = {})
  params[:accountNumber] = 

  response = post(access_token: authorization.access_token,
                  endpoint: endpoint(),
                  url: authorization.url,
                  body: params.to_json)

  build_orders(authorization, , response)
end

.endpoint(account_id) ⇒ Object



53
54
55
# File 'lib/questrade_api/rest/order.rb', line 53

def self.endpoint()
  "#{BASE_ENDPOINT}/accounts/#{account_id}/orders"
end

.fetch(authorization, account_number, params) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/questrade_api/rest/order.rb', line 40

def self.fetch(authorization, , params)
  response = super(access_token: authorization.access_token,
                   endpoint: endpoint(),
                   url: authorization.url,
                   params: params)

  build_orders(authorization, , response)
end

Instance Method Details

#endpointObject



49
50
51
# File 'lib/questrade_api/rest/order.rb', line 49

def endpoint
  self.class.endpoint() + "/#{id}"
end

#update(params = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/questrade_api/rest/order.rb', line 16

def update(params = {})
  params[:accountNumber] = 

  response = self.class.post(access_token: authorization.access_token,
                             endpoint: endpoint,
                             url: authorization.url,
                             body: params.to_json)

  parse_order(response.body) if response.status == 200

  response
end