module Yobit

Constants

PUBLIC_API_URL
TRADE_API_URL
VERSION

Attributes

config[RW]

Public Class Methods

active_orders(pair) click to toggle source
# File lib/yobit.rb, line 57
def self.active_orders(pair)
  get('ActiveOrders', client: trade_client, pair: pair)
end
cancel_order(order_id) click to toggle source
# File lib/yobit.rb, line 65
def self.cancel_order(order_id)
  post('CancelOrder', client: trade_client, order_id: order_id)
end
depth(pairs_list:, limit: 150) click to toggle source
# File lib/yobit.rb, line 37
def self.depth(pairs_list:, limit: 150)
  limit = 2000 if (limit > 2000)
  currencies = prepare_pairs(pairs_list)
  get('depth' + currencies, limit: limit)
end
get_deposit_address(coin_name:, need_new: 0) click to toggle source
# File lib/yobit.rb, line 81
def self.get_deposit_address(coin_name:, need_new: 0)
  get('GetDepositAddress', client: trade_client, coinName: coin_name, need_new: need_new)
end
get_info() click to toggle source
# File lib/yobit.rb, line 49
def self.get_info
  get('getInfo', client: trade_client)
end
info() click to toggle source
# File lib/yobit.rb, line 28
def self.info
  get('info')
end
order_info(order_id) click to toggle source
# File lib/yobit.rb, line 61
def self.order_info(order_id)
  get('OrderInfo', client: trade_client, order_id: order_id)
end
setup() { |config| ... } click to toggle source
# File lib/yobit.rb, line 23
def self.setup
  @config ||= ApiConfig.new
  yield config
end
ticker(pairs_list) click to toggle source
# File lib/yobit.rb, line 32
def self.ticker(pairs_list)
  currencies = prepare_pairs(pairs_list)
  get('ticker' + currencies)
end
trade(pair:, type:, rate:, amount:) click to toggle source
# File lib/yobit.rb, line 53
def self.trade(pair:, type:, rate:, amount:)
  post('Trade', client: trade_client, pair: pair, type: type, rate: rate, amount: amount)
end
trade_history(from: 0, count: 1000, from_id: 0, end_id: 1000, order: "DESC", since: 0, end_time: Time.new(3000).to_i, pair:) click to toggle source
# File lib/yobit.rb, line 69
def self.trade_history(from: 0, count: 1000, from_id: 0, end_id: 1000, order: "DESC", since: 0, end_time: Time.new(3000).to_i, pair:)
  post('TradeHistory', client: trade_client,
       from:     from, 
       count:    count, 
       from_id:  from_id,
       end_id:   end_id, 
       order:    order, 
       since:    since, 
       end_time: end_time,
       pair:     pair)
end
trades(pairs_list:, limit: 150) click to toggle source
# File lib/yobit.rb, line 43
def self.trades(pairs_list:, limit: 150)
  limit = 2000 if (limit > 2000)
  currencies = prepare_pairs(pairs_list)
  get('trades' + currencies, limit: limit)
end
withdraw_coins_to_address(coin_name:, amount:, address:) click to toggle source
# File lib/yobit.rb, line 85
def self.withdraw_coins_to_address(coin_name:, amount:, address:)
  post('WithdrawCoinsToAddress', client: trade_client, coinName: coin_name, amount: amount, address: address)
end

Protected Class Methods

create_sign(data) click to toggle source
# File lib/yobit.rb, line 113
def self.create_sign(data)
  encoded_data = Addressable::URI.form_encode(data)
  OpenSSL::HMAC.hexdigest('sha512', config.secret, encoded_data)
end
get(method_name, client: public_client, **params) click to toggle source
# File lib/yobit.rb, line 103
def self.get(method_name, client: public_client, **params)
  client[method_name].get(params)
end
post(method_name, client: public_client, **params) click to toggle source
# File lib/yobit.rb, line 107
def self.post(method_name, client: public_client, **params)
  params[:nonce] = (Time.now.to_f * 10000000).to_i
  params[:sign]  = create_sign(params)
  client[method_name].post(params, {key: config.key})
end
prepare_pairs(pairs_list) click to toggle source
# File lib/yobit.rb, line 91
def self.prepare_pairs(pairs_list)
  pairs_list.join("-").prepend("/")
end
public_client() click to toggle source
# File lib/yobit.rb, line 95
def self.public_client
  @@public_client ||= RestClient::Resource.new(Yobit::PUBLIC_API_URL)
end
trade_client() click to toggle source
# File lib/yobit.rb, line 99
def self.trade_client
  @@trade_client ||= RestClient::Resource.new(Yobit::TRADE_API_URL)
end