Class: ZaifWrapper::Client::ZaifPrivateApi
- Inherits:
-
Object
- Object
- ZaifWrapper::Client::ZaifPrivateApi
- Defined in:
- lib/zaif_wrapper/client.rb
Constant Summary collapse
- REQUEST_URL_BASE =
'https://api.zaif.jp/tapi'
Instance Method Summary collapse
- #active_orders(params = {}) ⇒ Object
- #cancel_order(params = {}) ⇒ Object
- #create_signature(body) ⇒ Object
- #deposit_history(params = {}) ⇒ Object
- #get_id_info ⇒ Object
- #get_info ⇒ Object
- #get_info2 ⇒ Object
- #get_nonce ⇒ Object
- #get_personal_info ⇒ Object
-
#initialize(api_key, api_secret) ⇒ ZaifPrivateApi
constructor
A new instance of ZaifPrivateApi.
- #request(method, params = {}) ⇒ Object
- #trade(params = {}) ⇒ Object
- #trade_history(params = {}) ⇒ Object
- #withdraw(params = {}) ⇒ Object
- #withdraw_history(params = {}) ⇒ Object
Constructor Details
#initialize(api_key, api_secret) ⇒ ZaifPrivateApi
Returns a new instance of ZaifPrivateApi.
36 37 38 39 |
# File 'lib/zaif_wrapper/client.rb', line 36 def initialize(api_key, api_secret) @api_key = api_key @api_secret = api_secret end |
Instance Method Details
#active_orders(params = {}) ⇒ Object
83 84 85 |
# File 'lib/zaif_wrapper/client.rb', line 83 def active_orders(params = {}) request('active_orders', params) end |
#cancel_order(params = {}) ⇒ Object
92 93 94 95 |
# File 'lib/zaif_wrapper/client.rb', line 92 def cancel_order(params = {}) raise "Required parameters are missing" if params["order_id"].nil? request('cancel_order', params) end |
#create_signature(body) ⇒ Object
116 117 118 |
# File 'lib/zaif_wrapper/client.rb', line 116 def create_signature(body) OpenSSL::HMAC::hexdigest(OpenSSL::Digest.new('sha512'), @api_secret, body.to_s) end |
#deposit_history(params = {}) ⇒ Object
102 103 104 105 |
# File 'lib/zaif_wrapper/client.rb', line 102 def deposit_history(params = {}) raise "Required parameters are missing" if params["currency"].nil? request('deposit_history', params) end |
#get_id_info ⇒ Object
75 76 77 |
# File 'lib/zaif_wrapper/client.rb', line 75 def get_id_info request('get_id_info') end |
#get_info ⇒ Object
63 64 65 |
# File 'lib/zaif_wrapper/client.rb', line 63 def get_info request('get_info') end |
#get_info2 ⇒ Object
67 68 69 |
# File 'lib/zaif_wrapper/client.rb', line 67 def get_info2 request('get_info2') end |
#get_nonce ⇒ Object
112 113 114 |
# File 'lib/zaif_wrapper/client.rb', line 112 def get_nonce Time.now.to_f.to_i end |
#get_personal_info ⇒ Object
71 72 73 |
# File 'lib/zaif_wrapper/client.rb', line 71 def get_personal_info request('get_personal_info') end |
#request(method, params = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zaif_wrapper/client.rb', line 41 def request(method, params = {}) body = { 'method' => method, 'nonce' => get_nonce } signature_text = "method=#{method}&nonce=#{get_nonce}" unless params.empty? params.each { |param| body.store(param[0], param[1]) signature_text = "#{signature_text}&#{param[0]}=#{param[1]}" } end response = RestClient.post REQUEST_URL_BASE, body, { content_type: :json, accept: :json, key: @api_key, sign: create_signature(signature_text) } JSON.parse(response.body) end |
#trade(params = {}) ⇒ Object
87 88 89 90 |
# File 'lib/zaif_wrapper/client.rb', line 87 def trade(params = {}) raise "Required parameters are missing" if params["currency_pair"].nil? || params["action"].nil? || params["price"].nil? || params["amount"].nil? request('trade', params) end |
#trade_history(params = {}) ⇒ Object
79 80 81 |
# File 'lib/zaif_wrapper/client.rb', line 79 def trade_history(params = {}) request('trade_history', params) end |
#withdraw(params = {}) ⇒ Object
97 98 99 100 |
# File 'lib/zaif_wrapper/client.rb', line 97 def withdraw(params = {}) raise "Required parameters are missing" if params["currency"].nil? || params["address"].nil? || params["amount"].nil? request('withdraw', params) end |
#withdraw_history(params = {}) ⇒ Object
107 108 109 110 |
# File 'lib/zaif_wrapper/client.rb', line 107 def withdraw_history(params = {}) raise "Required parameters are missing" if params["currency"].nil? request('withdraw_history', params) end |