bitflyer-cli 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4df0ff6bccf0ea0b19e193c932af9b953e95335f
4
+ data.tar.gz: 38cadbda3d6476c4d1029045611b93c3bb9b95b3
5
+ SHA512:
6
+ metadata.gz: 688c255e968749b406d9fe1f4fc928452cb2e271914cf75ed5f2c957565a9ae46c2f3b12652136214f1b4b3cee41fb14754b133ef6527951ef724d38bccccea4
7
+ data.tar.gz: f763a12d1ee4cd148e1940ae48a8e553c62aefdabe91b75a99fd165500900738ea66039b341ab12b783e336bea3ec68b0592b2eaf5f699a9f8600e521eed8e4b
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at unhappychoice@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bitflyer-cli.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,105 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitflyer-cli (0.0.1)
5
+ bitflyer (~> 0.1.0)
6
+ colorize (~> 0.8.1)
7
+ thor (~> 0.19.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ bitflyer (0.1.0)
13
+ faraday (~> 0.12.2)
14
+ faraday_middleware (~> 0.11.0.1)
15
+ pubnub (~> 4.0.22)
16
+ celluloid (0.17.3)
17
+ celluloid-essentials
18
+ celluloid-extras
19
+ celluloid-fsm
20
+ celluloid-pool
21
+ celluloid-supervision
22
+ timers (>= 4.1.1)
23
+ celluloid-essentials (0.20.5)
24
+ timers (>= 4.1.1)
25
+ celluloid-extras (0.20.5)
26
+ timers (>= 4.1.1)
27
+ celluloid-fsm (0.20.5)
28
+ timers (>= 4.1.1)
29
+ celluloid-pool (0.20.5)
30
+ timers (>= 4.1.1)
31
+ celluloid-supervision (0.20.6)
32
+ timers (>= 4.1.1)
33
+ colorize (0.8.1)
34
+ concurrent-ruby (1.0.5)
35
+ diff-lcs (1.3)
36
+ dry-configurable (0.7.0)
37
+ concurrent-ruby (~> 1.0)
38
+ dry-container (0.6.0)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-configurable (~> 0.1, >= 0.1.3)
41
+ dry-core (0.3.1)
42
+ concurrent-ruby (~> 1.0)
43
+ dry-equalizer (0.2.0)
44
+ dry-logic (0.4.1)
45
+ dry-container (~> 0.2, >= 0.2.6)
46
+ dry-core (~> 0.2)
47
+ dry-equalizer (~> 0.2)
48
+ dry-types (0.11.0)
49
+ concurrent-ruby (~> 1.0)
50
+ dry-configurable (~> 0.1)
51
+ dry-container (~> 0.3)
52
+ dry-core (~> 0.2, >= 0.2.1)
53
+ dry-equalizer (~> 0.2)
54
+ dry-logic (~> 0.4, >= 0.4.0)
55
+ inflecto (~> 0.0.0, >= 0.0.2)
56
+ dry-validation (0.11.0)
57
+ concurrent-ruby (~> 1.0)
58
+ dry-configurable (~> 0.1, >= 0.1.3)
59
+ dry-core (~> 0.2, >= 0.2.1)
60
+ dry-equalizer (~> 0.2)
61
+ dry-logic (~> 0.4, >= 0.4.0)
62
+ dry-types (~> 0.11.0)
63
+ faraday (0.12.2)
64
+ multipart-post (>= 1.2, < 3)
65
+ faraday_middleware (0.11.0.1)
66
+ faraday (>= 0.7.4, < 1.0)
67
+ hitimes (1.2.5)
68
+ httpclient (2.8.3)
69
+ inflecto (0.0.2)
70
+ json (2.1.0)
71
+ multipart-post (2.0.0)
72
+ pubnub (4.0.23)
73
+ celluloid (~> 0.17)
74
+ dry-validation (~> 0.10)
75
+ httpclient (~> 2.8, >= 2.8.3)
76
+ json (>= 1.8, < 3)
77
+ rake (10.5.0)
78
+ rspec (3.6.0)
79
+ rspec-core (~> 3.6.0)
80
+ rspec-expectations (~> 3.6.0)
81
+ rspec-mocks (~> 3.6.0)
82
+ rspec-core (3.6.0)
83
+ rspec-support (~> 3.6.0)
84
+ rspec-expectations (3.6.0)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.6.0)
87
+ rspec-mocks (3.6.0)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.6.0)
90
+ rspec-support (3.6.0)
91
+ thor (0.19.4)
92
+ timers (4.1.2)
93
+ hitimes
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ bitflyer-cli!
100
+ bundler (~> 1.12)
101
+ rake (~> 10.0)
102
+ rspec (~> 3.0)
103
+
104
+ BUNDLED WITH
105
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Yuji Ueki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # bitflyer-cli
2
+ [![Gem Version](https://badge.fury.io/rb/bitflyer-cli.svg)](https://badge.fury.io/rb/bitflyer-cli)
3
+ [![Circle CI](https://circleci.com/gh/unhappychoice/bitflyer-cli.svg?style=shield)](https://circleci.com/gh/unhappychoice/bitflyer-cli)
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
+ ![](http://ruby-gem-downloads-badge.herokuapp.com/bitflyer-cli?type=total)
7
+
8
+ bitflyer-cli is a CLI tool for [Bitflyer](https://bitflyer.jp/).
9
+
10
+ ## Installation
11
+
12
+ ```sh
13
+ gem install bitflyer-cli
14
+ ```
15
+
16
+ Set the `BITFLYER_API_TOKEN` and `BITFLYER_API_SECRET` environment variable.
17
+
18
+ ```sh
19
+ export BITFLYER_API_TOKEN=your-bitflyey-api-token
20
+ export BITFLYER_API_SECRET=your-bitflyey-api-secret
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ Commands:
27
+ bitflyer summary # show current balance information
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unhappychoice/bitflyer-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bitflyer-cli'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Yuji Ueki']
9
+ spec.email = ['unhappychoice@gmail.com']
10
+
11
+ spec.summary = 'CLI tool for Bitflyer'
12
+ spec.description = 'CLI tool for Bitflyer'
13
+ spec.homepage = 'https://github.com/unhappychoice/bitflyer-cli'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'thor', '~> 0.19.4'
22
+ spec.add_dependency 'bitflyer', '~> 0.1.0'
23
+ spec.add_dependency 'colorize', '~> 0.8.1'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ end
data/exe/bitflyer ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bitflyer/cli'
4
+
5
+ Bitflyer::CLI.start
@@ -0,0 +1,65 @@
1
+ require 'bitflyer'
2
+ require 'bitflyer/cli/ext/string'
3
+ require 'bitflyer/cli/model/position'
4
+
5
+ class SummaryCommand
6
+ BUFFER_SIZE = 30.freeze
7
+
8
+ def initialize
9
+ @current_price = 0.0
10
+ @http_clinet = Bitflyer.http_private_client(api_key, api_secret)
11
+ @realtime_client = Bitflyer.realtime_client
12
+
13
+ @realtime_client.executions_fx_btc_jpy = ->(message) {
14
+ message.each { |m| @current_price = m['price'].to_f }
15
+ }
16
+
17
+ update_balance
18
+ end
19
+
20
+ def run
21
+ $stdout.sync = true
22
+
23
+ Thread.new do
24
+ while true
25
+ update_balance
26
+ sleep 5
27
+ end
28
+ end
29
+
30
+ while true
31
+ print "\e[3F\e[0J"
32
+ print "Current: " + @current_price.to_i.to_s.split_by_comma
33
+ print "\nPosition: " + "#{@position.average} * #{@position.size}".to_s.split_by_comma
34
+ print "\nSpread: " + spread.to_s.split_by_comma.color_with_number(spread)
35
+ print "\nBalance: " + (@balance + profit).to_s.split_by_comma.ljust(15, ' ') + "(#{profit.to_s.split_by_comma.color_with_number(profit)})"
36
+ sleep 0.1
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def api_key
43
+ ENV['BITFLYER_API_KEY']
44
+ end
45
+
46
+ def api_secret
47
+ ENV['BITFLYER_API_SECRET']
48
+ end
49
+
50
+ def update_balance
51
+ @position = Position.new(@http_clinet.positions)
52
+ @balance = @http_clinet.collateral['collateral'].to_i
53
+ end
54
+
55
+ def profit
56
+ return 0 if @current_price == 0
57
+ @position.profit(@current_price).to_i
58
+ end
59
+
60
+ def spread
61
+ return 0 if @current_price == 0
62
+ return 0 if @position.average.to_i == 0
63
+ @current_price.to_i - @position.average.to_i
64
+ end
65
+ end
@@ -0,0 +1,12 @@
1
+ require 'colorize'
2
+
3
+ class String
4
+ def color_with_number(number)
5
+ sign = number >= 0.0 ? '+' : ''
6
+ sign + colorize(number >= 0.0 ? :green : :red)
7
+ end
8
+
9
+ def split_by_comma
10
+ reverse.gsub( /(\d{3})(?=\d)/, '\1,').reverse
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ class Position
2
+ def initialize(positions)
3
+ @positions = positions
4
+ end
5
+
6
+ def profit(current_price)
7
+ @positions.inject(0.0) do |sum, position|
8
+ sum + (current_price - position['price'].to_f) * position['size'].to_f * (position['side'] == 'BUY' ? 1.0 : -1.0)
9
+ end
10
+ end
11
+
12
+ def average
13
+ @positions.size > 0 ? (sum / size.abs).to_i : 0
14
+ end
15
+
16
+ def sum
17
+ @positions.inject(0.0) do |sum, position|
18
+ sum + position['price'].to_f * position['size'].to_f
19
+ end
20
+ end
21
+
22
+ def size
23
+ @positions.inject(0.0) { |sum, position| sum + position['size'].to_f * (position['side'] == 'BUY' ? 1.0 : -1.0) }.round(2)
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'thor'
2
+ require 'bitflyer/cli/command/summary_command'
3
+
4
+ module Bitflyer
5
+ class CLI < Thor
6
+ desc 'summary', 'show current balance information'
7
+ def summary
8
+ SummaryCommand.new.run
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitflyer-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Ueki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bitflyer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: CLI tool for Bitflyer
98
+ email:
99
+ - unhappychoice@gmail.com
100
+ executables:
101
+ - bitflyer
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bitflyer-cli.gemspec
112
+ - exe/bitflyer
113
+ - lib/bitflyer/cli.rb
114
+ - lib/bitflyer/cli/command/summary_command.rb
115
+ - lib/bitflyer/cli/ext/string.rb
116
+ - lib/bitflyer/cli/model/position.rb
117
+ homepage: https://github.com/unhappychoice/bitflyer-cli
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: CLI tool for Bitflyer
141
+ test_files: []