cryptoexchange 0.18.3 → 0.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a05f102d14e9eec8b52e69649aa624c1bcf3511d
4
- data.tar.gz: 3a44c9bf3d2371804fd1f9a14d982b54753577df
3
+ metadata.gz: e40d1c225c7d444ca1828e21e6d4dc9ddce78958
4
+ data.tar.gz: 75a3b19e390fe87240537ada42c8750b2aa86194
5
5
  SHA512:
6
- metadata.gz: 4841f3b05cee7641a3eda64e7517afbeacfce63acf60edd3beb8761fe78c9a5e0c89bb2e18b137fef20dc91607f1e0fd0c698792763cae06533286138d6201ba
7
- data.tar.gz: 9c208e3cf1c390314c8067b9843509902474cb73a11bd8ab98808584926406dcd5293fff797343cd93d5b19f88fbcd4147c728baad94de705b92f85808b5731d
6
+ metadata.gz: 694037122d89b0ebf9c68302f60c29fc2e398e81ff07738bcee1fa669dec54f222e1d677b2ecd30cc2f7803cd9b8d1f02c7e491322a6477b98a293a93d52eeda
7
+ data.tar.gz: f1c4536088635c26156fe8b10fd270a5b1d5105e0bab434a14d2d02a242b7151b6c0ae2a564401376c56b9a1505b935e0af6e4ae649802e7cacf3b6031acffbf
@@ -5,41 +5,47 @@ module Cryptoexchange
5
5
  end
6
6
 
7
7
  def pairs(exchange)
8
- pairs_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Pairs"
9
- Object.const_get(pairs_classname).new.fetch
10
- rescue HTTP::ConnectionError => e
11
- return { error: "#{exchange}'s service has connection error", message: e.to_s }
12
- rescue HTTP::TimeoutError => e
13
- return { error: "#{exchange}'s service time out", message: e.to_s }
14
- rescue JSON::ParserError => e
15
- return { error: "#{exchange}'s service does not send JSON", message: e.to_s }
16
- rescue TypeError => e
17
- return { error: "#{exchange}'s service does not respond with right format", message: e.to_s }
8
+ begin
9
+ pairs_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Pairs"
10
+ pairs_class = Object.const_get(pairs_classname)
11
+ pairs_object = pairs_class.new
12
+ pairs_object.fetch
13
+ rescue HTTP::ConnectionError => e
14
+ raise Cryptoexchange::HttpConnectionError, e
15
+ rescue HTTP::TimeoutError => e
16
+ raise Cryptoexchange::HttpTimeoutError, e
17
+ rescue JSON::ParserError => e
18
+ raise Cryptoexchange::JsonParseError, e
19
+ rescue TypeError => e
20
+ raise Cryptoexchange::TypeFormatError, e
21
+ end
18
22
  end
19
23
 
20
24
  def ticker(market_pair)
21
- exchange = market_pair.market
22
- market_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Market"
23
- market_class = Object.const_get(market_classname)
24
- market = market_class.new
25
+ begin
26
+ exchange = market_pair.market
27
+ market_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Market"
28
+ market_class = Object.const_get(market_classname)
29
+ market = market_class.new
25
30
 
26
- if market_class.supports_individual_ticker_query?
27
- market.fetch(market_pair)
28
- else
29
- tickers = market.fetch
30
- tickers.find do |t|
31
- t.base.casecmp(market_pair.base) == 0 &&
32
- t.target.casecmp(market_pair.target) == 0
31
+ if market_class.supports_individual_ticker_query?
32
+ market.fetch(market_pair)
33
+ else
34
+ tickers = market.fetch
35
+ tickers.find do |t|
36
+ t.base.casecmp(market_pair.base) == 0 &&
37
+ t.target.casecmp(market_pair.target) == 0
38
+ end
33
39
  end
40
+ rescue HTTP::ConnectionError => e
41
+ raise Cryptoexchange::HttpConnectionError, e
42
+ rescue HTTP::TimeoutError => e
43
+ raise Cryptoexchange::HttpTimeoutError, e
44
+ rescue JSON::ParserError => e
45
+ raise Cryptoexchange::JsonParseError, e
46
+ rescue TypeError => e
47
+ raise Cryptoexchange::TypeFormatError, e
34
48
  end
35
- rescue HTTP::ConnectionError => e
36
- return { error: "#{exchange}'s service has connection error", message: e.to_s }
37
- rescue HTTP::TimeoutError => e
38
- return { error: "#{exchange}'s service time out", message: e.to_s }
39
- rescue JSON::ParserError => e
40
- return { error: "#{exchange}'s service does not send JSON", message: e.to_s }
41
- rescue TypeError => e
42
- return { error: "#{exchange}'s service does not respond with right format", message: e.to_s }
43
49
  end
44
50
 
45
51
  def available_exchanges
@@ -0,0 +1,16 @@
1
+ module Cryptoexchange
2
+ class Error < StandardError
3
+ end
4
+
5
+ class HttpConnectionError < Error
6
+ end
7
+
8
+ class HttpTimeoutError < Error
9
+ end
10
+
11
+ class JsonParseError < Error
12
+ end
13
+
14
+ class TypeFormatError < Error
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Cryptoexchange
2
- VERSION = "0.18.3"
2
+ VERSION = "0.19.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptoexchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.3
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TM Lee
@@ -158,6 +158,7 @@ files:
158
158
  - cryptoexchange.gemspec
159
159
  - lib/cryptoexchange.rb
160
160
  - lib/cryptoexchange/client.rb
161
+ - lib/cryptoexchange/error.rb
161
162
  - lib/cryptoexchange/exchanges/abucoins/market.rb
162
163
  - lib/cryptoexchange/exchanges/abucoins/services/market.rb
163
164
  - lib/cryptoexchange/exchanges/abucoins/services/order_book.rb