cryptoexchange 0.2.1 → 0.3.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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -5
  3. data/lib/cryptoexchange.rb +3 -1
  4. data/lib/cryptoexchange/client.rb +5 -17
  5. data/lib/cryptoexchange/exchanges/anx/services/market.rb +11 -11
  6. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/market.rb +13 -13
  7. data/lib/cryptoexchange/exchanges/bitflyer/services/market.rb +10 -10
  8. data/lib/cryptoexchange/exchanges/bithumb/bithumb.yml +13 -0
  9. data/lib/cryptoexchange/exchanges/bithumb/market.rb +8 -0
  10. data/lib/cryptoexchange/exchanges/bithumb/models/market_pair.rb +8 -0
  11. data/lib/cryptoexchange/exchanges/bithumb/models/ticker.rb +8 -0
  12. data/lib/cryptoexchange/exchanges/bithumb/services/market.rb +40 -0
  13. data/lib/cryptoexchange/exchanges/bithumb/services/pairs.rb +26 -0
  14. data/lib/cryptoexchange/exchanges/bitstamp/market.rb +1 -1
  15. data/lib/cryptoexchange/exchanges/bitstamp/services/market.rb +13 -13
  16. data/lib/cryptoexchange/exchanges/bittrex/market.rb +8 -0
  17. data/lib/cryptoexchange/exchanges/bittrex/models/market_pair.rb +8 -0
  18. data/lib/cryptoexchange/exchanges/bittrex/models/ticker.rb +8 -0
  19. data/lib/cryptoexchange/exchanges/bittrex/services/market.rb +42 -0
  20. data/lib/cryptoexchange/exchanges/bittrex/services/pairs.rb +28 -0
  21. data/lib/cryptoexchange/exchanges/bleutrade/market.rb +8 -0
  22. data/lib/cryptoexchange/exchanges/bleutrade/models/market_pair.rb +8 -0
  23. data/lib/cryptoexchange/exchanges/bleutrade/models/ticker.rb +8 -0
  24. data/lib/cryptoexchange/exchanges/bleutrade/services/market.rb +50 -0
  25. data/lib/cryptoexchange/exchanges/bleutrade/services/pairs.rb +27 -0
  26. data/lib/cryptoexchange/exchanges/btcc/services/market.rb +12 -12
  27. data/lib/cryptoexchange/exchanges/bter/market.rb +8 -0
  28. data/lib/cryptoexchange/exchanges/bter/models/market_pair.rb +8 -0
  29. data/lib/cryptoexchange/exchanges/bter/models/ticker.rb +8 -0
  30. data/lib/cryptoexchange/exchanges/bter/services/market.rb +38 -0
  31. data/lib/cryptoexchange/exchanges/bter/services/pairs.rb +26 -0
  32. data/lib/cryptoexchange/exchanges/ccex/market.rb +8 -0
  33. data/lib/cryptoexchange/exchanges/ccex/models/market_pair.rb +8 -0
  34. data/lib/cryptoexchange/exchanges/ccex/models/ticker.rb +8 -0
  35. data/lib/cryptoexchange/exchanges/ccex/services/market.rb +48 -0
  36. data/lib/cryptoexchange/exchanges/ccex/services/pairs.rb +26 -0
  37. data/lib/cryptoexchange/exchanges/coin_exchange/market.rb +8 -0
  38. data/lib/cryptoexchange/exchanges/coin_exchange/models/market_pair.rb +8 -0
  39. data/lib/cryptoexchange/exchanges/coin_exchange/models/ticker.rb +8 -0
  40. data/lib/cryptoexchange/exchanges/coin_exchange/services/market.rb +70 -0
  41. data/lib/cryptoexchange/exchanges/coin_exchange/services/pairs.rb +24 -0
  42. data/lib/cryptoexchange/exchanges/coincheck/services/market.rb +12 -12
  43. data/lib/cryptoexchange/exchanges/coinone/services/market.rb +10 -10
  44. data/lib/cryptoexchange/exchanges/cryptopia/services/market.rb +13 -13
  45. data/lib/cryptoexchange/exchanges/ether_delta/market.rb +8 -0
  46. data/lib/cryptoexchange/exchanges/ether_delta/models/market_pair.rb +8 -0
  47. data/lib/cryptoexchange/exchanges/ether_delta/models/ticker.rb +8 -0
  48. data/lib/cryptoexchange/exchanges/ether_delta/services/market.rb +41 -0
  49. data/lib/cryptoexchange/exchanges/ether_delta/services/pairs.rb +26 -0
  50. data/lib/cryptoexchange/exchanges/gatecoin/services/market.rb +11 -11
  51. data/lib/cryptoexchange/exchanges/gemini/services/market.rb +4 -4
  52. data/lib/cryptoexchange/exchanges/hitbtc/market.rb +8 -0
  53. data/lib/cryptoexchange/exchanges/hitbtc/models/market_pair.rb +8 -0
  54. data/lib/cryptoexchange/exchanges/hitbtc/models/ticker.rb +8 -0
  55. data/lib/cryptoexchange/exchanges/hitbtc/services/market.rb +42 -0
  56. data/lib/cryptoexchange/exchanges/hitbtc/services/pairs.rb +24 -0
  57. data/lib/cryptoexchange/exchanges/korbit/services/market.rb +12 -12
  58. data/lib/cryptoexchange/exchanges/lakebtc/market.rb +8 -0
  59. data/lib/cryptoexchange/exchanges/lakebtc/models/market_pair.rb +8 -0
  60. data/lib/cryptoexchange/exchanges/lakebtc/models/ticker.rb +8 -0
  61. data/lib/cryptoexchange/exchanges/lakebtc/services/market.rb +51 -0
  62. data/lib/cryptoexchange/exchanges/lakebtc/services/pairs.rb +29 -0
  63. data/lib/cryptoexchange/exchanges/liqui/services/market.rb +6 -6
  64. data/lib/cryptoexchange/exchanges/livecoin/services/market.rb +12 -12
  65. data/lib/cryptoexchange/exchanges/novaexchange/services/market.rb +13 -13
  66. data/lib/cryptoexchange/exchanges/novaexchange/services/pairs.rb +6 -2
  67. data/lib/cryptoexchange/exchanges/okcoin/services/market.rb +12 -12
  68. data/lib/cryptoexchange/helpers/hash_helper.rb +20 -0
  69. data/lib/cryptoexchange/helpers/numeric_helper.rb +7 -0
  70. data/lib/cryptoexchange/version.rb +1 -1
  71. metadata +50 -2
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bleutrade
3
+ class Market
4
+ NAME = 'bleutrade'
5
+ API_URL = 'https://bleutrade.com/api/v2'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bleutrade
3
+ module Models
4
+ class MarketPair < Cryptoexchange::Models::MarketPair
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bleutrade
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,50 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bleutrade
3
+ module Services
4
+ class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ false
8
+ end
9
+ end
10
+
11
+ def fetch
12
+ output = super(ticker_url)
13
+ adapt_all(output)
14
+ end
15
+
16
+ def ticker_url
17
+ "#{Cryptoexchange::Exchanges::Bleutrade::Market::API_URL}/public/getmarketsummaries"
18
+ end
19
+
20
+ def adapt_all(output)
21
+ output['result'].map do |ticker|
22
+ currency_pair = ticker['MarketName'].split("_")
23
+ market_pair = Cryptoexchange::Exchanges::Bleutrade::Models::MarketPair.new(
24
+ base: currency_pair[1],
25
+ target: currency_pair[0],
26
+ market: Bleutrade::Market::NAME
27
+ )
28
+ adapt(ticker, market_pair)
29
+ end
30
+ end
31
+
32
+ def adapt(output, market_pair)
33
+ ticker = Bleutrade::Models::Ticker.new
34
+ ticker.base = market_pair.base
35
+ ticker.target = market_pair.target
36
+ ticker.market = Bleutrade::Market::NAME
37
+ ticker.ask = NumericHelper.to_d(output['Ask'])
38
+ ticker.bid = NumericHelper.to_d(output['Bid'])
39
+ ticker.last = NumericHelper.to_d(output['Last'])
40
+ ticker.high = NumericHelper.to_d(output['High'])
41
+ ticker.low = NumericHelper.to_d(output['Low'])
42
+ ticker.volume = NumericHelper.to_d(output['Volume'])
43
+ ticker.timestamp = Time.parse(output['TimeStamp']).to_i
44
+ ticker.payload = output
45
+ ticker
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bleutrade
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Bleutrade::Market::API_URL}/public/getmarkets"
6
+
7
+
8
+ def fetch
9
+ output = super
10
+ adapt(output)
11
+ end
12
+
13
+ def adapt(output)
14
+ market_pairs = []
15
+ output['result'].each do |pair|
16
+ market_pairs << Bleutrade::Models::MarketPair.new(
17
+ base: pair['BaseCurrency'],
18
+ target: pair['MarketCurrency'],
19
+ market: Bleutrade::Market::NAME
20
+ )
21
+ end
22
+ market_pairs
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -22,18 +22,18 @@ module Cryptoexchange::Exchanges
22
22
  end
