ruby-liquid 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb94452b9d9eece2fa1f0cd5e47b22c57637ed5a154d0e9001f5d752ba56d790
4
- data.tar.gz: '0086784eb77e0851ad2e36edb575fc2ff7314a637195dd69c224a0a13faaa48b'
3
+ metadata.gz: b870defd2092079296ffb2ef6d8f86c44ad51c08bed52d8ff79bab1ec7dfc476
4
+ data.tar.gz: e2876cdca6f837e6bbe57c6f9ef463f63207bf4bc29b5ba7dca9ffaa2a38df6b
5
5
  SHA512:
6
- metadata.gz: e9c55fce0965c3af738111e7ed51fed20c74446ea5c25029a18498ba8cf26ac9735be042df617163d08a80f15d4ec8a67ff3009d51812f569a0621ffbd6b9be9
7
- data.tar.gz: c481f3986d97d396beb4d85ec5ca90286e5d6425328abb21b5fccd41cfd487fd323730546c5f1224eb2ee059d728ee2f3b1a56456fea0c75744b875c84dce74d
6
+ metadata.gz: bc7e97cf8da7d4e0a1525154526d89946e723d372f0fec9512866754397028d33ecdf342a264af9fe020f48e3bbdf55971ff9e4f9d214ddbc2120e30a2af527a
7
+ data.tar.gz: 69aa01c715673f73c507f078806b05ee7d662c3b4dd0c76029ece241f1b1e4c8e5643a04b59a0e5339c09113e2f9dd74ea4526c0bb20a25671c62c27e147bdf4
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.00168 seconds |
4
- ./spec/liquid_spec.rb[1:2:1] | passed | 0.57795 seconds |
5
- ./spec/liquid_spec.rb[1:3:1] | passed | 0.42028 seconds |
3
+ ./spec/liquid_spec.rb[1:1] | passed | 0.00097 seconds |
4
+ ./spec/liquid_spec.rb[1:2:1] | passed | 0.18417 seconds |
5
+ ./spec/liquid_spec.rb[1:3:1] | passed | 0.2375 seconds |
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-liquid (0.1.2)
4
+ ruby-liquid (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -25,8 +25,11 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
  ```rb
28
- irb(main):014:0> require 'ruby-liquid'
29
- => true
28
+ require 'ruby-liquid'
29
+ Liquid::Client.new(token, secret).product
30
+ Liquid::Client.new(token, secret).product_id("BCHJPY")
31
+ Liquid::Client.new(token, secret).create_order(pair: "BCHJPY", side: 'buy', quantity: 0.01, price: 40000)
32
+
30
33
  ```
31
34
 
32
35
  ## Contributing
data/lib/liquid/client.rb CHANGED
@@ -1,18 +1,23 @@
1
1
  module Liquid
2
2
  class Client
3
- attr_reader :http, :token_id, :user_secret, :path
3
+ class InvalidArgument < StandardError; end
4
4
 
5
- URL = "https://api.liquid.com"
5
+ attr_reader :http, :token_id, :user_secret, :path, :params
6
+ attr_accessor :url
7
+
8
+
6
9
 
7
10
  def initialize(token, secret)
11
+ @url = "https://api.liquid.com"
8
12
  @http = http
9
13
  @token_id = token || ENV["LIQUID_KEY"]
10
14
  @user_secret = secret || ENV["LIQUID_SECRET"]
11
15
  end
12
16
 
17
+ # get
13
18
  def product
14
19
  @path = '/products'
15
- request
20
+ get_request
16
21
  end
17
22
 
18
23
  def product_detail(pair)
@@ -22,15 +27,7 @@ module Liquid
22
27
  end
23
28
 
24
29
  def product_id(pair)
25
- product_detail(pair)["id"]
26
- end
27
-
28
- def product_id(pair)
29
- product_detail(pair)["id"]
30
- end
31
-
32
- def product_id(pair)
33
- product_detail(pair)["id"]
30
+ product_detail(pair)["id"].to_i
34
31
  end
35
32
 
36
33
  def taker_buy_price(pair)
@@ -41,16 +38,33 @@ module Liquid
41
38
  product_detail(pair)["market_ask"].to_f
42
39
  end
43
40
 
41
+ # post
42
+ def create_order(order_type: "limit", pair: nil, side: nil, quantity: nil, price: nil)
43
+ pair_id = product_id(pair)
44
+ raise InvalidArgument if side.nil? || quantity.nil? || price.nil?
45
+ @path = '/orders'
46
+ @params =
47
+ {
48
+ "order": {
49
+ "order_type": order_type,
50
+ "product_id": pair_id,
51
+ "side": side,
52
+ "quantity": quantity,
53
+ "price": price
54
+ }
55
+ }.to_json
56
+ post_request
57
+ end
58
+
44
59
  private
45
60
  def http
46
- uri = URI.parse(URL)
61
+ uri = URI.parse(url)
47
62
  http = Net::HTTP.new(uri.host, uri.port)
48
63
  http.use_ssl = true
49
64
  http
50
65
  end
51
66
 
52
-
53
- def request
67
+ def get_request
54
68
  request = Net::HTTP::Get.new(path)
55
69
  request.add_field('X-Quoine-API-Version', '2')
56
70
  request.add_field('X-Quoine-Auth', signature)
@@ -60,6 +74,17 @@ module Liquid
60
74
  JSON.parse(response.body)
61
75
  end
62
76
 
77
+ def post_request
78
+ request = Net::HTTP::Post.new(path)
79
+ request.body = @params
80
+ request.add_field('X-Quoine-API-Version', '2')
81
+ request.add_field('X-Quoine-Auth', signature)
82
+ request.add_field('Content-Type', 'application/json')
83
+ response = http.request(request)
84
+ # TODO: error handling
85
+ JSON.parse(response.body)
86
+ end
87
+
63
88
  def auth_payload
64
89
  {
65
90
  path: path,
@@ -1,3 +1,3 @@
1
1
  module Liquid
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - emono
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2019-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler