Class: YobitApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yobit_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: '', secret: '', key_init_date: Time.now) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
# File 'lib/yobit_api.rb', line 13

def initialize(key: '', secret: '', key_init_date: Time.now)
  key_init_date = Time.parse(key_init_date) unless key_init_date.is_a? Time
  Struct.new('ApiConfig', :key, :secret, :key_init_date)
  @config = Struct::ApiConfig.new(key, secret, key_init_date)
  raise 'Nonce is expired' if nonce > 2147483646
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/yobit_api.rb', line 11

def config
  @config
end

Instance Method Details

#active_orders(pair) ⇒ Object



49
50
51
# File 'lib/yobit_api.rb', line 49

def active_orders(pair)
  post('ActiveOrders', client: trade_client, pair: pair)
end

#cancel_order(order_id) ⇒ Object



57
58
59
# File 'lib/yobit_api.rb', line 57

def cancel_order(order_id)
  post('CancelOrder', client: trade_client, order_id: order_id)
end

#depth(pairs_list:, limit: 150) ⇒ Object



29
30
31
32
33
# File 'lib/yobit_api.rb', line 29

def 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) ⇒ Object



73
74
75
# File 'lib/yobit_api.rb', line 73

def get_deposit_address(coin_name:, need_new: 0)
  post('GetDepositAddress', client: trade_client, coinName: coin_name, need_new: need_new)
end

#get_infoObject



41
42
43
# File 'lib/yobit_api.rb', line 41

def get_info
  post('getInfo', client: trade_client)
end

#infoObject



20
21
22
# File 'lib/yobit_api.rb', line 20

def info
  get('info')
end

#order_info(order_id) ⇒ Object



53
54
55
# File 'lib/yobit_api.rb', line 53

def order_info(order_id)
  post('OrderInfo', client: trade_client, order_id: order_id)
end

#ticker(pairs_list) ⇒ Object



24
25
26
27
# File 'lib/yobit_api.rb', line 24

def ticker(pairs_list)
  currencies = prepare_pairs(pairs_list)
  get('ticker' + currencies)
end

#trade(pair:, type:, rate:, amount:) ⇒ Object



45
46
47
# File 'lib/yobit_api.rb', line 45

def 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:) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/yobit_api.rb', line 61

def 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:      end_time,
       pair:     pair)
end

#trades(pairs_list:, limit: 150) ⇒ Object



35
36
37
38
39
# File 'lib/yobit_api.rb', line 35

def 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:) ⇒ Object



77
78
79
# File 'lib/yobit_api.rb', line 77

def withdraw_coins_to_address(coin_name:, amount:, address:)
  post('WithdrawCoinsToAddress', client: trade_client, coinName: coin_name, amount: amount, address: address)
end