cryptoexchange 0.1.1 → 0.2.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -12
  3. data/cryptoexchange.gemspec +2 -0
  4. data/lib/cryptoexchange.rb +5 -12
  5. data/lib/cryptoexchange/client.rb +46 -0
  6. data/lib/cryptoexchange/exchanges/anx/anx.yml +27 -0
  7. data/lib/cryptoexchange/exchanges/anx/market.rb +8 -0
  8. data/lib/cryptoexchange/exchanges/anx/models/market_pair.rb +8 -0
  9. data/lib/cryptoexchange/exchanges/anx/models/ticker.rb +8 -0
  10. data/lib/cryptoexchange/exchanges/anx/services/market.rb +41 -0
  11. data/lib/cryptoexchange/exchanges/anx/services/pairs.rb +25 -0
  12. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/bitcoin_indonesia.yml +19 -0
  13. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/market.rb +8 -0
  14. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/models/market_pair.rb +8 -0
  15. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/models/ticker.rb +8 -0
  16. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/market.rb +41 -0
  17. data/lib/cryptoexchange/exchanges/bitcoin_indonesia/services/pairs.rb +25 -0
  18. data/lib/cryptoexchange/exchanges/bitflyer/services/market.rb +8 -2
  19. data/lib/cryptoexchange/exchanges/bitflyer/services/pairs.rb +1 -2
  20. data/lib/cryptoexchange/exchanges/bitstamp/bitstamp.yml +19 -0
  21. data/lib/cryptoexchange/exchanges/bitstamp/market.rb +8 -0
  22. data/lib/cryptoexchange/exchanges/bitstamp/models/market_pair.rb +8 -0
  23. data/lib/cryptoexchange/exchanges/bitstamp/models/ticker.rb +8 -0
  24. data/lib/cryptoexchange/exchanges/bitstamp/services/market.rb +40 -0
  25. data/lib/cryptoexchange/exchanges/bitstamp/services/pairs.rb +26 -0
  26. data/lib/cryptoexchange/exchanges/btcc/btcc.yml +5 -0
  27. data/lib/cryptoexchange/exchanges/btcc/market.rb +9 -0
  28. data/lib/cryptoexchange/exchanges/btcc/models/market_pair.rb +8 -0
  29. data/lib/cryptoexchange/exchanges/btcc/models/ticker.rb +8 -0
  30. data/lib/cryptoexchange/exchanges/btcc/services/market.rb +42 -0
  31. data/lib/cryptoexchange/exchanges/btcc/services/pairs.rb +25 -0
  32. data/lib/cryptoexchange/exchanges/coincheck/services/market.rb +8 -2
  33. data/lib/cryptoexchange/exchanges/coincheck/services/pairs.rb +1 -2
  34. data/lib/cryptoexchange/exchanges/coinone/services/market.rb +8 -2
  35. data/lib/cryptoexchange/exchanges/coinone/services/pairs.rb +1 -2
  36. data/lib/cryptoexchange/exchanges/cryptopia/services/market.rb +7 -2
  37. data/lib/cryptoexchange/exchanges/cryptopia/services/pairs.rb +1 -2
  38. data/lib/cryptoexchange/exchanges/gatecoin/services/market.rb +28 -27
  39. data/lib/cryptoexchange/exchanges/gatecoin/services/pairs.rb +1 -2
  40. data/lib/cryptoexchange/exchanges/gemini/market.rb +8 -0
  41. data/lib/cryptoexchange/exchanges/gemini/models/market_pair.rb +8 -0
  42. data/lib/cryptoexchange/exchanges/gemini/models/ticker.rb +8 -0
  43. data/lib/cryptoexchange/exchanges/gemini/services/market.rb +49 -0
  44. data/lib/cryptoexchange/exchanges/gemini/services/pairs.rb +28 -0
  45. data/lib/cryptoexchange/exchanges/korbit/services/market.rb +8 -2
  46. data/lib/cryptoexchange/exchanges/korbit/services/pairs.rb +1 -2
  47. data/lib/cryptoexchange/exchanges/liqui/market.rb +8 -0
  48. data/lib/cryptoexchange/exchanges/liqui/models/market_pair.rb +8 -0
  49. data/lib/cryptoexchange/exchanges/liqui/models/ticker.rb +8 -0
  50. data/lib/cryptoexchange/exchanges/liqui/services/market.rb +43 -0
  51. data/lib/cryptoexchange/exchanges/liqui/services/pairs.rb +27 -0
  52. data/lib/cryptoexchange/exchanges/livecoin/market.rb +8 -0
  53. data/lib/cryptoexchange/exchanges/livecoin/models/market_pair.rb +8 -0
  54. data/lib/cryptoexchange/exchanges/livecoin/models/ticker.rb +8 -0
  55. data/lib/cryptoexchange/exchanges/livecoin/services/market.rb +51 -0
  56. data/lib/cryptoexchange/exchanges/livecoin/services/pairs.rb +27 -0
  57. data/lib/cryptoexchange/exchanges/novaexchange/market.rb +8 -0
  58. data/lib/cryptoexchange/exchanges/novaexchange/models/market_pair.rb +8 -0
  59. data/lib/cryptoexchange/exchanges/novaexchange/models/ticker.rb +8 -0
  60. data/lib/cryptoexchange/exchanges/novaexchange/services/market.rb +44 -0
  61. data/lib/cryptoexchange/exchanges/novaexchange/services/pairs.rb +26 -0
  62. data/lib/cryptoexchange/exchanges/okcoin/market.rb +8 -0
  63. data/lib/cryptoexchange/exchanges/okcoin/models/market_pair.rb +8 -0
  64. data/lib/cryptoexchange/exchanges/okcoin/models/ticker.rb +8 -0
  65. data/lib/cryptoexchange/exchanges/okcoin/okcoin.yml +7 -0
  66. data/lib/cryptoexchange/exchanges/okcoin/services/market.rb +40 -0
  67. data/lib/cryptoexchange/exchanges/okcoin/services/pairs.rb +25 -0
  68. data/lib/cryptoexchange/helpers/string_helper.rb +7 -0
  69. data/lib/cryptoexchange/lru_ttl_cache.rb +7 -0
  70. data/lib/cryptoexchange/services/market.rb +15 -1
  71. data/lib/cryptoexchange/services/pairs.rb +7 -2
  72. data/lib/cryptoexchange/version.rb +1 -1
  73. metadata +69 -2
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Gemini
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 Gemini
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Gemini
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::Gemini::Market::API_URL}/pubticker/#{market_pair.base}#{market_pair.target}"
18
+ end
19
+
20
+ def adapt(output, market_pair)
21
+ ticker = Gemini::Models::Ticker.new
22
+
23
+ #this api just have bid and ask like below:
24
+ # {
25
+ # "bid": "1960.92",
26
+ # "ask": "1962.82",
27
+ # "volume": {
28
+ # "BTC": "13239.1496613005",
29
+ # "USD": "25256846.437976508553",
30
+ # "timestamp": 1500257400000
31
+ # },
32
+ # "last": "1962.83"
33
+ # }
34
+
35
+ ticker.base = market_pair.base
36
+ ticker.target = market_pair.target
37
+ ticker.market = Gemini::Market::NAME
38
+ ticker.ask = output['ask'] ? BigDecimal.new(output['ask'].to_s) : nil
39
+ ticker.bid = output['bid'] ? BigDecimal.new(output['bid'].to_s) : nil
40
+ #this is BTC's volume
41
+ ticker.volume = output['volume'][market_pair.base] ? BigDecimal.new(output['volume'][market_pair.base].to_s) : nil
42
+ ticker.timestamp = output['volume']['timestamp'].to_i
43
+ ticker.payload = output
44
+ ticker
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Gemini
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Gemini::Market::API_URL}/symbols"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ market_pairs = []
14
+ output.each do |pair|
15
+ base =
16
+ target = pair[3..-1]
17
+ market_pairs << Gemini::Models::MarketPair.new(
18
+ base: pair[0..2],
19
+ target: pair[3..-1],
20
+ market: Gemini::Market::NAME
21
+ )
22
+ end
23
+ market_pairs
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,12 +2,18 @@ module Cryptoexchange::Exchanges
2
2
  module Korbit
