kaesen 0.1.1 → 0.2.0

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
  SHA1:
3
- metadata.gz: e5b1cd42537e9ba5277bb7c27ba333331e3cb261
4
- data.tar.gz: 13247c95cc7722a14c051277deb30416284ee74a
3
+ metadata.gz: d7f9aa86f298cf72a2d118c742effd439ff35941
4
+ data.tar.gz: ba42ec7cac482ac8fce8c68fbbc85ffc0fa3c4c4
5
5
  SHA512:
6
- metadata.gz: a508dbef6da2bc575902aa72aec55f7cb07e92654a6ebccf017f15a2029a7c1df7cdc6b2ef22709604735eaa35e1c88bef86eaef9b9f441691c784ab9cb5644c
7
- data.tar.gz: 6065eb0d89d374d926b8caa35c6cdf17ac4aebae882416175b38b669fc1ee596441f1225f1afd4e0b76b704c24c2fbefb9e8bbdb35a5da36f503bf2261208aed
6
+ metadata.gz: 7b885fe39f78e7ed96c3ec18d0de9c050d0a6e745b5e278415f9be0cc727b9fee135ca81fadb7f9aa76ec5f18748a61f25c7ef523e92c2ed47f86b566dbe662c
7
+ data.tar.gz: 71c75281c824bc1a32927676dd96dec6104ba0120e31fb4422dbf828b0ba38d27ec89458174983557a018f97e28b7c783c271d73324df91c8a664b8f66529b03
@@ -0,0 +1 @@
1
+ 2.2.5
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kaesen (0.1.1)
4
+ kaesen (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.2.5)
10
- dotenv (2.1.0)
9
+ diff-lcs (1.3)
10
+ dotenv (2.2.0)
11
11
  rake (10.5.0)
12
- rspec (3.4.0)
13
- rspec-core (~> 3.4.0)
14
- rspec-expectations (~> 3.4.0)
15
- rspec-mocks (~> 3.4.0)
16
- rspec-core (3.4.3)
17
- rspec-support (~> 3.4.0)
18
- rspec-expectations (3.4.0)
12
+ rspec (3.5.0)
13
+ rspec-core (~> 3.5.0)
14
+ rspec-expectations (~> 3.5.0)
15
+ rspec-mocks (~> 3.5.0)
16
+ rspec-core (3.5.4)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-expectations (3.5.0)
19
19
  diff-lcs (>= 1.2.0, < 2.0)
20
- rspec-support (~> 3.4.0)
21
- rspec-mocks (3.4.1)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-mocks (3.5.0)
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.4.0)
24
- rspec-support (3.4.1)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-support (3.5.0)
25
25
 
26
26
  PLATFORMS
27
27
  ruby
@@ -37,4 +37,4 @@ RUBY VERSION
37
37
  ruby 2.2.5p319
38
38
 
39
39
  BUNDLED WITH
40
- 1.12.5
40
+ 1.14.3
data/README.md CHANGED
@@ -2,18 +2,26 @@
2
2
 
3
3
  A module of the united wrapper for exchanging Japanese yen and Bitcoin and collecting market information of any exchange markets that provide ordinary customers with API access.
4
4
 
5
+ 日本国内のビットコインの取引所の API を統一された API で操作できる統合 API ラッパーです.
6
+
5
7
  ## Installation
6
8
 
7
9
  For each of your applications, add the following line to the application's Gemfile:
8
10
 
9
11
  ```ruby
10
- gem 'kaesen', github: "him0/kaesen"
12
+ gem 'kaesen'
11
13
  ```
12
14
 
13
15
  Then, run bundler:
14
16
 
15
17
  $ bundle install
16
18
 
19
+ or
20
+
21
+ ```shell
22
+ gem install kaesen
23
+ ```
24
+
17
25
  ## Usage
18
26
 
