Class: Liquid::Client

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

Defined Under Namespace

Classes: InvalidArgument, ResponseParseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, secret) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# File 'lib/liquid/client.rb', line 9

def initialize(token, secret)
  @url = "https://api.liquid.com"
  @http = http
  @token_id = token || ENV["LIQUID_KEY"]
  @user_secret = secret || ENV["LIQUID_SECRET"]
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/liquid/client.rb', line 6

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/liquid/client.rb', line 6

def path
  @path
end

#token_idObject (readonly)

Returns the value of attribute token_id.



6
7
8
# File 'lib/liquid/client.rb', line 6

def token_id
  @token_id
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/liquid/client.rb', line 7

def url
  @url
end

#user_secretObject (readonly)

Returns the value of attribute user_secret.



6
7
8
# File 'lib/liquid/client.rb', line 6

def user_secret
  @user_secret
end

Instance Method Details

#active_ordersObject



27
28
29
30
# File 'lib/liquid/client.rb', line 27

def active_orders
  @path = '/orders?status=live'
  get_request
end

#balanceObject



32
33
34
35
# File 'lib/liquid/client.rb', line 32

def balance
  @path = '/accounts/balance'
  get_request
end

#cancel_order(id) ⇒ Object

PUT



74
75
76
77
# File 'lib/liquid/client.rb', line 74

def cancel_order(id)
  @path = "/orders/#{id}/cancel"
  put_request
end

#create_order(order_type: "limit", pair: nil, side: nil, quantity: nil, price: nil) ⇒ Object

POST

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/liquid/client.rb', line 56

def create_order(order_type: "limit", pair: nil, side: nil, quantity: nil, price: nil)
  pair_id = product_id(pair)
  raise InvalidArgument if side.nil? || quantity.nil? || price.nil?
  @path = '/orders'
  @params = 
    {
      "order": {
        "order_type": order_type,
        "product_id": pair_id,
        "side": side,
        "quantity": quantity,
        "price": price
      }
    }.to_json
  post_request
end

#limit_buy_price(pair) ⇒ Object



47
48
49
# File 'lib/liquid/client.rb', line 47

def limit_buy_price(pair)
  product_detail(pair)["market_bid"].to_f
end

#limit_sell_price(pair) ⇒ Object



51
52
53
# File 'lib/liquid/client.rb', line 51

def limit_sell_price(pair)
  product_detail(pair)["market_ask"].to_f
end

#ordersObject



22
23
24
25
# File 'lib/liquid/client.rb', line 22

def orders
  @path = '/orders'
  get_request
end

#productObject

GET



17
18
19
20
# File 'lib/liquid/client.rb', line 17

def product
  @path = '/products'
  get_request
end

#product_detail(pair) ⇒ Object



37
38
39
40
41
# File 'lib/liquid/client.rb', line 37

def product_detail(pair)
  product.select{|p|
    p["currency_pair_code"] == pair
  }.first
end

#product_id(pair) ⇒ Object



43
44
45
# File 'lib/liquid/client.rb', line 43

def product_id(pair)
  product_detail(pair)["id"].to_i
end