bitcoin-api 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4138866fa90d5f4a791fda516c039d7148aed11b8ca5e6b800441ef0ede77d8
4
+ data.tar.gz: 6a9ad7dd7466b50f7aa890dca8340435a5ef3de810ecde3c330d1fcfb70e88e2
5
+ SHA512:
6
+ metadata.gz: bd93d51ff6109ce4db2d37345fb99902f0e41398c594f3e8214e61c820c5fd6185fd7642fbd1a25a1b3759b9087a2f59b809cfb4c7df59e34568a5c10d3d1f87
7
+ data.tar.gz: 24070de40a8615deba84721c969ab0f749b1c09f61cd1a4d74c57883503cd7c51d8f5aa4a3c630aabf08b05e4db704c7ce1791080eea8de282bcf62abe71c259
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nichol88@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bitcoin.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rest-client"
9
+ gem "json"
10
+ gem 'pry'
11
+ gem 'http'
12
+ #gem 'time'
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitcoin-api (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ domain_name (0.5.20190701)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ ffi (1.11.3)
16
+ ffi-compiler (1.0.1)
17
+ ffi (>= 1.0.0)
18
+ rake
19
+ gchart (1.0.0)
20
+ http (4.3.0)
21
+ addressable (~> 2.3)
22
+ http-cookie (~> 1.0)
23
+ http-form_data (~> 2.2)
24
+ http-parser (~> 1.2.0)
25
+ http-accept (1.7.0)
26
+ http-cookie (1.0.3)
27
+ domain_name (~> 0.5)
28
+ http-form_data (2.2.0)
29
+ http-parser (1.2.1)
30
+ ffi-compiler (>= 1.0, < 2.0)
31
+ json (2.3.0)
32
+ method_source (0.9.2)
33
+ mime-types (3.3.1)
34
+ mime-types-data (~> 3.2015)
35
+ mime-types-data (3.2019.1009)
36
+ netrc (0.11.0)
37
+ pry (0.12.2)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ public_suffix (4.0.3)
41
+ rake (12.3.3)
42
+ rest-client (2.1.0)
43
+ http-accept (>= 1.7.0, < 2.0)
44
+ http-cookie (>= 1.0.2, < 2.0)
45
+ mime-types (>= 1.16, < 4.0)
46
+ netrc (~> 0.8)
47
+ rspec (3.9.0)
48
+ rspec-core (~> 3.9.0)
49
+ rspec-expectations (~> 3.9.0)
50
+ rspec-mocks (~> 3.9.0)
51
+ rspec-core (3.9.1)
52
+ rspec-support (~> 3.9.1)
53
+ rspec-expectations (3.9.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.9.0)
56
+ rspec-mocks (3.9.1)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.9.0)
59
+ rspec-support (3.9.2)
60
+ unf (0.1.4)
61
+ unf_ext
62
+ unf_ext (0.0.7.6)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bitcoin-api!
69
+ gchart
70
+ http
71
+ json
72
+ pry
73
+ rake (~> 12.0)
74
+ rest-client
75
+ rspec (~> 3.0)
76
+
77
+ BUNDLED WITH
78
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Brian Nicholls
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.
@@ -0,0 +1,48 @@
1
+ # Bitcoin
2
+
3
+ This is a CLI using the bitcoin.com exchange API to view market data and provide limited analysis.
4
+
5
+ CLI Demo video: https://youtu.be/z5k0Hnl88eA
6
+
7
+ Planned features:
8
+ - More advanced analytical functions
9
+ - Support for trading
10
+ - Support for multiple exchanges
11
+ - Algotrading, arbitrage
12
+ - UI
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'bitcoin'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle install
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem "bitcoin_api", :git => "git://github.com/nichol88/bitcoin_api.git"
29
+
30
+ ## Usage
31
+
32
+ Run `bin/console` to play around, or `bin/bitcoin` to start the CLI.
33
+
34
+
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nichol88/bitcoin_api.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './lib/bitcoin'
4
+
5
+ Bitcoin::CLI.new
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bitcoin"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ require_relative 'lib/bitcoin/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "bitcoin-api"
5
+ spec.version = Bitcoin::VERSION
6
+ spec.authors = ["Brian Nicholls"]
7
+ spec.email = ["nichol88@gmail.com"]
8
+
9
+ spec.summary = %q{bitcoin.com API interface}
10
+ spec.homepage = "https://github.com/nichol88/bitcoin_api"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,49 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'pry'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'time'
7
+
8
+
9
+ #require_relative "./bitcoin/version"
10
+ require_relative "./bitcoin/version.rb"
11
+ require_relative "./bitcoin/display.rb"
12
+ require_relative "./bitcoin/cli.rb"
13
+ require_relative "./bitcoin/currency.rb"
14
+ require_relative "./bitcoin/order_book.rb"
15
+ require_relative "./bitcoin/trade.rb"
16
+ require_relative "./bitcoin/ssymbol.rb"
17
+ require_relative "./bitcoin/candle.rb"
18
+ require_relative "./bitcoin/ticker.rb"
19
+ require_relative "./bitcoin/analyzer.rb"
20
+
21
+
22
+ module Bitcoin
23
+
24
+ class Error < StandardError; end
25
+ # Your code goes here...
26
+ BASE = "https://api.exchange.bitcoin.com/api/2"
27
+ def self.get_datetime
28
+ puts "Enter Date (YYYY MM DD)"
29
+ d = gets.strip
30
+ puts "Enter Time (24-hour format) (hh mm ss)"
31
+ t = gets.strip
32
+ d = d.split(" ")
33
+ t = t.split(" ")
34
+ r = "#{d[0]}-#{d[1]}-#{d[2]}T#{t[0]}:#{t[1]}:#{t[2]}Z"
35
+ puts "Is this correct? #{d[0]}/#{d[1]}/#{d[2]}"
36
+ puts "Y / N"
37
+ gets.strip.upcase == 'Y' ? r : self.get_datetime
38
+ end
39
+
40
+ # returns 2-element array with datetimes in ISO format
41
+ def self.get_datetimes_from_user
42
+ puts "*** Enter Start Time *** (2014 or later)"
43
+ from = Bitcoin.get_datetime
44
+ puts "*** Enter End Time *** (2014 or later)"
45
+ to = Bitcoin.get_datetime
46
+ return [from, to]
47
+ end
48
+
49
+ end
@@ -0,0 +1,28 @@
1
+ class Bitcoin::Analyzer
2
+
3
+ def self.get_max(object_array, attribute = :price)
4
+ object_array.max_by{ |e|
5
+ e.send("#{attribute}")
6
+ }
7
+ end
8
+
9
+ def self.get_min(object_array, attribute = :price)
10
+ object_array.min_by{ |e|
11
+ e.send("#{attribute}")
12
+ }
13
+ end
14
+
15
+ def self.analyze_trades(symbol)
16
+ trades = Bitcoin::Trade.get_trades_in_range(symbol.id)
17
+ puts ""
18
+ puts " ///// [Analysis Results] /////"
19
+ puts "|"
20
+ puts "| Trade with highest price:"
21
+ puts "| #{self.get_max(trades).display_details}"
22
+ puts "| Trade with lowest price:"
23
+ puts "| #{self.get_min(trades).display_details}"
24
+ puts "| Largest trade:"
25
+ puts "| #{self.get_max(trades, :quantity).display_details}"
26
+ end
27
+
28
+ end
@@ -0,0 +1,35 @@
1
+ class Bitcoin::Candle
2
+
3
+ attr_accessor :timestamp, :open, :close, :min, :max, :volume, :volumeQuote
4
+
5
+ def self.all(symbol)
6
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/candles/#{symbol}?limit=1000"))
7
+ data.map{ |candle|
8
+ Bitcoin::Candle.new_from_object(candle)
9
+ }
10
+ end
11
+
12
+ def self.new_from_object(object)
13
+ c = Bitcoin::Candle.new
14
+ c.timestamp = Time.parse(object['timestamp'])
15
+ c.open = object['open']
16
+ c.close = object['close']
17
+ c.min = object['min']
18
+ c.max = object['max']
19
+ c.volume = object['volume']
20
+ c.volumeQuote = object['volumeQuote']
21
+ c
22
+ end
23
+
24
+ def display_details
25
+ puts <<-DOC
26
+ #{@timestamp}
27
+ Open: #{@open} || Close: #{@close}
28
+ Min: #{@min} || Max: #{@max}
29
+ Volume: #{@volume} || Volume Quote: #{@volumeQuote}
30
+
31
+ DOC
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,265 @@
1
+ class Bitcoin::CLI
2
+
3
+ def initialize
4
+ puts "Welcome!"
5
+ menu
6
+ end
7
+
8
+ def main_menu_display
9
+ puts ""
10
+ puts "Type 'exit' to quit"
11
+ puts ""
12
+ puts "***** [MAIN MENU] *****"
13
+ puts "* What would you like to do?"
14
+ puts "* [1] Select Symbol"
15
+ puts "* [2] View Currency Information"
16
+ puts "* [3] View Tickers"
17
+ # puts "[4] User Dashboard (Auth Needed)"
18
+ puts " "
19
+ end
20
+
21
+ def menu
22
+ # Display options
23
+ main_menu_display
24
+
25
+ input = gets.strip
26
+ symbol_menu if input == '1'
27
+ currency_menu if input == '2'
28
+ ticker_menu if input == '3'
29
+ user_menu if input == '4'
30
+ exit if input == 'exit'
31
+
32
+ puts "Invalid command. Try again."
33
+ menu
34
+
35
+ end
36
+
37
+ def iti(input)
38
+ input.to_i - 1 # input to index
39
+ end
40
+
41
+ # input: array to choose from
42
+ # output: object if choice is valid; -1 if '0', -2 if no choice (only return key is pressed)
43
+ def choose(array)
44
+ puts "Make a selection, or press return to show list"
45
+ choice = gets
46
+ if choice.strip == '0'
47
+ return -2
48
+ elsif choice == "\n" || choice.strip == ""
49
+ return -1
50
+ elsif choice.strip == '00'
51
+ return -3
52
+ elsif choice.strip != '0' && choice.to_i <= array.length
53
+ return array[iti(choice)]
54
+ else
55
+ puts "Invalid selection. Try again"
56
+ choose(array)
57
+ end
58
+ end
59
+
60
+ ### TODO: USER SUBMENU ###
61
+ def user_menu
62
+ puts "Nothing here yet!"
63
+ end
64
+
65
+ ### SYMBOL SUBMENUS ###
66
+ def symbol_menu(symbol = nil)
67
+
68
+ # display list & get symbol if it hasn't been selected yet
69
+ if !symbol
70
+ list = Bitcoin::Display.list_by_id(Bitcoin::Ssymbol.all)
71
+ selection = choose(list) #
72
+ menu if selection == -2
73
+ symbol_menu if selection == -1
74
+ symbol = selection
75
+ end
76
+
77
+ # display menu options for a symbol
78
+ symbol_menu_display(symbol)
79
+
80
+ # route choice to appropriate submenu
81
+ input = gets.strip
82
+ menu if input == '0'
83
+ trade_menu(symbol) if input == '1'
84
+ order_book_menu(symbol) if input == '2'
85
+ candles_menu(symbol) if input == '3'
86
+ analysis_menu(symbol) if input == '4'
87
+ exit if input == 'exit'
88
+ puts 'nope'
89
+ symbol_menu(symbol) # menu loop after action
90
+
91
+ end
92
+
93
+ def symbol_menu_display(symbol)
94
+ puts symbol.display_details
95
+ puts ""
96
+ puts "Type 'exit' to quit"
97
+ puts ""
98
+ puts "***** [Symbol Menu] #{symbol.id} *****"
99
+ puts "* [0] Main Menu"
100
+ puts "* [1] View Trades for #{symbol.id}"
101
+ puts "* [2] View Order Book for #{symbol.id}"
102
+ puts "* [3] View Candles for #{symbol.id}"
103
+ puts "* [4] Analysis Mode"
104
+ end
105
+
106
+ def trade_menu(symbol, trades_array = nil)
107
+ if !trades_array
108
+ # list all trades for symbol if first time
109
+ trades = Bitcoin::Trade.all(symbol.id)
110
+ Bitcoin::Display.list_trades(trades)
111
+ end
112
+
113
+ trade_menu_display
114
+
115
+ # User may either: select a trade to view, return to Main Menu, Symbol Menu,
116
+ # or loop method to show list again
117
+ selection = choose(trades)
118
+ trade_menu(symbol) if selection == -1
119
+ menu if selection == -2
120
+ symbol_menu(symbol) if selection == -3
121
+
122
+ selection.display_details
123
+ # Loop method without re-listing if action performed sucessfully
124
+ trade_menu(symbol, trades)
125
+ end
126
+
127
+ def trade_menu_display
128
+ puts ""
129
+ puts " Type 'exit' to quit"
130
+ puts ""
131
+ puts "***** [Trades Menu] *****"
132
+ puts "* [0] Main Menu"
133
+ puts "* [00] Symbol Menu"
134
+ puts "* [#] Select Entry to View Details"
135
+ puts ""
136
+ end
137
+
138
+ def order_book_menu(symbol, orders = nil)
139
+ if !orders
140
+ orders = Bitcoin::OrderBook.all(symbol.id)
141
+ Bitcoin::Display.list_order_book(orders)
142
+ end
143
+
144
+ order_book_menu_display
145
+
146
+ selection = choose(orders)
147
+ order_book_menu(symbol) if selection == -1
148
+ menu if selection == -2
149
+ symbol_menu(symbol) if selection == -3
150
+
151
+ selection.display_details
152
+
153
+ order_book_menu(symbol, orders)
154
+ end
155
+
156
+ def order_book_menu_display
157
+ puts ""
158
+ puts " Type 'exit' to quit"
159
+ puts ""
160
+ puts "***** [Order Book Menu] *****"
161
+ puts "* [0] Main Menu"
162
+ puts "* [00] Symbol Menu"
163
+ puts "* [#] Select Entry to View Details"
164
+ puts ""
165
+ end
166
+
167
+ def candles_menu(symbol, candles = nil)
168
+ if !candles
169
+ candles = Bitcoin::Candle.all(symbol.id)
170
+ Bitcoin::Display.list_candles(candles)
171
+ end
172
+
173
+ candles_menu_display
174
+
175
+ selection = choose(candles)
176
+ candles_menu(symbol) if selection == -1
177
+ menu if selection == -2
178
+ symbol_menu(symbol) if selection == -3
179
+
180
+ selection.display_details
181
+ end
182
+
183
+ def candles_menu_display
184
+ puts ""
185
+ puts " Type 'exit' to quit"
186
+ puts ""
187
+ puts "***** [Candles Menu] *****"
188
+ puts "* [0] Main Menu"
189
+ puts "* [00] Symbol Menu"
190
+ puts "* [#] Select Entry to View Details"
191
+ puts ""
192
+ end
193
+
194
+ ### CURRENCY SUBMENU ###
195
+ def currency_menu(list = nil)
196
+ if !list
197
+ list = Bitcoin::Display.list_by_id(Bitcoin::Currency.all)
198
+ end
199
+ currency_menu_display
200
+ selection = choose(list)
201
+ currency_menu if selection == -1
202
+ menu if selection == -2
203
+
204
+ selection.display_details
205
+ currency_menu(list)
206
+ end
207
+
208
+ def currency_menu_display
209
+ puts ""
210
+ puts " Type 'exit' to quit"
211
+ puts ""
212
+ puts "***** [Currency Menu] *****"
213
+ puts "* [0] Main Menu"
214
+ puts "* [#] Select Entry to View Details"
215
+ puts ""
216
+ end
217
+
218
+ ### TICKER SUBMENU ###
219
+ def ticker_menu(list = nil)
220
+ if !list
221
+ list = Bitcoin::Display.list_tickers(Bitcoin::Ticker.all)
222
+ end
223
+
224
+ ticker_menu_display
225
+
226
+ selection = choose(list)
227
+ ticker_menu if selection == -1
228
+ menu if selection == -2
229
+
230
+ selection.display_details
231
+ ticker_menu(list)
232
+ end
233
+
234
+ def ticker_menu_display
235
+ puts ""
236
+ puts " Type 'exit' to quit"
237
+ puts ""
238
+ puts "***** [Ticker Menu] *****"
239
+ puts "* [0] Main Menu"
240
+ puts "* [#] Select Entry to View Details"
241
+ puts ""
242
+ end
243
+
244
+ ### ANALYSIS SUBMENU ###
245
+ def analysis_menu(symbol)
246
+
247
+ analysis_menu_display(symbol)
248
+
249
+ input = gets.strip
250
+ menu if input == '0'
251
+ Bitcoin::Analyzer.analyze_trades symbol if input == '1'
252
+ analysis_menu(symbol)
253
+ end
254
+
255
+ def analysis_menu_display(symbol)
256
+ puts ""
257
+ puts " Type 'exit' to quit"
258
+ puts ""
259
+ puts "///// [Analysis Mode - #{symbol.id}] /////"
260
+ puts "/ [0] Main Menu"
261
+ puts "/ [1] Analyze Trades Within Range..."
262
+ puts ""
263
+ end
264
+
265
+ end
@@ -0,0 +1,39 @@
1
+ class Bitcoin::Currency
2
+
3
+ attr_accessor :id, :fullName, :crypto, :payinEnabled, :payinPaymentId,
4
+ :payinConfirmations, :payoutEnabled, :payoutIsPaymentId, :transferEnabled,
5
+ :delisted, :payoutFee
6
+
7
+ def self.all
8
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/currency"))
9
+ data.map{ |currency|
10
+ Bitcoin::Currency.new_from_object(currency)
11
+ }
12
+ end
13
+
14
+ def self.new_from_currency_name(name)
15
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/currency/#{name}"))
16
+ Bitcoin::Currency.new_from_object(data)
17
+ end
18
+
19
+ def self.new_from_object(data)
20
+ c = Bitcoin::Currency.new
21
+ c.id = data['id']
22
+ c.fullName = data['fullName']
23
+ c.crypto = data['crypto']
24
+ c.payoutFee = data['payoutFee']
25
+ c.payoutFee = c.payoutFee.to_f / 100 if c.id == 'USD'
26
+ c
27
+ end
28
+
29
+ def display_details
30
+ puts <<-DOC
31
+ #{@id} (#{@fullName})
32
+ Cryptocurrency?: #{@crypto.to_s}
33
+ Delisted?: #{@delisted.to_s}
34
+ Pay-Out Fee: #{@payoutFee} #{@id}
35
+
36
+ DOC
37
+ end
38
+
39
+ end
@@ -0,0 +1,49 @@
1
+ class Bitcoin::Display
2
+
3
+ def self.list(array)
4
+ numerize(array)
5
+ end
6
+
7
+ def self.list_by_symbol(array)
8
+ numerize(array, :symbol)
9
+ end
10
+
11
+ def self.list_by_id(array)
12
+ numerize(array, :id)
13
+ end
14
+
15
+ def self.list_trades(trades)
16
+ trades.each_with_index{ |trade, i|
17
+ puts "#{(i+1).to_s.rjust(4)}. #{trade.timestamp.strftime("%Y-%m-%d %H:%M:%S")} #{trade.side.rjust(4)} #{trade.price}"
18
+ }
19
+ end
20
+
21
+ def self.list_order_book(orderbook)
22
+ orderbook.each_with_index{ |order, i|
23
+ puts "#{(i+1).to_s.rjust(4)}. #{order.timestamp.strftime("%Y-%m-%d %H:%M:%S")}: #{order.side.upcase} - Order Size: #{order.size.to_s.rjust(12)}, Price: #{order.price.to_s.rjust(12)}"
24
+ }
25
+ end
26
+
27
+ def self.list_candles(candles)
28
+ candles.each_with_index{ |candle, i|
29
+ puts "#{(i+1).to_s.rjust(4)}. #{candle.timestamp} [#{candle.open.rjust(11)} -> #{candle.close.rjust(11)}] [#{candle.min.rjust(11)} - #{candle.max.rjust(11)}] vol: #{candle.volume.rjust(11)}"
30
+ }
31
+ end
32
+
33
+ def self.list_tickers(tickers)
34
+ tickers.each_with_index{ |ticker, i|
35
+ puts "#{(i+1).to_s.rjust(4)}. #{ticker.symbol}"
36
+ }
37
+ end
38
+
39
+ private
40
+ # input array of hashes, and desired displayed attribute (string key)
41
+ def self.numerize(array, attribute = nil)
42
+ if attribute
43
+ array.each_with_index{ |e, i| puts "#{i+1}. #{e.send("#{attribute}")}"}
44
+ else
45
+ array.each_with_index{ |e, i| puts "#{i+1}. #{e}"}
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,46 @@
1
+ class Bitcoin::OrderBook
2
+
3
+ attr_accessor :side, :price, :size, :timestamp, :limit, :symbol
4
+
5
+ def self.new_from_object(object)
6
+ o = Bitcoin::OrderBook.new
7
+ o.size = object['size'].to_f
8
+ o.side = object[:side]
9
+ o.price = object['price'].to_f
10
+ o.timestamp = Time.parse(object['timestamp'])
11
+ o.limit = object['limit']
12
+ o.symbol = object[:symbol]
13
+ o
14
+ end
15
+
16
+ def self.all(symbol_name)
17
+ data = JSON.parse RestClient.get "#{Bitcoin::BASE}/public/orderbook/#{symbol_name}?limit=0"
18
+ ask_orders = data['ask']
19
+ bid_orders = data['bid']
20
+
21
+ ask_orders.each{ |order|
22
+ order[:side] = 'ask'
23
+ order['timestamp'] = data['timestamp']
24
+ order[:symbol] = symbol_name
25
+ }
26
+ bid_orders.each{ |order|
27
+ order[:side] = 'bid'
28
+ order['timestamp'] = data['timestamp']
29
+ order[:symbol] = symbol_name
30
+ }
31
+
32
+ [ask_orders, bid_orders].flatten!.map{|order|
33
+ Bitcoin::OrderBook.new_from_object(order)
34
+ }
35
+ end
36
+
37
+ def display_details
38
+ puts <<-DOC
39
+ #{@symbol} #{@side.upcase} Order:
40
+ #{@price}
41
+ Quantity: #{@size}
42
+ #{@timestamp}
43
+
44
+ DOC
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ class Bitcoin::Ssymbol
2
+
3
+ attr_accessor :id, :baseCurrency, :quoteCurrency, :quantityIncrement, :tickSize,
4
+ :takeLiquidityRate, :provideLiquidityRate, :feeCurrency
5
+
6
+ def self.all
7
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/symbol"))
8
+ data.map{ |ssymbol|
9
+ Bitcoin::Ssymbol.new_from_object(ssymbol)
10
+ }
11
+ end
12
+
13
+ def self.new_from_object(data)
14
+ s = Bitcoin::Ssymbol.new
15
+ s.id = data['id']
16
+ s.baseCurrency = data['baseCurrency']
17
+ s.quoteCurrency = data['quoteCurrency']
18
+ s.quantityIncrement = data['quantityIncrement']
19
+ s.tickSize = data['tickSize']
20
+ s.takeLiquidityRate = data['takeLiquidityRate']
21
+ s.provideLiquidityRate = data['provideLiquidityRate']
22
+ s.feeCurrency = data['feeCurrency']
23
+ s
24
+ end
25
+
26
+ def self.new_from_symbol_name(symbol_name)
27
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/symbol/#{symbol_name}"))
28
+ Bitcoin::Ssymbol.new_from_object(data)
29
+ end
30
+
31
+ def display_details
32
+ puts <<-DOC
33
+ ID: #{@id}
34
+ Base Currency: #{@baseCurrency} || Quote Currency: #{@quoteCurrency}
35
+ Quantity Increment: #{@quantityIncrement} || Tick Size: #{@tickSize}
36
+ Take Liquidity Rate: #{@takeLiquidityRate} || Provide Liquidity Rate: #{@provideLiquidityRate}
37
+ Fee Currency: #{@feeCurrency}
38
+
39
+ DOC
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,45 @@
1
+ class Bitcoin::Ticker
2
+
3
+ attr_accessor :ask, :bid, :last, :open, :low, :high, :volume, :volumeQuote,
4
+ :timestamp, :symbol
5
+
6
+ def self.new_from_symbol_name(symbol)
7
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker/#{symbol}"))
8
+ Bitcoin::Ticker.new_from_object(data)
9
+ end
10
+
11
+ def self.new_from_object(data)
12
+ t = Bitcoin::Ticker.new
13
+ t.ask = data['ask'].to_f
14
+ t.bid = data['bid'].to_f
15
+ t.last = data['last'].to_f
16
+ t.open = data['open'].to_f
17
+ t.low = data['low'].to_f
18
+ t.high = data['high'].to_f
19
+ t.volume = data['volume'].to_f
20
+ t.volumeQuote = data['volumeQuote'].to_f
21
+ t.timestamp = Time.parse(data['timestamp'])
22
+ t.symbol = data['symbol']
23
+ t
24
+ end
25
+
26
+ def self.all
27
+ data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker"))
28
+ data.map{ |ticker|
29
+ Bitcoin::Ticker.new_from_object(ticker)
30
+ }
31
+ end
32
+
33
+ def display_details
34
+ puts <<-DOC
35
+ #{@symbol}
36
+ Best Ask : #{@ask.to_s.rjust(9)} || Best Bid: #{@bid}
37
+ Last Trade Price: #{@last}
38
+ Open: #{@open}
39
+ 24-Hour Low: #{@low.to_s.rjust(9)} || 24-Hour High: #{@high}
40
+ Total 24-Hour Volume (Base): #{@volume} (Quote): #{@volumeQuote}
41
+ #{@timestamp}
42
+
43
+ DOC
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ class Bitcoin::Trade
2
+
3
+ attr_accessor :id, :price, :quantity, :side, :timestamp, :symbol
4
+
5
+ def display_details
6
+ puts <<-DOC
7
+ | #{@symbol}
8
+ | ID: #{@id} : #{@side.upcase} : #{@price}
9
+ | Quantity: #{@quantity}
10
+ | #{@timestamp}
11
+ |_____________________
12
+ DOC
13
+ end
14
+
15
+ def self.new_from_object(symbol_name, data)
16
+ t = Bitcoin::Trade.new
17
+ t.id = data['id']
18
+ t.price = data['price'].to_f
19
+ t.quantity = data['quantity'].to_f
20
+ t.side = data['side']
21
+ t.timestamp = Time.parse(data['timestamp'])
22
+ t.symbol = symbol_name
23
+ t
24
+ end
25
+
26
+ def self.all(symbol_name)
27
+ data = JSON.parse RestClient.get("#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000")
28
+ data.map{ |e|
29
+ Bitcoin::Trade.new_from_object(symbol_name, e)
30
+ }
31
+ end
32
+
33
+ def self.get_trades_in_range(symbol_name, timestamps = Bitcoin.get_datetimes_from_user)
34
+ data = JSON.parse RestClient.get "#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000&sort=DESC&from=#{timestamps[0]}&till=#{timestamps[1]}"
35
+ data.map{|e|
36
+ Bitcoin::Trade.new_from_object(symbol_name, e)
37
+ }
38
+ end
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ module Bitcoin
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitcoin-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Nicholls
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - nichol88@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/bitcoin
30
+ - bin/console
31
+ - bin/setup
32
+ - bitcoin.gemspec
33
+ - lib/bitcoin.rb
34
+ - lib/bitcoin/analyzer.rb
35
+ - lib/bitcoin/candle.rb
36
+ - lib/bitcoin/cli.rb
37
+ - lib/bitcoin/currency.rb
38
+ - lib/bitcoin/display.rb
39
+ - lib/bitcoin/order_book.rb
40
+ - lib/bitcoin/ssymbol.rb
41
+ - lib/bitcoin/ticker.rb
42
+ - lib/bitcoin/trade.rb
43
+ - lib/bitcoin/version.rb
44
+ homepage: https://github.com/nichol88/bitcoin_api
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.3.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.0.6
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: bitcoin.com API interface
67
+ test_files: []