19
27
  ```
@@ -23,6 +31,16 @@ b = Kaesen::Bitflyer.new do |config|
23
31
  config.api_secret = "YYY"
24
32
  end
25
33
  b.ticker
34
+ b.buy(100000, 0.1) # Buy the 0.1 BTC at the rate is 100,000 BTC/JPY
35
+ ```
36
+
37
+ or
38
+
39
+ setting the enviromnet values base on `.env.sample`, and
40
+
41
+ ```
42
+ require 'kaesen'
43
+ b = Kaesen::Bitflyer.new
26
44
  ```
27
45
 
28
46
  ### Currently supported exchange markets to trade:
@@ -52,3 +70,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/him0/k
52
70
  ## License
53
71
 
54
72
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
74
+ ## Donation
75
+
76
+ bitcoin:1B1uB4Z4GoxejicoVs9c61S3jXx7BoHYDq
@@ -6,7 +6,7 @@ require 'date'
6
6
  require 'bigdecimal'
7
7
 
8
8
  module Kaesen
9
- # BitFlyer Wrapper Class
9
+ # bitFlyer Wrapper Class
10
10
  # https://lightning.bitflyer.jp/docs?lang=ja
11
11
  ## API制限
12
12
  ## . Private API は 1 分間に約 200 回を上限とします。
@@ -17,7 +17,7 @@ module Kaesen
17
17
 
18
18
  def initialize(options = {})
19
19
  super()
20
- @name = "BitFlyer"
20
+ @name = "bitFlyer"
21
21
  @api_key = ENV["BITFLYER_KEY"]
22
22
  @api_secret = ENV["BITFLYER_SECRET"]
23
23
  @url_public = "https://api.bitflyer.jp/v1"
@@ -132,7 +132,7 @@ module Kaesen
132
132
  a.map{|x|
133
133
  {
134
134
  "success" => "true",
135
- "id" => x["id"],
135
+ "id" => x["child_order_acceptance_id"],
136
136
  "rate" => BigDecimal.new(x["average_price"].to_s),
137
137
  "amount" => BigDecimal.new(x["size"].to_s),
138
138
  "order_type" => x["side"].downcase,
@@ -276,6 +276,35 @@ module Kaesen
276
276
  }
277
277
  end
278
278
 
279
+ # Cancel an open order
280
+ # @abstract
281
+ # @param [int or string] order id
282
+ # @return [hash]
283
+ # success: [bool] status
284
+ def cancel(id)
285
+ have_key?
286
+ address = @url_private + "/me/cancelchildorder"
287
+ body = {
288
+ "product_code" => @product_code,
289
+ "child_order_acceptance_id" => id
290
+ }
291
+ h = post_ssl_with_sign(address, body)
292
+ {
293
+ "success" => h
294
+ }
295
+ end
296
+
297
+ # Cancel all open orders
298
+ # @abstract
299
+ # @return [array]
300
+ # success: [bool] status
301
+ def cancel_all
302
+ have_key?
303
+ opens.collect{|h|
304
+ cancel(h["id"])
305
+ }
306
+ end
307
+
279
308
  private
280
309
 
281
310
  def initialize_https(uri)
@@ -379,6 +408,7 @@ module Kaesen
379
408
  response = w.request(req)
380
409
  case response
381
410
  when Net::HTTPSuccess
411
+ return true if response.body == "" # cancel success
382
412
  json = JSON.parse(response.body)
383
413
  raise JSONException, response.body if json == nil
384
414
  return json
@@ -6,7 +6,7 @@ require 'date'
6
6
  require 'bigdecimal'
7
7
 
8
8
  module Kaesen
9
- # BitFlyer FX Wrapper Class
9
+ # bitFlyer FX Wrapper Class
10
10
  # https://lightning.bitflyer.jp/docs?lang=ja
11
11
  ## API制限
12
12
  ## . Private API は 1 分間に約 200 回を上限とします。
@@ -15,7 +15,7 @@ module Kaesen
15
15
  class Bitflyerfx < Bitflyer
16
16
  def initialize(options = {})
17
17
  super()
18
- @name = "BitFlyerFX"
18
+ @name = "bitFlyerFX"
19
19
  @product_code = "FX_BTC_JPY"
20
20
 
21
21
  options.each do |key, value|
@@ -190,6 +190,34 @@ module Kaesen
190
190
  }
