ruby-liquid 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51afabf8f2d8c54ca585ef0212f34c8bc2136a1dbdd3b6df116db10dbc475109
4
- data.tar.gz: c6e385eac553b1f1e78f60a3a9024d3b4e9dbf3626284e75e9ddb9ffa9e55fe4
3
+ metadata.gz: 8665f261b108cff88db5347cd195bb2eb58118c80d6d65b62642367f4ed2efa9
4
+ data.tar.gz: 58d902fe3cf88b86fbb15e890ed8495877970d4a50457afdc9de06bc4dbc9c59
5
5
  SHA512:
6
- metadata.gz: 2298647cfc5f0fc8578f6057a5e44d03237b282e61cb69b58a2467a5a35613ca693078c26bf73d50a4bfce02a7cc1b25975daa4df80142ac78b5c64d6503fb7b
7
- data.tar.gz: 9e476555bdd84cf74240d47a5458fdeba036d498ac01f3ddee6730e177468fdc92096185f0bc20aca2497976180387515f943555dfd252819076436344bfa29c
6
+ metadata.gz: f40cf9cf6b90ddc83eb15fea7cb06dbfc3cc8efd91cb103650a5420a3eaae12a596bab64c7c7886cee5dbebf9c5bf1b36d2435d2825792a172c93acac582e2b1
7
+ data.tar.gz: d0881a40e3e5e880cade875585efd9995effb0b92fe886d4cd3fea467d69c6a949732c1558455601a7d4a2846c8f6e41de3141d57cb53b086717029dc8670410
data/.rspec_status CHANGED
@@ -1,5 +1,5 @@
1
1
  example_id | status | run_time |
2
2
  ---------------------------- | ------ | --------------- |
3
- ./spec/liquid_spec.rb[1:1] | passed | 0.00065 seconds |
4
- ./spec/liquid_spec.rb[1:2:1] | passed | 0.15876 seconds |
5
- ./spec/liquid_spec.rb[1:3:1] | passed | 0.14773 seconds |
3
+ ./spec/liquid_spec.rb[1:1] | passed | 0.0011 seconds |
4
+ ./spec/liquid_spec.rb[1:2:1] | passed | 0.73593 seconds |
5
+ ./spec/liquid_spec.rb[1:3:1] | passed | 0.48637 seconds |
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-liquid (0.1.4)
4
+ ruby-liquid (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -31,9 +31,14 @@ liquid_client = Liquid::Client.new(token: token, secret: secret)
31
31
  liquid_client.product
32
32
  liquid_client.product_id("BCHJPY")
33
33
  liquid_client.orders
34
+ liquid_client.active_orders
34
35
  liquid_client.balance
36
+ liquid_client.limit_buy_price
37
+ liquid_client.limit_sell_price
35
38
  # post
36
39
  liquid_client.create_order(pair: "BCHJPY", side: 'buy', quantity: 0.01, price: 40000)
40
+ # put
41
+ liquid_client.cancel_order(id)
37
42
  ```
38
43
 
39
44
  ## Contributing
data/lib/liquid/client.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  module Liquid
2
2
  class Client
3
3
  class InvalidArgument < StandardError; end
4
+ class ResponseParseError < StandardError; end
4
5
 
5
6
  attr_reader :http, :token_id, :user_secret, :path, :params
6
7
  attr_accessor :url
7
8
 
8
-
9
-
10
9
  def initialize(token, secret)
11
10
  @url = "https://api.liquid.com"
12
11
  @http = http
@@ -14,7 +13,7 @@ module Liquid
14
13
  @user_secret = secret || ENV["LIQUID_SECRET"]
15
14
  end
16
15
 
17
- # get
16
+ # GET
18
17
  def product
19
18
  @path = '/products'
20
19
  get_request
@@ -25,6 +24,11 @@ module Liquid
25
24
  get_request
26
25
  end
27
26
 
27
+ def active_orders
28
+ @path = '/orders?status=live'
29
+ get_request
30
+ end
31
+
28
32
  def balance
29
33
  @path = '/accounts/balance'
30
34
  get_request
@@ -40,15 +44,15 @@ module Liquid
40
44
  product_detail(pair)["id"].to_i
41
45
  end
42
46
 
43
- def taker_buy_price(pair)
47
+ def limit_buy_price(pair)
44
48
  product_detail(pair)["market_bid"].to_f
45
49
  end
46
50
 
47
- def taker_sell_price(pair)
51
+ def limit_sell_price(pair)
48
52
  product_detail(pair)["market_ask"].to_f
49
53
  end
50
54
 
51
- # post
55
+ # POST
52
56
  def create_order(order_type: "limit", pair: nil, side: nil, quantity: nil, price: nil)
53
57
  pair_id = product_id(pair)
54
58
  raise InvalidArgument if side.nil? || quantity.nil? || price.nil?
@@ -66,6 +70,12 @@ module Liquid
66
70
  post_request
67
71
  end
68
72
 
73
+ # PUT
74
+ def cancel_order(id)
75
+ @path = "/orders/#{id}/cancel"
76
+ put_request
77
+ end
78
+
69
79
  private
70
80
  def http
71
81
  uri = URI.parse(url)
@@ -76,23 +86,30 @@ module Liquid
76
86
 
77
87
  def get_request
78
88
  request = Net::HTTP::Get.new(path)
79
- request.add_field('X-Quoine-API-Version', '2')
80
- request.add_field('X-Quoine-Auth', signature)
81
- request.add_field('Content-Type', 'application/json')
82
- response = http.request(request)
83
- # TODO: error handling
84
- JSON.parse(response.body)
89
+ request(request)
85
90
  end
86
91
 
87
92
  def post_request
88
93
  request = Net::HTTP::Post.new(path)
89
94
  request.body = @params
95
+ request(request)
96
+ end
97
+
98
+ def put_request
99
+ request = Net::HTTP::Put.new(path)
100
+ request(request)
101
+ end
102
+
103
+ def request(request)
90
104
  request.add_field('X-Quoine-API-Version', '2')
91
105
  request.add_field('X-Quoine-Auth', signature)
92
106
  request.add_field('Content-Type', 'application/json')
93
107
  response = http.request(request)
94
- # TODO: error handling
95
- JSON.parse(response.body)
108
+ begin
109
+ JSON.parse(response.body)
110
+ rescue JSON::ParserError
111
+ raise ResponseParseError
112
+ end
96
113
  end
97
114
 
98
115
  def auth_payload
@@ -1,3 +1,3 @@
1
1
  module Liquid
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - emono