23
23
 
24
24
  def adapt(output, market_pair)
25
- ticker = Btcc::Models::Ticker.new
26
- ticker.base = market_pair.base
27
- ticker.target = market_pair.target
28
- ticker.market = Btcc::Market::NAME
29
- ticker.ask = output['ticker']['AskPrice']
30
- ticker.bid = output['ticker']['BidPrice']
31
- ticker.last = output['ticker']['Last']
32
- ticker.high = output['ticker']['High']
33
- ticker.low = output['ticker']['Low']
34
- ticker.volume = output['ticker']['Volume']
35
- ticker.timestamp = output['ticker']['Timestamp']
36
- ticker.payload = output
25
+ ticker = Btcc::Models::Ticker.new
26
+ ticker.base = market_pair.base
27
+ ticker.target = market_pair.target
28
+ ticker.market = Btcc::Market::NAME
29
+ ticker.ask = NumericHelper.to_d(output['ticker']['AskPrice'])
30
+ ticker.bid = NumericHelper.to_d(output['ticker']['BidPrice'])
31
+ ticker.last = NumericHelper.to_d(output['ticker']['Last'])
32
+ ticker.high = NumericHelper.to_d(output['ticker']['High'])
33
+ ticker.low = NumericHelper.to_d(output['ticker']['Low'])
34
+ ticker.volume = NumericHelper.to_d(output['ticker']['Volume'])
35
+ ticker.timestamp = output['ticker']['Timestamp'].to_i
36
+ ticker.payload = output
37
37
  ticker
