Skip to content
This repository was archived by the owner on May 28, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions lib/cryptopia/api/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module Private
trade_history: [:Market, :TradePairId],
transactions: [:Type],
submit_trade: [:Market, :TradePairId],
cancel_trade: [:OrderId, :TradeId]
cancel_trade: [:OrderId, :TradeId],
submit_withdraw: [:CurrencyId, :Currency],
submit_transfer: [:CurrencyId, :Currency]
}

OPTIONAL_PARAMS = {
Expand All @@ -24,7 +26,9 @@ module Private

EXACT_PARAMS = {
submit_trade: [:Type, :Rate, :Amount],
cancel_trade: [:Type]
cancel_trade: [:Type],
submit_withdraw: [:Address, :Amount],
submit_transfer: [:Username, :Amount]
}

def initialize(api_key = nil, api_secret = nil)
Expand All @@ -50,17 +54,17 @@ def deposit_address(options = {})

handle_response(auth_post('/GetDepositAddress', options))
end
end
end

def open_orders(options = {})
def open_orders(options = {})
for_uri(Private::ENDPOINT) do
if invalid_params?(:deposit_address, options)
raise ArgumentError, "Arguments must be #{params(:deposit_address)}"
end

handle_response(auth_post('/GetOpenOrders', options))
end
end
end

def trade_history(options = {})
for_uri(Private::ENDPOINT) do
Expand Down Expand Up @@ -106,6 +110,26 @@ def cancel_trade(options = {})
end
end

def submit_withdraw(options = {})
for_uri(Private::ENDPOINT) do
if invalid_params?(:submit_withdraw, options, true)
raise ArgumentError, "Arguments must be #{params(:submit_withdraw)}"
end

handle_response(auth_post('/SubmitWithdraw', options))
end
end

def submit_transfer(options = {})
for_uri(Private::ENDPOINT) do
if invalid_params?(:submit_transfer, options, true)
raise ArgumentError, "Arguments must be #{params(:submit_transfer)}"
end

handle_response(auth_post('/SubmitTransfer', options))
end
end

private

attr_reader :api_key, :api_secret, :url, :options
Expand Down Expand Up @@ -135,7 +159,7 @@ def auth_post(endpoint, options = {})

def keys_is_not_present?
(api_key.nil? || (!api_key.nil? && api_key == '')) ||
(api_secret.nil? || (!api_secret.nil? && api_secret == ''))
(api_secret.nil? || (!api_secret.nil? && api_secret == ''))
end

def authorization_formatted_value
Expand Down Expand Up @@ -173,7 +197,7 @@ def hashed_post_params
end

def nonce
@nonce ||= Time.now.to_i.to_s
@nonce ||= (Time.now.to_f * 100).to_i
end

def invalid_transaction_type?(options)
Expand All @@ -190,12 +214,12 @@ def invalid_params?(endpoint, options = {}, exact = false)
(
OPTIONAL_PARAMS.key?(endpoint) &&
(OPTIONAL_PARAMS[endpoint] - available_keys) >= 1
) &&
(
exact &&
EXACT_PARAMS.key?(endpoint) &&
EXACT_PARAMS[endpoint]
)
) &&
(
exact &&
EXACT_PARAMS.key?(endpoint) &&
EXACT_PARAMS[endpoint]
)
end

def params(endpoint)
Expand Down