Class: VaultOfSatoshi::API::Trade

Inherits:
Base
  • Object
show all
Defined in:
lib/vault_of_satoshi/api/trade.rb

Constant Summary

Constants inherited from Base

Base::ALL_CURRENCIES, Base::CRYPTO_CURRENCIES, Base::FIAT_CURRENCIES

Instance Method Summary collapse

Methods inherited from Base

#inspect

Constructor Details

#initialize(api_key, api_secret) ⇒ Trade

Returns a new instance of Trade.



5
6
7
# File 'lib/vault_of_satoshi/api/trade.rb', line 5

def initialize(api_key, api_secret)
  super
end

Instance Method Details

#cancel(params = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/vault_of_satoshi/api/trade.rb', line 22

def cancel(params = {})
  params.slice!(:order_id)
  params.merge!(nonce: nonce)
  endpoint = "/trade/cancel"

  response = self.class.post(endpoint, body: params.to_param, headers: headers(endpoint, params)).parsed_response
  raise VaultOfSatoshi::API::Error.new(response["message"]) if response["status"] == "error"

  parse_data(response["data"])
end

#place(params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vault_of_satoshi/api/trade.rb', line 9

def place(params = {})
  params.slice!(:type, :order_currency, :units, :payment_currency, :price)
  params[:units] = generate_currency_object(params[:units])
  params[:price] = generate_currency_object(params[:price])
  params.merge!(nonce: nonce)
  endpoint = "/trade/place"

  response = self.class.post(endpoint, body: params.to_param, headers: headers(endpoint, params)).parsed_response
  raise VaultOfSatoshi::API::Error.new(response["message"]) if response["status"] == "error"

  parse_data(response["data"])
end