quidax 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +28 -0
- data/.vscode/launch.json +22 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +85 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +12 -0
- data/lib/quidax/error.rb +11 -0
- data/lib/quidax/mocks/deposit_mock.rb +20 -0
- data/lib/quidax/mocks/fees_mock.rb +8 -0
- data/lib/quidax/mocks/markets_mock.rb +51 -0
- data/lib/quidax/mocks/order_mock.rb +23 -0
- data/lib/quidax/mocks/quotes_mock.rb +26 -0
- data/lib/quidax/mocks/user_mock.rb +63 -0
- data/lib/quidax/mocks/wallet_mock.rb +99 -0
- data/lib/quidax/mocks/withdrawal_mock.rb +27 -0
- data/lib/quidax/modules/api.rb +17 -0
- data/lib/quidax/objects/base.rb +60 -0
- data/lib/quidax/objects/beneficiary.rb +58 -0
- data/lib/quidax/objects/deposits.rb +40 -0
- data/lib/quidax/objects/fee.rb +17 -0
- data/lib/quidax/objects/instant_order.rb +120 -0
- data/lib/quidax/objects/markets.rb +115 -0
- data/lib/quidax/objects/order.rb +60 -0
- data/lib/quidax/objects/quote.rb +18 -0
- data/lib/quidax/objects/trade.rb +23 -0
- data/lib/quidax/objects/user.rb +41 -0
- data/lib/quidax/objects/wallet.rb +68 -0
- data/lib/quidax/objects/withdrawal.rb +33 -0
- data/lib/quidax/utils.rb +49 -0
- data/lib/quidax/validators/instant_order_validator.rb +32 -0
- data/lib/quidax/version.rb +5 -0
- data/lib/quidax.rb +41 -0
- data/sig/quidax.rbs +4 -0
- metadata +124 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Base object for HTTP requests
|
4
|
+
class QuidaxBaseObject
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
attr_reader :quidax
|
8
|
+
|
9
|
+
def initialize(quidax_object)
|
10
|
+
raise ArgumentError, "Quidax object cannot be nil!" if quidax_object.nil?
|
11
|
+
|
12
|
+
@quidax = quidax_object
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_request(q_object, path, params = {})
|
16
|
+
result = nil
|
17
|
+
begin
|
18
|
+
response = Faraday.get(url(path), params, { "Authorization" => "Bearer #{q_object.secret_key}" })
|
19
|
+
|
20
|
+
raise QuidaxServerError, response unless response.status == 200 || response.status == 201
|
21
|
+
|
22
|
+
result = JSON.parse(response.body)
|
23
|
+
rescue QuidaxServerError => e
|
24
|
+
Utils.handle_server_error(e)
|
25
|
+
rescue JSON::ParserError => e
|
26
|
+
raise QuidaxServerError.new(response),
|
27
|
+
"Invalid result data. Could not parse JSON response body \n #{e.message}"
|
28
|
+
end
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.post_request(q_object, path, body = {})
|
33
|
+
result = nil
|
34
|
+
|
35
|
+
begin
|
36
|
+
response = Faraday.post(url(path), body.to_json,
|
37
|
+
{ "Authorization" => "Bearer #{q_object.secret_key}", "Content-Type" => "application/json", "Accept" => "application/json" })
|
38
|
+
raise QuidaxServerError, response unless response.status == 200 || response.status == 201
|
39
|
+
|
40
|
+
result = JSON.parse(response.body)
|
41
|
+
rescue QuidaxServerError => e
|
42
|
+
Utils.handle_server_error(e)
|
43
|
+
end
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.put_request(q_object, path, body = {})
|
48
|
+
response = Faraday.put("#{API::BASE_URL}#{path}", body,
|
49
|
+
{ "Authorization" => "Bearer #{q_object.secret_key}" })
|
50
|
+
raise QuidaxServerError, response unless response.status == 200 || response.status == 201
|
51
|
+
|
52
|
+
JSON.parse(response.body)
|
53
|
+
rescue QuidaxServerError => e
|
54
|
+
Utils.handle_server_error(e)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.url(path)
|
58
|
+
"#{API::BASE_URL}#{path}"
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Beneficiary object
|
4
|
+
class QuidaxBeneficiary < QuidaxBaseObject
|
5
|
+
def get_all(user_id:, query:)
|
6
|
+
QuidaxBeneficiary.get_all(q_object: @quidax, user_id: user_id, query: query)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(user_id:, body:)
|
10
|
+
QuidaxBeneficiary.create(q_object: @quidax, user_id: user_id, body: body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_account(user_id:, beneficiary_id:)
|
14
|
+
QuidaxBeneficiary.get_account(q_object: @quidax, user_id: user_id, beneficiary_id: beneficiary_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit_account(user_id:, beneficiary_id:, body:)
|
18
|
+
QuidaxBeneficiary.edit_account(q_object: @quidax, user_id: user_id, beneficiary_id: beneficiary_id, body: body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_all(q_object:, user_id:, query:)
|
22
|
+
query.stringify_keys!
|
23
|
+
allowed_currencies = %w[btc ltc xrp dash trx doge]
|
24
|
+
Utils.check_missing_keys(required_keys: %w[currency], keys: query.keys, field: "query")
|
25
|
+
|
26
|
+
currency = query["currency"]
|
27
|
+
Utils.validate_value_in_array(array: allowed_currencies, value: currency, field: "currency")
|
28
|
+
|
29
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::BENEFICIARY_PATH}"
|
30
|
+
|
31
|
+
get_request(q_object, path, query)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create(q_object:, user_id:, body:)
|
35
|
+
body.stringify_keys!
|
36
|
+
expected_query_keys = %w[currency uid extra]
|
37
|
+
Utils.check_missing_keys(required_keys: expected_query_keys, keys: body.keys, field: "body")
|
38
|
+
|
39
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::BENEFICIARY_PATH}"
|
40
|
+
|
41
|
+
post_request(q_object, path, body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_account(q_object:, user_id:, beneficiary_id:)
|
45
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::BENEFICIARY_PATH}/#{beneficiary_id}"
|
46
|
+
|
47
|
+
get_request(q_object, path)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.edit_account(q_object:, user_id:, beneficiary_id:, body:)
|
51
|
+
body.stringify_keys!
|
52
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::BENEFICIARY_PATH}/#{beneficiary_id}"
|
53
|
+
|
54
|
+
Utils.check_missing_keys(required_keys: %w[uid], keys: body.keys, field: "body")
|
55
|
+
|
56
|
+
put_request(q_object, path, body)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Deposit Object
|
4
|
+
class QuidaxDeposits < QuidaxBaseObject
|
5
|
+
def by_user(user_id:, query:)
|
6
|
+
QuidaxDeposits.by_user(q_object: @quidax, user_id: user_id, query: query)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_a_deposit(user_id:, deposit_id:)
|
10
|
+
QuidaxDeposits.get_a_deposit(q_object: @quidax, user_id: user_id, deposit_id: deposit_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def by_sub_users
|
14
|
+
QuidaxDeposits.by_sub_users(q_object: @quidax)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.by_user(q_object:, user_id:, query:)
|
18
|
+
query.stringify_keys!
|
19
|
+
|
20
|
+
Utils.check_missing_keys(required_keys: %w[currency state], keys: query.keys, field: "query")
|
21
|
+
allowed_states = %w[submitting canceled submitted rejected failed accepted checked]
|
22
|
+
Utils.validate_value_in_array(array: allowed_states, value: query["state"], field: "state")
|
23
|
+
|
24
|
+
path = "#{API::USER_PATH}/#{user_id}/#{API::DEPOSIT_PATH}"
|
25
|
+
|
26
|
+
get_request(q_object, path, query)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_a_deposit(q_object:, user_id:, deposit_id:)
|
30
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::DEPOSIT_PATH}/#{deposit_id}"
|
31
|
+
|
32
|
+
get_request(q_object, path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.by_sub_users(q_object:)
|
36
|
+
path = "#{API::USER_PATH}#{API::DEPOSIT_PATH}/all"
|
37
|
+
|
38
|
+
get_request(q_object, path)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Fees object
|
4
|
+
class QuidaxFee < QuidaxBaseObject
|
5
|
+
def get(query:)
|
6
|
+
QuidaxFee.get(q_object: @quidax, query: query)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get(q_object:, query:)
|
10
|
+
query.stringify_keys!
|
11
|
+
|
12
|
+
Utils.check_missing_keys(required_keys: %w[currency network], keys: query.keys, field: "query")
|
13
|
+
path = API::FEE_PATH
|
14
|
+
|
15
|
+
get_request(q_object, path, query)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../validators/instant_order_validator"
|
4
|
+
|
5
|
+
# Instant Order Object
|
6
|
+
class QuidaxInstantOrder < QuidaxBaseObject
|
7
|
+
def get_all(user_id:, market: nil, state: nil, order_by: nil)
|
8
|
+
QuidaxInstantOrder.get_all(q_object: @quidax, user_id: user_id, market: market, state: state, order_by: order_by)
|
9
|
+
end
|
10
|
+
|
11
|
+
def by_sub_users(side:, start_date:, end_date:, market: nil, state: nil)
|
12
|
+
QuidaxInstantOrder.by_sub_users(q_object: @quidax, side: side, start_date: start_date, end_date: end_date, market: market,
|
13
|
+
state: state)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_detail(user_id:, instant_order_id:)
|
17
|
+
QuidaxInstantOrder.get_detail(q_object: @quidax, user_id: user_id, instant_order_id: instant_order_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def buy_crypto_from_fiat(user_id:, body:)
|
21
|
+
QuidaxInstantOrder.buy_crypto_from_fiat(q_object: @quidax, user_id: user_id, body: body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def sell_crypto_to_fiat(user_id:, body:)
|
25
|
+
QuidaxInstantOrder.sell_crypto_to_fiat(q_object: @quidax, user_id: user_id, body: body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def confirm(user_id:, instant_order_id:)
|
29
|
+
QuidaxInstantOrder.confirm(q_object: @quidax, user_id: user_id, instant_order_id: instant_order_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def requote(user_id:, instant_order_id:)
|
33
|
+
QuidaxInstantOrder.requote(q_object: @quidax, user_id: user_id, instant_order_id: instant_order_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_all(q_object:, user_id:, market: nil, state: nil, order_by: nil)
|
37
|
+
market ||= "btcngn"
|
38
|
+
state ||= "done"
|
39
|
+
order_by ||= "asc"
|
40
|
+
|
41
|
+
allowed_order_by = %w[asc desc]
|
42
|
+
Utils.validate_value_in_array(array: allowed_order_by, value: order_by, field: "order_by")
|
43
|
+
|
44
|
+
allowed_states = %w[done wait cancel confirm]
|
45
|
+
Utils.validate_value_in_array(array: allowed_states, value: state, field: "state")
|
46
|
+
|
47
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}"
|
48
|
+
params = {
|
49
|
+
market: market,
|
50
|
+
state: state,
|
51
|
+
order_by: order_by
|
52
|
+
}
|
53
|
+
|
54
|
+
get_request(q_object, path, params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.by_sub_users(q_object:, side:, start_date:, end_date:, market: nil, state: nil)
|
58
|
+
state ||= "done"
|
59
|
+
market ||= "btcngn"
|
60
|
+
|
61
|
+
allowed_sides = %w[buy sell]
|
62
|
+
Utils.validate_value_in_array(array: allowed_sides, value: side, field: "side")
|
63
|
+
|
64
|
+
allowed_states = %w[pend wait confirm done partially_done failed cancel]
|
65
|
+
Utils.validate_value_in_array(array: allowed_states, value: state, field: "state")
|
66
|
+
path = "#{API::USER_PATH}#{API::INSTANT_ORDER_PATH}/all"
|
67
|
+
|
68
|
+
params = {
|
69
|
+
side: side,
|
70
|
+
state: state,
|
71
|
+
market: market,
|
72
|
+
start_date: start_date,
|
73
|
+
end_date: end_date
|
74
|
+
}
|
75
|
+
|
76
|
+
get_request(q_object, path, params)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.get_detail(q_object:, user_id:, instant_order_id:)
|
80
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}/#{instant_order_id}"
|
81
|
+
|
82
|
+
get_request(q_object, path)
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.buy_crypto_from_fiat(q_object:, user_id:, body:)
|
86
|
+
body.transform_keys!(&:to_s)
|
87
|
+
|
88
|
+
InstantOrderValidator.validate_buy_from_crypto_body(body)
|
89
|
+
type = "buy"
|
90
|
+
unit = body["bid"]
|
91
|
+
body["unit"] = unit
|
92
|
+
body["type"] = type
|
93
|
+
|
94
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}"
|
95
|
+
post_request(q_object, path, body)
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.sell_crypto_to_fiat(q_object:, user_id:, body:)
|
99
|
+
body.transform_keys!(&:to_s)
|
100
|
+
InstantOrderValidator.validate_sell_crypto_to_fiat(body)
|
101
|
+
unit = body["bid"]
|
102
|
+
body["unit"] = unit
|
103
|
+
body["type"] = "sell"
|
104
|
+
|
105
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}"
|
106
|
+
post_request(q_object, path, body)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.confirm(q_object:, user_id:, instant_order_id:)
|
110
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}/#{instant_order_id}/confirm"
|
111
|
+
|
112
|
+
post_request(q_object, path)
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.requote(q_object:, user_id:, instant_order_id:)
|
116
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::INSTANT_ORDER_PATH}/#{instant_order_id}/requote"
|
117
|
+
|
118
|
+
post_request(q_object, path)
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Object for markets
|
4
|
+
class QuidaxMarkets < QuidaxBaseObject
|
5
|
+
def get_all
|
6
|
+
QuidaxMarkets.get_all(q_object: @quidax)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_all_tickers
|
10
|
+
QuidaxMarkets.get_all_tickers(q_object: @quidax)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_ticker(market:)
|
14
|
+
QuidaxMarkets.get_ticker(q_object: @quidax, market: market)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_k_line(market:, query: nil)
|
18
|
+
QuidaxMarkets.get_k_line(q_object: @quidax, market: market, query: query)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_k_line_with_pending_trades(market:, trade_id:, query: nil)
|
22
|
+
QuidaxMarkets.get_k_line_with_pending_trades(q_object: @quidax, market: market, trade_id: trade_id,
|
23
|
+
query: query)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_orderbook_items(market:, query: nil)
|
27
|
+
QuidaxMarkets.get_orderbook_items(q_object: @quidax, market: market, query: query)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_depth_for_a_market(market:, query: nil)
|
31
|
+
QuidaxMarkets.get_depth_for_a_market(q_object: @quidax, market: market, query: query)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_all(q_object:)
|
35
|
+
get_request(q_object, API::MARKET_PATH)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_all_tickers(q_object:)
|
39
|
+
path = "#{API::MARKET_PATH}/tickers"
|
40
|
+
get_request(q_object, path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.get_ticker(q_object:, market:)
|
44
|
+
path = "#{API::MARKET_PATH}/tickers/#{market}"
|
45
|
+
get_request(q_object, path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.get_k_line(q_object:, market:, query: nil)
|
49
|
+
query ||= {
|
50
|
+
period: 1,
|
51
|
+
limit: 30
|
52
|
+
}
|
53
|
+
|
54
|
+
query.stringify_keys!
|
55
|
+
|
56
|
+
Utils.check_missing_keys(required_keys: %w[period limit], keys: query.keys, field: "query")
|
57
|
+
allowed_periods = [1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10_080]
|
58
|
+
Utils.validate_value_in_array(array: allowed_periods, value: query["period"], field: "period")
|
59
|
+
|
60
|
+
raise ArgumentError, "limit must be in range 1..10_00" unless (1..10_000).include?(query["limit"])
|
61
|
+
|
62
|
+
path = "#{API::MARKET_PATH}/#{market}/k"
|
63
|
+
|
64
|
+
get_request(q_object, path, query)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.get_k_line_with_pending_trades(q_object:, market:, trade_id:, query: nil)
|
68
|
+
query ||= {
|
69
|
+
period: 1,
|
70
|
+
limit: 30
|
71
|
+
}
|
72
|
+
query.stringify_keys!
|
73
|
+
|
74
|
+
Utils.check_missing_keys(required_keys: %w[period limit], keys: query.keys, field: "query")
|
75
|
+
allowed_periods = [1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10_080]
|
76
|
+
|
77
|
+
Utils.validate_value_in_array(array: allowed_periods, value: query["period"], field: "period")
|
78
|
+
|
79
|
+
Utils.validate_value_in_range(range: 1..10_000, value: query["limit"], field: 'query["limit"]')
|
80
|
+
|
81
|
+
path = "#{API::MARKET_PATH}/#{market}/k_with_pending_trades/#{trade_id}"
|
82
|
+
|
83
|
+
get_request(q_object, path, query)
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.get_orderbook_items(q_object:, market:, query: nil)
|
87
|
+
query ||= {
|
88
|
+
ask_limit: "20",
|
89
|
+
bids_limit: "20"
|
90
|
+
}
|
91
|
+
|
92
|
+
query.stringify_keys!
|
93
|
+
|
94
|
+
Utils.check_missing_keys(required_keys: %w[ask_limit bids_limit], keys: query.keys, field: "query")
|
95
|
+
|
96
|
+
Utils.validate_value_in_range(range: 1..200, value: query["ask_limit"], field: 'query["ask_limit"]')
|
97
|
+
Utils.validate_value_in_range(range: 1..200, value: query["bids_limit"], field: 'query["bids_limit"]')
|
98
|
+
|
99
|
+
path = "#{API::MARKET_PATH}/#{market}/order_book"
|
100
|
+
|
101
|
+
get_request(q_object, path, query)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.get_depth_for_a_market(q_object:, market:, query: nil)
|
105
|
+
query ||= {
|
106
|
+
limit: 10
|
107
|
+
}
|
108
|
+
query.stringify_keys!
|
109
|
+
Utils.check_missing_keys(required_keys: %w[limit], keys: query.keys, field: "query")
|
110
|
+
Utils.validate_value_in_range(range: 1..10_000, value: query["limit"], field: 'query["limit"]')
|
111
|
+
path = "#{API::MARKET_PATH}/#{market}/depth"
|
112
|
+
|
113
|
+
get_request(q_object, path, query)
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Order object
|
4
|
+
class QuidaxOrder < QuidaxBaseObject
|
5
|
+
def get_all(user_id:, query:)
|
6
|
+
QuidaxOrder.get_all(q_object: @quidax, user_id: user_id, query: query)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(user_id:, body:)
|
10
|
+
QuidaxOrder.create(q_object: @quidax, user_id: user_id, body: body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def cancel(user_id:, order_id:)
|
14
|
+
QuidaxOrder.cancel(q_object: @quidax, user_id: user_id, order_id: order_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_details(user_id:, order_id:)
|
18
|
+
QuidaxOrder.get_details(q_object: @quidax, user_id: user_id, order_id: order_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_all(q_object:, user_id:, query:)
|
22
|
+
query.stringify_keys!
|
23
|
+
Utils.check_missing_keys(required_keys: %w[market], keys: query.keys, field: "query")
|
24
|
+
query["order_by"] = "asc" unless query.include?("order_by")
|
25
|
+
query["state"] = "done" unless query.include?("state")
|
26
|
+
Utils.validate_value_in_array(array: %w[asc desc], value: query["order_by"], field: 'query["order_by"]')
|
27
|
+
Utils.validate_value_in_array(array: %w[done wait cancel], value: query["state"], field: 'query["state"]')
|
28
|
+
|
29
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}"
|
30
|
+
|
31
|
+
get_request(q_object, path, query)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create(q_object:, user_id:, body:)
|
35
|
+
body.stringify_keys!
|
36
|
+
|
37
|
+
expected_data_keys = %w[market side ord_type price volume]
|
38
|
+
Utils.check_missing_keys(required_keys: expected_data_keys, keys: body.keys, field: "body")
|
39
|
+
|
40
|
+
Utils.validate_value_in_array(array: %w[buy sell], value: body["side"], field: 'body["side"]')
|
41
|
+
body["ord_type"] = "limit" unless body.include?("ord_type")
|
42
|
+
Utils.validate_value_in_array(array: %w[limit market], value: body["ord_type"], field: 'body["ord_type"]')
|
43
|
+
|
44
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}"
|
45
|
+
|
46
|
+
post_request(q_object, path, body)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.cancel(q_object:, user_id:, order_id:)
|
50
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}/#{order_id}/cancel"
|
51
|
+
|
52
|
+
post_request(q_object, path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_details(q_object:, user_id:, order_id:)
|
56
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::ORDER_PATH}/#{order_id}"
|
57
|
+
|
58
|
+
get_request(q_object, path)
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Object for quotes
|
4
|
+
class QuidaxQuote < QuidaxBaseObject
|
5
|
+
def get(query:)
|
6
|
+
QuidaxQuote.get(q_object: @quidax, query: query)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get(q_object:, query:)
|
10
|
+
query.stringify_keys!
|
11
|
+
Utils.check_missing_keys(required_keys: %w[market unit kind volume], keys: query.keys, field: "query")
|
12
|
+
Utils.validate_value_in_array(array: %w[ask bid], value: query["kind"], field: 'query["kind"]')
|
13
|
+
|
14
|
+
path = API::QUOTE_PATH
|
15
|
+
|
16
|
+
get_request(q_object, path, query)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Trade object
|
4
|
+
class QuidaxTrade < QuidaxBaseObject
|
5
|
+
def for_user(user_id:)
|
6
|
+
QuidaxTrade.for_user(q_object: @quidax, user_id: user_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def for_market(market:)
|
10
|
+
QuidaxTrade.for_market(q_object: @quidax, market: market)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.for_user(q_object:, user_id:)
|
14
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::TRADES_PATH}"
|
15
|
+
|
16
|
+
get_request(q_object, path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.for_market(q_object:, market:)
|
20
|
+
path = "#{API::TRADES_PATH}/#{market}"
|
21
|
+
get_request(q_object, path)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Object for user related operations
|
4
|
+
class QuidaxUser < QuidaxBaseObject
|
5
|
+
def get_account_details(user_id:)
|
6
|
+
QuidaxUser.get_account_details(q_object: @quidax, user_id: user_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_sub_account(body:)
|
10
|
+
QuidaxUser.create_sub_account(q_object: @quidax, body: body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_all_sub_accounts
|
14
|
+
QuidaxUser.get_all_sub_accounts(q_object: @quidax)
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit_account(user_id:, body:)
|
18
|
+
QuidaxUser.edit_account(q_object: @quidax, user_id: user_id, body: body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_account_details(q_object:, user_id:)
|
22
|
+
path = "#{API::USER_PATH}/#{user_id}"
|
23
|
+
get_request(q_object, path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.create_sub_account(q_object:, body:)
|
27
|
+
body.stringify_keys!
|
28
|
+
Utils.check_missing_keys(required_keys: %w[email first_name last_name phone_number], keys: body.keys,
|
29
|
+
field: "body")
|
30
|
+
post_request(q_object, API::USER_PATH, body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.get_all_sub_accounts(q_object:)
|
34
|
+
get_request(q_object, API::USER_PATH)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.edit_account(q_object:, user_id:, body:)
|
38
|
+
path = "#{API::USER_PATH}/#{user_id}"
|
39
|
+
put_request(q_object, path, body)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Object for wallet related actions
|
4
|
+
class QuidaxWallet < QuidaxBaseObject
|
5
|
+
def get_user_wallets(user_id:)
|
6
|
+
QuidaxWallet.get_user_wallets(q_object: @quidax, user_id: user_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_user_wallet(user_id:, currency:)
|
10
|
+
QuidaxWallet.get_user_wallet(q_object: @quidax, user_id: user_id, currency: currency)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_payment_address(user_id:, currency:)
|
14
|
+
QuidaxWallet.get_payment_address(q_object: @quidax, user_id: user_id, currency: currency)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_payment_address_by_id(user_id:, currency:, address_id:)
|
18
|
+
QuidaxWallet.get_payment_address_by_id(q_object: @quidax, user_id: user_id, currency: currency,
|
19
|
+
address_id: address_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_payment_addresses(user_id:, currency:)
|
23
|
+
QuidaxWallet.get_payment_addresses(q_object: @quidax, user_id: user_id, currency: currency)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_crypto_payment_address(user_id:, currency:)
|
27
|
+
QuidaxWallet.create_crypto_payment_address(q_object: @quidax, user_id: user_id, currency: currency)
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_address(currency:, address:)
|
31
|
+
QuidaxWallet.validate_address(q_object: @quidax, currency: currency, address: address)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_user_wallets(q_object:, user_id:)
|
35
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WALLET_PATH}"
|
36
|
+
get_request(q_object, path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get_user_wallet(q_object:, user_id:, currency:)
|
40
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WALLET_PATH}/#{currency}"
|
41
|
+
get_request(q_object, path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_payment_address(q_object:, user_id:, currency:)
|
45
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WALLET_PATH}/#{currency}/address"
|
46
|
+
get_request(q_object, path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_payment_address_by_id(q_object:, user_id:, currency:, address_id:)
|
50
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WALLET_PATH}/#{currency}/addresses/#{address_id}"
|
51
|
+
get_request(q_object, path)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.get_payment_addresses(q_object:, user_id:, currency:)
|
55
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WALLET_PATH}/#{currency}/addresses"
|
56
|
+
get_request(q_object, path)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.create_crypto_payment_address(q_object:, user_id:, currency:)
|
60
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WALLET_PATH}/#{currency}/addresses"
|
61
|
+
post_request(q_object, path)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.validate_address(q_object:, currency:, address:)
|
65
|
+
path = "/#{currency}/#{address}/validate_address"
|
66
|
+
get_request(q_object, path)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Object for withdrawal related actions
|
4
|
+
class QuidaxWithdrawal < QuidaxBaseObject
|
5
|
+
def get_all_withdrawals_detail(user_id:, query:)
|
6
|
+
QuidaxWithdrawal.get_all_withdrawals_detail(q_object: @quidax, user_id: user_id, query: query)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_detail(user_id:, withdrawal_id:)
|
10
|
+
QuidaxWithdrawal.get_detail(q_object: @quidax, user_id: user_id, withdrawal_id: withdrawal_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def cancel(withdrawal_id:)
|
14
|
+
QuidaxWithdrawal.cancel(q_object: @quidax, withdrawal_id: withdrawal_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_all_withdrawals_detail(q_object:, user_id:, query:)
|
18
|
+
Utils.check_missing_keys(required_keys: %w[currency state], keys: query.keys, field: "query")
|
19
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WITHDRAWAL_PATH}"
|
20
|
+
|
21
|
+
get_request(q_object, path, query)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_detail(q_object:, user_id:, withdrawal_id:)
|
25
|
+
path = "#{API::USER_PATH}/#{user_id}#{API::WITHDRAWAL_PATH}/#{withdrawal_id}"
|
26
|
+
get_request(q_object, path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.cancel(q_object:, withdrawal_id:)
|
30
|
+
path = "#{API::USER_PATH}/me#{API::WITHDRAWAL_PATH}/#{withdrawal_id}/cancel"
|
31
|
+
post_request(q_object, path)
|
32
|
+
end
|
33
|
+
end
|