Class: QuidaxInstantOrder

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

Overview

Instant 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

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



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/quidax/objects/instant_order.rb', line 85

def self.buy_crypto_from_fiat(q_object:, user_id:, body:)
  body.transform_keys!(&:to_s)

  InstantOrderValidator.validate_buy_from_crypto_body(body)
  type = "buy"
  unit = body["bid"]
  body["unit"] = unit
  body["type"] = type

  path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}"
  post_request(q_object, path, body)
end

.by_sub_users(q_object:, side:, start_date:, end_date:, market: nil, state: nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/quidax/objects/instant_order.rb', line 57

def self.by_sub_users(q_object:, side:, start_date:, end_date:, market: nil, state: nil)
  state ||= "done"
  market ||= "btcngn"

  allowed_sides = %w[buy sell]
  Utils.validate_value_in_array(array: allowed_sides, value: side, field: "side")

  allowed_states = %w[pend wait confirm done partially_done failed cancel]
  Utils.validate_value_in_array(array: allowed_states, value: state, field: "state")
  path = "#{API::USER_PATH}#{API::INSTANT_ORDER_PATH}/all"

  params = {
    side: side,
    state: state,
    market: market,
    start_date: start_date,
    end_date: end_date
  }

  get_request(q_object, path, params)
end

.confirm(q_object:, user_id:, instant_order_id:) ⇒ Object



109
110
111
112
113
# File 'lib/quidax/objects/instant_order.rb', line 109

def self.confirm(q_object:, user_id:, instant_order_id:)
  path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}/#{instant_order_id}/confirm"

  post_request(q_object, path)
end

.get_all(q_object:, user_id:, market: nil, state: nil, order_by: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/quidax/objects/instant_order.rb', line 36

def self.get_all(q_object:, user_id:, market: nil, state: nil, order_by: nil)
  market ||= "btcngn"
  state ||= "done"
  order_by ||= "asc"

  allowed_order_by = %w[asc desc]
  Utils.validate_value_in_array(array: allowed_order_by, value: order_by, field: "order_by")

  allowed_states = %w[done wait cancel confirm]
  Utils.validate_value_in_array(array: allowed_states, value: state, field: "state")

  path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}"
  params = {
    market: market,
    state: state,
    order_by: order_by
  }

  get_request(q_object, path, params)
end

.get_detail(q_object:, user_id:, instant_order_id:) ⇒ Object



79
80
81
82
83
# File 'lib/quidax/objects/instant_order.rb', line 79

def self.get_detail(q_object:, user_id:, instant_order_id:)
  path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}/#{instant_order_id}"

  get_request(q_object, path)
end

.requote(q_object:, user_id:, instant_order_id:) ⇒ Object



115
116
117
118
119
# File 'lib/quidax/objects/instant_order.rb', line 115

def self.requote(q_object:, user_id:, instant_order_id:)
  path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}/#{instant_order_id}/requote"

  post_request(q_object, path)
end

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



98
99
100
101
102
103
104
105
106
107
# File 'lib/quidax/objects/instant_order.rb', line 98

def self.sell_crypto_to_fiat(q_object:, user_id:, body:)
  body.transform_keys!(&:to_s)
  InstantOrderValidator.validate_sell_crypto_to_fiat(body)
  unit = body["bid"]
  body["unit"] = unit
  body["type"] = "sell"

  path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}"
  post_request(q_object, path, body)
end

Instance Method Details

#buy_crypto_from_fiat(user_id:, body:) ⇒ Object



20
21
22
# File 'lib/quidax/objects/instant_order.rb', line 20

def buy_crypto_from_fiat(user_id:, body:)
  QuidaxInstantOrder.buy_crypto_from_fiat(q_object: @quidax, user_id: user_id, body: body)
end

#by_sub_users(side:, start_date:, end_date:, market: nil, state: nil) ⇒ Object



11
12
13
14
# File 'lib/quidax/objects/instant_order.rb', line 11

def by_sub_users(side:, start_date:, end_date:, market: nil, state: nil)
  QuidaxInstantOrder.by_sub_users(q_object: @quidax, side: side, start_date: start_date, end_date: end_date, market: market,
                                  state: state)
end

#confirm(user_id:, instant_order_id:) ⇒ Object



28
29
30
# File 'lib/quidax/objects/instant_order.rb', line 28

def confirm(user_id:, instant_order_id:)
  QuidaxInstantOrder.confirm(q_object: @quidax, user_id: user_id, instant_order_id: instant_order_id)
end

#get_all(user_id:, market: nil, state: nil, order_by: nil) ⇒ Object



7
8
9
# File 'lib/quidax/objects/instant_order.rb', line 7

def get_all(user_id:, market: nil, state: nil, order_by: nil)
  QuidaxInstantOrder.get_all(q_object: @quidax, user_id: user_id, market: market, state: state, order_by: order_by)
end

#get_detail(user_id:, instant_order_id:) ⇒ Object



16
17
18
# File 'lib/quidax/objects/instant_order.rb', line 16

def get_detail(user_id:, instant_order_id:)
  QuidaxInstantOrder.get_detail(q_object: @quidax, user_id: user_id, instant_order_id: instant_order_id)
end

#requote(user_id:, instant_order_id:) ⇒ Object



32
33
34
# File 'lib/quidax/objects/instant_order.rb', line 32

def requote(user_id:, instant_order_id:)
  QuidaxInstantOrder.requote(q_object: @quidax, user_id: user_id, instant_order_id: instant_order_id)
end

#sell_crypto_to_fiat(user_id:, body:) ⇒ Object



24
25
26
# File 'lib/quidax/objects/instant_order.rb', line 24

def sell_crypto_to_fiat(user_id:, body:)
  QuidaxInstantOrder.sell_crypto_to_fiat(q_object: @quidax, user_id: user_id, body: body)
end