bitflyer-cli 0.2.1 → 0.3.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: dc5f3d5a40642d1d2444a05e882a8371d78fe94c
4
- data.tar.gz: f690fce5c074fddbd043fe1b24d8b558fe0699c8
3
+ metadata.gz: f49c29d95f8bcc96146e2a9cfb1f27d0c3689f66
4
+ data.tar.gz: e2cfaeabf096e224082e0cb8ce0d215ac1e1c0cf
5
5
  SHA512:
6
- metadata.gz: 81ddcc3aa433698922b739b51cad15b4f1cbb061d238dcc1d4f31052664b66b0d22c04585864b358728a74e4ee41289b120fff808b664fb14277f6120881e289
7
- data.tar.gz: 3758b85c54a002d4097f37acefbc456c5d6a5166b24d4b64b5b7c1fe9cfadfe2eb22b22e24c3894f05b624e843128eb439d400563450f5b62879787141235f11
6
+ metadata.gz: 165d8081b1758dc85fce8fdaad7e6a8bf171bcd75482946e872ad13b9abb91627d646aec04ae6da623755264c582f4ff05df899507265f73e03a57d2014222a5
7
+ data.tar.gz: 7dda475c8d12eebebc9dc3c7373ad66220fa85eeac5c768530078402f8db88e2443be3cce061b3dd3cff332e2456e79b66c9ae322f75fa9f99f931965562cc94
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitflyer-cli (0.2.1)
4
+ bitflyer-cli (0.3.0)
5
5
  bitflyer (~> 0.1.0)
6
6
  colorize (~> 0.8.1)
7
7
  thor (~> 0.19.4)
data/README.md CHANGED
@@ -16,18 +16,20 @@ gem install bitflyer-cli
16
16
  Set the `BITFLYER_API_TOKEN` and `BITFLYER_API_SECRET` environment variable.
17
17
 
18
18
  ```sh
19
- export BITFLYER_API_TOKEN=your-bitflyey-api-token
20
- export BITFLYER_API_SECRET=your-bitflyey-api-secret
19
+ export BITFLYER_API_TOKEN=your-bitflyer-api-token
20
+ export BITFLYER_API_SECRET=your-bitflyer-api-secret
21
21
  ```
22
22
 
23
23
  ## Usage
24
24
 
25
25
  ```
26
26
  Commands:
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
27
+ bitflyer cancel_all # cancel all of orders
28
+ bitflyer counter_trade # clear all positions
29
+ bitflyer help [COMMAND] # Describe available commands or one specific command
30
+ bitflyer order_by_best -a=amount -t=buy/sell # create limit order by best price in the board
31
+ bitflyer order_by_twap -a=amount -i=second -n=N -t=buy/sell # trade specified amount N times at specified intervals (TWAP algorithm).
32
+ bitflyer summary # show current balance information
31
33
  ```
32
34
 
33
35
  ## Contributing
@@ -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.2.1'
7
+ spec.version = '0.3.0'
8
8
  spec.authors = ['Yuji Ueki']
9
9
  spec.email = ['unhappychoice@gmail.com']
10
10
 
@@ -1,8 +1,9 @@
1
1
  require 'thor'
2
2
  require 'bitflyer/cli/command/cancel_all_command'
3
3
  require 'bitflyer/cli/command/counter_trade_command'
4
- require 'bitflyer/cli/command/summary_command'
5
4
  require 'bitflyer/cli/command/order_by_best_command'
5
+ require 'bitflyer/cli/command/order_by_twap_command'
6
+ require 'bitflyer/cli/command/summary_command'
6
7
 
7
8
  module Bitflyer
8
9
  class CLI < Thor
@@ -11,11 +12,9 @@ module Bitflyer
11
12
  SummaryCommand.new.run
12
13
  end
13
14
 
14
- desc 'order_by_best', 'create limit order by best price in the board'
15
- method_option :amount, aliases: 'a', type: :numeric, banner: 'amount'
16
- method_option :type, aliases: 't', type: :string, banner: 'buy or sell'
17
- def order_by_best
18
- OrderByBestCommand.new.run(options)
15
+ desc 'cancel_all', 'cancel all of orders'
16
+ def cancel_all
17
+ CancelAllCommand.new.run
19
18
  end
20
19
 
21
20
  desc 'counter_trade', 'clear all positions'
@@ -23,9 +22,20 @@ module Bitflyer
23
22
  CounterTradeCommand.new.run
24
23
  end
25
24
 
26
- desc 'cancel_all', 'cancel all of orders'
27
- def cancel_all
28
- CancelAllCommand.new.run
25
+ desc 'order_by_best', 'create limit order by best price in the board'
26
+ method_option :amount, aliases: 'a', type: :numeric, banner: 'amount', required: true
27
+ method_option :type, aliases: 't', type: :string, banner: 'buy/sell', required: true
28
+ def order_by_best
29
+ OrderByBestCommand.new.run(options)
30
+ end
31
+
32
+ desc 'order_by_twap', 'order by using TWAP algorithm'
33
+ method_option :amount, aliases: 'a', type: :numeric, banner: 'amount', required: true
34
+ method_option :type, aliases: 't', type: :string, banner: 'buy/sell', required: true
35
+ method_option :number_of_times, aliases: 'n', type: :numeric, banner: 'N', required: true
36
+ method_option :interval, aliases: 'i', type: :numeric, banner: 'second', required: true
37
+ def order_by_twap
38
+ OrderByTWAPCommand.new.run(options)
29
39
  end
30
40
  end
31
41
  end
@@ -6,11 +6,6 @@ class OrderByBestCommand
6
6
  def run(options)
7
7
  amount = options.amount
8
8
  type = options.type
9
- if amount == nil || type == nil
10
- puts 'You need set amount by -a and type by -t'
11
- puts 'ex: bitflyer order_by_best -a 10 -t buy'
12
- return
13
- end
14
9
 
15
10
  ticker = http_public_client.ticker('FX_BTC_JPY')
16
11
  price = type == 'buy' ? ticker['best_bid'] : ticker['best_ask']
@@ -0,0 +1,34 @@
1
+ require 'bitflyer/cli/has_http_client'
2
+
3
+ class OrderByTWAPCommand
4
+ include HasHTTPClient
5
+
6
+ def run(options)
7
+ type = options.type
8
+ amount = options.amount
9
+ number = options.number_of_times
10
+ interval = options.interval
11
+
12
+ number.to_i.times do |_|
13
+ order(type, amount)
14
+ sleep interval
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def order(type, amount)
21
+ response = http_private_client.send_child_order(
22
+ product_code: 'FX_BTC_JPY',
23
+ child_order_type: 'MARKET',
24
+ side: type.upcase,
25
+ size: amount
26
+ )
27
+
28
+ if response['child_order_acceptance_id'].nil?
29
+ puts "An error has occurred\n" + response.to_s
30
+ else
31
+ puts response.to_s
32
+ end
33
+ end
34
+ 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.2.1
4
+ version: 0.3.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-08-06 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -115,6 +115,7 @@ files:
115
115
  - lib/bitflyer/cli/command/cancel_all_command.rb
116
116
  - lib/bitflyer/cli/command/counter_trade_command.rb
117
117
  - lib/bitflyer/cli/command/order_by_best_command.rb
118
+ - lib/bitflyer/cli/command/order_by_twap_command.rb
118
119
  - lib/bitflyer/cli/command/summary_command.rb
119
120
  - lib/bitflyer/cli/ext/string.rb
120
121
  - lib/bitflyer/cli/has_http_client.rb