38
38
  end
39
39
  end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bter
3
+ class Market
4
+ NAME = 'bter'
5
+ API_URL = 'https://data.bter.com/api2/1'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bter
3
+ module Models
4
+ class MarketPair < Cryptoexchange::Models::MarketPair
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bter
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bter
3
+ module Services
4
+ class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ true
8
+ end
9
+ end
10
+
11
+ def fetch(market_pair)
12
+ output = super(ticker_url(market_pair))
13
+ adapt(output, market_pair)
14
+ end
15
+
16
+ def ticker_url(market_pair)
17
+ "#{Cryptoexchange::Exchanges::Bter::Market::API_URL}/ticker/#{market_pair.base}_#{market_pair.target}"
18
+ end
19
+
20
+ def adapt(output, market_pair)
21
+ ticker = Bter::Models::Ticker.new
22
+ ticker.base = market_pair.base
23
+ ticker.target = market_pair.target
24
+ ticker.market = Bter::Market::NAME
25
+ ticker.ask = NumericHelper.to_d(output['lowestAsk'])
26
+ ticker.bid = NumericHelper.to_d(output['highestBid'])
27
+ ticker.volume = NumericHelper.to_d(output['baseVolume'])
28
+ ticker.high = NumericHelper.to_d(output['high24hr'])
29
+ ticker.low = NumericHelper.to_d(output['low24hr'])
30
+ ticker.last = NumericHelper.to_d(output['last'])
31
+ ticker.timestamp = Time.now.to_i
32
+ ticker.payload = output
33
+ ticker
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Bter
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Bter::Market::API_URL}/pairs"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ output.map do |pair|
14
+ base, target = pair.upcase.split('_')
15
+
16
+ Bter::Models::MarketPair.new({
17
+ base: base,
18
+ target: target,
19
+ market: Bter::Market::NAME
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Ccex
3
+ class Market
4
+ NAME = 'ccex'
5
+ API_URL = 'https://c-cex.com/t'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Ccex
3
+ module Models
4
+ class MarketPair < Cryptoexchange::Models::MarketPair
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Ccex
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,48 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Ccex
3
+ module Services
4
+ class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ true
8
+ end
9
+ end
10
+
11
+ def fetch(market_pair)
12
+ ticker_output = super(ticker_url(market_pair))
13
+ volume_output = super(volume_url(market_pair))
14
+ adapt(ticker_output, volume_output, market_pair)
15
+ end
16
+
17
+ def ticker_url(market_pair)
18
+ name = "#{market_pair.base}-#{market_pair.target}".downcase
19
+ "#{Cryptoexchange::Exchanges::Ccex::Market::API_URL}/#{name}.json"
20
+ end
21
+
22
+ def volume_url(market_pair)
23
+ target = market_pair.target.downcase
24
+ "#{Cryptoexchange::Exchanges::Ccex::Market::API_URL}/volume_#{target}.json"
25
+ end
26
+
27
+ def adapt(ticker_output, volumes_output, market_pair)
28
+ market = ticker_output['ticker']
29
+ volume = HashHelper.dig(volumes_output, 'ticker', market_pair.base.downcase, 'vol')
30
+
31
+ ticker = Ccex::Models::Ticker.new
32
+ ticker.base = market_pair.base
33
+ ticker.target = market_pair.target
34
+ ticker.market = Ccex::Market::NAME
35
+ ticker.last = NumericHelper.to_d(market['lastprice'])
36
+ ticker.bid = NumericHelper.to_d(market['lastbuy'])
37
+ ticker.ask = NumericHelper.to_d(market['lastsell'])
38
+ ticker.high = NumericHelper.to_d(market['high'])
39
+ ticker.low = NumericHelper.to_d(market['low'])
40
+ ticker.volume = NumericHelper.to_d(volume)
41
+ ticker.timestamp = DateTime.now.to_time.to_i
42
+ ticker.payload = market
43
+ ticker
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Ccex
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Ccex::Market::API_URL}/pairs.json"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ output['pairs'].map do |pair|
14
+ base, target = pair.upcase.split('-')
15
+
16
+ Ccex::Models::MarketPair.new({
17
+ base: base,
18
+ target: target,
19
+ market: Ccex::Market::NAME
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module CoinExchange
3
+ class Market
4
+ NAME = 'coin_exchange'
5
+ API_URL = 'https://www.coinexchange.io/api/v1'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module CoinExchange
3
+ module Models
4
+ class MarketPair < Cryptoexchange::Models::MarketPair
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module CoinExchange
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,70 @@
1
+ require 'bigdecimal'
2
+
3
+ module Cryptoexchange::Exchanges
4
+ module CoinExchange
5
+ module Services
6
+ class Market < Cryptoexchange::Services::Market
7
+ class << self
8
+ def supports_individual_ticker_query?
9
+ true
10
+ end
11
+ end
12
+
13
+ def fetch(market_pair)
14
+ unless @market_id_cache
15
+ output = super(pairs_url)
16
+ hydrate_market_id_cache(output)
17
+ end
18
+
19
+ output = super(ticker_url(market_pair))
20
+ adapt(output, market_pair)
21
+ end
22
+
23
+ def pairs_url
24
+ "#{Cryptoexchange::Exchanges::CoinExchange::Market::API_URL}/getmarkets"
25
+ end
26
+
27
+ def ticker_url(market_pair)
28
+ id = market_id(market_pair)
29
+ "#{Cryptoexchange::Exchanges::CoinExchange::Market::API_URL}/getmarketsummary?market_id=#{id}"
30
+ end
31
+
32
+ def adapt(output, market_pair)
33
+ market = output['result']
34
+
35
+ ticker = CoinExchange::Models::Ticker.new
36
+ ticker.base = market_pair.base
37
+ ticker.target = market_pair.target
38
+ ticker.market = CoinExchange::Market::NAME
39
+ ticker.last = NumericHelper.to_d(market['LastPrice'])
40
+ ticker.bid = NumericHelper.to_d(market['BidPrice'])
41
+ ticker.ask = NumericHelper.to_d(market['AskPrice'])
42
+ ticker.high = NumericHelper.to_d(market['HighPrice'])
43
+ ticker.low = NumericHelper.to_d(market['LowPrice'])
44
+ ticker.volume = NumericHelper.to_d(market['Volume'])
45
+ ticker.timestamp = Time.now.to_i
46
+ ticker.payload = market
47
+ ticker
48
+ end
49
+
50
+ private
51
+
52
+ def market_id_cache_key(market_pair)
53
+ "#{market_pair.base}_#{market_pair.target}"
54
+ end
55
+
56
+ def hydrate_market_id_cache(output)
57
+ @market_id_cache = {}
58
+ output['result'].each do |market|
59
+ key = "#{market['MarketAssetCode']}_#{market['BaseCurrencyCode']}"
60
+ @market_id_cache[key] = market['MarketID']
61
+ end
62
+ end
63
+
64
+ def market_id(market_pair)
65
+ @market_id_cache[market_id_cache_key(market_pair)]
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ module Cryptoexchange::Exchanges
2
+ module CoinExchange
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::CoinExchange::Market::API_URL}/getmarkets"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ output['result'].map do |market|
14
+ CoinExchange::Models::MarketPair.new({
15
+ base: market['MarketAssetCode'],
16
+ target: market['BaseCurrencyCode'],
17
+ market: CoinExchange::Market::NAME
18
+ })
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end