bitflyer-cli 0.4.4 → 0.5.0

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
- SHA256:
3
- metadata.gz: d7c0705b36a0053dd4898316a9a1cf2c61c5ade33357e34810fb0623b69d567c
4
- data.tar.gz: 16fc62b531c4abe481b54ee292dbcb6f24e2f86b471263c4272bb3b98e5f3035
2
+ SHA1:
3
+ metadata.gz: eddec9fdab7e0144f2446ddedb5df78ad1f4049a
4
+ data.tar.gz: e6304e8648c4cb41105449693cddff812e69e8dc
5
5
  SHA512:
6
- metadata.gz: ef9071b39de92e0e3f15dc2a8a5e7905791bf712f212250659c016247ec368e37632f1c937271170a9b6350ac64b761eb265508609cfcda7b0cc171b68412e49
7
- data.tar.gz: b8da11296b52c391238130813ecf99da235f0026e38d10c9f9e28d09daaff66b0ba4a471016b8b8d774808e91569f388991e4ee825e9a1e619a26658668dbf28
6
+ metadata.gz: 965bebf6e21317192d60fb643b6855c677a6545fbef0c2c7ebf0a41178d29afdf7b96ae5665df0815ac0490546ac2f359bdf8e5810a3cb8d8152add37c5569cc
7
+ data.tar.gz: 77fbfd170935a02610ecf319d2ab147115a80ff5a63a56b2ffe0c4f8cf6550dfa87b39b7e9a679a717eee66f88d32fab8dc579531de29e3e859e71a162473248
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitflyer-cli (0.4.4)
4
+ bitflyer-cli (0.5.0)
5
5
  bitflyer (~> 0.2.2)
6
6
  colorize (~> 0.8.1)
7
7
  thor (~> 0.20.0)
@@ -51,4 +51,4 @@ DEPENDENCIES
51
51
  rspec
52
52
 
53
53
  BUNDLED WITH