3
3
  module Services
4
4
  class Market < Cryptoexchange::Services::Market
5
+ class << self
6
+ def supports_individual_ticker_query?
7
+ true
8
+ end
9
+ end
10
+
5
11
  def fetch(market_pair)
6
- output = super(market_url(market_pair))
12
+ output = super(ticker_url(market_pair))
7
13
  adapt(output, market_pair)
8
14
  end
9
15
 
10
- def market_url(market_pair)
16
+ def ticker_url(market_pair)
11
17
  base = market_pair.base.downcase
12
18
  target = market_pair.target.downcase
13
19
  "#{Cryptoexchange::Exchanges::Korbit::Market::API_URL}/ticker/detailed?currency_pair=#{base}_#{target}"
@@ -2,7 +2,6 @@ module Cryptoexchange::Exchanges
2
2
  module Korbit
3
3
  module Services
4
4
  class Pairs < Cryptoexchange::Services::Pairs
5
- MARKET = Korbit::Market
6
5
 
7
6
  def fetch
8
7
  output = super
@@ -15,7 +14,7 @@ module Cryptoexchange::Exchanges
15
14
  market_pairs << Korbit::Models::MarketPair.new(
16
15
  base: pair[:base],
17
16
  target: pair[:target],
18
- market: MARKET::NAME
17
+ market: Korbit::Market::NAME
19
18
  )