191
191
  end
192
192
 
193
+ # Cancel an open order
194
+ # @abstract
195
+ # @param [int or string] order id
196
+ # @return [hash]
197
+ # success: [bool] status
198
+ def cancel(id)
199
+ have_key?
200
+ address = @url_private + "/trade_cancel/"
201
+ params = {
202
+ "id" => id,
203
+ }
204
+ h = post_ssl_with_sign(address, params)
205
+ {
206
+ "success" => h["result"],
207
+ }
208
+ end
209
+
210
+ # Cancel all open orders
211
+ # @abstract
212
+ # @return [array]
213
+ # success: [bool] status
214
+ def cancel_all
215
+ have_key?
216
+ opens.collect{|h|
217
+ cancel(h["id"])
218
+ }
219
+ end
220
+
193
221
  private
194
222
 
195
223
  def initialize_https(uri)
@@ -259,6 +259,32 @@ module Kaesen
259
259
  }
260
260
  end
261
261
 
262
+ # Cancel an open order
263
+ # @abstract
264
+ # @param [int or string] order id
265
+ # @return [hash]
266
+ # success: [bool] status
267
+ def cancel(id)
268
+ have_key?
269
+ address = @url_privat + "/api/exchange/orders/" + id
270
+ body = { }
271
+ h = delete_ssl_with_sign(address, body)
272
+ {
273
+ "success" => h["success"],
274
+ }
275
+ end
276
+
277
+ # Cancel all open orders
278
+ # @abstract
279
+ # @return [array]
280
+ # success: [bool] status
281
+ def cancel_all
282
+ have_key?
283
+ opens.collect{|h|
284
+ cancel(h["id"])
285
+ }
286
+ end
287
+
262
288
  private
263
289
 
264
290
  def initialize_https(uri)
@@ -372,5 +398,30 @@ module Kaesen
372
398
  raise
373
399
  end
374
400
  end
401
+
402
+ def delete_ssl_with_sign(address, body="")
403
+ uri = URI.parse(address)
404
+ nonce = get_nonce
405
+ headers = get_headers(address, nonce, body)
406
+
407
+ begin
408
+ req = Net::HTTP::Delete.new(uri, headers)
409
+ req.body = body.to_json
410
+
411
+ https = initialize_https(uri)
412
+ https.start {|w|
413
+ response = w.request(req)
414
+ case response
415
+ when Net::HTTPSuccess
416
+ json = JSON.parse(response.body)
417
+ return json
418
+ else
419
+ raise ConnectionFailedException, "Failed to connect to #{@name}: " + response.value
420
+ end
421
+ }
422
+ rescue
423
+ raise
424
+ end
425
+ end
375
426
  end
376
427
  end
@@ -1,3 +1,3 @@
1
1
  module Kaesen
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -296,8 +296,9 @@ module Kaesen
296
296
  # @return [array]
297
297
  # success: [bool] status
298
298
  def cancel_all
299
- opens.each{|h|
300
- print cancel(h["id"])
299
+ have_key?
300
+ opens.collect{|h|
301
+ cancel(h["id"])
301
302
  }
302
303
  end
303
304
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaesen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - him0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-02 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,7 @@ files:
77
77
  - ".env.sample"
78
78
  - ".gitignore"
79
79
  - ".rspec"
80
+ - ".ruby-version"
80
81
  - ".travis.yml"
81
82
  - CODE_OF_CONDUCT.md
82
83
  - Gemfile
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  version: '0'
121
122
  requirements: []
122
123
  rubyforge_project:
123
- rubygems_version: 2.4.5.1
124
+ rubygems_version: 2.6.6
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: A module of the united wrapper for exchanging Japanese yen and Bitcoin and