bitflyer-cli 0.4.4 → 0.5.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 +5 -5
- data/Gemfile.lock +2 -2
- data/README.md +0 -1
- data/bitflyer-cli.gemspec +1 -1
- data/lib/bitflyer/cli.rb +10 -0
- data/lib/bitflyer/cli/command/ifdoco_by_range_command.rb +78 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eddec9fdab7e0144f2446ddedb5df78ad1f4049a
|
4
|
+
data.tar.gz: e6304e8648c4cb41105449693cddff812e69e8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 965bebf6e21317192d60fb643b6855c677a6545fbef0c2c7ebf0a41178d29afdf7b96ae5665df0815ac0490546ac2f359bdf8e5810a3cb8d8152add37c5569cc
|
7
|
+
data.tar.gz: 77fbfd170935a02610ecf319d2ab147115a80ff5a63a56b2ffe0c4f8cf6550dfa87b39b7e9a679a717eee66f88d32fab8dc579531de29e3e859e71a162473248
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
[](https://badge.fury.io/rb/bitflyer-cli)
|
3
3
|
[](https://circleci.com/gh/unhappychoice/bitflyer-cli)
|
4
4
|
[](https://codeclimate.com/github/unhappychoice/bitflyer-cli)
|
5
|
-
[](https://gemnasium.com/github.com/unhappychoice/bitflyer-cli)
|
6
5
|

|
7
6
|
|
8
7
|
bitflyer-cli is a CLI tool for [Bitflyer](https://bitflyer.jp/) FXBTC.
|
data/bitflyer-cli.gemspec
CHANGED
data/lib/bitflyer/cli.rb
CHANGED
@@ -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
|
+
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-
|
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.
|
146
|
+
rubygems_version: 2.6.14
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: CLI tool for Bitflyer
|