20
19
  end
21
20
  market_pairs
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Liqui
3
+ class Market
4
+ NAME = 'liqui'
5
+ API_URL = 'https://api.liqui.io/api/3'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Liqui
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 Liqui
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ require 'bigdecimal'
2
+
3
+ module Cryptoexchange::Exchanges
4
+ module Liqui
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
+ output = super(ticker_url(market_pair))
15
+ adapt(output, market_pair)
16
+ end
17
+
18
+ def ticker_url(market_pair)
19
+ market = "#{market_pair.base}_#{market_pair.target}".downcase
20
+ "#{Cryptoexchange::Exchanges::Liqui::Market::API_URL}/ticker/#{market}"
21
+ end
22
+
23
+ def adapt(output, market_pair)
24
+ market = output["#{market_pair.base}_#{market_pair.target}".downcase]
25
+
26
+ ticker = Liqui::Models::Ticker.new
27
+ ticker.base = market_pair.base
28
+ ticker.target = market_pair.target
29
+ ticker.market = Liqui::Market::NAME
30
+ ticker.last = market['last'] ? BigDecimal.new(market['last'].to_s) : nil
31
+ ticker.bid = market['buy'] ? BigDecimal.new(market['buy'].to_s) : nil
32
+ ticker.ask = market['sell'] ? BigDecimal.new(market['sell'].to_s) : nil
33
+ ticker.high = market['high'] ? BigDecimal.new(market['high'].to_s) : nil
34
+ ticker.low = market['low'] ? BigDecimal.new(market['low'].to_s) : nil
35
+ ticker.volume = market['vol'] ? BigDecimal.new(market['vol'].to_s) : nil
36
+ ticker.timestamp = DateTime.now.to_time.to_i
37
+ ticker.payload = market
38
+ ticker
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Liqui
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Liqui::Market::API_URL}/info"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ market_pairs = []
14
+ output['pairs'].keys.map do |pair|
15
+ base, target = pair.upcase.split('_')
16
+
17
+ Liqui::Models::MarketPair.new({
18
+ base: base,
19
+ target: target,
20
+ market: Liqui::Market::NAME
21
+ })
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Livecoin
3
+ class Market
4
+ NAME = 'livecoin'
5
+ API_URL = 'https://api.livecoin.net'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Livecoin
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 Livecoin
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,51 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Livecoin
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(self.ticker_url)
13
+ adapt_all(output)
14
+ end
15
+
16
+ def ticker_url
17
+ "#{Cryptoexchange::Exchanges::Livecoin::Market::API_URL}/exchange/ticker"
18
+ end
19
+
20
+ def adapt_all(output)
21
+ output.map do |ticker|
22
+ base, target = ticker['symbol'].split('/')
23
+ market_pair = Cryptoexchange::Exchanges::Livecoin::Models::MarketPair.new(
24
+ base: base,
25
+ target: target,
26
+ market: Livecoin::Market::NAME
27
+ )
28
+
29
+ adapt(ticker, market_pair)
30
+ end
31
+ end
32
+
33
+ def adapt(output, market_pair)
34
+ ticker = Livecoin::Models::Ticker.new
35
+ ticker.base = market_pair.base
36
+ ticker.target = market_pair.target
37
+ ticker.market = Livecoin::Market::NAME
38
+ ticker.last = output['last']
39
+ ticker.bid = output['best_bid']
40
+ ticker.ask = output['best_ask']
41
+ ticker.high = output['high']
42
+ ticker.low = output['low']
43
+ ticker.volume = output['volume']
44
+ ticker.timestamp = DateTime.now.to_time.to_i
45
+ ticker.payload = output
46
+ ticker
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,27 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Livecoin
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Livecoin::Market::API_URL}/exchange/ticker"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ market_pairs = []
14
+ output.each do |ticker|
15
+ base, target = ticker['symbol'].split('/')
16
+ market_pair = Livecoin::Models::MarketPair.new
17
+ market_pair.base = base
18
+ market_pair.target = target
19
+ market_pair.market = Livecoin::Market::NAME
20
+ market_pairs << market_pair
21
+ end
22
+ market_pairs
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Novaexchange
3
+ class Market
4
+ NAME = 'novaexchange'
5
+ API_URL = 'https://novaexchange.com/remote/v2'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Novaexchange
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 Novaexchange
3
+ module Models
4
+ class Ticker < Cryptoexchange::Models::Ticker
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ require 'bigdecimal'
2
+
3
+ module Cryptoexchange::Exchanges
4
+ module Novaexchange
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
+ output = super(ticker_url(market_pair))
15
+ adapt(output, market_pair)
16
+ end
17
+
18
+ def ticker_url(market_pair)
19
+ name = "#{market_pair.base}_#{market_pair.target}"
20
+
21
+ "#{Cryptoexchange::Exchanges::Novaexchange::Market::API_URL}/market/info/#{name}/"
22
+ end
23
+
24
+ def adapt(output, market_pair)
25
+ market = output['markets'][0]
26
+
27
+ ticker = Novaexchange::Models::Ticker.new
28
+ ticker.base = market_pair.base
29
+ ticker.target = market_pair.target
30
+ ticker.market = Novaexchange::Market::NAME
31
+ ticker.last = BigDecimal.new(market['last_price'])
32
+ ticker.bid = BigDecimal.new(market['bid'])
33
+ ticker.ask = BigDecimal.new(market['ask'])
34
+ ticker.high = BigDecimal.new(market['high24h'])
35
+ ticker.low = BigDecimal.new(market['low24h'])
36
+ ticker.volume = BigDecimal.new(market['volume24h'])
37
+ ticker.timestamp = DateTime.now.to_time.to_i
38
+ ticker.payload = market
39
+ ticker
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ module Cryptoexchange::Exchanges
2
+ module Novaexchange
3
+ module Services
4
+ class Pairs < Cryptoexchange::Services::Pairs
5
+ PAIRS_URL = "#{Cryptoexchange::Exchanges::Novaexchange::Market::API_URL}/markets/"
6
+
7
+ def fetch
8
+ output = super
9
+ adapt(output)
10
+ end
11
+
12
+ def adapt(output)
13
+ market_pairs = []
14
+ output['markets'].each do |ticker|
15
+ market_pair = Novaexchange::Models::MarketPair.new
16
+ market_pair.base = ticker['basecurrency']
17
+ market_pair.target = ticker['currency']
18
+ market_pair.market = Novaexchange::Market::NAME
19
+ market_pairs << market_pair
20
+ end
21
+ market_pairs
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end