54
- 1.17.2
54
+ 1.17.3
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
  [![Gem Version](https://badge.fury.io/rb/bitflyer-cli.svg)](https://badge.fury.io/rb/bitflyer-cli)
3
3
  [![Circle CI](https://circleci.com/gh/unhappychoice/bitflyer-cli.svg?style=shield)](https://circleci.com/gh/unhappychoice/bitflyer-cli)
4
4
  [![Code Climate](https://codeclimate.com/github/unhappychoice/bitflyer-cli/badges/gpa.svg)](https://codeclimate.com/github/unhappychoice/bitflyer-cli)
5
- [![Dependency Status](https://gemnasium.com/badges/github.com/unhappychoice/bitflyer-cli.svg)](https://gemnasium.com/github.com/unhappychoice/bitflyer-cli)
6
5
  ![](http://ruby-gem-downloads-badge.herokuapp.com/bitflyer-cli?type=total)
7
6
 
8
7
  bitflyer-cli is a CLI tool for [Bitflyer](https://bitflyer.jp/) FXBTC.
@@ -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.4.4'
7
+ spec.version = '0.5.0'
8
8
  spec.authors = ['Yuji Ueki']
9
9
  spec.email = ['unhappychoice@gmail.com']
10
10
 
@@ -1,6 +1,7 @@
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/ifdoco_by_range_command'
4
5
  require 'bitflyer/cli/command/order_by_best_command'
5
6
  require 'bitflyer/cli/command/order_by_twap_command'
6
7
  require 'bitflyer/cli/command/stop_by_range_command'
@@ -40,6 +41,15 @@ module Bitflyer
40
41
  StopByRangeCommand.new.run(options)
41
42
  end
42
43
 
44
+ desc 'ifdoco_by_range', 'create IFDOCO order by range based on current price'
45
+ method_option :amount, aliases: 'a', type: :numeric, banner: 'amount', required: true
46
+ method_option :type, aliases: 't', type: :string, banner: 'buy/sell', required: true
47
+ method_option :range, aliases: 'r', type: :numeric, banner: 'price range', required: true
48
+ method_option :percentage, aliases: 'p', type: :numeric, banner: 'price ratio percentage', required: true
49
+ def ifdoco_by_range
50
+ IFDOCOByRangeCommand.new.run(options)
51
+ end
52
+
43
53
  desc 'summary', 'show current balance information'
44
54
  def summary
45
55
  SummaryCommand.new.run
@@ -0,0 +1,78 @@
1
+ require 'bitflyer/cli/has_http_client'
2
+ require 'bitflyer/cli/model/position'
3
+
4
+ class IFDOCOByRangeCommand
5
+ include HasHTTPClient
6
+
7
+ def run(options)
8
+ side = options.type.upcase
9
+ size = options.amount.abs
10
+ ratio = options.percentage.to_f
11
+ range = options.range.to_f
12
+
13
+ current_price = http_public_client.ticker('FX_BTC_JPY')['ltp'].to_i
14
+ profit_price = profit_line(side: side, current_price: current_price, range: range, ratio: ratio).to_i
15
+ loss_price = loss_line(side: side, current_price: current_price, range: range, ratio: ratio).to_i
16
+ request = request(side: side, size: size, profit_price: profit_price, loss_price: loss_price)
17
+ response = http_private_client.send_parent_order(request)
18
+
19
+ if response['parent_order_acceptance_id'].nil?
20
+ puts 'An error has occurred' + response.to_s
21
+ else
22
+ puts "Send market order #{side} / #{size.to_f}"
23
+ puts "Set limit order #{side} / #{profit_price} / #{size.to_f}"
24
+ puts "Set stop order #{side} / #{loss_price} / #{size.to_f}"
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def request(side:, size:, profit_price:, loss_price:)
31
+ {
32
+ order_method: 'IFDOCO',
33
+ time_in_force: 'GTC',
34
+ parameters: [
35
+ {
36
+ product_code: 'FX_BTC_JPY',
37
+ condition_type: 'MARKET',
38
+ side: side,
39
+ size: size
40
+ },
41
+ {
42
+ product_code: 'FX_BTC_JPY',
43
+ condition_type: 'LIMIT',
44
+ side: side == 'BUY' ? 'SELL' : 'BUY',
45
+ price: profit_price,
46
+ size: size
47
+ },
48
+ {
49
+ product_code: 'FX_BTC_JPY',
50
+ condition_type: 'STOP',
51
+ side: side == 'BUY' ? 'SELL' : 'BUY',
52
+ trigger_price: loss_price,
53
+ size: size
54
+ }
55
+ ]
56
+ }
57
+ end
58
+
59
+ def profit_line(side:, current_price:, range:, ratio:)
60
+ if side == 'BUY'
61
+ current_price + range * ratio / 100.0
62
+ elsif side == 'SELL'
63
+ current_price - range * ratio / 100.0
64
+ else
65
+ 0
66
+ end
67
+ end
68
+
69
+ def loss_line(side:, current_price:, range:, ratio:)
70
+ if side == 'BUY'
71
+ current_price - range * (100.0 - ratio) / 100.0
72
+ elsif side == 'SELL'
73
+ current_price + range * (100.0 - ratio) / 100.0
74
+ else
75
+ 0
76
+ end
77
+ end
78
+ 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.4.4
4
+ version: 0.5.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: 2019-01-06 00:00:00.000000000 Z
11
+ date: 2019-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -114,6 +114,7 @@ files:
114
114
  - lib/bitflyer/cli/authorization.rb
115
115
  - lib/bitflyer/cli/command/cancel_all_command.rb
116
116
  - lib/bitflyer/cli/command/counter_trade_command.rb
117
+ - lib/bitflyer/cli/command/ifdoco_by_range_command.rb
117
118
  - lib/bitflyer/cli/command/order_by_best_command.rb
118
119
  - lib/bitflyer/cli/command/order_by_twap_command.rb
119
120
  - lib/bitflyer/cli/command/stop_by_range_command.rb
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  requirements: []
144
145
  rubyforge_project:
145
- rubygems_version: 2.7.6
146
+ rubygems_version: 2.6.14
146
147
  signing_key:
147
148
  specification_version: 4
148
149
  summary: CLI tool for Bitflyer