bitflyer-cli 0.0.2 → 0.1.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: fe3b1083bfba3863ba05c5392835726bb1196651
4
- data.tar.gz: e56b42847236c7b4b70f787587e6d73c265b99ab
3
+ metadata.gz: 8e17ec185d7cb7e8a3f6a790f7a049c25adc558b
4
+ data.tar.gz: 500794980ae1a86398b330a75ea3a2824fc302f2
5
5
  SHA512:
6
- metadata.gz: 63636c019ec58edc5d0ee3b7502d1c0c44ecfd4a939aa95e11e307aed9b9c89502d84a13a97fba0fa08f72ced1e1a90bda1481e2257439be7d781cca390f7db7
7
- data.tar.gz: da8d550da655d6bf60b56837be6c449ddc103d9e8db260a847b7a111dd2195fa147b3ef73f285f1b703d1b2ff3ca3fbbd04f0816589dc59dad01ecd7da274b96
6
+ metadata.gz: a2385e0ca1aeb6494c33532478ca631fc59cb5a549c632721aff995005ca48c4befa1a8b442e9740941066cb1eeaeb77aa1220e0dce95178903839c5b00187e5
7
+ data.tar.gz: c354342c4b9a78e23a44e74540236acbd9ac3b991c3f357d27ae0b842ef9031b17d948464ba5198c3c449928085e7e574697e9273f4d895e01bc6a23ba33aec7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitflyer-cli (0.0.2)
4
+ bitflyer-cli (0.1.0)
5
5
  bitflyer (~> 0.1.0)
6
6
  colorize (~> 0.8.1)
7
7
  thor (~> 0.19.4)
@@ -9,9 +9,9 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- bitflyer (0.1.1)
12
+ bitflyer (0.1.2)
13
13
  faraday (~> 0.12.2)
14
- faraday_middleware (~> 0.11.0.1)
14
+ faraday_middleware (~> 0.12.0)
15
15
  pubnub (~> 4.0.22)
16
16
  celluloid (0.17.3)
17
17
  celluloid-essentials
@@ -62,9 +62,9 @@ GEM
62
62
  dry-types (~> 0.11.0)
63
63
  faraday (0.12.2)
64
64
  multipart-post (>= 1.2, < 3)
65
- faraday_middleware (0.11.0.1)
65
+ faraday_middleware (0.12.2)
66
66
  faraday (>= 0.7.4, < 1.0)
67
- hitimes (1.2.5)
67
+ hitimes (1.2.6)
68
68
  httpclient (2.8.3)
69
69
  inflecto (0.0.2)
