cryptowatch 0.0.2

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: 662c3dca7603c941b71ae52bac099dd5752a0de7
4
+ data.tar.gz: a15b07fe593328600fbc90d1769f49948a361d03
5
+ SHA512:
6
+ metadata.gz: b7310839cd7df577efecfa502496fe6b5e36a889a47b6a8402b2fac9bcac72844d53ac19c20f8c6afd903d87ee0c0190acfadbce48195b9b5445241bb3f3d439
7
+ data.tar.gz: 6626637832278b55a2b8cec147a63e29b1083d080a75561ac757e92d8e7c9f1df7ced8bf906f3f88a2b605c78757e50a1c27beeca877a282711de36566ac8db6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+
6
+ # gem "rails"
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Cryptowatch Library for Ruby
2
+
3
+ Developpement of *a simple interface in Ruby for Cryptowatch.*
4
+
5
+ To describe the use of the methods I used the phrases of the Cryptowat.ch documentation: API: https://cryptowat.ch/docs/
6
+
7
+ ## Get started
8
+
9
+ Install it yourself as:
10
+ ```
11
+ gem install 'cryptowatch'
12
+ ```
13
+ Require the gem into your project with:
14
+ ```
15
+ require 'cryptowatch'
16
+ ```
17
+ ## Requests list
18
+ Let's construct or first request with the gem:
19
+ ```ruby
20
+ cw = Cryptowatch::Wrapper.new({:timeout => 10}) #By default timeout = 5.
21
+
22
+ cw.assets #Returns all assets (in no particular order).
23
+ cw.assets(:btc) #Lists all markets which have this asset as a base or quote.
24
+
25
+ cw.pairs #Returns all pairs (in no particular order).
26
+ cw.pairs(:btcusd) #Returns a single pair. Lists all markets for this pair.
27
+
28
+ cw.exchanges #Returns a list of all supported exchanges.
29
+ cw.exchanges(:kraken) #Returns a single exchange, with associated routes.
30
+
31
+ cw.markets #Returns a list of all supported markets.
32
+ cw.markets(:kraken, :btcusd) #Returns a single market, with associated routes.
33
+
34
+ #In writing...
35
+ ```
@@ -0,0 +1,30 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Tuesday, October 31st 2017, 11:05:52 am
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Thursday, November 2nd 2017, 4:13:38 pm
7
+ # -*- encoding: utf-8 -*-
8
+ lib = File.expand_path('../lib', __FILE__)
9
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
10
+ require 'cryptowatch/version'
11
+
12
+ Gem::Specification.new do |gem|
13
+ gem.name = 'cryptowatch'
14
+ gem.version = Cryptowatch::Api::VERSION_FORMAT
15
+ gem.date = '2017-10-31'
16
+ gem.authors = ["Esteban Gonzalez"]
17
+ gem.summary = 'Simple Cryptowat.ch interface in Ruby.'
18
+ gem.description = 'Simple interface in Ruby to facilite the use Cryptowatch.'
19
+ gem.email = 'gonzal_e@etna-alternance.net'
20
+ gem.homepage = 'https://github.com/estebgonza/Cryptowatch'
21
+ gem.require_paths = ['lib/cryptowatch']
22
+ gem.licenses = ['MIT']
23
+
24
+ gem.files = `git ls-files`.split($/)
25
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
26
+ gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
27
+ gem.require_paths = ["lib"]
28
+
29
+ gem.add_development_dependency "rest-client", '~> 0'
30
+ end
@@ -0,0 +1,47 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Wednesday, November 1st 2017, 9:26:19 am
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 7:11:00 pm
7
+
8
+ require 'rest-client'
9
+ require 'logger'
10
+ require 'json'
11
+
12
+ module Cryptowatch
13
+ class RestClientAdapter
14
+
15
+ attr_accessor :options
16
+
17
+ def initialize (options)
18
+ @options = options
19
+ end
20
+
21
+ def get (*elements)
22
+
23
+ if (elements.size == 0)
24
+ Messages::LOG.error(Messages::ERROR_NO_URL)
25
+ return nil
26
+ end
27
+
28
+ url = Api::format_url(*elements)
29
+
30
+ begin
31
+ milli_start = Time.now
32
+ answer = JSON.parse(RestClient::Request.execute(
33
+ method: :get,
34
+ url: url,
35
+ timeout: @options[:timeout]),
36
+ accept: :json
37
+ )
38
+ milli_end = Time.now
39
+ elapsed = Utils::time_elapsed(milli_start, milli_end)
40
+ Messages::LOG.info("[#{elapsed.round} ms] #{Messages::GET}'#{url}'")
41
+ return answer
42
+ rescue SocketError, RestClient::ExceptionWithResponse => e
43
+ Messages::LOG.error("'#{e.message}' on => #{url}")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ # @Author: Esteban GONZALEZ <Esteban>
2
+ # @Date: Tuesday, October 17th 2017, 9:32:56 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 6:42:01 pm
7
+
8
+ module Cryptowatch
9
+ module Api
10
+
11
+ API_BASE_URL = "https://api.cryptowat.ch"
12
+
13
+ def self.format_url(*args)
14
+ args -= [nil]
15
+ return args.join'/'
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 12:31:59 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 2:29:23 pm
7
+
8
+ module Cryptowatch
9
+ module Assets
10
+
11
+ API_URL = "#{Api::API_BASE_URL}/assets"
12
+
13
+ def self.index
14
+ return API_URL
15
+ end
16
+
17
+ def self.asset(asset)
18
+ return Api::format_url(API_URL, asset)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 12:55:04 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 2:44:21 pm
7
+
8
+ module Cryptowatch
9
+ module Exchanges
10
+
11
+ API_URL = "#{Api::API_BASE_URL}/exchanges"
12
+
13
+ def self.index
14
+ return API_URL
15
+ end
16
+
17
+ def self.exchange(exchange)
18
+ return Api::format_url(API_URL, exchange)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 1:39:50 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 6:40:33 pm
7
+
8
+ module Cryptowatch
9
+ module Markets
10
+
11
+ API_URL = "#{Api::API_BASE_URL}/markets"
12
+ ROUTES = [
13
+ :price, #Returns a market’s last price.
14
+ :summary, #Other stats based on a 24-hour sliding window.
15
+ :orderbook, #Returns a market’s order book.
16
+ :trades, #Returns a market’s most recent trades, incrementing chronologically.
17
+ :ohlc #Returns a market’s OHLC candlestick data.
18
+ ]
19
+
20
+ def self.index
21
+ return API_URL
22
+ end
23
+
24
+ def self.market(exchange)
25
+ return Api::format_url(API_URL, exchange)
26
+ end
27
+
28
+ def self.market(exchange, asset, route = nil)
29
+ if (route != nil && !ROUTES.include?(route))
30
+ Messages::LOG.error(Messages::ERROR_UNKNOW_MARKET_ROUTE)
31
+ else
32
+ return Api::format_url(API_URL, exchange, asset, route)
33
+ end
34
+ end
35
+
36
+ def self.price(exchange, asset)
37
+ return self.market(exchange, asset, :price)
38
+ end
39
+
40
+ def self.summary(exchange, asset)
41
+ return self.market(exchange, asset, :summary)
42
+ end
43
+
44
+ def self.orderbook(exchange, asset)
45
+ return self.market(exchange, asset, :orderbook)
46
+ end
47
+
48
+ def self.trades(exchange, asset)
49
+ return self.market(exchange, asset, :trades)
50
+ end
51
+
52
+ def self.ohlc(exchange, asset)
53
+ return self.market(exchange, asset, :ohlc)
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 12:45:58 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 2:29:20 pm
7
+
8
+ module Cryptowatch
9
+ module Pairs
10
+
11
+ API_URL = "#{Api::API_BASE_URL}/pairs"
12
+
13
+ def self.index
14
+ return API_URL
15
+ end
16
+
17
+ def self.pair(pair)
18
+ return Api::format_url(API_URL, pair)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 2:26:39 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 7:39:39 pm
7
+ require 'logger'
8
+
9
+ module Cryptowatch
10
+ module Messages
11
+
12
+ LOG = Logger.new(STDOUT)
13
+
14
+ GET = "GET => "
15
+ ERROR_NO_URL = "Can not execute a 'GET' request without url."
16
+ ERROR_UNKNOW_MARKET_ROUTE = "Unknow route: "
17
+
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 6:44:18 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 7:05:20 pm
7
+ module Cryptowatch
8
+ module Utils
9
+ def self.time_elapsed(start, finish)
10
+ return ((finish - start) * 1000.0)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # @Author: Esteban GONZALEZ <Esteban
2
+ # @Date: Tuesday, October 17th 2017, 9:38:57 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 7:39:23 pm
7
+
8
+ module Cryptowatch
9
+ module Api
10
+ VERSION = [0, 0, 2]
11
+ VERSION_FORMAT = VERSION.join('.')
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Thursday, November 2nd 2017, 9:48:46 am
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 9:06:17 pm
7
+
8
+ require 'cryptowatch'
9
+
10
+ module Cryptowatch
11
+ class Wrapper
12
+
13
+ attr_accessor :rest_adapter
14
+
15
+ def initialize(options = nil)
16
+ if options == nil
17
+ options = {
18
+ :timeout => 5,
19
+ :display_infos => true,
20
+ :display_errors => true
21
+ }
22
+ end
23
+ @rest_adapter = RestClientAdapter.new(options)
24
+ end
25
+
26
+ def get(url)
27
+ return @rest_adapter.get(url)
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ # @Author: Esteban GONZALEZ <Esteban>
2
+ # @Date: Tuesday, October 17th 2017, 8:39:43 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 6:49:39 pm
7
+
8
+ require "rubygems"
9
+
10
+ require "cryptowatch/version"
11
+ require "cryptowatch/api/api"
12
+ require "cryptowatch/messages"
13
+ require "cryptowatch/utils"
14
+ require "cryptowatch/wrapper"
15
+ require "cryptowatch/adapter/rest_client_adapter"
16
+
17
+
18
+ require "cryptowatch/business/assets"
19
+ require "cryptowatch/business/exchanges"
20
+ require "cryptowatch/business/markets"
21
+ require "cryptowatch/business/pairs"
22
+
23
+ module Cryptowatch
24
+ module Api
25
+ end
26
+ end
Binary file
@@ -0,0 +1,30 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Tuesday, October 31st 2017, 10:29:25 am
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 8:59:13 pm
7
+
8
+ require 'cryptowatch'
9
+
10
+ class MyApplication
11
+ include Cryptowatch
12
+
13
+ wrapper = Wrapper.new;
14
+
15
+ wrapper.get(Assets::index)
16
+ wrapper.get(Assets::asset(:btc))
17
+
18
+ wrapper.get(Exchanges::index)
19
+ wrapper.get(Exchanges::exchange(:kraken))
20
+
21
+ wrapper.get(Markets::index)
22
+ wrapper.get(Markets::price(:kraken, :btcusd))
23
+ wrapper.get(Markets::summary(:gdax, :btceur))
24
+ wrapper.get(Markets::trades(:poloniex, :ethbtc))
25
+ wrapper.get(Markets::orderbook(:kraken, :xrpbtc))
26
+ wrapper.get(Markets::ohlc(:kraken, :xrpbtc))
27
+
28
+ wrapper.get(Pairs::index)
29
+ wrapper.get(Pairs::pair(:btcusd))
30
+ end
@@ -0,0 +1,6 @@
1
+ # @Author: Esteban GONZALEZ <esteban>
2
+ # @Date: Sunday, November 5th 2017, 12:26:35 pm
3
+ # @Email: gonzal_e@etna-alternance.net
4
+ # @Project: RubyCryptowatch
5
+ # @Last modified by: esteban
6
+ # @Last modified time: Sunday, November 5th 2017, 12:26:35 pm
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptowatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Esteban Gonzalez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Simple interface in Ruby to facilite the use Cryptowatch.
28
+ email: gonzal_e@etna-alternance.net
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - Gemfile
34
+ - README.md
35
+ - cryptowatch.gemspec
36
+ - lib/cryptowatch.rb
37
+ - lib/cryptowatch/adapter/rest_client_adapter.rb
38
+ - lib/cryptowatch/api/api.rb
39
+ - lib/cryptowatch/business/assets.rb
40
+ - lib/cryptowatch/business/exchanges.rb
41
+ - lib/cryptowatch/business/markets.rb
42
+ - lib/cryptowatch/business/pairs.rb
43
+ - lib/cryptowatch/messages.rb
44
+ - lib/cryptowatch/utils.rb
45
+ - lib/cryptowatch/version.rb
46
+ - lib/cryptowatch/wrapper.rb
47
+ - unit_tests/.DS_Store
48
+ - unit_tests/test_requests.rb
49
+ - worktest/script.rb
50
+ homepage: https://github.com/estebgonza/Cryptowatch
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.6.14
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Simple Cryptowat.ch interface in Ruby.
74
+ test_files: []