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 +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +5 -2
- data/bitflyer-cli.gemspec +1 -1
- data/lib/bitflyer/cli/command/counter_trade_command.rb +34 -0
- data/lib/bitflyer/cli/command/order_by_best_command.rb +44 -0
- data/lib/bitflyer/cli/model/position.rb +1 -1
- data/lib/bitflyer/cli.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e17ec185d7cb7e8a3f6a790f7a049c25adc558b
|
4
|
+
data.tar.gz: 500794980ae1a86398b330a75ea3a2824fc302f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
12
|
+
bitflyer (0.1.2)
|
13
13
|
faraday (~> 0.12.2)
|
14
|
-
faraday_middleware (~> 0.
|
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.
|
65
|
+
faraday_middleware (0.12.2)
|
66
66
|
faraday (>= 0.7.4, < 1.0)
|
67
|
-
hitimes (1.2.
|
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
|
[](https://gemnasium.com/github.com/unhappychoice/bitflyer-cli)
|
6
6
|

|
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
|
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
@@ -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) }
|
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
|
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-
|
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
|