70
70
  json (2.1.0)
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Dependency Status](https://gemnasium.com/badges/github.com/unhappychoice/bitflyer-cli.svg)](https://gemnasium.com/github.com/unhappychoice/bitflyer-cli)
6
6
  ![](http://ruby-gem-downloads-badge.herokuapp.com/bitflyer-cli?type=total)
7
7
 
8
- bitflyer-cli is a CLI tool for [Bitflyer](https://bitflyer.jp/).
8
+ bitflyer-cli is a CLI tool for [Bitflyer](https://bitflyer.jp/) FXBTC.
9
9
 
10
10
  ## Installation
11
11
 
@@ -24,7 +24,10 @@ export BITFLYER_API_SECRET=your-bitflyey-api-secret
24
24
 
25
25
  ```
26
26
  Commands:
27
- bitflyer summary # show current balance information
27
+ bitflyer counter_trade # clear all positions
28
+ bitflyer help [COMMAND] # Describe available commands or one specific command
29
+ bitflyer order_by_best # create limit order by best price in the board
30
+ bitflyer summary # show current balance information
28
31
  ```
29
32
 
30
33
  ## Contributing
data/bitflyer-cli.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'bitflyer-cli'
7
- spec.version = '0.0.2'
7
+ spec.version = '0.1.0'
8
8
  spec.authors = ['Yuji Ueki']
9
9
  spec.email = ['unhappychoice@gmail.com']
10
10
 
@@ -0,0 +1,34 @@
1
+ require 'bitflyer'
2
+
3
+ class CounterTradeCommand
4
+ def initialize
5
+ @http_client = Bitflyer.http_private_client(api_key, api_secret)
6
+ end
7
+
8
+ def run
9
+ position = Position.new(@http_client.positions)
10
+ size = position.size
11
+ type = position.size > 0 ? 'SELL' : 'BUY'
12
+ response = @http_client.send_child_order(
13
+ product_code: 'FX_BTC_JPY',
14
+ child_order_type: 'MARKET',
15
+ side: type,
16
+ size: size
17
+ )
18
+ if response['child_order_acceptance_id'].nil?
19
+ puts 'An error has occurred' + response.to_s
20
+ else
21
+ puts "Clear position #{type} / #{size}"
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def api_key
28
+ ENV['BITFLYER_API_KEY']
29
+ end
30
+
31
+ def api_secret
32
+ ENV['BITFLYER_API_SECRET']
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ require 'bitflyer'
2
+
3
+ class OrderByBestCommand
4
+ def initialize
5
+ @http_public_client = Bitflyer.http_public_client
6
+ @http_private_client = Bitflyer.http_private_client(api_key, api_secret)
7
+ end
8
+
9
+ def run(options)
10
+ amount = options.amount
11
+ type = options.type
12
+ if amount == nil || type == nil
13
+ puts 'You need set amount by -a and type by -t'
14
+ puts 'ex: bitflyer order_by_best -a 10 -t buy'
15
+ return
16
+ end
17
+
18
+ ticker = @http_public_client.ticker('FX_BTC_JPY')
19
+ price = type == 'buy' ? ticker['best_bid'] : ticker['best_ask']
20
+
21
+ response = @http_private_client.send_child_order(
22
+ product_code: 'FX_BTC_JPY',
23
+ child_order_type: 'LIMIT',
24
+ side: type.upcase,
25
+ price: price,
26
+ size: amount
27
+ )
28
+ if response['child_order_acceptance_id'].nil?
29
+ puts 'An error has occurred' + response.to_s
30
+ else
31
+ puts "An order is created #{type} / #{price} / #{amount}"
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def api_key
38
+ ENV['BITFLYER_API_KEY']
39
+ end
40
+
41
+ def api_secret
42
+ ENV['BITFLYER_API_SECRET']
43
+ end
44
+ end
@@ -20,6 +20,6 @@ class Position
20
20
  end
21
21
 
22
22
  def size
23
- @positions.inject(0.0) { |sum, position| sum + position['size'].to_f * (position['side'] == 'BUY' ? 1.0 : -1.0) }.round(2)
23
+ @positions.inject(0.0) { |sum, position| sum + position['size'].to_f * (position['side'] == 'BUY' ? 1.0 : -1.0) }
24
24
  end
25
25
  end
data/lib/bitflyer/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'thor'
2
+ require 'bitflyer/cli/command/counter_trade_command'
2
3
  require 'bitflyer/cli/command/summary_command'
4
+ require 'bitflyer/cli/command/order_by_best_command'
3
5
 
4
6
  module Bitflyer
5
7
  class CLI < Thor
@@ -7,5 +9,17 @@ module Bitflyer
7
9
  def summary
8
10
  SummaryCommand.new.run
9
11
  end
12
+
13
+ desc 'order_by_best', 'create limit order by best price in the board'
14
+ method_option :amount, aliases: 'a', type: :numeric, banner: 'amount'
15
+ method_option :type, aliases: 't', type: :string, banner: 'buy or sell'
16
+ def order_by_best
17
+ OrderByBestCommand.new.run(options)
18
+ end
19
+
20
+ desc 'counter_trade', 'clear all positions'
21
+ def counter_trade
22
+ CounterTradeCommand.new.run
23
+ end
10
24
  end
11
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitflyer-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Ueki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-28 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -111,6 +111,8 @@ files:
111
111
  - bitflyer-cli.gemspec
112
112
  - exe/bitflyer
113
113
  - lib/bitflyer/cli.rb
114
+ - lib/bitflyer/cli/command/counter_trade_command.rb
115
+ - lib/bitflyer/cli/command/order_by_best_command.rb
114
116
  - lib/bitflyer/cli/command/summary_command.rb
115
117
  - lib/bitflyer/cli/ext/string.rb
116
118
  - lib/bitflyer/cli/model/position.rb