Module: StocksExchangeApiClient
- Defined in:
- lib/stocks_exchange_api_client.rb,
lib/stocks_exchange_api_client/public.rb,
lib/stocks_exchange_api_client/private.rb,
lib/stocks_exchange_api_client/version.rb,
lib/stocks_exchange_api_client/configuration.rb,
lib/stocks_exchange_api_client/errors/configuration_error.rb
Defined Under Namespace
Modules: Errors
Classes: Configuration, Private, Public
Constant Summary
collapse
- METHOD_NAME =
{
get_info: 'GetInfo',
active_orders: 'ActiveOrders',
trade: 'Trade',
cancel_order: 'CancelOrder',
trade_history: 'TradeHistory',
trade_register_history: 'TradeRegisterHistory',
user_history: 'UserHistory',
trans_history: 'TransHistory',
grafic: 'Grafic',
generate_wallets: 'GenerateWallets',
deposit: 'Deposit',
withdraw: 'Withdraw'
}.freeze
- HEX_ALGORITHM =
'sha512'
- ASC =
'ASC'.freeze
- ALL =
'ALL'.freeze
- MAX_COUNT =
50
- STATUS_ORDER =
{
pending: 1,
processing: 2,
finished: 3,
canceled: 4
}.freeze
- STATUS_ORDER_HUMAN_NAME =
{
1 => 'PENDING',
2 => 'PROCESSING',
3 => 'FINISHED',
4 => 'CANCELED'
}.freeze
- OWNER =
{
all: 'ALL',
own: 'OWN'
}.freeze
- INTERVAL =
{
day: '1D',
month: '1M',
three_month: '3M',
year: '1Y'
}.freeze
- DEFAULT_PAIRS =
'ETH_BTC'.freeze
- VERSION =
'0.1.2'
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
64
65
66
|
# File 'lib/stocks_exchange_api_client.rb', line 64
def configuration
@configuration ||= Configuration.new
end
|
41
42
43
|
# File 'lib/stocks_exchange_api_client.rb', line 41
def configure
yield(configuration)
end
|
.make_api_request(method = :post, params = {}, type) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/stocks_exchange_api_client.rb', line 45
def make_api_request(method = :post, params = {}, type)
configuration.validate!
if method == :post
params.merge!({method: type, nonce: Time.now.to_i})
encode_www_form = URI.encode_www_form(params)
sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new(HEX_ALGORITHM), configuration.api_secret, encode_www_form)
response = JSON.parse(
HTTParty.post(configuration.url, body: params, headers: {
:Sign => sign,
:Key => configuration.api_key
}).body)
response = OpenStruct.new(response)
end
if method == :get
response = JSON.parse(HTTParty.get("#{configuration.url}/#{type}").body)
end
response
end
|