Class: QuidaxOrder

Inherits:
QuidaxBaseObject show all
Defined in:
lib/quidax/objects/order.rb

Overview

Order object

Instance Attribute Summary

Attributes inherited from QuidaxBaseObject

#quidax

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from QuidaxBaseObject

get_request, #initialize, post_request, put_request, url

Constructor Details

This class inherits a constructor from QuidaxBaseObject

Class Method Details

.cancel(q_object:, user_id:, order_id:) ⇒ Object



49
50
51
52
53
# File 'lib/quidax/objects/order.rb', line 49

def self.cancel(q_object:, user_id:, order_id:)
  path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}/#{order_id}/cancel"

  post_request(q_object, path)
end

.create(q_object:, user_id:, body:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/quidax/objects/order.rb', line 34

def self.create(q_object:, user_id:, body:)
  body.stringify_keys!

  expected_data_keys = %w[market side ord_type price volume]
  Utils.check_missing_keys(required_keys: expected_data_keys, keys: body.keys, field: "body")

  Utils.validate_value_in_array(array: %w[buy sell], value: body["side"], field: 'body["side"]')
  body["ord_type"] = "limit" unless body.include?("ord_type")
  Utils.validate_value_in_array(array: %w[limit market], value: body["ord_type"], field: 'body["ord_type"]')

  path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}"

  post_request(q_object, path, body)
end

.get_all(q_object:, user_id:, query:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/quidax/objects/order.rb', line 21

def self.get_all(q_object:, user_id:, query:)
  query.stringify_keys!
  Utils.check_missing_keys(required_keys: %w[market], keys: query.keys, field: "query")
  query["order_by"] = "asc" unless query.include?("order_by")
  query["state"] = "done" unless query.include?("state")
  Utils.validate_value_in_array(array: %w[asc desc], value: query["order_by"], field: 'query["order_by"]')
  Utils.validate_value_in_array(array: %w[done wait cancel], value: query["state"], field: 'query["state"]')

  path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}"

  get_request(q_object, path, query)
end

.get_details(q_object:, user_id:, order_id:) ⇒ Object



55
56
57
58
59
# File 'lib/quidax/objects/order.rb', line 55

def self.get_details(q_object:, user_id:, order_id:)
  path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}/#{order_id}"

  get_request(q_object, path)
end

Instance Method Details

#cancel(user_id:, order_id:) ⇒ Object



13
14
15
# File 'lib/quidax/objects/order.rb', line 13

def cancel(user_id:, order_id:)
  QuidaxOrder.cancel(q_object: @quidax, user_id: user_id, order_id: order_id)
end

#create(user_id:, body:) ⇒ Object



9
10
11
# File 'lib/quidax/objects/order.rb', line 9

def create(user_id:, body:)
  QuidaxOrder.create(q_object: @quidax, user_id: user_id, body: body)
end

#get_all(user_id:, query:) ⇒ Object



5
6
7
# File 'lib/quidax/objects/order.rb', line 5

def get_all(user_id:, query:)
  QuidaxOrder.get_all(q_object: @quidax, user_id: user_id, query: query)
end

#get_details(user_id:, order_id:) ⇒ Object



17
18
19
# File 'lib/quidax/objects/order.rb', line 17

def get_details(user_id:, order_id:)
  QuidaxOrder.get_details(q_object: @quidax, user_id: user_id, order_id: order_id)
end