stocks_exchange 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
+ SHA1:
3
+ metadata.gz: 61879aa757b655264b77b75b68f34af999c32bff
4
+ data.tar.gz: 70572931c4325f491417ae675b2327bfac06ca3c
5
+ SHA512:
6
+ metadata.gz: b68267d74d3eedd7d35c5033976ace2b3806a7738ae2fdc70fa6e96e4f64b5dce6d779c5ae513f0c3336ebb3659f1715c08cd9cc28959780a862f3a0138ab2df
7
+ data.tar.gz: 980e6993b0f9e25acc7d533827a542977188f8f1a3b45e6f764fc51e1782c7e5a7e96bc1c5a9574dd295f82eac3116a0ea5d8b5e72f84f4c7eb47a64c940e160
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in stocks_exchange.gemspec
6
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stocks_exchange (0.1.0)
5
+ httparty (~> 0.15.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.15.6)
11
+ multi_xml (>= 0.5.2)
12
+ multi_xml (0.6.0)
13
+ rake (10.5.0)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.16)
20
+ rake (~> 10.0)
21
+ stocks_exchange!
22
+
23
+ BUNDLED WITH
24
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 alabeco
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,94 @@
1
+ # StocksExchange
2
+
3
+ This gem consumes the public API of [stocks.exchange]('https://stocks.exchange') to give you a ruby friendly version.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'stocks_exchange'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install stocks_exchange
20
+
21
+ ## Usage
22
+
23
+ All [currencies](https://stocks.exchange/api2/currencies) are converted into modules with their respective symbols(in uppercase) as the names.
24
+ For example, for a currency, Intensecoin with the symbol ITNS you access it as:
25
+
26
+ ```ruby
27
+ StocksExchange::ITNS
28
+ ```
29
+ The corresponding keys are converted into methods that return their values
30
+ For example, to get the minimum withdrawal amount for Intensecoin above. You can use:
31
+ ```ruby
32
+ StocksExchange::ITNS.minimum_withdrawal_amount
33
+ #=> "<some_value>"
34
+ ```
35
+ since [stocks.exchange](https://stocks.exchange) provides `"minimum_withdrawal_amount":"<some_value>"` in their API.
36
+
37
+ All [markets](https://stocks.exchange/api2/markets) are converted into modules with their respective market names(as in the API, in uppercase) as the names.
38
+ For example, for a market, DERO/BTC, you can access it as:
39
+ ```ruby
40
+ StocksExchange::DERO_BTC
41
+ ```
42
+ The corresponding keys are converted into methods that return their values.
43
+ The values from the [ticker](https://stocks.exchange/api2/ticker) and [prices](https://stocks.exchange/api2/prices) are also added to their respective market names.
44
+ Examples:
45
+
46
+ ```ruby
47
+ #to get buy fee percentage
48
+ #sample from API: "buy_fee_percent":"0.2"
49
+ StocksExchange::DERO_BTC.buy_fee_percent
50
+ #=> "0.2"
51
+
52
+ #to get market volume from ticker url
53
+ #sample from API: "vol":"240114.98504904"
54
+ StocksExchange::DERO_BTC.vol
55
+ #=> "240114.98504904"
56
+
57
+ #to get buy price from prices url
58
+ #sample from API: "buy":"0.000142"
59
+ StocksExchange::DERO_BTC.buy
60
+ #=> "0.000142"
61
+ ```
62
+
63
+ ### Other Methods
64
+
65
+ It is important to keep updating the values since the initital values are the values grabbed during gem load time.
66
+ To do so, use:
67
+ ```ruby
68
+ StocksExchange.refresh
69
+ #=> true
70
+ ```
71
+ To check whether a market or currency exists use:
72
+
73
+ ```ruby
74
+ #StocksExchange.listed?(<coin_symbol or market_name>)
75
+ StocksExchange.listed?("ITNS_BTC")
76
+ #=> true
77
+ StocksExchange.listed?("dhjdcdhjcbhsjcb")
78
+ #=> false
79
+ ```
80
+
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it ( https://github.com/alabeco/stocks_exchange/fork )
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create a new Pull Request
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alabeco/stocks_exchange.
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stocks_exchange"
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,92 @@
1
+ require "stocks_exchange/version"
2
+ require "httparty"
3
+
4
+ $VERBOSE=nil #silence "warning: already initialized constant" appearing during refresh
5
+
6
+ module StocksExchange
7
+ include HTTParty
8
+ @base_uri="https://stocks.exchange/api2"
9
+
10
+ #updates the values of modules and functions
11
+ def self.refresh
12
+ begin
13
+ setup_currencies
14
+ setup_markets
15
+ return true
16
+ rescue => e
17
+ puts "StocksExchange failed to load required Modules and Methods. Error: #{e.message}"
18
+ return false
19
+ end
20
+ end
21
+
22
+ #checks whether a market or currency is present
23
+ def self.listed?(name)
24
+ StocksExchange.const_defined?("#{name}".upcase)
25
+ end
26
+
27
+ #gets all available currencies from https://stocks.exchange/api2/currencies and creates dynamic modules with dynamic methods as from the API
28
+ def self.setup_currencies
29
+ setup("/currencies")
30
+ end
31
+
32
+ #gets all available markets from https://stocks.exchange/api2/currencies and sets their respective modules and methods as #self.setup_currencies above
33
+ #the markets are then supplimentented with values from ticker and prices
34
+ def self.setup_markets
35
+ setup("/markets")
36
+ setup_ticker
37
+ setup_prices
38
+ end
39
+
40
+ #add methods from https://stocks.exchange/api2/ticker to respective markets(Modules) created in #self.setup_markets above
41
+ #if market does not exist for some reason, it is created
42
+ def self.setup_ticker
43
+ suppliment("/ticker")
44
+ end
45
+
46
+ #add methods from https://stocks.exchange/api2/prices to respective markets(Modules) created in #self.setup_markets above
47
+ #if market does not exist for some reason, it is created
48
+ def self.setup_prices
49
+ suppliment("/prices")
50
+ end
51
+
52
+ private
53
+
54
+ #setup_currencies
55
+ #setup_markets
56
+ def self.setup(path)
57
+ get("#@base_uri#{path}").parsed_response.each do |response|
58
+ case path
59
+ when "/currencies"
60
+ module_name = response['currency'].upcase
61
+ when "/markets"
62
+ module_name = "#{response['currency'].upcase}_#{response['partner']}"
63
+ else
64
+ return false
65
+ end
66
+ StocksExchange.const_set(module_name, Module.new{
67
+ response.map{|key,value| define_singleton_method(key){value}}
68
+ })
69
+ end
70
+
71
+ return true
72
+ end
73
+
74
+ #setup_ticker
75
+ #setup_prices
76
+ def self.suppliment(path)
77
+ get("#@base_uri#{path}").parsed_response.each do |response|
78
+ if StocksExchange.const_defined?(response['market_name'].upcase)
79
+ current_module=StocksExchange.const_get(response['market_name'].upcase)
80
+ response.map{|key,value| current_module.define_singleton_method(key){value}}
81
+ current_module=nil
82
+ else
83
+ StocksExchange.const_set(response['market_name'].upcase, Module.new(response.map{|key,value| define_singleton_method(key){value}}))
84
+ end
85
+ end
86
+ return true
87
+ end
88
+
89
+ #do the initital setup
90
+ refresh
91
+
92
+ end
@@ -0,0 +1,3 @@
1
+ module StocksExchange
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "stocks_exchange/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stocks_exchange"
8
+ spec.version = StocksExchange::VERSION
9
+ spec.authors = ["alabeco"]
10
+ spec.email = ["alabecocliquebuster@gmail.com"]
11
+
12
+ spec.summary = %q{Ease the use of stocks.exchange public api}
13
+ spec.description = %q{Easily consume the public API of https://stocks.exchange to give a ruby friendly version}
14
+ spec.homepage = "https://github.com/alabeco/stocks_exchange"
15
+ spec.license = "MIT"
16
+
17
+
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "httparty","~> 0.15.6"
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stocks_exchange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - alabeco
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Easily consume the public API of https://stocks.exchange to give a ruby
56
+ friendly version
57
+ email:
58
+ - alabecocliquebuster@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/stocks_exchange.rb
72
+ - lib/stocks_exchange/version.rb
73
+ - stocks_exchange.gemspec
74
+ homepage: https://github.com/alabeco/stocks_exchange
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.14
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Ease the use of stocks.exchange public api
98
+ test_files: []